Skip to content

fix encoding issues when using umlauts in from/to headers#405

Open
MrTango wants to merge 2 commits into
masterfrom
fix_encoding_for_utf8_headers
Open

fix encoding issues when using umlauts in from/to headers#405
MrTango wants to merge 2 commits into
masterfrom
fix_encoding_for_utf8_headers

Conversation

@MrTango

@MrTango MrTango commented May 16, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@MrTango MrTango requested a review from petschki May 16, 2023 10:07

@petschki petschki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd use plone.base.utils.safe_bytes instead.

And the import at the top should be changed to plone.base.utils.safe_text

@MrTango MrTango force-pushed the fix_encoding_for_utf8_headers branch 3 times, most recently from b2654ad to db6dbf0 Compare May 16, 2023 10:46

@mauritsvanrees mauritsvanrees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks.

@mauritsvanrees mauritsvanrees dismissed petschki’s stale review July 27, 2023 15:17

Requested changes have been made.

@mauritsvanrees mauritsvanrees force-pushed the fix_encoding_for_utf8_headers branch from db6dbf0 to c858d53 Compare July 27, 2023 15:19
@mauritsvanrees

Copy link
Copy Markdown
Member

I rebased on master and force-pushed.

@mauritsvanrees

Copy link
Copy Markdown
Member

Lots of test failures like this:

AttributeError: 'bytes' object has no attribute 'encode'

@mauritsvanrees

Copy link
Copy Markdown
Member

@MrTango I don't know why no tests show up here. But locally lots of tests fail like this:

Error in test testMultiRecipientOverrideByString (collective.easyform.tests.testMailer.TestFunctions.testMultiRecipientOverrideByString)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/community/collective.easyform/src/collective/easyform/tests/testMailer.py", line 380, in testMultiRecipientOverrideByString
    mailer.onSuccess(data, request)
  File "/Users/maurits/community/collective.easyform/src/collective/easyform/actions.py", line 553, in onSuccess
    mailtext = self.get_mail_text(fields, request, context)
  File "/Users/maurits/community/collective.easyform/src/collective/easyform/actions.py", line 548, in get_mail_text
    return outer.as_string()
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/message.py", line 188, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/generator.py", line 117, in flatten
    self._write(msg)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/generator.py", line 200, in _write
    self._write_headers(msg)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/generator.py", line 227, in _write_headers
    folded = self.policy.fold(h, v)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/_policybase.py", line 334, in fold
    return self._fold(name, value, sanitize=True)
  File "/Users/maurits/.pyenv/versions/3.11.11/lib/python3.11/email/_policybase.py", line 377, in _fold
    parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
AttributeError: 'bytes' object has no attribute 'encode'

I wonder if on Python 3 these headers need to be passed in as strings (text) anyway now...

@MrTango MrTango force-pushed the fix_encoding_for_utf8_headers branch from c858d53 to 6826fe4 Compare August 5, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants