summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorLisa Junger <ljunger@thoughtworks.com>2015-01-06 11:25:10 +0100
committerLisa Junger <ljunger@thoughtworks.com>2015-01-06 11:47:16 +0100
commitbd903ece01d9a1f85f3459f6495ad342bb64500e (patch)
tree978219d5b1668fc83d3346afae9d0cdea60e2526 /service
parente36e4e95b80b8ac2265136f12d16510877db4282 (diff)
Issue #215: Fixed missing From header for sent mails.
- Fixes problem with trailing comma for reply all
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/model/mail.py18
-rw-r--r--service/test/support/test_helper.py5
-rw-r--r--service/test/unit/adapter/mail_test.py13
3 files changed, 31 insertions, 5 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 690137ff..4b128d8c 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -93,6 +93,9 @@ class InputMail(Mail):
self._bd = None
self._chash = None
self._mime = None
+ self.headers = {}
+ self.body = ''
+ self._status = []
@property
def ident(self):
@@ -126,13 +129,17 @@ class InputMail(Mail):
if self._hd:
return self._hd
+ # InputMail does not have a from header but we need it when persisted into soledad.
+ headers = self.headers.copy()
+ headers['From'] = InputMail.FROM_EMAIL_ADDRESS
+
hd = {}
- hd[fields.HEADERS_KEY] = self.headers
- hd[fields.DATE_KEY] = self.headers['Date']
+ hd[fields.HEADERS_KEY] = headers
+ hd[fields.DATE_KEY] = headers['Date']
hd[fields.CONTENT_HASH_KEY] = self._get_chash()
hd[fields.MSGID_KEY] = ''
hd[fields.MULTIPART_KEY] = True
- hd[fields.SUBJECT_KEY] = self.headers.get('Subject')
+ hd[fields.SUBJECT_KEY] = headers.get('Subject')
hd[fields.TYPE_KEY] = fields.TYPE_HEADERS_VAL
hd[fields.BODY_KEY] = self._get_body_phash()
hd[fields.PARTS_MAP_KEY] = \
@@ -350,7 +357,10 @@ class PixelatedMail(Mail):
'attachments': self.parts['attachments'] if self.parts else []}
dict_mail['replying'] = {'single': None, 'all': {'to-field': [], 'cc-field': []}}
- sender_mail = self.headers.get('Reply-To', self.headers['From'])
+ sender_mail = self.headers.get('Reply-To', self.headers.get('From'))
+ # Issue #215: Fix for existing mails without any from address.
+ if sender_mail is None:
+ sender_mail = InputMail.FROM_EMAIL_ADDRESS
recipients = [recipient for recipient in self.headers['To'] if recipient != InputMail.FROM_EMAIL_ADDRESS]
recipients.append(sender_mail)
diff --git a/service/test/support/test_helper.py b/service/test/support/test_helper.py
index b2d3cf43..ff1de64a 100644
--- a/service/test/support/test_helper.py
+++ b/service/test/support/test_helper.py
@@ -43,10 +43,13 @@ def mail_dict():
}
-class TestDoc:
+class TestDoc(object):
def __init__(self, content):
self.content = content
+ def __getitem__(self, key):
+ return self.content[key]
+
def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INBOX', body='body',
chash='chash'):
diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py
index e8fd8755..e0b7a498 100644
--- a/service/test/unit/adapter/mail_test.py
+++ b/service/test/unit/adapter/mail_test.py
@@ -21,6 +21,8 @@ from mockito import *
from test.support import test_helper
import dateutil.parser as dateparser
import base64
+from leap.mail.imap.fields import fields
+from datetime import datetime
class TestPixelatedMail(unittest.TestCase):
@@ -69,6 +71,17 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(mail.fdoc.content['flags'], [])
+ def test_get_for_save_adds_from(self):
+ InputMail.FROM_EMAIL_ADDRESS = 'me@pixelated.org'
+ headers = {'Subject': 'The subject',
+ 'Date': str(datetime.now()),
+ 'To': 'me@pixelated.org'}
+
+ input_mail = InputMail()
+ input_mail.headers = headers
+
+ self.assertEqual('me@pixelated.org', input_mail.get_for_save(1, 'SENT')[1][fields.HEADERS_KEY]['From'])
+
def test_as_dict(self):
headers = {'Subject': 'The subject',
'From': 'someone@pixelated.org',