summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authormnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 11:21:48 +0100
committermnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 11:22:34 +0100
commitb73185d27fe5d59d64b0759c1efbbcdf89086d11 (patch)
tree2d9d00d1a0b977878b1aad736464313b5fdc66e7 /service/pixelated
parent06ac408dbd7629d387dd7b311a26c144ee56631e (diff)
ensuring the same file is not saved twice
Issue #548
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/mailstore/leap_attachment_store.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_attachment_store.py b/service/pixelated/adapter/mailstore/leap_attachment_store.py
index 86121db9..982d9222 100644
--- a/service/pixelated/adapter/mailstore/leap_attachment_store.py
+++ b/service/pixelated/adapter/mailstore/leap_attachment_store.py
@@ -17,7 +17,7 @@ class LeapAttachmentStore(object):
@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):
+ if results:
content = ContentDocWrapper(**results[0].content)
defer.returnValue({'content-type': content.content_type, 'content': self._try_decode(
content.raw, content.content_transfer_encoding)})
@@ -27,8 +27,12 @@ class LeapAttachmentStore(object):
@defer.inlineCallbacks
def add_attachment(self, content, content_type):
cdoc = self._attachment_to_cdoc(content, content_type)
- yield self.soledad.create_doc(cdoc.serialize(), doc_id=cdoc.phash)
- defer.returnValue(cdoc.phash)
+ attachment_id = cdoc.phash
+ try:
+ yield self.get_mail_attachment(attachment_id)
+ except ValueError:
+ yield self.soledad.create_doc(cdoc.serialize(), doc_id=attachment_id)
+ defer.returnValue(attachment_id)
def _try_decode(self, raw, encoding):
encoding = encoding.lower()