Procmail 是否有小写函数或类似的功能?
我正在使用以下(经典)procmail 配方来捕获邮件列表电子邮件并按列表名称将它们归档到文件夹中:
:0
* ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
{
LISTID=$MATCH
:0
* LISTID ?? ^\/[^@\.]*
Lists/$MATCH/
}
问题是:如果列表名称从全部小写更改为 Firstlettercap,我最终会得到两个文件夹,一个用于“列表名称”,另一个用于“列表名称”。
我想在最终传递规则中使用 $MATCH 变量之前将其小写,但我无法找到对 lc() 函数的引用,或可用于执行此操作的正则表达式/替换。
下面的一条评论提出了这一点:
:0
* ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
{
LISTID=`echo "$MATCH" | tr A-Z a-z`
:0
* LISTID ?? ^\/[^@\.]*
.Lists.$MATCH/
}
这似乎也没有达到我的要求。不过,现在看,显然音译只发生在第一次出现 $MATCH 时,我的猜测是它根本没有改变它以用于文件夹分配行。
更新#1:如果我尝试在文件夹分配行中使用 LISTID,我会得到类似“Bricolage.project.29601.lighthouseapp”的内容,而不仅仅是“Bricolage”或 - 我所追求的 - 只是“bricolage”。
I'm using the following (classic) procmail recipe to catch mailing list e-mails and file them into a folder by list name:
:0
* ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
{
LISTID=$MATCH
:0
* LISTID ?? ^\/[^@\.]*
Lists/$MATCH/
}
The problem is: if a list name changes from all lowercase to Firstlettercap, I end up with two folders, one for 'listname' and another for 'Listname'.
I'd like to lowercase the $MATCH variable before using it in the final delivery rule, but I'm not able to find a reference to a lc() function, or a regex/replacement that can be used to do this.
One comment below suggested this:
:0
* ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
{
LISTID=`echo "$MATCH" | tr A-Z a-z`
:0
* LISTID ?? ^\/[^@\.]*
.Lists.$MATCH/
}
Which also doesn't appear to do what I'm after. Though, looking at it now, clearly the transliteration is only happening on the first occurrence of $MATCH and my guess is that it's not changing it at all for the use in the folder assignment line.
UPDATE #1: If I try to use LISTID in the folder assignment line, I get something like 'Bricolage.project.29601.lighthouseapp' instead of just 'Bricolage' or -- what I'm after -- just 'bricolage'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Procmail 本身没有用其他文本替换文本的功能。您可以通过
tr
运行匹配,或者如果避免外部进程确实很重要,请为需要映射的每个字母创建一个规则。您可以将其与最终的 MATCH 处理结合起来,但为了清楚起见,我将其保留于此。
Procmail itself has no functionality to replace text with other text. You can run the match through
tr
, or if avoiding external processes is really important, create a rule for each letter you need to map.You could combine this with the final MATCH processing but I leave it at this for purposes of clarity.
AFAIK procmail 正则表达式总是不区分大小写的,所以你不需要做任何特殊的事情就已经得到你想要的了。至少我总是这样使用它,并且我检查过的所有具有 procmail 文档的网站(3+)也都是这么说的。
AFAIK procmail regular expressions are always case INsensitive anyway, so you already get what you want without doing anything special. At least I always used it that way, and all the sites with procmail documentation I checked (3+) said so too.