2012-09-07 70 views
2

我收到電子郵件進入我的Rails應用程序,但將電子郵件正文設置爲message.body.decoded會將電子郵件顯示爲亂七八糟。下面是一個例子。有沒有更好的方式來顯示電子郵件正文?或者,有沒有辦法將電子郵件轉發到另一個電子郵件地址而無需解碼和重新編碼?message.body.decoded電子郵件顯示亂七八糟

message.body.decoded例如:

--Apple-Mail=_C8C99366-9FF9-4DD0-AA35-6469D60C3701 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Begin forwarded message: > From: "Herringbone" <[email protected]>=20 > Subject: Don't miss out on our Multi Buy Shirt Offer - ends Sunday! > Date: 6 September, 2012 7:08:15 PM PDT > To: "Nick" <[email protected]> > Reply-To: [email protected] >=20 > =09 >=20 > Having trouble viewing this email? Click here to see the web version. >=20 >=20 > =09 >=20 >=20 >=20 > =09 > Dear Nick >=20 > Don't miss out on our famous Multi Buy Shirt Offer - ends this Sunday. >=20 > Shop now for new styles available instore and online! > =20 >=20 >=20 >=20 >=20 >=20 >=20 > Facebook=20 > www.facebook.com/HerringboneSydney = Herringbone=92s official blog=20 > http://herringbonetheweave.tumblr.com/=09 >=20 >=20 >=20 > This email was sent to Nick > To ensure that our messages get to you (and don't go to your junk or = bulk email folders), > please add [email protected] to your address book. >=20 > Enquiries? Contact us directly! +61 2 9362 9901 > Visit us instore! Click here for Herringbone locations > Don't want to hear from us anymore? Click here to Unsubscribe >=20 >=20 >=20 >=20 >=20 > =20 >=20 --Apple-Mail=_C8C99366-9FF9-4DD0-AA35-6469D60C3701 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252 <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html = charset=3Dwindows-1252"><base href=3D"x-msg://890/"></head><body = style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; = -webkit-line-break: after-white-space; "><br><div><br><div>Begin = forwarded message:</div><br = class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div = style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; = margin-left: 0px;"><span style=3D"font-family:'Helvetica'; = font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>From: </b></span><span = style=3D"font-family:'Helvetica'; font-size:medium;">"Herringbone" = &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt;= <br></span></div><div style=3D"margin-top: 0px; margin-right: 0px; = margin-bottom: 0px; margin-left: 0px;"><span = style=3D"font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, = 1.0);"><b>Subject: </b></span><span style=3D"font-family:'Helvetica'; = font-size:medium;"><b>Don't miss out on our Multi Buy Shirt Offer - ends = Sunday!</b><br></span></div><div style=3D"margin-top: 0px; margin-right: = 0px; margin-bottom: 0px; margin-left: 0px;"><span = style=3D"font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, = 1.0);"><b>Date: </b></span><span style=3D"font-family:'Helvetica'; = font-size:medium;">6 September, 2012 7:08:15 PM PDT<br></span></div><div = style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; = margin-left: 0px;"><span style=3D"font-family:'Helvetica'; = font-size:medium; color:rgba(0, 0, 0, 1.0);"><b>To: </b></span><span = style=3D"font-family:'Helvetica'; font-size:medium;">"Nick" &lt;<a = href=3D"mailto:[email protected]">[email protected]</a>&gt;<br><= /span></div><div style=3D"margin-top: 0px; margin-right: 0px; = margin-bottom: 0px; margin-left: 0px;"><span = style=3D"font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, = 1.0);"><b>Reply-To: </b></span><span style=3D"font-family:'Helvetica'; = font-size:medium;"><a = href=3D"mailto:[email protected]">[email protected]</a><br></span>= </div><br><div leftmargin=3D"0" marginwidth=3D"0" topmargin=3D"0" = marginheight=3D"0" bgcolor=3D"#f7f7f7" style=3D"font-family: Helvetica; = font-size: medium; font-style: normal; font-variant: normal; = font-weight: normal; letter-spacing: normal; line-height: normal; = orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: = none; white-space: normal; widows: 2; word-spacing: 0px; = -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><table = width=3D"100%" cellspacing=3D"0" cellpadding=3D"0" = bgcolor=3D"#f7f7f7"><tbody><tr><td width=3D"50%">&nbsp;</td><td><table = cellpadding=3D"0" cellspacing=3D"0" width=3D"600"><tbody><tr><td = colspan=3D"3" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"20" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td colspan=3D"3" align=3D"center" = style=3D"text-align: center; "><font face=3D"Arial, Helvetica, = sans-serif" size=3D"1" color=3D"#666666" style=3D"font-size: 10px; = line-height: 12px; ">Having trouble viewing this email?<span = class=3D"Apple-converted-space">&nbsp;</span><a = href=3D"http://herringbone.cmail1.com/t/j-e-ghuidl-vudjkiuk-r/">Click = here to see the web version.</a></font></td></tr><tr><td colspan=3D"3" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"16" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td colspan=3D"3" = bgcolor=3D"#e7e7e7" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td width=3D"1" bgcolor=3D"#e7e7e7" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td><table cellpadding=3D"0" = cellspacing=3D"0" width=3D"598" bgcolor=3D"#ffffff"><tbody><tr><td = colspan=3D"3" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"53" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td colspan=3D"3" valign=3D"top" = align=3D"center" style=3D"text-align: center; font-size: 0px; = line-height: 0; "><a href=3D"#" style=3D"text-decoration: none; "><img = src=3D"http://i3.cmail1.com/ti/j/1B/C6A/366/132258/logo.gif" width=3D"242"= height=3D"47" border=3D"0" alt=3D"Herringbone = Sidney"></a></td></tr><tr><td colspan=3D"3" style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"47" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td width=3D"9" style=3D"font-size: = 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td><table width=3D"580" cellpadding=3D"0" = cellspacing=3D"0"><tbody><tr><td><table cellpadding=3D"0" = cellspacing=3D"0" width=3D"422" align=3D"center"><tbody><tr><td = style=3D"text-align: center; "><font face=3D"'Times New Roman', Times, = serif" size=3D"1" color=3D"#00274c" style=3D"font-size: 13px; = line-height: 15px; ">Dear Nick</font></td></tr><tr><td style=3D"font-size:= 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"19" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td><font face=3D"Times New Roman, = Times New Roman, Times, seriff" size=3D"1" color=3D"#00274c" = style=3D"font-size: 13px; line-height: 16px; ">Don't miss out on our = famous<span class=3D"Apple-converted-space">&nbsp;</span><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-j/">Multi = Buy Shirt Offer</a><span class=3D"Apple-converted-space">&nbsp;</span>- = ends this Sunday.<br><br><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-t/">Shop = now</a><span class=3D"Apple-converted-space">&nbsp;</span>for new styles = available&nbsp;<a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-h/">instore</a= ><span class=3D"Apple-converted-space">&nbsp;</span>and<span = class=3D"Apple-converted-space">&nbsp;</span><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-k/">online</a>= !<br>&nbsp;</font><img = src=3D"http://i10.cmail1.com/ti/j/1B/C6A/366/132258/text-herringbone.gif" = width=3D"186" vspace=3D"0" hspace=3D"0" align=3D"right" border=3D"0" = alt=3D"image description" label=3D"Herringbone"></td></tr><tr><td = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"23" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table><table cellpadding=3D"0"= cellspacing=3D"0" bgcolor=3D"#002a4d" width=3D"580" = align=3D"center"><tbody><tr><td style=3D"font-size: 0px; line-height: 0; = "><img src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" = width=3D"1" height=3D"10" hspace=3D"0" vspace=3D"0" border=3D"0" = align=3D"left" alt=3D"img description"></td></tr><tr><td = style=3D"font-size: 0px; line-height: 0; "><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-u/" = style=3D"text-decoration: none; "><img = src=3D"http://i1.cmail1.com/ei/j/FA/9FD/E2A/csimport/MainImage.120359.jpg"= width=3D"580" vspace=3D"0" hspace=3D"0" border=3D"0" align=3D"left" = alt=3D"Multi-Buy Shirt Offer" label=3D"Call to Action" = height=3D"724"></a></td></tr><tr><td style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"10" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table><table cellpadding=3D"0"= cellspacing=3D"0" width=3D"580"><tbody><tr><td bgcolor=3D"#00273e" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"19" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td><table cellpadding=3D"0" = cellspacing=3D"0" width=3D"580"><tbody><tr><td width=3D"24" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"35" valign=3D"middle" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i7.cmail1.com/ti/j/1B/C6A/366/132258/img-fb.gif" = width=3D"26" height=3D"26" vspace=3D"0" hspace=3D"0" border=3D"0" = align=3D"left" alt=3D"img description"></td><td width=3D"1" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i8.cmail1.com/ti/j/1B/C6A/366/132258/sep-1.gif" width=3D"1" = height=3D"39" vspace=3D"0" hspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"10" style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"220" valign=3D"middle" = style=3D"line-height: 14px; "><font face=3D"Arial, Helvetica, = sans-serif" size=3D"1" color=3D"#00273e" style=3D"line-height: 14px; = ">Facebook<span class=3D"Apple-converted-space">&nbsp;</span><br><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-o/" = style=3D"text-decoration: none; color: rgb(0, 39, 62); "><font = color=3D"#00273e">www.facebook.com/HerringboneSydney</font></a></font></td= ><td width=3D"10" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"71 valign=3D" middle""=3D"" = style=3D"font-size: 0px; line-height: 0; "><a href=3D"#" = style=3D"text-decoration: none; "><img = src=3D"http://i9.cmail1.com/ti/j/1B/C6A/366/132258/partner-logo-1.gif" = width=3D"61" height=3D"39" vspace=3D"0" hspace=3D"0" border=3D"0" = align=3D"left" alt=3D"The weave"></a></td><td width=3D"1" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i8.cmail1.com/ti/j/1B/C6A/366/132258/sep-1.gif" width=3D"1" = height=3D"39" vspace=3D"0" hspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"9" style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td><td width=3D"189" valign=3D"middle" = style=3D"line-height: 14px; "><font face=3D"Arial, Helvetica, = sans-serif" size=3D"1" color=3D"#00273e" style=3D"line-height: 14px; = ">Herringbone=92s official blog<span = class=3D"Apple-converted-space">&nbsp;</span><br><a = href=3D"http://herringbone.cmail1.com/t/j-l-ghuidl-vudjkiuk-b/" = style=3D"text-decoration: none; color: rgb(0, 39, 62); "><font = color=3D"#00273e">http://herringbonetheweave.tumblr.com/</font></a></font>= </td><td width=3D"10" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table></td></tr><tr><td = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"18" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td bgcolor=3D"#00273e" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table><table cellpadding=3D"0"= cellspacing=3D"0" width=3D"580"><tbody><tr><td style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"19" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td align=3D"center"><font = face=3D"Arial, Helvetica, sans-serif" size=3D"1" color=3D"#00274c" = style=3D"font-size: 10px; line-height: 14px; ">This email was sent to = Nick<br>To ensure that our messages get to you (and don't go to your = junk or bulk email folders),<br>please add<span = class=3D"Apple-converted-space">&nbsp;</span><a = href=3D"mailto:[email protected]">[email protected]</a><span = class=3D"Apple-converted-space">&nbsp;</span>to your address = book.<br><br>Enquiries? Contact us directly! +61 2 9362 9901<br>Visit us = instore!<span class=3D"Apple-converted-space">&nbsp;</span><a href=3D"#" = style=3D"text-decoration: none; color: rgb(0, 39, 76); "><font = color=3D"#00274c">Click here</font></a><span = class=3D"Apple-converted-space">&nbsp;</span>for Herringbone = locations<br>Don't want to hear from us anymore?<span = class=3D"Apple-converted-space">&nbsp;</span><a = href=3D"http://herringbone.cmail1.com/t/j-u-ghuidl-vudjkiuk-y/">Click = here to Unsubscribe</a></font></td></tr><tr><td style=3D"font-size: 0px; = line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"24" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img = description"></td></tr></tbody></table></td></tr></tbody></table></td><td = width=3D"9" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table></td><td width=3D"1" = bgcolor=3D"#e7e7e7" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td colspan=3D"3" = bgcolor=3D"#e7e7e7" style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"1" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr><tr><td colspan=3D"3" = style=3D"font-size: 0px; line-height: 0; "><img = src=3D"http://i2.cmail1.com/ti/j/1B/C6A/366/132258/none.gif" width=3D"1" = height=3D"40" hspace=3D"0" vspace=3D"0" border=3D"0" align=3D"left" = alt=3D"img description"></td></tr></tbody></table></td><td = width=3D"50%">&nbsp;</td></tr></tbody></table><img = src=3D"https://cmail1.com/t/j-o-ghuidl-vudjkiuk/o.gif" width=3D"1" = height=3D"1" border=3D"0" style=3D"height: 1px !important; width: 1px = !important; border-width: 0px !important; margin: 0px !important; = padding: 0px !important; "></div></blockquote></div><br></body></html>= --Apple-Mail=_C8C99366-9FF9-4DD0-AA35-6469D60C3701-- 

回答

1

看到郵件的寶石文檔的部分Reading a Multipart Email

例如,如果您想對電子郵件的HTML部分執行某些操作,則必須找到內容類型爲「text/html」的部分,然後在該部分中調用decode_body

mail = Mail.read('example_multipart_mail.eml') 
mail.parts.each do |part| 
    next unless part.content_type =~ /^text\/html/ 
    puts part.decode_body 
end 
相關問題