解析前几行内容的电子邮件?

时间:2013-06-14 15:57:50

标签: iphone ios objective-c xcode email

我在NSString中包含了一封电子邮件的HTML,并希望将前几行文本显示为预览。我尝试了许多不同的东西来尝试从中获取有意义的内容,但似乎无法找到有效的解决方案。我注意到iOS在显示消息列表和锁定屏幕的视图上做得很好。

我想知道是否有办法解析电子邮件的内容,就像这样?

好的,我发送给自己的一封简单的测试邮件,没有故意的HTML格式:

<div style="padding-bottom: 20px;"><div style="background-color:#eee">                                  <div><b>From:</b> Andrew &lt;my@emailaddress.com&gt;</div>                                                   <div><b>To:</b> Andrew &lt;My@emailaddress.com&gt;</div>                                                                                                      <div><b>Subject:</b> This is an email</div>                                                   <div><b>Date:</b> 14 June 2013 16:44:00 BST</div>                 </div></div><div><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 (experimental) for Mac OS X https://github.com/w3c/tidy-html5/tree/c63cc39" />
<title></title>
</head>
<body>
<div dir="ltr">Hey Andrew,
<div><br /></div>
<div>I haven't seen you in so long. Anyway, i wanted to ask you
about something.</div>
<div><br /></div>
<div style="">It's really important.</div>
</div>
</body>
</html>
</div>

在Mail应用程序中,Apple显示预览:

  嘿安德鲁,我好久没见到你了。无论如何,我想问你   关于某事......

然后从订阅电子邮件:

<div style="padding-bottom: 20px;"><div style="background-color:#eee">                                  <div><b>From:</b> Sidebar &lt;hello@sidebar.io&gt;</div>                                                   <div><b>To:</b> Me@emailaddress.com</div>                                                                                                      <div><b>Subject:</b> Front-End Design Conf, iOS 7, Secret Handshake, NSA Slides, Award-Winning Work</div>                                                   <div><b>Date:</b> 14 June 2013 08:59:30 BST</div>                 </div></div><div><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 (experimental) for Mac OS X https://github.com/w3c/tidy-html5/tree/c63cc39" />
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8" />
<title>Front-End Design Conf, iOS 7, Secret Handshake, NSA Slides,
Award-Winning Work</title>

<style type="text/css">

/*<![CDATA[*/
                #outlook a{
                        padding:0;
                }
                .ReadMsgBody{
                        width:100%;
                }
                .ExternalClass{
                        width:100%;
                }
                body{
                        margin:0;
                        padding:0;
                }
//Loads of css stuff here


/*]]>*/
</style>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0"
offset="0" style="margin: 0;padding: 0;background-color: #F4F4F4;">
<center>
<table border="0" cellpadding="0" cellspacing="0" height="100%"
width="100%" id="bodyTable" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;margin: 0;padding: 0;background-color: #F4F4F4;height: 100% !important;width: 100% !important;">
<tr>
<td align="center" valign="top" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<!-- // BEGIN PREHEADER -->
<table border="0" cellpadding="10" cellspacing="0" width="100%" id=
"templatePreheader" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;background-color: #f36c3d;border-bottom: 0;">
<tr>
<td align="center" valign="top" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<table border="0" cellpadding="0" cellspacing="0" width="600"
style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td valign="top" class="preheaderContent" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #FFFFFF;font-family: Helvetica;font-size: 10px;line-height: 125%;text-align: left;">
The 5 best design links every day, curated by a selection of great
editors.</td>
<!--
 -->
<td valign="top" width="220" class="preheaderContent" style=
"padding-left: 20px;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #FFFFFF;font-family: Helvetica;font-size: 10px;line-height: 125%;text-align: left;">
Email not displaying correctly?<br />
<a href=
"http://us2.campaign-archive2.com/?u=b5af47765edbd2fc173dbf27a&amp;id=c214e283a3&amp;e=4fa588f2fc"
target="_blank" style=
"color: #FFFFFF;font-weight: normal;text-decoration: underline;">View
it in your browser</a>.</td>
<!--
 --></tr>
