summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py2
-rw-r--r--service/pixelated/adapter/model/mail.py4
-rw-r--r--service/pixelated/adapter/search/__init__.py4
-rw-r--r--service/pixelated/support/date.py10
-rw-r--r--service/test/support/integration/model.py4
-rw-r--r--service/test/unit/adapter/test_mail.py6
6 files changed, 15 insertions, 15 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 215cd74a..0182efd9 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -169,7 +169,7 @@ class LeapMail(Mail):
def from_dict(mail_dict):
# TODO: implement this method and also write tests for it
headers = {key.capitalize(): value for key, value in mail_dict.get('header', {}).items()}
- headers['Date'] = date.iso_now()
+ headers['Date'] = date.mail_date_now()
body = mail_dict.get('body', '')
tags = set(mail_dict.get('tags', []))
status = set(mail_dict.get('status', []))
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 9f2db32e..5a0a1b92 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -241,7 +241,7 @@ class InputMail(Mail):
input_mail = InputMail()
input_mail.headers = {key.capitalize(): value for key, value in mail_dict.get('header', {}).items()}
- input_mail.headers['Date'] = date.iso_now()
+ input_mail.headers['Date'] = date.mail_date_now()
input_mail.body = mail_dict.get('body', '')
@@ -254,7 +254,7 @@ class InputMail(Mail):
def from_python_mail(mail):
input_mail = InputMail()
input_mail.headers = {key.capitalize(): value for key, value in mail.items()}
- input_mail.headers['Date'] = date.iso_now()
+ input_mail.headers['Date'] = date.mail_date_now()
input_mail.headers['Subject'] = mail['Subject']
input_mail.headers['To'] = InputMail.FROM_EMAIL_ADDRESS
input_mail._mime = MIMEMultipart()
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index 0c86582d..51ef6cd7 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -18,6 +18,7 @@ from pixelated.support.encrypted_file_storage import EncryptedFileStorage
import os
import re
+import dateutil.parser
from pixelated.adapter.model.status import Status
from pixelated.adapter.search.contacts import contacts_suggestions
from whoosh.index import FileIndex
@@ -27,7 +28,6 @@ from whoosh.qparser import MultifieldParser
from whoosh.writing import AsyncWriter
from whoosh import sorting
from pixelated.support.functional import unique
-from pixelated.support.date import milliseconds
import traceback
@@ -126,7 +126,7 @@ class SearchEngine(object):
index_data = {
'sender': self._empty_string_to_none(header.get('from', '')),
'subject': self._empty_string_to_none(header.get('subject', '')),
- 'date': milliseconds(header.get('date', '')),
+ 'date': dateutil.parser.parse(header.get('date', '')).strftime('%s'),
'to': self._format_recipient(header, 'to'),
'cc': self._format_recipient(header, 'cc'),
'bcc': self._format_recipient(header, 'bcc'),
diff --git a/service/pixelated/support/date.py b/service/pixelated/support/date.py
index e7cdbb30..0012aeea 100644
--- a/service/pixelated/support/date.py
+++ b/service/pixelated/support/date.py
@@ -16,6 +16,7 @@
import datetime
import dateutil.parser
+from email.utils import formatdate
from dateutil.tz import tzlocal
@@ -23,9 +24,6 @@ def iso_now():
return datetime.datetime.now(tzlocal()).isoformat()
-def milliseconds(date):
- date = dateutil.parser.parse(date)
- date = date.replace(tzinfo=None)
- epoch = datetime.datetime.utcfromtimestamp(0)
- delta = date - epoch
- return int(delta.total_seconds() * 1000)
+def mail_date_now():
+ date = dateutil.parser.parse(iso_now())
+ return formatdate(float(date.strftime('%s')))
diff --git a/service/test/support/integration/model.py b/service/test/support/integration/model.py
index 8b6f9759..c6f6a754 100644
--- a/service/test/support/integration/model.py
+++ b/service/test/support/integration/model.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import json
+from pixelated.support import date
from pixelated.adapter.model.mail import InputMail
from pixelated.adapter.model.status import Status
@@ -26,7 +27,8 @@ class MailBuilder:
'to': ['recipient@to.com'],
'cc': ['recipient@cc.com'],
'bcc': ['recipient@bcc.com'],
- 'subject': 'Hi! This the subject'
+ 'subject': 'Hi! This the subject',
+ 'date': date.mail_date_now()
},
'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n",
'status': []
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index bd6ed25b..dc344992 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -62,7 +62,7 @@ def multipart_mail_dict():
class InputMailTest(unittest.TestCase):
def test_to_mime_multipart_should_add_blank_fields(self):
- pixelated.support.date.iso_now = lambda: 'date now'
+ pixelated.support.date.mail_date_now = lambda: 'date now'
mail_dict = simple_mail_dict()
mail_dict['header']['to'] = ''
@@ -93,7 +93,7 @@ class InputMailTest(unittest.TestCase):
self.assertRegexpMatches(result, 'To: to@pixelated.org')
def test_to_mime_multipart(self):
- pixelated.support.date.iso_now = lambda: 'date now'
+ pixelated.support.date.mail_date_now = lambda: 'date now'
mime_multipart = InputMail.from_dict(simple_mail_dict()).to_mime_multipart()
@@ -107,7 +107,7 @@ class InputMailTest(unittest.TestCase):
def test_to_mime_multipart_with_special_chars(self):
mail_dict = simple_mail_dict()
mail_dict['header']['to'] = u'"Älbert Übrö \xF0\x9F\x92\xA9" <äüö@example.mail>'
- pixelated.support.date.iso_now = lambda: 'date now'
+ pixelated.support.date.mail_date_now = lambda: 'date now'
mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()