快速查看并永久删除 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
文件。之后,下次运行该程序时,它会提示授权您自己的应用程序,而不是默认的应用程序。