1 个不稳定版本
0.3.2 | 2022年11月20日 |
---|---|
0.3.1 |
|
0.3.0 |
|
#12 in #sieve
44KB
944 行
sieve-generator
这是一个命令行界面,用于根据接收者电子邮件地址生成不同文件夹的.sieve
电子邮件过滤器允许列表,通过JSON
文件配置。我有一个捕获所有电子邮件域,并使用它自动化允许列表创建过程,每次使用新电子邮件时。(例如,将something@domain.com
过滤到something
文件夹)
安装
cargo install sieve-generator
或下载二进制文件,仅在Linux上测试。
用法
假设我们有一个这样的JSON
配置文件
{
"domain.com": {
"options": { // global options
// if every folder should be a sub-folder of a domain named folder
"domain-as-first-folder": false,
},
"Newsletter": {
"Software": ["google", "facebook"],
"Business": "wallstreet"
},
"Utilities": {
"self": ["electricity"],
"Grocery": {
"localparts": "market",
// if title or sender contains keyword then go to label
// by default every labeled mail will not be marked read
// even if silent is set
"labels": {
"label": "keyword",
"label2": ["keyword2"]
},
"options": {
// the generic filter here will be grocery.secret and
// not utilities.grocery.secret
"orphan": true,
// mark all email of this folder as read
"silent": true,
// not generate generic filter for this folder
"generic": false
}
}
}
}
}
将生成一个.sieve
过滤器允许列表,其中
- 它适用于发送到
*@domain.com
的所有电子邮件 wallstreet@domain.com
将被过滤到Newsletter
父文件夹中的Business
文件夹,依此类推。- 使用
self
关键字设置具有子文件夹的父文件夹的过滤器(例如,Utilities
)。 - 有简写过滤器(例如,
Business
文件夹)和全称过滤器(例如,Grocery
),允许指定选项和标签规则。 - 为文件夹树中的每个生成一个通用过滤器,例如,
newsletter.business.*@domain.com
被过滤到Business
文件夹。 - 默认情况下,未允许列表的所有邮件都将放入一个名为
Unknown
的文件夹中。 Unknown
是一个特殊文件夹,所有放入那里的邮件都将保持沉默,即使显式配置。
上面的JSON将产生
# @domain.com
if envelope :domain :is "to" "domain.com" {
# Custom filters
if envelope :localpart :matches "to" ["market"] {
if header :contains ["from","subject"] ["keyword","keyword2"] {
if header :contains ["from","subject"] ["keyword"] {
fileinto "label";
}
if header :contains ["from","subject"] ["keyword2"] {
fileinto "label2";
}
} else {
addflag "\\Seen";
fileinto "unread";
}
fileinto "Utilities";
fileinto "Utilities/Grocery";
} elsif envelope :localpart :matches "to" ["electricity"] {
fileinto "Utilities";
} elsif envelope :localpart :matches "to" ["google","facebook"] {
fileinto "Newsletter";
fileinto "Newsletter/Software";
} elsif envelope :localpart :matches "to" ["wallstreet"] {
fileinto "Newsletter";
fileinto "Newsletter/Business";
}
# Generic filters
elsif envelope :localpart :matches "to" ["utilities","utilities.*"] {
fileinto "Utilities";
} elsif envelope :localpart :matches "to" ["newsletter.software","newsletter.software.*"] {
fileinto "Newsletter";
fileinto "Newsletter/Software";
} elsif envelope :localpart :matches "to" ["newsletter.business","newsletter.business.*"] {
fileinto "Newsletter";
fileinto "Newsletter/Business";
} elsif envelope :localpart :matches "to" ["newsletter","newsletter.*"] {
fileinto "Newsletter";
} else {
addflag "\\Seen";
fileinto "Unknown";
}
}
依赖关系
~4–5.5MB
~103K SLoC