jakartaee / jakartaee/mail-api
envelope parse Invaild symbol
- Dominant language
- Java
- Stars
- 285
- Forks
- 109
- Avg merge
- 15h 19m
- Merged PRs (30d)
- 1
Description
**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."cv@notice.zhipin.com"@v-bosszpmail-01>"**) INTERNALDATE "6-Apr-2022 17:10:18 +0800" RFC822.SIZE 1103217)
`"<1763943481.139839.1649236218178.JavaMail."cv@notice.zhipin.com"@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
```java
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,
```java
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
```plain
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."cv@notice.zhipin.com"@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.(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.(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.
Contributor guide
Research direction
Start with com.sun.mail.iap.Response#parseString() and com/sun/mail/imap/protocol/ENVELOPE.java:112, then reproduce the supplied Tencent IMAP response. Trace how the quoted message ID is consumed and verify that the envelope parses successfully while escaped-quote handling remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100