在执行Postfix before-queue(perl)milter

时间:2016-08-26 07:26:36

标签: perl postfix-mta milter

问题:

尝试为Postfix编写一个milter,将电子邮件中某些标题的存在与出站中继主机的目标IP地址和TCP端口联系起来。

在Postfix milter guide之后,似乎我需要实现before-queue milter。

使用Sendmail::Milter perl模块执行此操作。

我可以在标题,信封等中获取所需的一切,除了它将被转发到的最终目的地(IP和端口)。显然对于before-queue milter来说是有道理的

从何处获取中继信息?

查看我们的Postfix日志,我可以看到以下格式的消息:

TIMESTAMP HOST postfix/qmgr[pid]: XXXXXXXXXX: log message here
TIMESTAMP HOST postfix/smtp[pid]: XXXXXXXXXX: log message here
TIMESTAMP HOST postfix/smtpd[pid]: XXXXXXXXXX: log message here

有些日志行有我正在寻找的中继信息,即:

<TIMESTAMP> <HOST> postfix/smtp[pid]: XXXXXXXXXX: to=EMAIL, relay=HOST[ADDR]:PORT, ...

ADDRPORT正是我正在寻找的。 XXXXXXXXXX似乎在日志中将它们联系在一起。根据你所谈论的内容,我被认为这被称为“队列ID”或“工作ID”。

如果我能从milter获得XXXXXXXXXX队列/作业ID,那么将日志绑定在一起就没问题了。

试过吗

看起来我可以通过从回调中调用$ctx->getsymval SYMNAME来获取某些供应商特定信息。

Additional information is passed in to the vendor filter routines using symbols. 
Symbols correspond closely to sendmail macros. The symbols defined depend on the 
context. SYMNAME is the name of the symbol to access.

This function returns the value of the symbol name SYMNAME.

milter指南有如下代码来获取'队列ID':

/* Determine the job ID for logging. */
if (dfc->mctx_jobid == 0 || strcmp(dfc->mctx_jobid, JOBIDUNKNOWN) == 0) {
        char *jobid = smfi_getsymval(ctx, "i");
        if (jobid != 0)
                dfc->mctx_jobid = jobid;
}

我无法弄清楚我是否可以通过getsymval(以及SYMNAME可能是什么)或通过其他一些上下文方法来获得该工作。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

使用以下内容获取queue_id。

my $queue_id = $ctx->getsymval('i');