mail-api icon indicating copy to clipboard operation
mail-api copied to clipboard

envelope parse Invaild symbol

Open DawnSouther opened this issue 2 years ago • 0 comments

Describe the bug This is the envelope of a mail, please pay attention to the bold part

* 364 FETCH (ENVELOPE ("Wed, 6 Apr 2022 17:10:18 +0800 (CST)" "=?utf-8?B?44CQQk9TU+ebtOiBmOOAkeW0lOS9s+aXreeahOeugOWOhg==?=" (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?NTcxODYzNTU5?=" NIL "571863559" "qq.com")) NIL NIL NIL "<1763943481.139839.1649236218178.JavaMail."[email protected]"@v-bosszpmail-01>") INTERNALDATE "6-Apr-2022 17:10:18 +0800" RFC822.SIZE 1103217)

"<1763943481.139839.1649236218178.JavaMail."[email protected]"@v-bosszpmail-01>" This is the part of messageId, but due to the existence of ", when com.sun.mail.iap.Response#readString() is called, it is detected and returned directly, and then com/sun/mail/imap/protocol/ENVELOPE.java:112 contains

if (!r.isNextNonSpace(')'))
     throw new ParsingException("ENVELOPE parse error");

because it cannot be detected ) Second, the parsing fails, but the email has not been parsed yet.

The reason is that ·com.sun.mail.iap.Response#parseString()· detected "termination,

	    while (index < size && (b = buffer[index]) != '"') {
		if (b == '\\') // skip escaped byte
		    index++;
		if (index != copyto) { // only copy if we need to
		    // Beware: this is a destructive copy. I'm 
		    // pretty sure this is OK, but ... ;>
		    buffer[copyto] = buffer[index];
		}

I don't know if his format violates the specification of envelop, but other libs can be parsed,So is this a bug?

Expected behavior parse success

Screenshots error stack

A22 OK FETCH Completed
A23 FETCH 364 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 364 FETCH (ENVELOPE ("Wed, 6 Apr 2022 17:10:18 +0800 (CST)" "=?utf-8?B?44CQQk9TU+ebtOiBmOOAkeW0lOS9s+aXreeahOeugOWOhg==?=" (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?Qk9TU+ebtOiBmA==?=" NIL "cv" "notice.zhipin.com")) (("=?utf-8?B?NTcxODYzNTU5?=" NIL "571863559" "qq.com")) NIL NIL NIL "<1763943481.139839.1649236218178.JavaMail."[email protected]"@v-bosszpmail-01>") INTERNALDATE "6-Apr-2022 17:10:18 +0800" RFC822.SIZE 1103217)
A23 OK FETCH Completed
DEBUG IMAPS: ignoring bad response, THROW: 
com.sun.mail.iap.ParsingException: ENVELOPE parse error
	at com.sun.mail.imap.protocol.ENVELOPE.<init>(ENVELOPE.java:113)
	at com.sun.mail.imap.protocol.FetchResponse.parseItem(FetchResponse.java:220)
	at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:188)
	at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:72)
	at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:390)
	at com.sun.mail.iap.Protocol.command(Protocol.java:370)
	at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2135)
	at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2127)
	at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1469)
	at com.sun.mail.imap.IMAPMessage.getSentDate(IMAPMessage.java:448)

Mail server:

  • Protocol being used: imap
  • Vendor/product: tencent
  • Mail service URL: imap.qq.com

Additional context Add any other context about the problem here.

DawnSouther avatar Apr 21 '23 08:04 DawnSouther