Skip to content

Same behaviour in py2 and py3#60

Merged
ecarreras merged 2 commits intomasterfrom
fix-attachments-py3
Jul 30, 2025
Merged

Same behaviour in py2 and py3#60
ecarreras merged 2 commits intomasterfrom
fix-attachments-py3

Conversation

@ecarreras
Copy link
Member

This pull request refactors the email attachment handling in qreu/email.py to improve MIME type handling, base64 encoding, and payload decoding. It also updates the corresponding tests in spec/qreu_spec.py to align with the changes. The most important changes include restructuring the add_attachment method, fixing payload decoding in the attachments method, and cleaning up the test cases.

Refactoring in qreu/email.py:

  • Improved MIME type handling and base64 encoding in add_attachment:

    • Refactored the method to use base64.b64encode for encoding and mimetypes.guess_type for determining the MIME type.
    • Simplified the creation of the MIME part and removed unnecessary charset settings.
  • Fixed payload decoding in attachments:

    • Updated get_payload to decode the content automatically by passing decode=True.

Updates in spec/qreu_spec.py:

  • Test updates for attachment content decoding:

    • Modified tests to decode attachment content using .decode('utf-8') for comparison with expected values. [1] [2]
  • Removed outdated and commented code:

    • Cleaned up legacy Python 2 compatibility code and unused commented lines in test cases.

@ecarreras ecarreras requested review from Copilot and polsala July 30, 2025 09:32
@ecarreras ecarreras self-assigned this Jul 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request improves cross-platform compatibility between Python 2 and 3 by refactoring email attachment handling logic and updating corresponding tests. The changes focus on standardizing MIME type handling, base64 encoding, and payload decoding to ensure consistent behavior across Python versions.

Key changes:

  • Standardized attachment encoding/decoding to use base64 encoding consistently
  • Simplified MIME type detection and attachment creation logic
  • Updated tests to handle decoded attachment content properly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
qreu/email.py Refactored add_attachment method to use consistent base64 encoding and improved attachments property to decode payloads automatically
spec/qreu_spec.py Updated test cases to decode attachment content and removed legacy Python 2 compatibility code

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ecarreras ecarreras merged commit b37a31d into master Jul 30, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants