Skip to content

Commit

Permalink
Fix multipart inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
jherencia committed Jul 23, 2015
1 parent 46578a6 commit 59b157f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions maildump/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def create_tables():
""")


def iter_message_parts(message):
if message.is_multipart():
for message in message.get_payload():
for part in iter_message_parts(message):
yield part
else:
yield message


def add_message(sender, recipients, body, message):
sql = """
INSERT INTO message
Expand All @@ -80,15 +89,16 @@ def add_message(sender, recipients, body, message):
len(body)))
message_id = cur.lastrowid
# Store parts (why do we do this for non-multipart at all?!)
parts = [message] if not message.is_multipart() else message.get_payload()
for part in parts:
parts = 0
for part in iter_message_parts(message):
cid = part.get('Content-Id') or str(uuid.uuid4())
if cid[0] == '<' and cid[-1] == '>':
cid = cid[1:-1]
_add_message_part(message_id, cid, part)
parts += 1
_conn.commit()
cur.close()
log.debug('Stored message {0} (parts={1})'.format(message_id, len(parts)))
log.debug('Stored message {0} (parts={1})'.format(message_id, parts))
broadcast('add_message', message_id)
return message_id

Expand Down

0 comments on commit 59b157f

Please # to comment.