]> git.droids-corp.org - imapami.git/log
imapami.git
9 years agoutils: relax conversion to unicode
Olivier Matz [Sun, 29 Nov 2015 11:01:30 +0000 (12:01 +0100)]
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>
9 years agoutils: fix decoding of invalid headers
Olivier Matz [Sun, 29 Nov 2015 10:51:34 +0000 (11:51 +0100)]
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>
9 years agoactions: remove undeclared variables in log
Olivier Matz [Sun, 29 Nov 2015 10:50:28 +0000 (11:50 +0100)]
actions: remove undeclared variables in log

This log comes from a bad copy/paste.

Fixes: 95f172d6c ("actions: fix move")
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
9 years agoconditions: fix criteria for 'or'
Olivier Matz [Wed, 25 Nov 2015 17:54:18 +0000 (18:54 +0100)]
conditions: fix criteria for 'or'

The criteria was wrongly set to None as the following code has
no return value:
  criteria = set().add(criteria)

We should do this instead:
  criteria = set([criteria])

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
9 years agoconditions: fix criteria for 'not'
Olivier Matz [Wed, 25 Nov 2015 17:53:24 +0000 (18:53 +0100)]
conditions: fix criteria for 'not'

Only the check was inverted, but the criteria should be too.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
9 years agoactions: fix move
Olivier Matz [Wed, 25 Nov 2015 17:52:12 +0000 (18:52 +0100)]
actions: fix move

It is not possible to use ImapamiActionCopy.process() or
ImapamiActionDelete.process() methods on the ImapamiActionMove
object. So just duplicate the code for now.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
9 years agoFirst public revision
Olivier Matz [Sun, 22 Nov 2015 12:57:41 +0000 (13:57 +0100)]
First public revision

Signed-off-by: Olivier Matz <zer0@droids-corp.org>