GAM-team / got-your-back

Got Your Back (GYB) is a command line tool for backing up your Gmail messages to your computer using Gmail's API over HTTPS.
https://github.com/GAM-team/got-your-back/wiki
Apache License 2.0
2.6k stars 205 forks source link

--cleanup on From headers with utf-8 characters #359

Open dantasfiles opened 2 years ago

dantasfiles commented 2 years ago

Please confirm the following:

Full steps to reproduce the issue: Try to cleanup and restore an email that has utf-8 characters in the From header

Expected outcome (what are you trying to do?): Email is cleaned up and restored

Actual outcome (what errors or bad behavior do you see instead?):

Traceback (most recent call last):
  File "gyb.py", line 2532, in <module>
  File "gyb.py", line 2007, in main
  File "gyb.py", line 1769, in message_hygiene
  File "gyb.py", line 1713, in cleanup_from
  File "email\utils.py", line 215, in parseaddr
  File "email\_parseaddr.py", line 513, in __init__
  File "email\_parseaddr.py", line 256, in getaddrlist
TypeError: object of type 'Header' has no len()
[8912] Failed to execute script 'gyb' due to unhandled exception!

Normally, the line https://github.com/GAM-team/got-your-back/blob/e6f3c7b056a971dec9081d5254aceed941d414af/gyb.py#L1728 will return a string containing the contents of the From header

But if the From header has a utf-8 character (U+00AE in my case), the above line will return an email.header.Header object

Then in line https://github.com/GAM-team/got-your-back/blob/e6f3c7b056a971dec9081d5254aceed941d414af/gyb.py#L1706 parseaddr dies because it's passed an email.header.Header object, not a string.

I'm not even sure if From headers are supposed to have utf-8 characters in them, as this only came up in 3 emails I was restoring that happened to be spam. My workaround was to run the restore operation without the cleanup option for a block of 15 emails (that contained the offending character), then Ctrl-C, and run the restore operation with the cleanup operation on the rest of my emails.

chazy commented 2 years ago

I can confirm I am also seeing this issue.