diff options
author | Gislene Pereira <gislene01@gmail.com> | 2015-12-24 19:28:04 -0200 |
---|---|---|
committer | Gislene Pereira <gislene01@gmail.com> | 2015-12-24 19:28:04 -0200 |
commit | 311d7fb96f6e1d4850d60078b5f9b276e5b8d9bd (patch) | |
tree | 384857aa637c200c81171719d2ff79bec81b5fda /service | |
parent | 5b32f9f9d10e3de3cd142414e40b75d1672a076e (diff) |
Issue #557 - Fixed REGEX to receive attachments from Apple Mail.
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 2 | ||||
-rw-r--r-- | service/test/unit/adapter/mailstore/test_leap_mailstore.py | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index 5637e763..1fce388d 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -190,7 +190,7 @@ class LeapMail(Mail): def _extract_filename(content_disposition): - match = re.compile('.*name=\"(.*)\".*').search(content_disposition) + match = re.compile('.*name=\"?(.*[^\"\'])').search(content_disposition) filename = '' if match: filename = match.group(1) diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py index b5b6a742..a2f2d935 100644 --- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py +++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py @@ -258,6 +258,25 @@ class TestLeapMailStore(TestCase): expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64'}] self.assertEqual(expected, message.as_dict()['attachments']) + def test_extract_attachment_filename_with_or_without_quotes(self): + input_mail = MIMEMultipart() + input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) + + attachment_without_quotes = MIMEApplication('pretend to be an attachment from apple mail') + attachment_without_quotes.add_header('Content-Disposition', 'u\'attachment;\n\tfilename=batatinha.rtf') + input_mail.attach(attachment_without_quotes) + + attachment_with_quotes = MIMEApplication('pretend to be an attachment from thunderbird') + attachment_with_quotes.add_header('Content-Disposition', 'u\'attachment; filename="receipt.pdf"') + input_mail.attach(attachment_with_quotes) + + message = self._add_create_mail_mocks_to_soledad(input_mail) + store = LeapMailStore(self.soledad) + attachment_info = store._extract_attachment_info_from(message) + + self.assertEqual('batatinha.rtf', attachment_info[0].name) + self.assertEqual('receipt.pdf', attachment_info[1].name) + @defer.inlineCallbacks def test_add_mail_with_special_chars(self): input_mail = MIMEText(u'a utf8 message', _charset='utf-8') |