Forum: Ruby email structure

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adam A. (Guest)
on 2008-12-14 11:56
I have accessed my gmail account and using imap downloaded an email and
saved it too text.

Im wondering why the body of the message is repeated twice when in gmail
the message is not repeated - is this a standard for emails? by the way
my message itself was just a test so doesnt really make sense. One copy
has \r\n for line breaks whilst the other has <br>.

any reasons for this duplication?


Received: by 10.214.79.10 with HTTP; Sun, 14 Dec 2008 00:20:25 -0800
(PST)

Message-ID:
<removed_email_address@domain.invalid>

Date: Sun, 14 Dec 2008 17:20:25 +0900

From: "XXXXX" <removed_email_address@domain.invalid>

To: removed_email_address@domain.invalid

Subject: new receipt

MIME-Version: 1.0

Content-Type: multipart/alternative;

  boundary="----=_Part_24864_15890710.1229242825307"

Delivered-To: removed_email_address@domain.invalid



------=_Part_24864_15890710.1229242825307

Content-Type: text/plain; charset=ISO-8859-1

Content-Transfer-Encoding: 7bit

Content-Disposition: inline



#title:go shop at 2.30

#value:1450.00

#desc:me and teh fmaily will go shopping at the new 109 shops in

shibuya!!!and it will be great

really want to go and looking forward to oit

lets go

#envelope:



------=_Part_24864_15890710.1229242825307

Content-Type: text/html; charset=ISO-8859-1

Content-Transfer-Encoding: 7bit

Content-Disposition: inline



#title:go shop at 2.30<br>#value:1450.00<br>#desc:me and teh fmaily will
go shopping at the new 109 shops in shibuya!!!and it will be
great<br>really want to go and looking forward to oit<br>lets
go<br>#envelope:<br><br>



------=_Part_24864_15890710.1229242825307--
Matt D. (Guest)
on 2008-12-14 12:06
It's not repeating the message, it is giving you a text version and a
HTML version of the message. Just create a parse method to rip the two
versions out.

- matt
Adam A. (Guest)
on 2008-12-14 13:28
ahhh i thought both sections were identical, i didnt notice text and
html tags in there.

can tmail do this parsing for me, dont really want to reinvent the
wheel.i looked in teh docs and did a bit of experimenting in irb but
coudnt find a way to specify if i wanted the whole body or just the text
or html parts of it.
James G. (Guest)
on 2008-12-15 01:48
(Received via mailing list)
On Dec 14, 2008, at 5:20 AM, Adam A. wrote:

> can tmail do this parsing for me, dont really want to reinvent the
> wheel.

Sure can.

> i looked in teh docs and did a bit of experimenting in irb but
> coudnt find a way to specify if i wanted the whole body or just the
> text
> or html parts of it.

I use some code like the following to find the text portion of a
message in the Ruby gateway code:

     extract_text = lambda do |message_or_part|
       if message_or_part.multipart?
         message_or_part.each_part { |part| extract_text[part] }
       elsif message_or_part.content_type == "text/plain"
         # use message_or_part hereā€¦
       end
     end
     extract_text[message]

Hope that helps.

James Edward G. II
Adam A. (Guest)
on 2008-12-15 13:36
thanks james for your proc. The rdoc for tmail doesnt have details for
all the methods so your example has really helped.

Thank you
Brian C. (Guest)
on 2008-12-15 13:58
Adam A. wrote:
> ahhh i thought both sections were identical, i didnt notice text and
> html tags in there.
>
> can tmail do this parsing for me, dont really want to reinvent the
> wheel.i looked in teh docs and did a bit of experimenting in irb but
> coudnt find a way to specify if i wanted the whole body or just the text
> or html parts of it.

If you want to do this in a robust way, google for ruby mime
This topic is locked and can not be replied to.