GAM-team / GAM-team/got-your-back

--cleanup on From headers with utf-8 characters

Open
#359 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3.1k
Forks
245
PR merge metrics
No merged PRs in 30d

Description

Please confirm the following:
* I have upgraded to the latest GYB release from https://github.com/jay0lee/got-your-back/releases and I still have this issue.
_v1.55 for Windows_
* I am typing the command as described in the GAM Wiki at https://github.com/jay0lee/got-your-back/wiki
Using `./gyb --email [email]@gmail.com --action restore --local-folder GYB-GMail-Backup-[email]@[domain].com --cleanup`

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
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](https://docs.python.org/3/library/email.header.html#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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in gyb.py at cleanup_from around lines 1706 and 1728, then trace the restore path through message_hygiene. Reproduce restore with --cleanup using a message whose From header contains a UTF-8 character and inspect the value passed to parseaddr. Done means the cleanup and restore complete without the reported Header-related TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.