-
Notifications
You must be signed in to change notification settings - Fork 58
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
How to handle literals in FETCH response #72
Comments
Ok thanks for this issue and the link. I'm having a look on this soon. |
as for #71 the API is not the same as imaplib. It is formatting less the responses from the imapserver. Yet it it is structured with a uniform type (list of bytes chains for IMAP protocol parts, and bytearrays for the data). This is not related to whether there is double quote or not. For example i tried with a double quote in subject. The first line should be the app getting the last searched UID, without the body for example with only the uid/flags/subject here. Then when the user asks for a specific mail, then the body is searched with the second command. result, lines = await imap_client.uid('fetch', '1950:*', '(UID FLAGS BODY.PEEK[HEADER.FIELDS (SUBJECT)])')
print(lines)
result, lines = await await imap_client.uid('fetch', '1984', 'BODY.PEEK[]')
print(lines) This will display (I separated each list item for clarity):
so we see that there are groups of 3 lines
Then the BODY.PEEK will display :
Here is quite the same : first is the IMAP response, then the mail content is always at the index 1, and can be directly passed to python mail API with : msg = email.message_from_bytes(lines[1])
print(msg['subject'])
# will print 'Test "guillemets" ' |
I think it would be nice if aioimaplib would provide a more high-level API for the fetch (similar to imaplib). While the current format has some structure, relying on it seems a bit hacky. Especially, if one wants to read out multiple data items (e.g. the
To actually be sure to handle all these corner cases, I think it is currently required that the consumer parses the response based on the RFC. I did this here using an implemenation of the grammar with pyparsing. However, this still seems to not work with Office365 IMAP (jgosmann/dmarc-metrics-exporter#17). It also has some rough edges:
|
I agree with the above - in my app, I'm making a FETCH request for ENVELOPES for mails in my mailbox. My understanding is that I believe that's similar to what @jgosmann is talking about. |
My statements about the unknown order of data items and potential additional data items included were correct. RFC3501 actually references RFC2683 with recommendations for implementors and clearly states these points. |
Thanks for this library - I've had some good success with it so far.
However, if I have an email with a double quote in the subject, then the
FETCH
response for the message is split over multiple lines, and uses a literal line for the subject.Is there a recommended way to handle this? If I do a
FETCH
for all messages, then the situation seems even trickier to handle, as there seems to be no easy way to tell which line belongs to which message.The standard lib
imaplib
seems to bundle the responses into tuples of envelopes and data but we only get the response lines (unless I've missed something).The text was updated successfully, but these errors were encountered: