メール製品を作って気づいたmailライブラリの光と闇について語る
-
Upload
maki-toshio -
Category
Engineering
-
view
350 -
download
2
Transcript of メール製品を作って気づいたmailライブラリの光と闇について語る
16 5 29
self.about• Toshio Maki(Twitter: @Kirika_K2)
• Hatena id:Kirika, Github: kirikak2
••
(MilterManager / Ruby / Rails)
•(GitLab / Drone / CloudFoundry)
16 5 29
• https://github.com/mikel/mail
• ActionMailer
16 5 29
Context• mail
•••
• gem mail gem
16 5 29
Generate new mailmail = Mail.new do to "[email protected]" from "[email protected]" subject "Test mail" body "This is a test mail"end
puts mail.to_sDate: Sun, 15 May 2016 14:10:34 +0900From: [email protected]: [email protected]: <[email protected]>Subject: Test mailMime-Version: 1.0Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 7bit
This is a test mail
16 5 29
Parse new mailmail = Mail.new(File.read(‘/path/to/mail’))
puts mail.to_sDate: Sun, 15 May 2016 14:10:34 +0900From: [email protected]: [email protected]: <[email protected]>Subject: Test mailMime-Version: 1.0Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 7bit
This is a test mail
16 5 29
mail•
• Notes / Outlook RFC
• Syntax
••
• uuencode okkez PR
•
16 5 29
maildata = File.read("japanese_shift_jis.eml") => "Delivered-To: [email protected]\nDate: Wed, 28 May 2014 17:18:19 +0900 (JST)\nFrom: [email protected]\nTo: [email protected]\nSubject: test\nMessage-ID: <[email protected]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=\"Shift_JIS\"\nContent-Transfer-Encoding: 8bit\n\n\x82\xA0\x82\xA2\x82\xA4\x82\xA6\x82\xA8\n\n\x82\xB1\x82\x81\x81[\x83\x8B\x82e\x83X\x83g\x97p\x82\x81\x81[\x83\x8B\x82ł\xB7\x81B\n\n\x8D\xA1\x8C\xE3\x82Ƃ\xE0\x82\xE6\x82낵\x82\xAD\x82\xA8\x8A \x90\\\x82\xB5\x8F \x82ݏݎݍܯܮܭܬܫܪܩܨܧܦܥܤܣܢܡܠܟܞܝܜܛܚܙܘܗܖܕܔܓܒܐ܍܌܋܊܉܈܇܆܅܄܃܂܁܀\xB7\x81I\n"
Mail.new(File.read("japanese_shift_jis.eml")).to_s => "Date: Wed, 28 May 2014 17:18:19 +0900\r\nFrom: [email protected]\r\nTo: [email protected]\r\nMessage-ID: <[email protected]>\r\nSubject: test\r\nMime-Version: 1.0\r\nContent-Type: text/plain;\r\n charset=Shift_JIS\r\nContent-Transfer-Encoding: base64\r\nDelivered-To: [email protected]\r\n\r\ngqCCooKkgqaCqAoKgrGCzIOBgVuDi4LNg2WDWINnl3CCzIOBgVuDi4LFgreB\r\nQgoKjaGM44LGguCC5oLrgrWCrYKoiuiCopBcgrWP44KwgtyCt4FJCg==\r\n"
16 5 29
• Content-Transfer-Encoding
body Encoding
Encoding
Encoding
16 5 29
• RFC
••
2
•
16 5 29
……
•content-transfer-encoding → Content-Transfer-Encoding
mail gem
16 5 29
:no_header_formatted
PR
16 5 29
To get mail data
• To get headermail.tomail.header[:to]
• To get mail bodymail.body.to_s
16 5 29
To modify header
• mail.to = ‘[email protected]’
• smtp_envelope_to
mail.smtp_envelope_to = ‘[email protected]’
16 5 29
To get attachment files
• To get attachment filesmail.attachments
• readme ……
• HTML HTML
16 5 29
nested multipart
header partContent-Type: multipart/mixed; boundary="----=_Part_2192_32400445.1115745999735"
multipart header
multipart header
multipart body
mail.parts << Mail::Part.new do “This is multipart body”end
mail.parts << Mail::Part.new do part do “This is nested multipart body” endend
Content-Type: text/plain; boundary="--==_mimepart_57387affe6d00_c2e8082dbf8514b
nested multipart
16 5 29
attachment
Mail::Message
Mail::Part(Mail::Message
16 5 29
• Mail::Part
attachment?
• mail.parts.select(&:attachment?)
•
16 5 29
• Mail::Parser
• Ragel
DSL
• Ruby
•
16 5 29
16 5 29
Thanks to mail• mail
•
•
16 5 29