SDB:清理您的 IMAP 帐户

跳转到:导航搜索


对于你的IMAP账户来说,相当于一个好的扫帚的计算工具是你的朋友findgrep。 你需要访问你的IMAP账户的shell权限,该账户必须是Maildir格式。 Maildir将每封电子邮件存储为目录中的一个单独文件。

获取你的电子邮件

如前所述,首先,你需要将你的IMAP文件夹以Maildir格式获取到你的硬盘上。 这并不难,因为一些邮件客户端使用Maildir来存储你的电子邮件。 如果你喜欢的邮件客户端没有或者你不知道如何操作,你可以使用offlineimap来获取本地Maildir和远程IMAP之间的同步。

基本的offlineimap配置

你可以从以下最小配置开始

# Sample minimal config file.  Copy this to ~/.offlineimaprc and edit it

[general]
accounts = Test

[Account Test]
localrepository = Local
remoterepository = Remote

[Repository Local]
type = Maildir
localfolders = ~/Mail

[Repository Remote]
type = IMAP
remotehost = examplehost
remoteuser = geeko
remotepass = supersecret

然后你只需要运行offlineimap。 它将下载你所有的邮件,并且你将在硬盘上以Maildir格式拥有它们。 完成过滤后,你可能需要再次运行它以将你的更改同步回服务器。

过滤

我们想要find一些邮件。 我们将使用find来做到这一点。 这个工具将帮助我们获取所有文件。 但是我们只想要其中的一些,所以我们将使用grep来过滤我们想要和不想要的文件。 我们想要删除选定的文件。 让我们看几个例子。 通常我们将使用以下命令

find ~/Mail -type f -exec grep -l "any character pattern you would like to find goes here" \{\} \; -delete

它表示,我们想要find ~/Mail目录中的所有内容,这些内容是文件(-type f),对于所有文件,我们想要使用grep测试它们是否包含我们正在查找的表达式(-exec grep -l "expresion" \{\} \;),并且我们想要删除包含这些内容的邮件(-delete)。

示例 1

find ~/Mail -type f -exec grep -l "mailing-list@somewhere-you-do-not-subcribe-anymore.com" \{\} \; -delete

这将删除任何包含“mailing-list@somewhere-you-do-not-subcribe-anymore.com”的电子邮件。

示例 2

find ~/Mail -type f -exec grep -li "viagra" \{\} \; -delete

这将删除所有包含单词viagra的电子邮件。 grep中的额外i表示搜索不区分大小写,因此即使是ViAGrA也会匹配。

请键入

man find
man grep

以了解更多你可能喜欢的选项。 提示:你也可以使用它来清理你的主目录。