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 206 forks source link

Restore from MBOX opens file in read AND write mode #327

Closed jay-eleven closed 2 years ago

jay-eleven commented 2 years ago

https://github.com/jay0lee/got-your-back/blob/0b721627a9b1a680b63dc7c43eda2e8e8b828ac5/fmbox.py#L75

When restoring from an .mbox file, gyb opens the file in binary mode both for reading and writing.

Wouldn't it be safer to open the file just in rb mode? 😅

jay0lee commented 2 years ago

That was copied pretty much line-for-line from Python's mailbox library:

https://github.com/python/cpython/blob/main/Lib/mailbox.py#L584

but agreed there's no reason for GYB to be opening RW at this point. I've gone ahead and made this change:

https://github.com/jay0lee/got-your-back/commit/bc784186c97fa638687235ea77e1a0c8c7e980f5

and nothing blew up in the tests so this should be fixed.