Skip to content

Backup your Gmail

Previous

之前是使用Thunderbird同步,但是这个GUI工具并不能让我自动化的脚步就此停下。 1

另外Thunderbird的设置有两处让我迷糊:

  1. Account Settings/ACCOUNT NAME/Synchronization & Storage,这里可以设置为同步所有邮件,且不删除任何邮件。
  2. Preferences/Advance/Network & Disk Space这儿的的值只能设置为1024和2048,没法更大。

最后找到文档 Advanced panel - System, network, updates, and other advanced settings in Thunderbird,才知道这个是针对那些本机不保留的邮件,也就是第一个设置里 Message Synchronization 标题下的 Keep messages for this account on this computer 勾选了,这儿的disk space设置对其不影响。

Tips

Messages you view, which are not kept on your computer, are normally stored in a special cache folder for quicker viewing the next time you view the message. You can specify the amount of disk space the cache can use here. You can also immediately clear the contents of the cache.

Mbox vs Maildir

Thunderbird使用的是mbox格式,也就是一个Folder的邮件放到一个文件,例如INBOX(header放在INBOX.msf)。 而我更倾向于Maildir,但是呢,似乎Thunderbird对其支持并不成熟,Maildir in Thunderbird,开发完成度也不是很高,Thunderbird/Maildir

On the road

当然也可以自己造一个轮子,但是暂时精力有限,我还是先Get Things Done吧。2 搜索一番,发现基本就两个项目还算可以入选:3 4

  1. gmvault 尽管文档丰富,但是最后一次更新是2016年,所以就出局了。
  2. offlineimap 这个作者已经不开发新功能了(因为他又起了新的坑imapfw),但是好歹还是没放弃,也一直在修修补补。

Get the job done

  1. pip install --user offlineimap
  2. 配置 ~/.offlineimap,例子如下,设置了两个账户,一个是test,是通过密码认证(运行时会提示输入),这个需要开启less secure apps access。另外一个账户是prod,这个需要通过gmail-oauth2-tools手工获取token。 5
  3. offlineimap -a test,prod

XOAuth认证的不需要输入密码,普通用户名和密码方式如果不设置remotepass是需要在运行时输入密码,不建议采用此种方式。 还有,需要注意一点是,记得去Gmail的Settings/Labels里把需要同步的label都打开,Show in IMAP,然后确保All Mail, Important, Starred这几个取消显示,否则会重复备份。

~/.offlineimaprc
[general]
accounts = test,prod
# Server said: command: EXAMINE
# https://github.com/OfflineIMAP/offlineimap/issues/183
#maxconnections = 1
#maxsynaccounts = 1

[Account test]
localrepository = test-local
remoterepository = test-remote

[Repository test-local]
type = Maildir
localfolders = /path/to/imap/test

[Repository test-remote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = xxx
remotepass = xxx
ssl = yes
starttls = no
sslcacertfile = /etc/ssl/certs/ca-certificates.crt

[Account prod]
localrepository = prod-local
remoterepository = prod-remote

[Repository prod-local]
type = Maildir
localfolders = /path/to/imap/prod

[Repository prod-remote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = xxx
ssl = yes
starttls = no
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
auth_mechanisms = XOAUTH2
oauth2_client_id = xxx
oauth2_client_secret = xxx
oauth2_request_url = https://accounts.google.com/o/oauth2/token
oauth2_refresh_token = xxx

  1. 去年听说Thunderbird要挂了,例如 Mozilla: We will keep Thunderbird after all, so long as it's not a burden to Firefox,虽然后来官网发了 Thunderbird’s Future prodNew Thunderbird Releases and New Thunderbird Staff。 

  2. 已经有个小轮子mailsync.py来从davmail处(davmail负责将私有exchange协议转化为imap)同步邮件到本地了。 

  3. 看到有人妻子去世发帖寻求帮助,备份Gmail邮件,Download all mail messages from Gmail including Sent folder items,最后估计是使用takeout备份的。 

  4. 这个got-your-back也还行,虽然提交少多了,但是看一堆issue报告,我也就放弃它了。 

  5. 参考Using Offlineimap with the Gmail IMAP API,需要去API & Services/Credentials 新建一个OAuth 2.0 other 类型的crendential。 

Comments

Comments