Created
May 7, 2019 21:07
メール本文読み出しサンプル
This file contains hidden or 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