</table>
</td>
</tr>
</table>
<!-- END PREHEADER \\ -->
<!-- // BEGIN TEMPLATE SECTIONS -->
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td align="center" valign="top" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<!-- // BEGIN HEADER -->
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td align="center" valign="top" id="templateHeader" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;background-color: #FFFFFF;border-top: 0;border-bottom: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="600"
class="templateContainer" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td class="headerContent" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #505050;font-family: Helvetica;font-size: 20px;font-weight: bold;line-height: 100%;padding-top: 20px;padding-right: 0;padding-bottom: 20px;padding-left: 0;text-align: left;vertical-align: middle;">
<br />
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=9b41202aa5&amp;e=4fa588f2fc"
target="_self" style=
"text-decoration: none;color: #26ABE2;font-weight: normal;"><span style="color:#f36c3d; font-size:48px;">
Sidebar</span></a><br />
<br />
<h2 style=
"margin-bottom: 0px;padding: 0px;border: 0px;font: inherit;font-size: 18px;vertical-align: baseline;font-weight: 500;line-height: 1;color: rgb(170, 170, 170);font-family: chaparral-pro, Georgia, serif;display: block;font-style: normal;letter-spacing: normal;margin-top: 0;margin-right: 0;margin-left: 0;text-align: left;">
The 5 best design links, every day.</h2>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- END HEADER \\ --></td>
</tr>
<tr>
<td align="center" valign="top" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<!-- // BEGIN BODY -->
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td align="center" valign="top" id="templateBody" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;background-color: #ffffff;border-top: 0;border-bottom: 0;padding: 20px;">
<table border="0" cellpadding="0" cellspacing="0" width="600"
class="templateContainer" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td valign="top" class="bodyContent" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #505050;font-family: Helvetica;font-size: 13px;line-height: 150%;text-align: left;">
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=675cf30f66&amp;e=4fa588f2fc"
class="post-title" target="_blank" style=
"color: #333333;font-weight: normal;text-decoration: none;"><span style="font-size:24px; font-family: georgia, serif; line-height:1.3;">
Help Us Record the Front-End Design Conf Videos</span></a>
<a style="margin-top: -5px;vertical-align: middle;border-radius: 3px;background: #eee;font-size: 10px;text-transform: uppercase;font-weight: regular;color: #aaa;padding: 1px 5px;display: inline-block;text-decoration: none;"
href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=9750bb83aa&amp;e=4fa588f2fc">
Sponsored</a><br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=eb029eb24a&amp;e=4fa588f2fc"
style=
"color: #a9a9a9;font-weight: normal;text-decoration: none;">www.indiegogo.com</a><br />

<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=76bc52b512&amp;e=4fa588f2fc"
style=
"color: #333333;font-weight: normal;text-decoration: none;"><img src="http://twitter.com/api/users/profile_image/dandenney"
height="20px" width="20px" style=
"vertical-align: middle;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
</a> Added by <a style=
"font-weight: bold;color: #f36c3d;text-decoration: none;" href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=a28f0f360a&amp;e=4fa588f2fc">
@dandenney</a> <span style="color:#a9a9a9">|</span> <a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=9f046689f0&amp;e=4fa588f2fc"
style="color: #a9a9a9;font-weight: bold;text-decoration: none;"
target="_blank"><img src=
"http://sidebar.io/img/twitter-icon-grey.png" style=
"height: 12px;width: 12px;border: 0;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
Tweet</a><br />
<br />
<br />
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=cc1961954d&amp;e=4fa588f2fc"
class="post-title" target="_blank" style=
"color: #333333;font-weight: normal;text-decoration: none;"><span style="font-size:24px; font-family: georgia, serif; line-height:1.3;">
iOS 7</span></a><br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=d7d7251559&amp;e=4fa588f2fc"
style=
"color: #a9a9a9;font-weight: normal;text-decoration: none;">mattgemmell.com</a><br />

