Skip to content

Instantly share code, notes, and snippets.

@endymion
Last active November 28, 2022 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endymion/97ddb51e61a488a5746fec4399718c4a to your computer and use it in GitHub Desktop.
Save endymion/97ddb51e61a488a5746fec4399718c4a to your computer and use it in GitHub Desktop.
mime_message = DATA.read
puts "To line before: "
puts ' ' + mime_message.match(/^(To\:.*)$/i)[1]
# Massage the To: line.
changed_to = 'CHANGED@example.com'
mime_message.gsub!(/^To\:.*$/i, "To: #{changed_to}")
puts "To line after: "
puts ' ' + mime_message.match(/^(To\:.*)$/)[1]
# Remove the BCC: line.
mime_message.gsub!(/^BCC\:.*\n/,'')
puts "Removed BCC:"
puts mime_message
__END__
BCC: support@ourcompany.com
To: Guest <guest@example.com>
From: Some One <someone@example.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="XXXXboundary text"
This is a multipart message in MIME format.
--XXXXboundary text
Content-Type: text/plain
this is the body text
--XXXXboundary text
Content-Type: text/plain;
Content-Disposition: attachment;
filename="test.txt"
this is the attachment text
--XXXXboundary text--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment