Skip to content

Instantly share code, notes, and snippets.

@intinig
Created June 4, 2011 10:03
Show Gist options
  • Save intinig/1007770 to your computer and use it in GitHub Desktop.
Save intinig/1007770 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'mail'
# source = 'archives/2005-11.txt'
# month = 11
# year = 2005
#
# system "perl -ne 'if(/^From /){open F,\">eml/msg-#{year}-#{month}-\".++$m.\".eml\"}print F' #{source}"
Dir.glob("eml/*.eml").each do |f|
mail = File.read f
mail.gsub!(/From(:)?(.*) a (.*)/, 'From\1\2@\3')
File.open(f, "w") {|f| f.puts mail}
mail = Mail.read f
# puts mail.methods.sort.inspect
puts mail.envelope_from #=> vanno pulite le email sorgenti
# puts mail.from.addresses #=> ['[email protected]', '[email protected]']
# puts mail.sender.address #=> '[email protected]'
# puts mail.to #=> '[email protected]'
# puts mail.subject #=> "This is the subject"
# puts mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
# puts mail.message_id #=> '<[email protected]>'
# # puts mail.body.decoded #=> 'This is the body of the email...
# puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment