switch to From: Header instead of date to compensate for older libmagic versions

This commit is contained in:
phail 2022-05-19 22:51:17 +02:00
parent 6809b15ce1
commit c04b9fd7f6

View File

@ -342,7 +342,7 @@ class MailAccountHandler(LoggingMixin):
suffix=".eml", suffix=".eml",
) )
with open(temp_filename, "wb") as f: with open(temp_filename, "wb") as f:
# Move "Date"-header to beginning of file # Move "From"-header to beginning of file
# TODO: This ugly workaround is needed because the parser is # TODO: This ugly workaround is needed because the parser is
# chosen only by the mime_type detected via magic # chosen only by the mime_type detected via magic
# (see documents/consumer.py "mime_type = magic.from_file") # (see documents/consumer.py "mime_type = magic.from_file")
@ -351,12 +351,12 @@ class MailAccountHandler(LoggingMixin):
# detects text/plain. # detects text/plain.
# This also effects direct file consumption of .eml files # This also effects direct file consumption of .eml files
# which are not treated with this workaround. # which are not treated with this workaround.
date_element = None from_element = None
for i, header in enumerate(message.obj._headers): for i, header in enumerate(message.obj._headers):
if header[0] == "Date": if header[0] == "From":
date_element = i from_element = i
if date_element: if from_element:
new_headers = [message.obj._headers.pop(date_element)] new_headers = [message.obj._headers.pop(from_element)]
new_headers += message.obj._headers new_headers += message.obj._headers
message.obj._headers = new_headers message.obj._headers = new_headers