diff options
| -rw-r--r-- | service/pixelated/adapter/mail.py | 12 | ||||
| -rw-r--r-- | service/test/unit/adapter/mail_test.py | 19 | 
2 files changed, 29 insertions, 2 deletions
diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py index a5f0d5d2..3003f9eb 100644 --- a/service/pixelated/adapter/mail.py +++ b/service/pixelated/adapter/mail.py @@ -230,11 +230,17 @@ class PixelatedMail(Mail):          for header in ['From', 'Subject']:              _headers[header] = hdoc_headers.get(header) +          _headers['Date'] = self._get_date() +          if self.parts and len(self.parts['alternatives']) > 1:              _headers['content_type'] = 'multipart/alternative; boundary="%s"' % self.boundary          elif self.hdoc.content['headers'].get('Content-Type'):              _headers['content_type'] = hdoc_headers.get('Content-Type') + +        if hdoc_headers.get('Reply-To'): +            _headers['Reply-To'] = hdoc_headers.get('Reply-To') +          return _headers      def _get_date(self): @@ -326,11 +332,13 @@ class PixelatedMail(Mail):          dict_mail = super(PixelatedMail, self).as_dict()          dict_mail['replying'] = {'single': None, 'all': {'to-field': [], 'cc-field': []}} +        sender_mail = self.headers.get('Reply-To', self.headers['From']) +          recipients = [recipient for recipient in self.headers['To'] if recipient != InputMail.FROM_EMAIL_ADDRESS] -        recipients.append(self.headers['From']) +        recipients.append(sender_mail)          ccs = [cc for cc in self.headers['Cc'] if cc != InputMail.FROM_EMAIL_ADDRESS] -        dict_mail['replying']['single'] = self.headers['From'] +        dict_mail['replying']['single'] = sender_mail          dict_mail['replying']['all']['to-field'] = recipients          dict_mail['replying']['all']['cc-field'] = ccs          return dict_mail diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py index 4cc29287..f436bb6c 100644 --- a/service/test/unit/adapter/mail_test.py +++ b/service/test/unit/adapter/mail_test.py @@ -103,6 +103,25 @@ class TestPixelatedMail(unittest.TestCase):                                        }                                    }}) +    def test_use_reply_to_address_for_replying(self): +        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent']) +        hdoc.content['headers']['Subject'] = 'The subject' +        hdoc.content['headers']['From'] = 'someone@pixelated.org' +        hdoc.content['headers']['Reply-To'] = 'reply-to-this-address@pixelated.org' +        hdoc.content['headers']['To'] = 'me@pixelated.org, \nalice@pixelated.org' + +        InputMail.FROM_EMAIL_ADDRESS = 'me@pixelated.org' + +        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier) + +        _dict = mail.as_dict() + +        self.assertEquals(_dict['replying'], {'single': 'reply-to-this-address@pixelated.org', +                                              'all': { +                                                  'to-field': ['alice@pixelated.org', 'reply-to-this-address@pixelated.org'], +                                                  'cc-field': [] +                                              }}) +      def test_alternatives_body(self):          parts = {'alternatives': [], 'attachments': []}          parts['alternatives'].append({'content': 'blablabla', 'headers': {'Content-Type': 'text/plain'}})  | 
