2

https://github.com/mikel/mailmailのgemを使用しています

私は生のメールデータを解析するためにそれを使用します:例えば

require 'mail'

maildata = Mail.new(body) #where body is the raw text of an email message

#from there I can see info such as
p maildata.body.decoded #displays the decoded email body
p maildata.from #shows who the email is from

電子メールがこれを行うための組み込みの方法であるplaintextかどうかをどのように判断しますか?html

4

1 に答える 1

2

あなたは見ることができますmaildata.content_type

maildata.content_type
#=> "text/plain; charset=us-ascii"

マルチパートの電子メールの場合は、プレーンテキストとHTMLの両方を使用できます。次に、配列を調べて、parts配列に含まれるコンテンツタイプを確認できます。

maildata.content_type
#=> "multipart/alternative; boundary=\"--==_mimepart_4f848491e618f_7e4b6c1f3849940\"; charset=utf-8"

maildata.parts.collect { |part| part.content_type }
#=> ["text/plain; charset=utf-8", "text/html; charset=utf-8"]
于 2012-04-10T19:11:51.957 に答える