我正在尝试将来自票证系统的传入邮件分类到包含票号的邮件目录中。
发件人是:[email protected]
主题始终包含:RequestID: <numbers>
所以我尝试使用以下规则集:
match "^From:.*ticketsys@test\.de" in headers {
match "^Subject:.*RequestID:[ \t]*([0-9]*)" action tag "ticketno" value "%1" continue
match matched action "ticket"
match unmatched action keep
}
行动票看起来像这样:
action "ticket" maildir "%h/Mails/work/INBOX.Ticket-%[ticketno]"
它匹配,但新创建的文件夹以减号 ( Mails/work/INBOX.Ticket-
) 结尾,就好像标记不成功一样。
更新:
以下是来自的日志fdm -kvvvv fetch
:
WORK: trying (match) message 26
WORK: matching from 0 to 1586 (size=3876, body=1586)
WORK: tried regexp "^From:.*ticketsys@test\.de" in headers, result now 1
WORK: finished rule 17, result 1
WORK: matched to rule 17
WORK: entering nested rules
WORK: trying (match) message 26
WORK: matching from 0 to 3876 (size=3876, body=1586)
WORK: tried regexp "^Subject:.*RequestID:[ ]*([0-9]*)" in any, result now 1
WORK: finished rule 18, result 1
WORK: matched to rule 18
WORK: action <rule 18>:0 (tag), user andres
WORK: match message 26, deliver
WORK: trying (deliver) message 26
WORK: message 26, running action <rule 18>:0 (tag) as user andres
WORK: tagging message: ticketno ()
WORK: message 26 delivered (rule 18, tag) in 0.000 seconds
WORK: trying (deliver) message 26
WORK: deliver message 26, blocked
WORK: calling fetch state (0x416b00, flags 0x00)
WORK: 5 file descriptors in use
WORK: deliver started, pid 10023
WORK: deliver user is: andres (1001/1001), home is: /home/andres
WORK: saving to maildir /home/andres/Mails/work/INBOX.Ticket-
WORK: creating /home/andres/Mails/work
WORK: trying /home/andres/Mails/work/INBOX.Ticket-/tmp/1485412884.10023_0.HGL-049
WORK: writing to /home/andres/Mails/work/INBOX.Ticket-/tmp/1485412884.10023_0.HGL-049
WORK: moving .../tmp/1485412884.10023_0.HGL-049 to .../new/1485412884.10023_0.HGL-049
WORK: reading mail from: /home/andres/Mails/work/INBOX/cur/1485348562_1.29104.HGL-049,U=443306,FMD5=7e33429f656f1e6e9d79b29c3f82c57e:2,S
票号未写入邮件目录。
更新2:
更新到最新的 fdm 版本以确保包含所有修复
如何将标签写入邮件目录名称?
更新3:
主题行如下所示:
Subject: =?iso-8859-1?Q?Empfangsbest=E4tigung_f=FCr_Service?=
=?iso-8859-1?Q?_Request_mit_der_Service_RequestID:?=
=?iso-8859-1?Q?_1710000261_/__Domain:.test.de?=
=?iso-8859-1?Q?_Subdmonains_f=FCr_Staging_Zwecke?=
答案1
似乎fdm
没有进行 MIME 标头解码,因此当邮件标头被编码时,例如 as =?iso-8859-1?Q?...
,您必须在正则表达式中明确考虑这一点。请注意,fdm 会在正则表达式阶段将多行标题连接到一行中以帮助您。
因此,如果您可以保证邮件的发件人始终使用完全相同的标头编码,您可以将正则表达式替换为类似的内容
match "^Subject:.*RequestID:.*\?Q\?_([0-9]*)" action tag "ticketno" value "%1" continue
这样您就可以跳过编码标头。然而,一个更干净的解决方案是引入一些 perl 代码(或类似的代码)将标头解码为 uft8,然后与原始正则表达式匹配。创建一个文件,例如/tmp/decodesubject
,包含以下内容:
#!/usr/bin/perl
use open qw/:std :encoding(utf-8)/;
use Mail::Header; # perl-MailTools
use Encode;
my $head = new Mail::Header \*STDIN, FoldLength=>999;
my $subject = $head->get('Subject');
$subject = Encode::decode('MIME-Header', $subject); # -> utf8
print "Subject: $subject";
并使其可执行chmod +x /tmp/decodesubject
。您可能需要安装诸如perl-MIME-tools
或 之类的软件包libmime-tools-perl
才能获取这些Mail::Header
功能。该脚本读取标准输入上的邮件并仅打印解码后的主题标头。要从配置文件中调用它,请将上面的match
行替换为
match pipe "/tmp/decodesubject" returns (0,"Subject:.*RequestID:[ \t]*([0-9]*)")
action tag "ticketno" value "%[command1]" continue
请注意,要获取命令的正则表达式中的捕获组,pipe
您似乎不能使用%1
但必须使用"%[command1]"
。