I have created a script on my Postfix server which basically adds a banner to incoming external emails. Currently I'm facing the problem that when the sender sends a digitally signed email from Outlook on prem and has the recipient in his address book the email comes in displaying the text/plain part and attaching the winmail.dat to it. If the email is not signed it comes in as winmail.dat but my script processes it fine and it gets displayed as it should.
My idea is to check the incoming mail for winmail.dat with the following function: def is_winmail(email): for part in email.walk(): if part.get_content_type() == "application/ms-tnef": return True return False
and if thats true I would like to use tnefparse to check if the winmail.dat contains either multipart/signed; application/pgp-signature, application/x-pkcs7-signature
if already tried a few functions like: def check_signature_in_winmail(winmail_bytes):
t = TNEF(winmail_bytes)
for attach in t.attachments:
if attach.name.endswith('.p7s'):
return True
for attr in attach.mapi_attrs:
if attr.attid == 0x6F02:
return True
return False
or def check_signature_in_winmail(payload):
t = tnefparse.TNEF(payload)
for a in t.attachments:
if a.long_filename and (a.long_filename.lower().endswith('.p7s') or a.long_filename.lower().endswith('.sig')):
return True
return False
but unfortunately none of them were working... Does anyone has an idea or hint how to get this working?