summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-08 11:39:14 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-08 12:27:41 -0300
commit4d654c66af16d0b737669865758faf24b9e77378 (patch)
tree0783fd506746dedc20af2d8d567d5bf956d0e313
parent308450300b2bde492a996af1b5edebb3656397d6 (diff)
Adding date to PixelatedMail#from_dict
-rw-r--r--service/pixelated/adapter/pixelated_mail.py3
-rw-r--r--service/pixelated/support/date.py21
-rw-r--r--service/test/adapter/pixelated_mail_test.py13
3 files changed, 35 insertions, 2 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index 2b9ccd35..e8aab1eb 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from pixelated.adapter.status import Status
+import pixelated.support.date
import dateutil.parser as dateparser
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
@@ -107,6 +108,7 @@ class PixelatedMail:
mime_multipart['Cc'] = ", ".join(self.headers['cc'])
mime_multipart['Bcc'] = ", ".join(self.headers['bcc'])
mime_multipart['Subject'] = self.headers['subject']
+ mime_multipart['Date'] = self.headers['date']
mime_multipart.attach(MIMEText(self.body, 'plain'))
return mime_multipart
@@ -130,6 +132,7 @@ class PixelatedMail:
def from_dict(mail_dict):
mail = PixelatedMail()
mail.headers = mail_dict.get('header', {})
+ mail.headers['date'] = pixelated.support.date.iso_now()
mail.body = mail_dict.get('body', '')
mail.ident = mail_dict.get('ident', None)
mail.tags = mail_dict.get('tags', [])
diff --git a/service/pixelated/support/date.py b/service/pixelated/support/date.py
new file mode 100644
index 00000000..1593022c
--- /dev/null
+++ b/service/pixelated/support/date.py
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2014 ThoughtWorks, Inc.
+#
+# Pixelated is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pixelated is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import datetime
+from dateutil.tz import tzlocal
+
+
+def iso_now():
+ return datetime.datetime.now(tzlocal()).isoformat()
diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py
index 557c3f6a..67922893 100644
--- a/service/test/adapter/pixelated_mail_test.py
+++ b/service/test/adapter/pixelated_mail_test.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import unittest
+import pixelated.support.date
from pixelated.adapter.pixelated_mail import PixelatedMail
import test_helper
@@ -64,6 +65,13 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEqual(mail.tags, ['sent'])
self.assertEqual(mail.body, 'Este \xe9 o corpo')
+ def test_from_dict_adds_current_date(self):
+ pixelated.support.date.iso_now = lambda: 'date now'
+
+ mail = PixelatedMail.from_dict(self.mail_dict)
+
+ self.assertEqual('date now', mail.headers['date'])
+
def test_update_tags_return_a_set_for_added_tags_and_a_set_for_removed_ones(self):
pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_headers={'X-tags': ['custom_1', 'custom_2']}))
added, removed = pixelated_mail.update_tags(set(['custom_1', 'custom_3']))
@@ -71,13 +79,14 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(set(['custom_2']), removed)
def test_to_mime_multipart(self):
- mail = PixelatedMail.from_dict(self.mail_dict)
+ pixelated.support.date.iso_now = lambda: 'date now'
- mime_multipart = mail.to_mime_multipart()
+ mime_multipart = PixelatedMail.from_dict(self.mail_dict).to_mime_multipart()
self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: to@pixelated.org, anotherto@pixelated.org\n")
self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: cc@pixelated.org, anothercc@pixelated.org\n")
self.assertRegexpMatches(mime_multipart.as_string(), "\nBcc: bcc@pixelated.org, anotherbcc@pixelated.org\n")
+ self.assertRegexpMatches(mime_multipart.as_string(), "\nDate: date now\n")
self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n")
self.assertRegexpMatches(mime_multipart.as_string(), "\nEste \xe9 o corpo")