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

imap fetch command response parsing #135

Open
yjm6560 opened this issue Aug 26, 2023 · 2 comments
Open

imap fetch command response parsing #135

yjm6560 opened this issue Aug 26, 2023 · 2 comments

Comments

@yjm6560
Copy link

yjm6560 commented Aug 26, 2023

As you know, if imap client send UID FETCH command, then imap server must send UID data in the response.
https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8
image

However there is no rule which specifies the order between UID and other data(RFC822 or RFC822.HEADER).
For example, if client send 123 UID FETCH 10 (RFC822)\r\n command, imap server can send following responses.
(123 is tag, 10 is uid)

RFC822 data after UID data

  1. * 3 FETCH (UID 10 RFC822 {6}\r\n
    • 3 is message sequence number
  2. abcd\r\n
  3. )\r\n
  4. 123 OK Fetch completed.\r\n

UID data after RFC822 data

  1. * 3 FETCH (RFC822 {6}\r\n
    • 3 is message sequence number
  2. abcd\r\n
  3. UID 10)\r\n
  4. 123 OK Fetch completed.\r\n

The second case cannot be covered by the current mailio:imap::fetch function logic because it gets out of for loop(checking if requested tokens exist or not) when it met RFC822 token.
So even though it gets UID data after receiving literal response, it can't parse UID data.

This case actually happens often.

So... i recommend to parse response after receiving all responses is completed(until parenthesis_list_counter_ becomes 0).

@karastojko
Copy link
Owner

For the test purposes, I am using Dovecot, Gmail, Outlook, Zoho, Yahoo, Vkontakte servers. So far, I did not see such case, but I will take a more detailed look with UIDs.

@yjm6560
Copy link
Author

yjm6560 commented Aug 30, 2023

Thank you for replying!
Naver(the parent company of LINE) mail service is the most famous in Korea, and it gives UID FETCH response like following example.

$ openssl s_client -connect imap.naver.com:993 -quiet
... # login, select
3 UID FETCH 38 (RFC822) # request UID FETCH command
# receive data
* 1 FETCH (RFC822 {1998} # untagged response
... # mime data
 UID 38) # receive UID data after RFC822 data
3 OK Fetch completed. # tagged response

i searched rfc document but i cannot find that UID should come before RFC822.
I have used mailio::imap after fixing it, it works well whether UID comes before RFC822 or not.
(I tested in more than 10 imap servers including Gmail, Outlook, Naver and minor imap server)
If you don't have time, I can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants