summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@riseup.net>2015-09-24 17:58:16 -0300
committerBruno Wagner <bwagner@riseup.net>2015-09-25 16:54:36 -0300
commitd186b0204f738367d530514707d0f95a6d4bf865 (patch)
tree276f5254aed59efdf5ce3cfc70be43ac448f2189 /service/pixelated
parent6eba069fdb566fd006fa48b8b9c5d5b44085f524 (diff)
Changed date format to conform to mail RFC #438
Diffstat (limited to 'service/pixelated')
-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
4 files changed, 9 insertions, 11 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')))