Skip to content

Instantly share code, notes, and snippets.

@stealthinu
Last active June 24, 2019 08:22
Show Gist options
  • Save stealthinu/3a4c26d6d069677fdcbdaff0cc9010ca to your computer and use it in GitHub Desktop.
Save stealthinu/3a4c26d6d069677fdcbdaff0cc9010ca to your computer and use it in GitHub Desktop.
mailparser sample 1
# -*- 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