【问题标题】:Issue While fetching bodyHTML using partID in Mailcore2在 Mailcore2 中使用 partID 获取 bodyHTML 时出现问题
【发布时间】:2016-01-10 04:39:29
【问题描述】:

我尝试使用以下代码获取 bodyHTML

MCOIMAPFetchContentOperation * op = [imapsession     fetchMessageAttachmentOperationWithFolder:folderName uid:uid partID:partId    encoding:MCOEncoding8Bit

我得到了带有一些不需要的额外代码的 bodyHTML。我为其中一封邮件获得的 Html 是

   <div style="padding-bottom: 20px;"></div><div>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org=
<br/>/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<br/>&lt;html xmlns=3D"http://www.w3.org/1999/xhtml"&gt;
<br/>&lt;head&gt;
<br/>&lt;meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" /&gt;
<br/>&lt;meta name=3D"viewport" content=3D"width=3Ddevice-width" /&gt;
<br/>&lt;meta http-equiv=3D"X-UA-Compatible" content=3D"IE=3Dedge" /&gt;
<br/>&lt;/head&gt;
<br/>&lt;body style=3D"-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; =
<br/>background: #EEEEEE; color: #222222; font-family: 'Open Sans', Arial, sans-=
<br/>serif; font-size: 14px; font-weight: normal; line-height: 22px; margin: 0; =
<br/>min-width: 100%; padding: 0; text-align: left; width: 100% !important" bgco=
<br/>lor=3D"#EEEEEE"&gt;&lt;style type=3D"text/css"&gt;
<br/>body {
<br/>width: 100% !important; min-width: 100%; -webkit-text-size-adjust: 100%; -m=
<br/>s-text-size-adjust: 100%; margin: 0; padding: 0;
<br/>}
<br/>.ExternalClass {
<br/>width: 100%;
<br/>}
<br/>.ExternalClass {
<br/>line-height: 100%;
<br/>}
<br/>#backgroundTable {
<br/>margin: 0; padding: 0; width: 100% !important; line-height: 100% !important=
<br/>;
<br/>}
<br/>img {
<br/>outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; widt=
<br/>h: auto; max-width: 100%; float: left; clear: both; display: block;
<br/>}
<br/>body {
<br/>color: #222222; font-family: "Open Sans", Arial, sans-serif; font-weight: n=
<br/>ormal; padding: 0; margin: 0; text-align: left; line-height: 1.3;
<br/>}
<br/>body {
<br/>font-size: 14px; line-height: 22px;
<br/>}
<br/>a:hover {
<br/>color: #222222 !important;
<br/>}

而且我无法在 Web 视图上呈现它。但是当我尝试使用以下方法获取主体时

MCOIMAPFetchContentOperation * opr = [imapsession fetchMessageOperationWithFolder:folderName uid:uid urgent:YES]; 

我得到了正确的正文 html 并且能够在 webview 上呈现它。我为上述方法得到的 html 是:-

<div style="padding-bottom: 20px;"></div><div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
</head>
<body style=
"-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; background: #EEEEEE; color: #222222; font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; font-weight: normal; line-height: 22px; margin: 0; min-width: 100%; padding: 0; text-align: left; width: 100% !important"
bgcolor="#EEEEEE">
<style type="text/css">
/*<![CDATA[*/
body {
width: 100% !important; min-width: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; margin: 0; padding: 0;
}
.ExternalClass {
width: 100%;
}
.ExternalClass {
line-height: 100%;
}
#backgroundTable {
margin: 0; padding: 0; width: 100% !important; line-height: 100% !important;
}
img {
outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; width: auto; max-width: 100%; float: left; clear: both; display: block;
}
body {
color: #222222; font-family: "Open Sans", Arial, sans-serif; font-weight: normal; padding: 0; margin: 0; text-align: left; line-height: 1.3;
}
body {
font-size: 14px; line-height: 22px;
}
a:hover {
color: #222222 !important;
}

是否有任何解析器或任何其他方式来获取正文 html。因为我必须使用使用 partID 的方法来获取 bodyHTML。

【问题讨论】:

  • part的内容类型是什么?
  • Mime 类型是“文本/HTML”

标签: ios objective-c iphone mailcore2


【解决方案1】:

问题是在使用部分获取消息时,它总是使用 MCOEncoding8Bit 进行编码,而不是我们必须提供我们在获取消息时获得的编码,如下所示。

for(MCOAbstractPart *abstractPart in multiAbstractPart.parts)
    {
MCOIMAPPart *part = (MCOIMAPPart *)abstractPart;
MCOIMAPFetchContentOperation * op = [imapsession     fetchMessageAttachmentOperationWithFolder:folderName uid:uid partID:partId    encoding:part.encoding];
}

【讨论】:

    猜你喜欢
    • 2022-11-02
    • 2011-09-16
    • 2016-08-27
    • 2019-12-31
    • 2021-11-20
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多