postfix milter简介

Milter介绍

Sendmail Content Management API
Open source Sendmail 8.12 and later
Postfix 2.3 开始支持 Milter 协议
Postfix 2.4 支持 sendmail 8.13.0 所有的请求接口
Postfix2.6 后支持所有 sendmail 8.14.0 所有请求接口


功能

enables third-party programs to access mail messages as theyare being processed by the Mail Transfer Agent (MTA)
allows them to examine and modify message content andmeta-information during the SMTP transaction


SMTP 和milter对应


SMTP Commands

Milter Callbacks

(open SMTP connection)

xxfi_connect

HELO ...

xxfi_helo

MAIL From: ...

xxfi_envfrom

RCPT To: ...

xxfi_envrcpt

[more RCPTs]

[xxfi_envrcpt]

DATA

xxfi_data

Header: ...

xxfi_header

[more headers]

[xxfi_header]

 

xxfi_eoh

body...

xxfi_body

[more body...]

[xxfi_body]

.

xxfi_eom

QUIT

xxfi_close


工作原理

For each of N connections

{

        For each filter

                processconnection (xxfi_connect)

        For each filter

                processhelo (xxfi_helo)

MESSAGE:For each message in thisconnection (sequentially)

        {

                Foreach filter

                       process sender (xxfi_envfrom)

                Foreach recipient

                {

                       For each filter

                                processrecipient (xxfi_envrcpt)

                }

                Foreach filter

                {

                       process DATA (xxfi_data)

                       For each header

                                process header(xxfi_header)

                       process end of headers (xxfi_eoh)

                       For each body block

                                process thisbody block (xxfi_body)

                       process end of message (xxfi_eom)

                }

        }

        For each filter

                processend of connection (xxfi_close)

}


The lifetime of a connection is bracketed by calls to thecallbacks xxfi_connect and xxfi_close
•Each message is bracketed by calls to xxfi_envfrom and xxfi_eom (or xxfi_abort )


API

Library Control Functions

Function

Description

smfi_opensocket

Try to create the interface socket.

smfi_register

Register a filter.

smfi_setconn

Specify socket to use.

smfi_settimeout

Set timeout.

smfi_setbacklog

Define the incoming listen(2) queue size.

smfi_setdbg

Set the milter library debugging (tracing) level.

smfi_stop

Cause an orderly shutdown.

smfi_main

Hand control to libmilter.


Data Access Functions

Function

Description

smfi_getsymval

Return the value of a symbol.

smfi_getpriv

Get the private data pointer.

smfi_setpriv

Set the private data pointer.

smfi_setreply

Set the specific reply code to be used.

smfi_setmlreply

Set the specific multi-line reply to be used.


Message Modification Functions

Function

Description

SMFIF_* flag

smfi_addheader

Add a header to the message.

SMFIF_ADDHDRS

smfi_chgheader

Change or delete a header.

SMFIF_CHGHDRS

smfi_insheader

Insert a header into the message.

SMFIF_ADDHDRS

smfi_chgfrom

Change the envelope sender address.

SMFIF_CHGFROM

smfi_addrcpt

Add a recipient to the envelope.

SMFIF_ADDRCPT

smfi_addrcpt_par

Add a recipient including ESMTP parameter to the envelope.

SMFIF_ADDRCPT_PAR

smfi_delrcpt

Delete a recipient from the envelope.

SMFIF_DELRCPT

smfi_replacebody

Replace the body of the message.

SMFIF_CHGBODY


Callbacks

Function

Description

xxfi_connect

connection info

xxfi_helo

SMTP HELO/EHLO command

xxfi_envfrom

envelope sender

xxfi_envrcpt

envelope recipient

xxfi_data

DATA command

xxfi_unknown

Unknown SMTP command

xxfi_header

header

xxfi_eoh

end of header

xxfi_body

body block

xxfi_eom

end of message

xxfi_abort

message aborted

xxfi_close

connection cleanup

xxfi_negotiate

option negotiattion


Other Message Handling Functions

Function

Description

smfi_progress

Report operation in progress.

smfi_quarantine

Quarantine a message.


•Miscellaneous

Function

Description

smfi_version

libmilter (runtime) version info

smfi_setsymlist

Set the list of macros that the milter wants to receive from the MTA for a protocol stage.



return value

Return value

SMFIS_CONTINUE

Continue processing the current connection, message, or recipient.

SMFIS_REJECT

For a connection-oriented routine, reject this connection; callxxfi_close.

For a message-oriented routine (except xxfi_eom orxxfi_abort), reject this message.

For a recipient-oriented routine, reject the current recipient (but continue processing the current message).

SMFIS_DISCARD

For a message- or recipient-oriented routine, accept this message, but silently discard it.

SMFIS_DISCARD should not be returned by a connection-oriented routine.


SMFIS_SKIP

Skip further callbacks of the same type in this transaction. Currently this return value is only allowed in xxfi_body(). It can be used if a milter has received sufficiently many body chunks to make a decision, but still wants to invoke message modification functions that are only allowed to be called from xxfi_eom(). Note: the milter must negotiate this behavior with the MTA, i.e., it must check whether the protocol action SMFIP_SKIP is available and if so, the milter must request it.

SMFIS_NOREPLY

Do not send a reply back to the MTA. The milter must negotiate this behavior with the MTA, i.e., it must check whether the appropriate protocol action SMFIP_NR_* is available and if so, the milter must request it. If you set the SMFIP_NR_* protocol action for a callback, that callback must always reply with SMFIS_NOREPLY. Using any other reply code is a violation of the API. If in some cases your callback may return another value (e.g., due to some resource shortages), then you must not set SMFIP_NR_* and you must use SMFIS_CONTINUE as the default return code. (Alternatively you can try to delay reporting the problem to a later callback for which SMFIP_NR_* is not

SMFIS_ACCEPT

For a connection-oriented routine, accept this connection without further filter processing; call xxfi_close.

For a message- or recipient-oriented routine, accept this message without further filtering.

SMFIS_TEMPFAIL

Return a temporary failure, i.e., the corresponding SMTP command will return an appropriate 4xx status code. For a message-oriented routine (except xxfi_envfrom), fail for this message.

For a connection-oriented routine, fail for this connection; call xxfi_close.

For a recipient-oriented routine, only fail for the current recipient; continue message processing.



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值