快速查看並永久刪除 Gmail 中與特定標籤和搜尋查詢相符的電子郵件。
建立此命令是為了刪除 GMail Web 介面和 IMAP 無法處理的超過 120k 則訊息(它們只是逾時)。另外,我還需要一個專案來測試一堆 CI 工具。
從發布頁面下載適用於您的作業系統的壓縮二進位檔案並解壓縮。
或者,如果您安裝了節點,則只需使用git
複製此儲存庫,然後執行npm install
。之後,您可以按照下面的範例操作,將所有對gmail_cleaner-linux
引用替換為node gmail_cleaner.js
。
刪除Categories/Updates
標籤中最多 15k 封電子郵件:
$ ./gmail_cleaner-linux delete -l " CATEGORY_UPDATES " -n 15000
Found 10381 matching emails in CATEGORY_UPDATES. Deleting them ...
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
1000 messages deleted.
381 messages deleted.
使用emails
命令驗證結果:
$ ./gmail_cleaner-linux emails -l " CATEGORY_UPDATES "
No emails found.
使用 Gmail 查詢來定位特定電子郵件,並在刪除它們之前檢查範例:
$ ./gmail_cleaner-linux delete -s -l " Corp " -q " subject:Birthday " --dry-run
Found 47 matching emails in Corp. Deleting them ...
dry-run is active, skip deleting emails.
$ ./gmail_cleaner-linux emails -s -l " Corp " -q " subject:Birthday " -n 3 --no-snippet
retrieving headers for 3 emails ..
Matching email messages:
Date From Subject
Thu, 7 Nov 2019 22:00:14 +0000 Corp App < [email protected] > [Employee] Happy Birthday To Foo
Wed, 6 Nov 2019 22:06:52 +0000 Corp App < [email protected] > [Employee] Happy Birthday To Bar
Tue, 5 Nov 2019 22:00:13 +0000 Corp App < [email protected] > [Employee] Happy Birthday To 42
$ ./gmail_cleaner-linux delete -l " Corp " -q " subject:Birthday "
Found 47 matching emails in Corp. Deleting them ...
47 messages deleted.
$ ./gmail_cleaner-linux emails -s -l " Corp " -q " subject:Birthday "
no emails found.
使用--help
或-h
查看使用資訊。
$ ./gmail_cleaner-linux -h
Usage: gmail_cleaner-linux < command > [options]
Commands:
gmail_cleaner-linux labels List all available Gmail labels
gmail_cleaner-linux emails List emails matching specific label and query
gmail_cleaner-linux delete Delete emails matching specific label and query
Options:
--version Show version number [boolean]
--sec-warning-off, -s Don ' t display security warning [boolean]
--verbose, -v Show more verbose information [boolean]
--help, -h Show help [boolean]
Examples:
gmail_cleaner-linux delete -l "SPAM" Delete all emails labeled "SPAM"
gmail_cleaner-linux delete -l "INBOX" -q Delete emails in "INBOX" that has
"subject:spam" --unsafe ' spam ' in subject
您還可以查看有關特定命令的更多信息,如下所示:
$ ./gmail_cleaner-linux delete -h
$ ./gmail_cleaner-linux emails -h
作為身份驗證過程的一部分,該程式預設將暫時開啟本機主機上的連接埠 31338/tcp。您可以透過指定環境變數GMAIL_CLEANER_PORT
來使用其他端口,例如:
$ GMAIL_CLEANER_PORT=1337 ./gmail_cleaner.js labels
該程式使用 Gmail API,因此您必須先授權它才能存取您的 Gmail 帳戶。
第一次存取 Gmail 時,程式將無法找到gmail_token.json
文件,並會回退顯示授權 URL。在瀏覽器中開啟它,然後按照步驟授權程式存取您的帳戶。
第一次運行後,您應該小心處理gmail_token.json
檔案:有權存取該檔案的任何人也將有權存取您的 Gmail 帳戶。除非使用-s
開關將其關閉,否則 Gmail Cleaner 將在每次運行時顯示以下安全警告。
** SECURITY WARNING **
Do the following when you no longer need to use this program in the near future.
- Remove the app access to your account from https://myaccount.google.com/u/2/permissions
- Remove gmail_token.json file. Anyone who has access to it will have full control over your Gmail account.
請注意,從 https://myaccount.google.com/u/2/permissions 中刪除應用程式存取權限只會使gmail_token.json
失效,因此它無法再用於存取您的 Gmail 帳戶。 Gmail Cleaner「應用程式」實際上並不具有或不需要儲存gmail_token.json
內容或有關您帳戶的任何資訊的伺服器/雲端元件。如果這還不夠好,那麼您可以隨時使用以下說明建立自己的「應用程式」。
https://mail.google.com/
新增至要授權的範圍清單( gmail_cleaner
使用的 batchDelete API 需要該範圍)。./lib/client_id.json
檔案。gmail_token.json
檔案。之後,下次運行該程式時,它會提示授權您自己的應用程序,而不是預設的應用程式。