Created
May 7, 2019 21:07
-
-
Save smallfield/a86ceb21e56f5bb0b2fcb86a01f53941 to your computer and use it in GitHub Desktop.
メール本文読み出しサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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