Skip to content

Commit

Permalink
fixed 500 error for attachments closes #62
Browse files Browse the repository at this point in the history
  • Loading branch information
geek-at committed Nov 21, 2023
1 parent b821441 commit 45f2693
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/mailserver3.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ async def handle_DATA(self, server, session, envelope):
else:
filename = part.get_filename()
cid = part.get('Content-ID')
if cid is not None:
cid = cid[1:-1]
elif part.get('Content-ID') is not None:
cid = part.get('Content-ID')
else:
cid = str(uuid.uuid4())
logger.debug('Handling attachment: "%s" of type "%s" with CID "%s"',filename, part.get_content_type(), cid)
if filename is None:
filename = 'untitled'
Expand Down Expand Up @@ -106,7 +112,7 @@ async def handle_DATA(self, server, session, envelope):
edata["attachments"].append(filenamebase+"-"+attd[0])
edata["attachments_details"].append({
"filename":attd[0],
"cid":attd[2][1:-1],
"cid":attd[2],
"id":filenamebase+"-"+attd[0],
"download_url":URL+"/api/attachment/"+em+"/"+filenamebase+"-"+attd[0],
"size":len(attd[1])
Expand Down
30 changes: 30 additions & 0 deletions tools/testmail-quotedprintable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
EHLO example.com
MAIL FROM: <sender@example.com>
RCPT TO: <recipient@example.com>
DATA
From: me <me@example.org>
To: you <recipient@example.net>
Subject: MIME encapsulation demo
Mime-Version: 1.0
Content-type: multipart/alternative; boundary="covfefe"

--covfefe
Content-type: text/plain; charset="utf-8"
Content-transfer-encoding: quoted-printable

You had me at "H=
ello."

--covfefe
Content-type: text/html; charset="utf-8"
Content-transfer-encoding: base64

PGh0bWw+PGhlYWQ+PHRpdGxlPkhlbGxvLCBpcyBpdCBtZSB5b3UncmUgbG9va2luZyBmb3I/PC
90aXRsZT48L2hlYWQ+PGJvZHk+PHA+VGhlIGNvdiBpbiB0aGUgZmUgZmU8L3A+PC9ib2R5Pjwv
aHRtbD4K

--covfefe--

.

QUIT

0 comments on commit 45f2693

Please sign in to comment.