<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=0c03fe4e92&amp;e=4fa588f2fc"
style=
"color: #333333;font-weight: normal;text-decoration: none;"><img src="http://twitter.com/api/users/profile_image/leemunroe"
height="20px" width="20px" style=
"vertical-align: middle;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
</a> Added by <a style=
"font-weight: bold;color: #f36c3d;text-decoration: none;" href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=7bebad29c7&amp;e=4fa588f2fc">
@leemunroe</a> <span style="color:#a9a9a9">|</span> <a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=d6f24f0007&amp;e=4fa588f2fc"
style="color: #a9a9a9;font-weight: bold;text-decoration: none;"
target="_blank"><img src=
"http://sidebar.io/img/twitter-icon-grey.png" style=
"height: 12px;width: 12px;border: 0;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
Tweet</a><br />
<br />
<br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=69dbcd64c1&amp;e=4fa588f2fc"
class="post-title" target="_blank" style=
"color: #333333;font-weight: normal;text-decoration: none;"><span style="font-size:24px; font-family: georgia, serif; line-height:1.3;">
The Secret Handshake</span></a><br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=50506839ec&amp;e=4fa588f2fc"
style=
"color: #a9a9a9;font-weight: normal;text-decoration: none;">learnthesecrethandshake.com</a><br />

<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=cc0b484a05&amp;e=4fa588f2fc"
style=
"color: #333333;font-weight: normal;text-decoration: none;"><img src="http://twitter.com/api/users/profile_image/SachaGreif"
height="20px" width="20px" style=
"vertical-align: middle;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
</a> Added by <a style=
"font-weight: bold;color: #f36c3d;text-decoration: none;" href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=ce4cb421c7&amp;e=4fa588f2fc">
@SachaGreif</a> <span style="color:#a9a9a9">|</span> <a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=62fcb6bfdf&amp;e=4fa588f2fc"
style="color: #a9a9a9;font-weight: bold;text-decoration: none;"
target="_blank"><img src=
"http://sidebar.io/img/twitter-icon-grey.png" style=
"height: 12px;width: 12px;border: 0;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
Tweet</a><br />
<br />
<br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=aa3c1c59f3&amp;e=4fa588f2fc"
class="post-title" target="_blank" style=
"color: #333333;font-weight: normal;text-decoration: none;"><span style="font-size:24px; font-family: georgia, serif; line-height:1.3;">
Dear NSA, let me take care of your slides.</span></a><br />
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=cc73a11a9f&amp;e=4fa588f2fc"
style=
"color: #a9a9a9;font-weight: normal;text-decoration: none;">slideshare.net</a><br />

<a href=
"http://sidebar.us2.list-manage2.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=ff1a04a456&amp;e=4fa588f2fc"
style=
"color: #333333;font-weight: normal;text-decoration: none;"><img src="http://twitter.com/api/users/profile_image/StarBurst1977"
height="20px" width="20px" style=
"vertical-align: middle;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
</a> Added by <a style=
"font-weight: bold;color: #f36c3d;text-decoration: none;" href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=e9a5a5d7c6&amp;e=4fa588f2fc">
@StarBurst1977</a> <span style="color:#a9a9a9">|</span> <a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=d399b19267&amp;e=4fa588f2fc"
style="color: #a9a9a9;font-weight: bold;text-decoration: none;"
target="_blank"><img src=
"http://sidebar.io/img/twitter-icon-grey.png" style=
"height: 12px;width: 12px;border: 0;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
Tweet</a><br />
<br />
<br />
<a href=
"http://sidebar.us2.list-manage1.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=daeecc8e56&amp;e=4fa588f2fc"
class="post-title" target="_blank" style=
"color: #333333;font-weight: normal;text-decoration: none;"><span style="font-size:24px; font-family: georgia, serif; line-height:1.3;">
How award-winning work can make or break you</span></a><br />
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=576c592751&amp;e=4fa588f2fc"
style=
"color: #a9a9a9;font-weight: normal;text-decoration: none;">blog.f-i.com</a><br />

