offlineimap
跳转到导航
跳转到搜索
配置示例
腾讯邮箱
[general]
# List of accounts to be synced, separated by a comma.
accounts = main
maxsyncaccounts = 10
[Account main]
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.
localrepository = main-local
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.
remoterepository = main-remote
# Minutes between syncs
autorefresh = 2
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the
# only changes were to IMAP flags
quick = 10
[Repository main-local]
# Currently, offlineimap only supports maildir and IMAP for local repositories.
type = Maildir
# Where should the mail be placed?
localfolders = ~/.Maildir
nametrans = lambda foldername: foldername.decode('utf-8').encode('imap4-utf-7')
[Repository main-remote]
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.
type = IMAP
remotehost = imap.exmail.qq.com
remoteuser = xxxxxxx
remotepass = yyyyyyy
nametrans = lambda foldername: foldername.decode('imap4-utf-7').encode('utf-8')
# Instead of closing the connection once a sync is complete, offlineimap will
# send empty data to the server to hold the connection open. A value of 60
# attempts to hold the connection for a minute between syncs (both quick and
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen
# are not both set.
keepalive = 60
# OfflineIMAP normally closes IMAP server connections between refreshes if
# the global option autorefresh is specified. If you wish it to keep the
# connection open, set this to true. This setting has no effect if autorefresh
# is not set.
holdconnectionopen = yes
# vim: se ft=dosini:
Gmail
只同步部分目录,并进行重命名:
~/.offlineimaprc:
[general]
accounts = gmail
maxsyncaccounts = 10
socktimeout = 60
pythonfile = ~/.offlineimap.py
[Account gmail]
localrepository = gmail-local
remoterepository = gmail-remote
[Repository gmail-local]
type = GmailMaildir
localfolders = ~/.Maildir
filename_use_mail_timestamp = no
nametrans = gmail_nametrans_local
[Repository gmail-remote]
type = Gmail
remoteuser = lilydjwg@gmail.com
sslcacertfile = /etc/ssl/cert.pem
ssl = yes
starttls = no
oauth2_client_id_eval = get_client_id("xxx@gmail.com")
oauth2_client_secret_eval = get_client_secret("xxx@gmail.com")
oauth2_access_token_eval = get_access_token("xxx@gmail.com")
nametrans = gmail_nametrans_remote
folderfilter = lambda foldername: foldername.encode('ascii').decode('imap4-utf-7') in ['INBOX', '[Gmail]/垃圾邮件', '[Gmail]/草稿']
~/.offlineimap.py:
import os
import json
import subprocess
_LOADED_DATA = {}
def _load_data(account):
with open(os.path.expanduser(f'~/.getmail/gmail/{account}.json')) as f:
_LOADED_DATA[account] = json.load(f)
def get_client_id(account):
if account not in _LOADED_DATA:
_load_data(account)
return _LOADED_DATA[account]['client_id']
def get_client_secret(account):
if account not in _LOADED_DATA:
_load_data(account)
return _LOADED_DATA[account]['client_secret']
def get_access_token(account):
cmd = [
'getmail-gmail-xoauth-tokens',
os.path.expanduser(f'~/.getmail/gmail/{account}.json'),
]
out = subprocess.check_output(cmd, text=True)
return out
def gmail_nametrans_remote(foldername):
foldername = foldername.removeprefix('[Gmail]/').encode('ascii').decode('imap4-utf-7')
if foldername == '垃圾邮件':
foldername = 'Spam'
elif foldername == '草稿':
foldername = 'Drafts'
return foldername
def gmail_nametrans_local(foldername):
if foldername == 'Spam':
foldername = '[Gmail]/垃圾邮件'
elif foldername == 'Drafts':
foldername = '[Gmail]/草稿'
return foldername.encode('imap4-utf-7').decode('ascii')