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.61k stars 207 forks source link

[feature request] Replacing labels on mbox-restore #227

Open smarek opened 5 years ago

smarek commented 5 years ago

Using latest version of GIT provided GYB

Situation: Google Takeout (G Suite Takeout) is from "Czech" locale (label Inbox is "Doručené", etc...)

Feature request: Map original label name to new label name, such as

./gyb.py --action restore-mbox --label-map Doručené,Inbox --label-map Důležité,Important ...

Temporary solution, i've successfully used, is to replace given labels with new ones in the mbox file, like this

# get list of labels sorted with count
grep X-Gmail-Labels Veškerá\ pošta\ včetně\ spamu\ a\ koše.mbox | sort -h | uniq -c | sort -n
# replace one of the labels appropriately
# care about placing ^ on the beginning of label and $ on the end, to not match partial labels
sed -i "s|^X-Gmail-Labels: =?UTF-8?Q?Odesl=C3=A1no,Nep=C5=99e=C4=8Dten=C3=A9?=$|X-Gmail-Labels: Sent,Unread|g" Veškerá\ pošta\ včetně\ spamu\ a\ koše.mbox
# after all the labels are replaced with correct ones, proceed with restore-mbox action
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

smarek commented 4 years ago

That's silly, marking issues without maintainer reaction as stale

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

kibeb commented 2 years ago

A workaround is to switch takeout.google.com to English first, then export. A simple query string ?hl=en would do, e.g. use https://takeout.google.com/settings/takeout?hl=en .

Otherwise gyb fails with e.g. this error message:

Creating label Nepřečtené
400: Invalid label name - invalidArgument

I presume this workaround only applies to Gmail system labels (Unread in this case), I'm yet to encounter any user defined label with non-ASCII characters.