Skip to content

Instantly share code, notes, and snippets.

@smallfield
Created May 7, 2019 21:07
Show Gist options
  • Save smallfield/a86ceb21e56f5bb0b2fcb86a01f53941 to your computer and use it in GitHub Desktop.
Save smallfield/a86ceb21e56f5bb0b2fcb86a01f53941 to your computer and use it in GitHub Desktop.
メール本文読み出しサンプル
require 'mail'
require 'nkf'
Dir.glob("*.eml").each do |eml|
m = Mail.new(File.read(eml))
File.open("#{eml}.txt", "w") do |f|
f << m.subject
f << "\n" * 3
if m.multipart?
m.parts.each do |part|
f << NKF.nkf("-w -Lu -d", part.decoded)
end
else
f << NKF.nkf("-w -Lu -d", m.body.decoded)
end
f << "\n" * 20
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment