summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 17:22:23 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 17:22:23 +0200
commit5f08f82cc2f15e15ab894ed4f0514fcc60348511 (patch)
tree20d0ce5e8d59bceb46151ec6bce65fd8fb867dc7 /service/pixelated/adapter/mailstore
parenta43f3a7c9c47dc9c9239414a0eba9bbc1f3cfdbf (diff)
Added get_mail_attachment to MailStore and LeapMailStore.
- Issue #435
Diffstat (limited to 'service/pixelated/adapter/mailstore')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py23
-rw-r--r--service/pixelated/adapter/mailstore/mailstore.py3
2 files changed, 26 insertions, 0 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 9b1afdd4..b72c8804 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -13,7 +13,9 @@
#
# 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 base64
from email.header import decode_header
+import quopri
import re
from uuid import uuid4
from leap.mail.adaptors.soledad import SoledadMailAdaptor
@@ -177,6 +179,27 @@ class LeapMailStore(MailStore):
return defer.gatherResults(deferreds, consumeErrors=True)
@defer.inlineCallbacks
+ def get_mail_attachment(self, attachment_id):
+ results = yield self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', attachment_id) if attachment_id else []
+ if len(results):
+ content = results[0]
+ defer.returnValue({'content-type': content.content_type, 'content': self._try_decode(
+ content.raw, content.content_transfer_encoding)})
+ else:
+ raise ValueError('No attachment with id %s found!' % attachment_id)
+
+ def _try_decode(self, raw, encoding):
+ encoding = encoding.lower()
+ if encoding == 'base64':
+ data = base64.decodestring(raw)
+ elif encoding == 'quoted-printable':
+ data = quopri.decodestring(raw)
+ else:
+ data = str(raw)
+
+ return bytearray(data)
+
+ @defer.inlineCallbacks
def update_mail(self, mail):
message = yield self._fetch_msg_from_soledad(mail.mail_id)
message.get_wrapper().set_tags(tuple(mail.tags))
diff --git a/service/pixelated/adapter/mailstore/mailstore.py b/service/pixelated/adapter/mailstore/mailstore.py
index 425def92..60716dfe 100644
--- a/service/pixelated/adapter/mailstore/mailstore.py
+++ b/service/pixelated/adapter/mailstore/mailstore.py
@@ -19,6 +19,9 @@ class MailStore(object):
def get_mail(self, mail_id):
pass
+ def get_mail_attachment(self, attachment_id):
+ pass
+
def get_mails(self, mail_ids):
pass