Last active
June 24, 2019 08:22
-
-
Save stealthinu/3a4c26d6d069677fdcbdaff0cc9010ca to your computer and use it in GitHub Desktop.
mailparser sample 1
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
# -*- coding: utf-8 -*- | |
require 'mailparser' | |
f = File.open("test.txt") | |
@raw = f.read | |
m = MailParser::Message.new(@raw, :decode_mime_header=>true) | |
body = "" | |
if m.multipart? then | |
@boundary = m.header["content-type"][0].params["boundary"] | |
m.part.each_with_index do |part, index| | |
# index使ったなにか処理も可能 | |
body += "--" + @boundary + "\n" + part.raw | |
end | |
body += "--" + @boundary + "--\n" | |
else | |
body = m.body | |
end | |
puts body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment