使用 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