Fix test IMAP parsing

This commit is contained in:
Quentin 2022-07-05 12:04:04 +02:00
parent 50b2efe6da
commit f3f0673c3c
Signed by: quentin
GPG Key ID: E9602264D639FF68
6 changed files with 22 additions and 18 deletions

View File

@ -1,2 +1,2 @@
(BODY (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16)("application" "mac-binhex40" ("name" "blueball.png") NIL NIL "7bit" 1929)("application" "mac-binhex40" ("name" {19}
HasenundFrösche.txt
HasenundFrösche.txt) NIL NIL "7bit" 1131) "mixed"))

View File

@ -1,2 +1,3 @@
(BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16 NIL NIL NIL NIL)("application" "mac-binhex40" ("name" "blueball.png") NIL NIL "7bit" 1929 NIL ("attachment" ("filename" "blueball.png")) NIL NIL)("application" "mac-binhex40" ("name" {19}
HasenundFrösche.txt
HasenundFrösche.txt) NIL NIL "7bit" 1131 NIL ("attachment" ("filename" {19}
HasenundFrösche.txt)) NIL NIL) "mixed" ("boundary" "=====================_716373961==_") NIL NIL NIL))

View File

@ -1,2 +1,2 @@
(BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16 NIL NIL NIL NIL)("image" "png" ("name" "blueball.png") NIL NIL "base64" 1814 NIL ("attachment" ("filename" "blueball.png")) NIL NIL)("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 804 17 NIL ("attachment" ("filename" "farmerandstork.txt")) NIL NIL)("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16 NIL ("attachment" ("filename" {19}
HasenundFrösche.txt
HasenundFrösche.txt)) NIL NIL) "mixed" ("boundary" "=====================_716541962==_") NIL NIL NIL))

View File

@ -1,2 +1,2 @@
(BODY (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16)("text" "plain" ("name" {19}
HasenundFrösche.txt
HasenundFrösche.txt "x-mac-type" "54455854" "x-mac-creator" "74747874" "charset" "us-ascii") NIL NIL "x-uuencode" 1088 21)("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 804 17) "mixed"))

View File

@ -1,2 +1,3 @@
(BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 809 16 NIL NIL NIL NIL)("text" "plain" ("name" {19}
HasenundFrösche.txt
HasenundFrösche.txt "x-mac-type" "54455854" "x-mac-creator" "74747874" "charset" "us-ascii") NIL NIL "x-uuencode" 1088 21 NIL ("attachment" ("filename" {19}
HasenundFrösche.txt)) NIL NIL)("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 804 17 NIL ("attachment" ("filename" "farmerandstork.txt")) NIL NIL) "mixed" ("boundary" "=====================_716740438==_") NIL NIL NIL))

View File

@ -3,6 +3,17 @@ from os import listdir
from os.path import isfile, join
import sys
def rebuild_body_res(b):
bb = b''
for e in b:
if type(e) is tuple:
bb += b'\r\n'.join([p for p in e])
else:
bb += e
f = bb[bb.find(b'('):]
return f
path = sys.argv[1]
onlyfiles = [join(path, f) for f in listdir(path) if isfile(join(path, f)) and len(f) > 4 and f[-4:] == ".eml"]
@ -20,24 +31,15 @@ with IMAP4_SSL(host="localhost") as M:
seq = (f"{idx+1}:{idx+1}").encode()
(r, b) = M.fetch(seq, "(BODY)")
assert r == 'OK'
if type(b[0]) is tuple:
bb = b'\r\n'.join([p for p in b[0]])
else:
bb = b[0]
f = bb[bb.find(b'('):]
with open(f_noext + ".body", 'w+b') as w:
w.write(f)
w.write(rebuild_body_res(b))
(r, b) = M.fetch(seq, "(BODYSTRUCTURE)")
assert r == 'OK'
if type(b[0]) is tuple:
bb = b'\r\n'.join([p for p in b[0]])
else:
bb = b[0]
f = bb[bb.find(b'('):]
with open(f_noext + ".bodystructure", 'w+b') as w:
w.write(f)
w.write(rebuild_body_res(b))
M.close()
M.logout()