45 if not m.is_multipart():
49 Files[fn] = (cfn,
None)
51 save_file(cfn, m.get_payload(decode=
True))
52 return Text, Html, Files, 1
53 cp = m.get_content_type()
56 Text += m.get_payload(decode=
True).decode(
"utf-8")
59 Text += m.get_payload(decode=
True).decode(
"cp437")
61 print(
"failed to process text attachment with either utf-8 or cp437 code pages.")
65 soup = BeautifulSoup(m.get_payload(decode=
True).decode(
"utf-8"), features=
"html.parser")
66 Html += soup.get_text(
'\n', strip=
True)
69 soup = BeautifulSoup(m.get_payload(decode=
True).decode(
"cp437"), features=
"html.parser")
70 Html += soup.get_text(
'\n', strip=
True)
72 print(
"failed to process html attachment with either utf-8 or cp437 code pages.")
75 cp = m.get(
"content-type")
76 try: id =
disgra(m.get(
"content-id"))
79 if o==-1:
return Text, Html, Files, 1
87 save_file(cfn, m.get_payload(decode=
True))
88 return Text, Html, Files, 1
95 Text += t; Html += h; Files.update(f); Parts += p
97 return Text, Html, Files, Parts
100 m = message_from_file(msgfile)
101 From, To, Subject, Date =
caption(m)
102 Text, Html, Files, Parts =
pullout(m, key)
103 Text = Text.strip(); Html = Html.strip()
104 msg = {
"subject": Subject,
"from": From,
"to": To,
"date": Date,
105 "text": Text,
"html": Html,
"parts": Parts}
106 if Files: msg[
"files"] = Files