[fix] attachments handling
This commit is contained in:
parent
209317ba21
commit
0ffb69de30
1 changed files with 13 additions and 8 deletions
21
mms2mail
21
mms2mail
|
@ -29,6 +29,7 @@ import re
|
||||||
import time
|
import time
|
||||||
import getpass
|
import getpass
|
||||||
import socket
|
import socket
|
||||||
|
import mimetypes
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from messaging.mms.message import MMSMessage
|
from messaging.mms.message import MMSMessage
|
||||||
|
@ -183,20 +184,24 @@ class MMS2Mail:
|
||||||
message.headers.append((f"X-MMS-{header}",
|
message.headers.append((f"X-MMS-{header}",
|
||||||
f"{mms.headers[header]}"))
|
f"{mms.headers[header]}"))
|
||||||
|
|
||||||
|
message.plain = " "
|
||||||
|
data_id = 1
|
||||||
for data_part in mms.data_parts:
|
for data_part in mms.data_parts:
|
||||||
datacontent = data_part.headers['Content-Type']
|
datacontent = data_part.headers['Content-Type']
|
||||||
if datacontent is not None:
|
if datacontent is not None:
|
||||||
if 'text/plain' in datacontent[0]:
|
if 'text/plain' in datacontent[0]:
|
||||||
message.plain = f"{data_part.data} \n"
|
encoding = datacontent[1].get('Charset', 'utf-8')
|
||||||
if 'Name' in datacontent[1]:
|
plain = data_part.data.decode(encoding)
|
||||||
filename = datacontent[1]['Name']
|
message.plain += plain + '\n'
|
||||||
message.attach(filename, data_part.data)
|
continue
|
||||||
# Ensure a proper body content in the resulting mail
|
extension = mimetypes.guess_extension(datacontent[0])
|
||||||
if not message.plain:
|
filename = datacontent[1].get('Name', str(data_id))
|
||||||
message.plain = " "
|
message.attach(filename + extension, data_part.data)
|
||||||
|
data_id = data_id + 1
|
||||||
|
|
||||||
# Add MMS binary file, for debugging purpose or reparsing in the future
|
# Add MMS binary file, for debugging purpose or reparsing in the future
|
||||||
if self.attach_mms:
|
if self.attach_mms:
|
||||||
message.attach(path, None, None, None, False, "mms.bin")
|
message.attach(path, None, None, None, False, path.split('/')[-1])
|
||||||
|
|
||||||
# Creating an empty file stating the mms as been converted
|
# Creating an empty file stating the mms as been converted
|
||||||
self.mark_mms_read(dbus_path)
|
self.mark_mms_read(dbus_path)
|
||||||
|
|
Loading…
Reference in a new issue