使用 offlineIMAP 仅下载 gmail 的收件箱

使用 offlineIMAP 仅下载 gmail 的收件箱

因此我的 offlineimap.conf 如下所示:

[general]
accounts = Gmail-raub

[Account Gmail-raub]
localrepository = Gmaillocal-mine
remoterepository = Gmailserver-mine
synclabels = yes
# This header is where labels go.  Usually you will be fine
# with default value (X-Keywords), but in case you want it
# different, here we go:
labelsheader = X-Keywords

[Repository Gmailserver-mine]
#This is the remote repository
type = Gmail
ssl = yes
remotepass = super-sercret-password
remoteuser = [email protected]
sslcacertfile = /etc/ssl/certs/ca-bundle.crt
ssl_version = tls1_2

folderfilter = lambda folder: folder in ('[Gmail]/Drafts')

[Repository Gmaillocal-mine]
#This is the 'local' repository
# type = Maildir
type = GmailMaildir
localfolders = ~/mail/gmail_offlineimap

通过上述设置,我可以下载草稿,但如果我用 [Gmail]/Inbox 替换 [Gmail]/Drafts 文件夹过滤器条目,它会照常启动

offlineimap -d imap -c offlineimap.conf 
OfflineIMAP 6.7.0
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
Debug mode: Forcing to singlethreaded.
Now debugging for imap: IMAP protocol debugging
Now debugging for : Other offlineimap related sync messages
Account sync Gmail-raub:
 [imap]: Using authentication mechanisms ['GSSAPI', 'XOAUTH2', 'CRAM-MD5', 'PLAI
N', 'LOGIN']
 *** Processing account Gmail-raub
 Establishing connection to imap.gmail.com:993
 [imap]:   39:53.12 Account sync Gmail-raub imaplib2 version 2.52
 [imap]:   39:53.12 Account sync Gmail-raub imaplib2 debug level 5, buffer level
 3

然后验证并列出我拥有的所有不同邮件文件夹。然后根据我的文件夹过滤器设置将它们全部过滤掉。但随后它只是关闭了连接:

    [...]
[imap]:   35:06.22 Account sync Gmail-raub state => LOGOUT
     [imap]:   35:06.22 Account sync Gmail-raub [sync] LOGOUT ()
     [imap]:   35:06.22 Account sync Gmail-raub state_change_pending.acquire
     [imap]:   35:06.22 Account sync Gmail-raub _request_push(IDEE11, LOGOUT, {}) = IDEE11
     [imap]:   35:06.22 Account sync Gmail-raub data=IDEE11 LOGOUT
    imap.gmail.com writer:
     [imap]:   35:06.22 imap.gmail.com writer > IDEE11 LOGOUT\r\n
    Account sync Gmail-raub:
     [imap]:   35:06.22 Account sync Gmail-raub LOGOUT:IDEE11.ready.wait
    imap.gmail.com reader:
     [imap]:   35:06.29 imap.gmail.com reader poll => [(4, 1)]
     [imap]:   35:06.29 imap.gmail.com reader rcvd 57
     [imap]:   35:06.29 imap.gmail.com reader < * BYE LOGOUT Requested\r\n
     [imap]:   35:06.29 imap.gmail.com reader < IDEE11 OK 73 good day (Success)\r\n
    imap.gmail.com handler:
     [imap]:   35:06.29 imap.gmail.com handler _put_response(* BYE LOGOUT Requested)
     [imap]:   35:06.29 imap.gmail.com handler untagged_responses[BYE] 0 += ["LOGOUT Requested"]
     [imap]:   35:06.29 imap.gmail.com handler BYE response: LOGOUT Requested
     [imap]:   35:06.29 imap.gmail.com handler terminating: 'connection terminated'
     [imap]:   35:06.29 imap.gmail.com handler LOGOUT:IDEE11.ready.set
    imap.gmail.com writer:
     [imap]:   35:06.29 imap.gmail.com writer finished
    imap.gmail.com handler:
     [imap]:   35:06.29 imap.gmail.com handler state_change_free.set
     [imap]:   35:06.29 imap.gmail.com handler finished
    imap.gmail.com reader:
     [imap]:   35:06.30 imap.gmail.com reader poll => [(4, 1)]
     [imap]:   35:06.30 imap.gmail.com reader rcvd 0
    Account sync Gmail-raub:
     [imap]:   35:06.34 Account sync Gmail-raub ["<class 'offlineimap.imaplib2.abort'>: command: LOGOUT => connection terminated"]
     [imap]:   35:06.34 Account sync Gmail-raub _close_threads
     [imap]:   35:06.34 Account sync Gmail-raub call shutdown
    imap.gmail.com reader:
     [imap]:   35:06.40 imap.gmail.com reader finished
    Account sync Gmail-raub:
     [imap]:   35:06.40 Account sync Gmail-raub state_change_pending.release
     [imap]:   35:06.40 Account sync Gmail-raub connection closed
     [imap]:   35:06.40 Account sync Gmail-raub _get_untagged_response(BYE) => ['LOGOUT Requested']
     *** Finished account 'Gmail-raub' in 0:01

为什么它会终止连接?它不像 [Gmail]/Inbox 吗?我也试过了

# folderfilter = lambda folder: folder in ('[Gmail]/INBOX')
# folderfilter = lambda folder: folder in ('INBOX')

并且它们中的任何一个都会导致不同的错误(但它们之间是相同的):

ERROR: getfolder() asked for a nonexisting folder 'INBOX'.

答案1

它不“喜欢” Inbox,因为收件箱的名称全部大写,名为

INBOX

使用一个小的 Python 脚本进行尝试

import getpass, imaplib

M = imaplib.IMAP4_SSL('pop.gmail.com', 'imaps')
M.login('[email protected]', getpass.getpass())

ret, data = M.select('INBOX', True)
print(ret, data)
M.close()

M.logout()

相关内容