From 41e76814be86ac45190c2ace1d02fdd827d6c88e Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Fri, 5 Sep 2014 10:18:05 +0200 Subject: Fixed functional tests. --- py-fake-service/app/adapter/contacts.py | 2 +- py-fake-service/app/adapter/mail.py | 2 +- py-fake-service/app/adapter/mail_service.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'py-fake-service/app/adapter') diff --git a/py-fake-service/app/adapter/contacts.py b/py-fake-service/app/adapter/contacts.py index f241de98..19debdf1 100644 --- a/py-fake-service/app/adapter/contacts.py +++ b/py-fake-service/app/adapter/contacts.py @@ -22,7 +22,7 @@ class Contacts: self.contacts = [] def add(self, mbox_mail): - contact = mbox_mail.get('From') + contact = mbox_mail.from_addr self.contacts.append(Contact(contact)) def search(self, query): diff --git a/py-fake-service/app/adapter/mail.py b/py-fake-service/app/adapter/mail.py index a18f6276..d2ae5789 100644 --- a/py-fake-service/app/adapter/mail.py +++ b/py-fake-service/app/adapter/mail.py @@ -71,7 +71,7 @@ class Mail: def _get_headers(self, mbox_mail): headers = {} - headers['from'] = mbox_mail.get('From') + headers['from'] = mbox_mail.from_addr headers['to'] = [mbox_mail.get('To')] headers['subject'] = mbox_mail.get('Subject') headers['date'] = datetime.fromtimestamp( diff --git a/py-fake-service/app/adapter/mail_service.py b/py-fake-service/app/adapter/mail_service.py index a422ad9a..2825af9d 100644 --- a/py-fake-service/app/adapter/mail_service.py +++ b/py-fake-service/app/adapter/mail_service.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . import os +import re import mailbox from tagsset import TagsSet @@ -41,9 +42,14 @@ class MailService: def _create_message_from_file(self, filename): data = self._read_file(filename) + return self.create_message_from_string(data, filename) + + def create_message_from_string(self, data, filename=None): if data.startswith('From '): - msg = mailbox.mbox(filename).popitem()[1] - msg.from_addr = msg.get_from() + msg = mailbox.mboxMessage(data) + from_addr = re.sub(r"^From ", "", msg.get_unixfrom()) + msg.from_addr = from_addr + msg.set_from(from_addr) else: msg = mailbox.Message(data) msg.from_addr = msg.get('From') -- cgit v1.2.3