<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=8ee8c5f303&amp;e=4fa588f2fc"
style=
"color: #333333;font-weight: normal;text-decoration: none;"><img src="http://twitter.com/api/users/profile_image/allfordesign"
height="20px" width="20px" style=
"vertical-align: middle;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
</a> Added by <a style=
"font-weight: bold;color: #f36c3d;text-decoration: none;" href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=f2c7ff1a5f&amp;e=4fa588f2fc">
@allfordesign</a> <span style="color:#a9a9a9">|</span> <a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=b2af1fdd83&amp;e=4fa588f2fc"
style="color: #a9a9a9;font-weight: bold;text-decoration: none;"
target="_blank"><img src=
"http://sidebar.io/img/twitter-icon-grey.png" style=
"height: 12px;width: 12px;border: 0;line-height: 100%;outline: none;text-decoration: none;display: inline;max-width: 600px;" />
Tweet</a><br />
<br />
<br /></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- END BODY \\ --></td>
</tr>
<tr>
<td align="center" valign="top" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<!-- // BEGIN FOOTER -->
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td align="center" valign="top" id="templateFooter" style=
"padding-bottom: 40px;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;border-top: 0;padding: 20px;">
<table border="0" cellpadding="0" cellspacing="0" width="600"
class="templateContainer" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;">
<tr>
<td colspan="3" valign="top" class="footerContent" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #808080;font-family: Helvetica;font-size: 10px;line-height: 150%;text-align: left;">
<a href=
"http://sidebar.us2.list-manage.com/track/click?u=b5af47765edbd2fc173dbf27a&amp;id=e281d1415a&amp;e=4fa588f2fc"
style=
"color: #606060;font-weight: normal;text-decoration: underline;">Follow
on Twitter</a>&nbsp;&nbsp;<a href=
"http://us2.forward-to-friend.com/forward?u=b5af47765edbd2fc173dbf27a&amp;id=c214e283a3&amp;e=4fa588f2fc"
style=
"color: #606060;font-weight: normal;text-decoration: underline;">Forward
to Friend</a>&nbsp; <a href=
"http://us2.campaign-archive2.com/?u=b5af47765edbd2fc173dbf27a&amp;id=c214e283a3&amp;e=4fa588f2fc"
target="_blank" style=
"color: #606060;font-weight: normal;text-decoration: underline;">View
in Browser</a></td>
</tr>
<tr>
<td valign="top" class="footerContent" style=
"padding-top: 20px;padding-bottom: 20px;border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #808080;font-family: Helvetica;font-size: 10px;line-height: 150%;text-align: left;">
<em>Copyright © 2013 Sacha Greif, All rights reserved.</em><br />
You're receiving this because you signed up on
http://sidebar.io<br />
<br />
<strong>Our mailing address is:</strong><br />
<div class="vcard"><span class="org fn">Sacha Greif</span>
<div class="adr">
<div class="street-address">---</div>
<span class="locality">Paris</span> <span class=
"postal-code">-</span>
<div class="country-name">France</div>
<br />
<a href=
"http://sidebar.us2.list-manage2.com/vcard?u=b5af47765edbd2fc173dbf27a&amp;id=9abeab36bb"
class="hcard-download">Add us to your address book</a></div>
<br />
<br /></div>
</td>
</tr>
<tr>
<td colspan="3" valign="top" class="footerContent" style=
"border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;color: #808080;font-family: Helvetica;font-size: 10px;line-height: 150%;text-align: left;">
<a href=
"http://sidebar.us2.list-manage.com/unsubscribe?u=b5af47765edbd2fc173dbf27a&amp;id=9abeab36bb&amp;e=4fa588f2fc&amp;c=c214e283a3"
style=
"color: #606060;font-weight: normal;text-decoration: underline;">unsubscribe
from this list</a>&nbsp;&nbsp;&nbsp;<a href=
"http://sidebar.us2.list-manage.com/profile?u=b5af47765edbd2fc173dbf27a&amp;id=9abeab36bb&amp;e=4fa588f2fc"
style=
"color: #606060;font-weight: normal;text-decoration: underline;">update
subscription preferences</a>&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- END FOOTER \\ --></td>
</tr>
</table>
<!-- END TEMPLATE SECTIONS \\ --></td>
</tr>
</table>
</center>
<img src=
"http://sidebar.us2.list-manage.com/track/open.php?u=b5af47765edbd2fc173dbf27a&amp;id=c214e283a3&amp;e=4fa588f2fc"
height="1" width="1" />
</body>
</html>
</div>

Apple再次预览:

  

每天都有5个最好的设计链接,精选的精选   编辑器。

我一直在尝试使用HTMLParser来解析它,但每封电子邮件都不同,所以这不容易实现。

0 个答案:

没有答案