Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Yandex] GetBodyPart() throws Syntax error in BODY. Unexpected token: ')' for MimeParts with empty content #1708

Closed
sq5 opened this issue Feb 12, 2024 Discussed in #1707 · 3 comments
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server

Comments

@sq5
Copy link

sq5 commented Feb 12, 2024

Discussed in #1707

Originally posted by sq5 February 12, 2024
Mailkit Version 4.3.0, mail server - Yandex

Error:

Exception has occurred: CLR/MailKit.Net.Imap.ImapProtocolException
Exception thrown: 'MailKit.Net.Imap.ImapProtocolException' in System.Private.CoreLib.dll: 'Syntax error in BODY. Unexpected token: ')''
at MailKit.Net.Imap.ImapFolder.d__213.MoveNext()
at MailKit.Net.Imap.ImapEngine.d__189.MoveNext()
at MailKit.Net.Imap.ImapCommand.d__84.MoveNext()
at MailKit.Net.Imap.ImapEngine.d__190.MoveNext()
at MailKit.Net.Imap.ImapEngine.d__191.MoveNext()
at MailKit.Net.Imap.ImapFolder.d__237.MoveNext()
at MailKit.Net.Imap.ImapFolder.GetBodyPart(UniqueId uid, String partSpecifier, CancellationToken cancellationToken, ITransferProgress progress)
at MailKit.Net.Imap.ImapFolder.GetBodyPart(UniqueId uid, BodyPart part, CancellationToken cancellationToken, ITransferProgress progress)

@jstedfast
Copy link
Owner

These types if exceptions are typically due to a syntax error in the server response.

What I need from you is a protocol log. Specifically, the last response from the server when you get this exception.

You can get a protocol log by passing in a new ProtocolLogger ("imap.log") to the ImapClient constructor like this:

var client = new ImapClient (new ProtocolLogger ("imap.log"));

@jstedfast jstedfast added the need-info More information is needed in order to diagnose the issue. label Feb 12, 2024
@sq5
Copy link
Author

sq5 commented Feb 13, 2024

Please, find it in the attachment
imap.log

@jstedfast
Copy link
Owner

jstedfast commented Feb 13, 2024

Here's the problem:

S: * 1 FETCH (UID 3016 BODY[2.MIME] {389}
S: Content-Disposition: attachment;
S: 	filename="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: Content-Transfer-Encoding: base64
S: Content-Type: application/pdf;
S: 	name="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: 
S:  BODY[2] )

See the BODY[2]? IMAP responds with key/value pairs. In this case, it gives us a key (BODY[2]), but no corresponding value.

A correct response would be any of the following:

S: * 1 FETCH (UID 3016 BODY[2.MIME] {389}
S: Content-Disposition: attachment;
S: 	filename="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: Content-Transfer-Encoding: base64
S: Content-Type: application/pdf;
S: 	name="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: 
S:  BODY[2] "")

or

S: * 1 FETCH (UID 3016 BODY[2.MIME] {389}
S: Content-Disposition: attachment;
S: 	filename="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: Content-Transfer-Encoding: base64
S: Content-Type: application/pdf;
S: 	name="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: 
S:  BODY[2] NIL)

or

S: * 1 FETCH (UID 3016 BODY[2.MIME] {389}
S: Content-Disposition: attachment;
S: 	filename="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: Content-Transfer-Encoding: base64
S: Content-Type: application/pdf;
S: 	name="=?UTF-8?B?0KHRh9C10YIg0LTQtCDQotC+0L8t0JrQvtGE0LUg0YPQuy4g0KPRgNCw0LvRjNGB0LrQsNGPLCDQtC4x?=
S: 	=?UTF-8?B?INC90L7Rj9Cx0YDRjC5wZGY=?="
S: 
S:  BODY[2] {0}
S:  )

I'll see what I can do about adding a work-around.

@jstedfast jstedfast added server-bug The bug appears to be in the server and removed need-info More information is needed in order to diagnose the issue. labels Feb 13, 2024
@jstedfast jstedfast changed the title Problem with fetching some letters: Syntax error in BODY. Unexpected token: ')' [Yandex] GetBodyPart() throws Syntax error in BODY. Unexpected token: ')' for MimeParts with empty content Feb 13, 2024
@jstedfast jstedfast added the compatibility Compatibility with existing software label Feb 14, 2024
jstedfast added a commit that referenced this issue Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server
Projects
None yet
Development

No branches or pull requests

2 participants