[GH-ISSUE #73] UnicodeDecodeError #53

Open
opened 2026-02-25 23:39:43 +03:00 by kerem · 9 comments
Owner

Originally created by @aleohl on GitHub (Dec 15, 2023).
Original GitHub issue: https://github.com/HaschekSolutions/opentrashmail/issues/73

Hello,

During receive of an email I got this error message 'utf-8' codec can't decode byte 0xf6 in position 499: invalid start byte.
I do think it was caused by åäö in the subject or body but not sure yet. Will try to reproduce and check what I can do in the code.

Thanks.

Originally created by @aleohl on GitHub (Dec 15, 2023). Original GitHub issue: https://github.com/HaschekSolutions/opentrashmail/issues/73 Hello, During receive of an email I got this error message `'utf-8' codec can't decode byte 0xf6 in position 499: invalid start byte`. I do think it was caused by `åäö` in the subject or body but not sure yet. Will try to reproduce and check what I can do in the code. Thanks.
Author
Owner

@geek-at commented on GitHub (Dec 15, 2023):

I too have seen this error but was never able to reproduce it. Please tell me when you can reproduce it 😁

<!-- gh-comment-id:1857925772 --> @geek-at commented on GitHub (Dec 15, 2023): I too have seen this error but was never able to reproduce it. Please tell me when you can reproduce it 😁
Author
Owner

@aleohl commented on GitHub (Dec 15, 2023):

I have the same issue, can't seem to find a way to reproduce it. Strange stuff

<!-- gh-comment-id:1857973099 --> @aleohl commented on GitHub (Dec 15, 2023): I have the same issue, can't seem to find a way to reproduce it. Strange stuff
Author
Owner

@DasDunkel commented on GitHub (Jan 19, 2024):

I have managed to reproduce this error by using ö in the recipient address

Using it within the subject/body does not seem to cause the error

I'm using version 1.4.4

<!-- gh-comment-id:1900556185 --> @DasDunkel commented on GitHub (Jan 19, 2024): I have managed to reproduce this error by using `ö` in the recipient address Using it within the subject/body does not seem to cause the error I'm using version 1.4.4
Author
Owner

@sebastianflint commented on GitHub (Jan 23, 2024):

I have the same error. Happens when sending mail from Outlook Client and inserting characters like "ö,ä"

<!-- gh-comment-id:1905863907 --> @sebastianflint commented on GitHub (Jan 23, 2024): I have the same error. Happens when sending mail from Outlook Client and inserting characters like "ö,ä"
Author
Owner

@sebastianflint commented on GitHub (Jan 23, 2024):

Still the same error with the newest 1.4.5 version.

Remote Server returned '554 5.0.0 <[45.9.60.49] #5.0.0 smtp; 5.3.0 - Other mail system problem 500-"Error: (UnicodeDecodeError) 'utf-8' codec can't decode byte 0xe4 in position 0: invalid continuation byte" (delivery attempts: 0)>'

<!-- gh-comment-id:1906964384 --> @sebastianflint commented on GitHub (Jan 23, 2024): Still the same error with the newest 1.4.5 version. Remote Server returned '554 5.0.0 <[45.9.60.49] #5.0.0 smtp; 5.3.0 - Other mail system problem 500-"Error: (UnicodeDecodeError) 'utf-8' codec can't decode byte 0xe4 in position 0: invalid continuation byte" (delivery attempts: 0)>'
Author
Owner

@Pay1337 commented on GitHub (Apr 9, 2024):

I solved the problem by using "latin1" instead of "utf8" in mailserver3.py.

<!-- gh-comment-id:2044592082 --> @Pay1337 commented on GitHub (Apr 9, 2024): I solved the problem by using "latin1" instead of "utf8" in mailserver3.py.
Author
Owner

@geek-at commented on GitHub (Apr 15, 2024):

Thanks for telling us this @Pay1337

I wonder though if this means it would crash, receiving UTF8 encoded email 🧐

<!-- gh-comment-id:2056438573 --> @geek-at commented on GitHub (Apr 15, 2024): Thanks for telling us this @Pay1337 I wonder though if this means it would crash, receiving UTF8 encoded email 🧐
Author
Owner

@realalexandergeorgiev commented on GitHub (Nov 5, 2024):

2024-11-05 10:27:27,836 - __main__ - DEBUG - Receiving message from: ('193.169.180.112', 40718) (Plaintext)
2024-11-05 10:27:27,836 - __main__ - DEBUG - Message addressed from: return@service.rmvmail.de
2024-11-05 10:27:27,836 - __main__ - DEBUG - Message addressed to: ['foo@foo.com']
('193.169.180.112', 40718) SMTP session exception
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 756, in _handle_client
    await method(arg)
  File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 1519, in smtp_DATA
    status = await self._call_handler_hook('DATA')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 473, in _call_handler_hook
    status = await hook(self, self.session, self.envelope, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/www/opentrashmail/python/mailserver3.py", line 74, in handle_DATA
    plaintext += part.get_payload(decode=True).decode('utf-8')
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 249: invalid start byte

If you register at https://www.rmv.de/ you can reproduce it.

Cant retry, seems like there is a rate limit. If someone wants to try:
(vi /var/www/opentrashmail/python/mailserver3.py)

try:
    plaintext += part.get_payload(decode=True).decode('utf-8')
except UnicodeDecodeError:
    plaintext += part.get_payload(decode=True).decode('latin1')
except Exception as e:
        print(f"Error decoding payload: {e}")

fixed in fork, works for latin1:
github.com/realalexandergeorgiev/opentrashmail@9aeae959c2

<!-- gh-comment-id:2456806350 --> @realalexandergeorgiev commented on GitHub (Nov 5, 2024): ``` 2024-11-05 10:27:27,836 - __main__ - DEBUG - Receiving message from: ('193.169.180.112', 40718) (Plaintext) 2024-11-05 10:27:27,836 - __main__ - DEBUG - Message addressed from: return@service.rmvmail.de 2024-11-05 10:27:27,836 - __main__ - DEBUG - Message addressed to: ['foo@foo.com'] ('193.169.180.112', 40718) SMTP session exception Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 756, in _handle_client await method(arg) File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 1519, in smtp_DATA status = await self._call_handler_hook('DATA') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/aiosmtpd/smtp.py", line 473, in _call_handler_hook status = await hook(self, self.session, self.envelope, *args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/var/www/opentrashmail/python/mailserver3.py", line 74, in handle_DATA plaintext += part.get_payload(decode=True).decode('utf-8') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 249: invalid start byte ``` If you register at https://www.rmv.de/ you can reproduce it. Cant retry, seems like there is a rate limit. If someone wants to try: (vi /var/www/opentrashmail/python/mailserver3.py) ``` try: plaintext += part.get_payload(decode=True).decode('utf-8') except UnicodeDecodeError: plaintext += part.get_payload(decode=True).decode('latin1') except Exception as e: print(f"Error decoding payload: {e}") ``` fixed in fork, works for latin1: https://github.com/realalexandergeorgiev/opentrashmail/commit/9aeae959c29e9d554347a12dea71f7be7918b619
Author
Owner

@geek-at commented on GitHub (Nov 14, 2024):

Oh nice, sounds like a good solution until the root cause is fixed. Can you do a pull request?

<!-- gh-comment-id:2476168696 --> @geek-at commented on GitHub (Nov 14, 2024): Oh nice, sounds like a good solution until the root cause is fixed. Can you do a pull request?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentrashmail#53
No description provided.