使用ImapX阅读电子邮件正文时,最后会出现意外的文字。代码的简化版本是
using (var imapClient = new ImapClient(host, port, useSSL))
{
if (!imapClient.Connect())
throw new Exception(string.Format("Failed to connect to {0}:{1}", host, port));
if (!imapClient.Login(username, password))
throw new Exception(string.Format("Login failed for {0} connecting to {1}:{2}", username, host, port));
imapClient.Folders.Inbox.Messages.Download();
foreach (var message in imapClient.Folders.Inbox.Messages)
{
var body = message.Body.HasText ? message.Body.Text : message.Body.Html;
//Other stuff
}
imapClient.Disconnect();
}
以及与身体一起发送测试电子邮件
qwertyqwerqewrqwrqerwqreqrewrq
使用该代码读取的身体是
qwertyqwerqewrqwrqerwqreqrewrq
)
IMAPX10 OK UID已完成
有没有什么办法可以在没有额外内容的情况下返回正文?邮件服务器发送了以下内容
SENT: * OK IMAPrev1
RECEIVED: IMAPX1 CAPABILITY
SENT: * CAPABILITY IMAP4 IMAP4rev1 CHILDREN IDLE QUOTA SORT ACL NAMESPACE RIGHTS=texk[nl]IMAPX1 OK CAPABILITY completed
RECEIVED: IMAPX2 LOGIN "the email address" ***
SENT: IMAPX2 OK LOGIN completed
RECEIVED: IMAPX3 LIST "" %
SENT: * LIST (\HasNoChildren) "." "INBOX"[nl]* LIST (\HasNoChildren) "." "Trash"[nl]IMAPX3 OK LIST completed
RECEIVED: IMAPX4 EXAMINE "INBOX"
SENT: * 1 EXISTS[nl]* 1 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1453984022] current uidvalidity[nl]* OK [UIDNEXT 9] next uid[nl]* OK [PERMANENTFLAGS ()] limited[nl]IMAPX4 OK [READ-ONLY] EXAMINE completed
RECEIVED: IMAPX5 EXAMINE "Trash"
SENT: * 0 EXISTS[nl]* 0 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1454000202] current uidvalidity[nl]* OK [UIDNEXT 1] next uid[nl]* OK [PERMANENTFLAGS ()] limited[nl]IMAPX5 OK [READ-ONLY] EXAMINE completed
RECEIVED: IMAPX6 SELECT "INBOX"
SENT: * 1 EXISTS[nl]* 1 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1453984022] current uidvalidity[nl]* OK [UIDNEXT 9] next uid[nl]* OK [PERMANENTFLAGS (\Deleted \Seen \Draft \Answered \Flagged)] limited[nl]IMAPX6 OK [READ-WRITE] SELECT completed
RECEIVED: IMAPX7 EXAMINE "INBOX"
SENT: * 1 EXISTS[nl]* 0 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1453984022] current uidvalidity[nl]* OK [UIDNEXT 9] next uid[nl]* OK [PERMANENTFLAGS ()] limited[nl]IMAPX7 OK [READ-ONLY] EXAMINE completed
RECEIVED: IMAPX8 UID SEARCH ALL
SENT: * SEARCH 8
SENT: IMAPX8 OK UID completed
RECEIVED: IMAPX9 UID FETCH 8 (FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (FROM TO DATE SUBJECT CC CONTENT-TYPE)] BODYSTRUCTURE)
SENT: * 1 FETCH (UID 8 RFC822.SIZE 2553 FLAGS (\Seen) INTERNALDATE "29-Jan-2016 14:47:58 +0000" BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "7bit" 6 2)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "7bit" 27 2) "ALTERNATIVE" ("BOUNDARY" "001a113fefbe6b8657052a7a1da1") NIL NIL) BODY[HEADER.FIELDS (FROM TO DATE SUBJECT CC CONTENT-TYPE)] {235}
SENT: )
SENT: IMAPX9 OK UID completed
RECEIVED: IMAPX10 UID FETCH 8 (BODY.PEEK[1.MIME] BODY.PEEK[1])
SENT: * 1 FETCH (UID 8 BODY[1.MIME] {43}
SENT: BODY[1] {6}
SENT: )
SENT: IMAPX10 OK UID completed
RECEIVED: IMAPX11 UID FETCH 8 (BODY.PEEK[2.MIME] BODY.PEEK[2])
SENT: * 1 FETCH (UID 8 BODY[2.MIME] {42}
SENT: BODY[2] {27}
SENT: )
SENT: IMAPX11 OK UID completed
RECEIVED: IMAPX12 SELECT "INBOX"
SENT: * 1 EXISTS[nl]* 0 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1453984022] current uidvalidity[nl]* OK [UIDNEXT 9] next uid[nl]* OK [PERMANENTFLAGS (\Deleted \Seen \Draft \Answered \Flagged)] limited[nl]IMAPX12 OK [READ-WRITE] SELECT completed
RECEIVED: IMAPX13 UID STORE 8 +FLAGS (\Seen \Deleted)
SENT: * 1 FETCH (FLAGS (\Deleted \Seen) UID 8)
SENT: IMAPX13 OK UID completed
RECEIVED: IMAPX14 SELECT "INBOX"
SENT: * 1 EXISTS[nl]* 0 RECENT[nl]* FLAGS (\Deleted \Seen \Draft \Answered \Flagged)[nl]* OK [UIDVALIDITY 1453984022] current uidvalidity[nl]* OK [UIDNEXT 9] next uid[nl]* OK [PERMANENTFLAGS (\Deleted \Seen \Draft \Answered \Flagged)] limited[nl]IMAPX14 OK [READ-WRITE] SELECT completed
RECEIVED: IMAPX15 EXPUNGE
答案 0 :(得分:4)
从codeplex下载最新的源代码,只需更改下面描述的序列。
转到>>
MessageContent.CS
&安培;找到以下代码
else if (CommandEndRex.IsMatch(data))
{
for (var i = _contentBuilder.Length - 1; i >= 0; i--)
{
if (_contentBuilder[i] == ')')
{
_contentBuilder.Remove(i, _contentBuilder.Length - i);
return;
}
}
}
并保持比以前的其他if语句高出一步并完成它。
如果你仍然面临同样的问题,请告诉我。
快乐的编码。答案 1 :(得分:0)
另一种更简单的方法是,如果您不特别需要从那时起更改/修复/添加的任何内容,请降级到ImapX
版本2.0.0.15
。也许某些中间版本也可以使用,但这肯定有用。