_create_forward_message fixed for multipart messages

This commit is contained in:
Andreas Knuth 2026-01-25 17:23:08 -06:00
parent 046111e267
commit 406cce6270
1 changed files with 54 additions and 45 deletions

View File

@ -272,13 +272,22 @@ class RulesProcessor:
msg.attach(body_part)
# Copy attachments
# Copy attachments - FIX FILENAMES
if original_parsed.is_multipart():
for part in original_parsed.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get_content_type() in ['text/plain', 'text/html']:
continue
# Fix malformed filename in Content-Disposition
content_disp = part.get('Content-Disposition', '')
if 'filename=' in content_disp and '"' not in content_disp:
# Add quotes around filename with spaces
import re
fixed_disp = re.sub(r'filename=([^;"\s]+(?:\s+[^;"\s]+)*)', r'filename="\1"', content_disp)
part.replace_header('Content-Disposition', fixed_disp)
msg.attach(part)
return msg