Skip to main content
ALT Linux Bugzilla
– Attachment 21960 Details for
Bug 50198
broken output for beehive results
New bug
|
Search
|
[?]
|
Help
Register
|
Log In
[x]
|
Forgot Password
Login:
[x]
|
EN
|
RU
converts broken emails into the expected form
regen.py (text/plain), 1.69 KB, created by
Arseny Maslennikov
on 2026-07-30 22:54:05 MSK
(
hide
)
Description:
converts broken emails into the expected form
Filename:
MIME Type:
Creator:
Arseny Maslennikov
Created:
2026-07-30 22:54:05 MSK
Size:
1.69 KB
patch
obsolete
>#!/usr/bin/python3 >import gzip >import mailbox >from email.message import EmailMessage > >import sys > > >def replace_all_parts(message, by): > message.set_payload(by) > # Update headers > message.replace_header('Content-Type', 'text/plain') > message.set_param('charset', 'unknown-8bit', header='Content-Type') > message.replace_header('Content-Disposition', 'inline') > if 'Content-Transfer-Encoding' in message: > del message['Content-Transfer-Encoding'] > > >def process(message): > if not message.is_multipart(): > return message > > parts = [part for part in message.walk()] > if len(parts) != 3: > # Do not risk losing data. > print(f'{len(parts)=}', file=sys.stderr) > return message > > for part in parts: > filename = part.get_filename() or "" > c_type = part.get_content_type() > if c_type in [ > "application/x-gzip", > "application/gzip", > ] and filename.endswith("message.gz"): > c_data = part.get_payload(decode=True) > if c_data: > try: > unc_data = gzip.decompress(c_data) > replace_all_parts(message, unc_data) > break > except (OSError, EOFError) as e: > # Skip if decompression fails. > print(e) > > return message > > >if __name__ == '__main__': > src_mbox_path = sys.argv[1] > dst_mbox_path = sys.argv[2] > > src_mbox = mailbox.mbox(src_mbox_path) > dst_mbox = mailbox.mbox(dst_mbox_path) > dst_mbox.lock() > try: > for message in src_mbox: > dst_mbox.add(process(message)) > finally: > dst_mbox.unlock() > dst_mbox.close() > src_mbox.close()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 50198
: 21960