actions: surround flags with parenthesis It looks that when using uid, some servers expects that the flags are surrounded by parenthesis. Else, we get this error: UID command error: BAD ['Error in IMAP command UID STORE: Flags list contains non-atoms.'] Seen also here: https://github.com/coddingtonbear/django-mailbox/commit/dad65d802c7eab86c88dca3ef466dc4c43daffc0 Signed-off-by: Olivier Matz <zer0@droids-corp.org>
fix race when receiving mail during rule process Get the state (uidnext) for each inbox used in the configuration. It gives the uid of the next message the will be added in the mbox. We will only care about messages with a uid lower than this uidnext, to avoid race conditions with a message arriving while we are in the Signed-off-by: Olivier Matz <zer0@droids-corp.org>
use uids to manipulate mails The item identifier can be modified in some conditions, for instance after an expunge operation. This could leads to manipulate the wrong mail. Use uids instead, which does not vary for a given mail. Signed-off-by: Olivier Matz <zer0@droids-corp.org>
utils: relax conversion to unicode Some mails have incorrectly encoded headers, resulting in an exception when decoding them. This can be reproduced manually: >>> s='Vos deux avantages : 20% de r\xc3\xa9duction + Q1|\x051\xa5\xd9\xc9\x85\xa5\xcd\xbd\xb8\x80\xd0\xe1\xa0\x81\xbd\x99\x99\x95\xc9\xd1\x94\x80\x84' >>> s.decode("utf-8") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) Be more relax and try to fix the encoding errors instead of throwing an exception. Signed-off-by: Olivier Matz <zer0@droids-corp.org>
utils: fix decoding of invalid headers For some mails, the following exception was thrown: Traceback (most recent call last): File "/usr/local/bin/imapami", line 9, in <module> load_entry_point('imapami==0.1.0', 'console_scripts', 'imapami')() File "build/bdist.linux-x86_64/egg/imapami/__init__.py", line 321, in main File "build/bdist.linux-x86_64/egg/imapami/__init__.py", line 221, in process_rules File "build/bdist.linux-x86_64/egg/imapami/rules.py", line 251, in process File "build/bdist.linux-x86_64/egg/imapami/actions.py", line 149, in process File "build/bdist.linux-x86_64/egg/imapami/actions.py", line 317, in process File "build/bdist.linux-x86_64/egg/imapami/actions.py", line 98, in evaluate File "build/bdist.linux-x86_64/egg/imapami/utils.py", line 65, in headers_to_unicode File "/usr/lib/python2.7/email/header.py", line 108, in decode_header raise HeaderParseError email.errors.HeaderParseError It can be reproduced manually with: >>> import email.header >>> email.header.decode_header('=?UTF-8?B?UG91ciB2b3MgYWNoYXRzIGRlIE5vw6tsLCBwcm9maXRleiBkJ3VuIGRv?==?UTF-8?B?dWJsZSBhdmFudGFnZSAh?=') According to: http://stackoverflow.com/questions/7384006/email-header-decode-headers-throws-an-headerparseerror A workaround is to fix the header manually. Signed-off-by: Olivier Matz <zer0@droids-corp.org>
First public revision Signed-off-by: Olivier Matz <zer0@droids-corp.org>