2

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

2 回答 2

4

我已经抛出了同样的问题。经过几个小时后,我发现正则表达式模式序列存在问题。

从 codeplex 下载最新的源代码,只需更改下面描述的顺序。

转到>>

消息内容.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;
                    }
                }
            }

并保持它比上一个 else if 语句高出一步,它就完成了。

让我知道你是否仍然面临同样的问题..

快乐编码。

于 2016-01-30T12:29:27.680 回答
0

另一种更简单的方法是,如果您不特别需要从那时起更改/修复/添加的任何内容,则降级到ImapXversion 2.0.0.15。也许一些中间版本也可以,但这肯定有效。

于 2016-03-10T14:06:53.193 回答