You are a Senior Python Developer, Senior Email Protocol Engineer, and Senior Desktop UI Engineer.
Build a Python application that receives emails using my existing Python script and displays them in a human-readable format.
My existing script already downloads emails successfully. DO NOT change the email receiving logic unless absolutely necessary. Instead, build a parser and viewer on top of it.
I will provide my existing Python code.
The downloaded email is currently a raw MIME message containing:
- HTML
- Plain text
- MIME multipart sections
- Attachments
- Embedded images
- Various encodings
- Quoted printable
- Base64
- Different charsets
The application must analyze the MIME structure automatically and present the email like a normal email client.
Correctly handle:
- multipart/mixed
- multipart/alternative
- multipart/related
- text/plain
- text/html
- nested multipart sections
Automatically locate the actual message body.
Support decoding:
- Base64
- Quoted Printable
- UTF-8
- UTF-16
- ISO-8859-1
- GBK
- EUC-KR
- Shift-JIS
- Unknown charset (fallback safely)
Never crash because of an unknown charset.
Convert HTML into readable content.
Requirements:
- Remove unnecessary HTML
- Remove scripts
- Remove styles
- Remove tracking pixels
- Decode HTML entities
- Preserve formatting
- Preserve paragraphs
- Preserve tables when possible
- Preserve hyperlinks
- Preserve inline images when possible
The output should look similar to Gmail or Outlook.
Display
From To CC BCC Subject Date Reply-To Message-ID
Decode encoded words such as
=?UTF-8?B?...?=
correctly.
Detect attachments.
Display
Filename Size Content Type
Allow saving attachments.
Detect CID images.
Display them inside the HTML if possible.
If not possible, show placeholders.
If HTML does not exist
display the plain text version.
Create a clean desktop interface.
Preferred:
PySide6
Alternative:
PyQt6
Features:
Left panel
- email list
Right panel
- From
- Subject
- Date
- HTML viewer
Bottom
- attachment list
Support:
scrolling search copy select text
Never terminate because of malformed email.
Gracefully handle
broken MIME invalid encoding missing headers unknown charset broken HTML
Organize the project into modules.
Example:
mail_receiver.py mail_parser.py mime_decoder.py html_processor.py attachment_manager.py models.py viewer.py main.py
Avoid putting everything into one file.
Use
type hints
dataclasses
classes where appropriate
logging
exception handling
clean architecture
Readable code is more important than clever code.
Prefer standard library first.
Recommended libraries when necessary:
email email.policy email.header html BeautifulSoup4 lxml bleach chardet charset-normalizer
Only introduce dependencies when they provide clear benefits.
Some emails exceed 20 MB.
Avoid unnecessary copying.
Parse incrementally where possible.
For every implementation step provide:
- Design explanation
- File structure
- Complete source code
- Reasoning
- Testing strategy
Do NOT rewrite my existing email retrieval code.
Integrate with it.
If the existing code has problems, explain them before changing anything.
If there are multiple implementation choices, explain the tradeoffs and recommend the most robust solution.
When parsing MIME messages, follow RFC-compliant behavior whenever practical.
Focus on correctness, maintainability, and compatibility with real-world emails from providers such as Gmail, Outlook, Yahoo, Apple Mail, and Exchange.