.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Milter 3pm" .TH Milter 3pm "2015-09-27" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Sendmail::Milter \- Interface to sendmail's Mail Filter API .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Sendmail::Milter; \& \& my %my_milter_callbacks = \& ( \& \*(Aqconnect\*(Aq => \e&my_connect_callback, \& \*(Aqhelo\*(Aq => \e&my_helo_callback, \& \*(Aqenvfrom\*(Aq => \e&my_envfrom_callback, \& \*(Aqenvrcpt\*(Aq => \e&my_envrcpt_callback, \& \*(Aqheader\*(Aq => \e&my_header_callback, \& \*(Aqeoh\*(Aq => \e&my_eoh_callback, \& \*(Aqbody\*(Aq => \e&my_body_callback, \& \*(Aqeom\*(Aq => \e&my_eom_callback, \& \*(Aqabort\*(Aq => \e&my_abort_callback, \& \*(Aqclose\*(Aq => \e&my_close_callback, \& ); \& \& sub my_connect_callback; \& sub my_helo_callback; \& sub my_envfrom_callback; \& sub my_envrcpt_callback; \& sub my_header_callback; \& sub my_eoh_callback; \& sub my_body_callback; \& sub my_eom_callback; \& sub my_abort_callback; \& sub my_close_callback; \& \& \& BEGIN: \& { \& # Get myfilter\*(Aqs connection information \& # from /etc/mail/sendmail.cf \& \& Sendmail::Milter::auto_setconn("myfilter"); \& Sendmail::Milter::register("myfilter", \& \e%my_milter_callbacks, SMFI_CURR_ACTS); \& \& Sendmail::Milter::main(); \& \& # Never reaches here, callbacks are called from Milter. \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBSendmail::Milter\fR is a Perl extension to sendmail's Mail Filter \s-1API \s0(Milter). .PP \&\fBNote:\fR You need to have a Perl 5.6 or later interpreter built with \&\fB\-Dusethreads\fR. .SH "FUNCTIONS" .IX Header "FUNCTIONS" Portions of this document come from comments in the \fBlibmilter/mfapi.h\fR header file. .SS "Main Functions" .IX Subsection "Main Functions" \&\fBNote:\fR No functions are exported. You must call these functions explicitly from the \fBSendmail::Milter\fR package. .IP "register \s-1NAME, CALLBACKS\s0 [, \s-1FLAGS\s0]" 4 .IX Item "register NAME, CALLBACKS [, FLAGS]" Registers a mail filter \s-1NAME\s0 with hash reference \s-1CALLBACKS\s0 callbacks, and optional capability flags \s-1FLAGS. NAME\s0 is the same filter name that you would pass to \fBauto_setconn\fR. \s-1CALLBACKS\s0 is a hash reference that can contain any of the following keys: .Sp .Vb 10 \& connect \& helo \& envfrom \& envrcpt \& header \& eoh \& body \& eom \& abort \& close .Ve .Sp The values for these keys indicate the callback routine that is associated with each Milter callback. The values must be either function names, code references or closures. .Sp This function returns nonzero upon success, the undefined value otherwise. .Sp \&\fB\f(CB%Sendmail::Milter::DEFAULT_CALLBACKS\fB\fR is a hash with default function names for all of the Milter callbacks. The default callback function names are: .Sp \&\fBconnect_callback\fR, \fBhelo_callback\fR, \fBenvfrom_callback\fR, \&\fBenvrcpt_callback\fR, \fBheader_callback\fR, \fBeoh_callback\fR, \fBbody_callback\fR, \&\fBeom_callback\fR, \fBabort_callback\fR, \fBclose_callback\fR. .Sp See the section \fBWriting Milter Callbacks\fR for more information on writing the callbacks themselves. .Sp For more information on capability flags, see the section \fBCapability Flags\fR in the \fB\f(CB@EXPORT\fB\fR section. .IP "main [\s-1MAX_INTERPRETERS\s0] [, \s-1MAX_REQUESTS\s0]" 4 .IX Item "main [MAX_INTERPRETERS] [, MAX_REQUESTS]" Starts the mail filter. If successful, this function never returns. Instead, it launches the Milter engine which will call each of the callback routines as appropriate. .Sp \&\s-1MAX_INTERPRETERS\s0 sets the limit on the maximum number of interpreters that \&\fBSendmail::Milter\fR is allowed to create. These interpreters will only be created as the need arises and are not all created at startup. The default value is 0. (No maximum limit) .Sp \&\s-1MAX_REQUESTS\s0 sets the limit on the maximum number of requests an interpreter will process before being recycled. The default value is 0. (Don't recycle interpreters) .Sp This function returns nonzero on success (if a kill was signaled or something), the undefined value otherwise. .Sp \&\fBNote:\fR You should have at least registered a callback and set the connection information string before calling this function. .IP "setconn \s-1CONNECTION_INFO\s0" 4 .IX Item "setconn CONNECTION_INFO" Sets the connection information string for the filter. The format of this string is identical to that found in the Milter documentation. Some examples are \f(CW\*(C`local:/var/run/f1.sock\*(C'\fR, \f(CW\*(C`inet6:999@localhost\*(C'\fR, \f(CW\*(C`inet:3333@localhost\*(C'\fR. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "auto_setconn \s-1NAME\s0 [, \s-1SENDMAIL_CF_FILENAME\s0]" 4 .IX Item "auto_setconn NAME [, SENDMAIL_CF_FILENAME]" This function automatically sets the connection information by parsing the sendmail .cf file for the appropriate X line containing the connection information for the \s-1NAME\s0 mail filter and calling \fBsetconn\fR if it was successful. It is provided as a helper function and does not exist in the current Milter library. .Sp \&\fBNote:\fR This connection information isn't useful for implementing a Milter that resides on a machine that is remote to the machine running sendmail. In those cases, you will want to set the connection information manually with \&\fBsetconn\fR. .Sp This function returns nonzero upon success, the undefined value otherwise. .Sp \&\s-1SENDMAIL_CF_FILENAME\s0 defaults to \f(CW\*(C`/etc/mail/sendmail.cf\*(C'\fR if not specified. .IP "auto_getconn \s-1NAME\s0 [, \s-1SENDMAIL_CF_FILENAME\s0]" 4 .IX Item "auto_getconn NAME [, SENDMAIL_CF_FILENAME]" Similar to \fBauto_setconn\fR, this function parses the sendmail .cf file for the appropriate X line containing the connection information for \s-1NAME.\s0 It does not, however, call \fBsetconn\fR. It only retrieves the connection information. .Sp This function returns the connection information string for \s-1NAME,\s0 or undef on failure. .Sp \&\s-1SENDMAIL_CF_FILENAME\s0 defaults to \f(CW\*(C`/etc/mail/sendmail.cf\*(C'\fR if not specified. .IP "settimeout \s-1TIMEOUT\s0" 4 .IX Item "settimeout TIMEOUT" Sets the timeout for reads/writes in the Milter engine. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "setdbg \s-1LEVEL\s0" 4 .IX Item "setdbg LEVEL" Sets the debug level for the Milter engine. .Sp This function returns nonzero upon success, the undefined value otherwise. .SS "Writing Milter Callbacks" .IX Subsection "Writing Milter Callbacks" Writing Milter callbacks is pretty easy when you're doing simple text processing. .PP But remember one thing: Each Milter callback could quite possibly run in a different instance of the Perl interpreter. .PP \&\fBSendmail::Milter\fR launches multiple persistent Perl interpreters to increase performance (so it doesn't have to startup and shutdown the interpreters constantly). Thus, you can't rely on setting external package variables, global variables, or even running other modules which rely on such things. This will continue to be true while interpreter thread support in Perl is experimental. For more information, see perlfork. Most of that information applies here. .PP Remember to return one of the \fBSMFIS_*\fR result codes from the callback routine. Remember there can be multiple message body chunks. And remember that only \fBeom_callback\fR is allowed to manipulate the headers, recipients, message body, etc. .PP See the \fB\f(CB@EXPORT\fB\fR section for information on the \fBSMFIS_*\fR result codes. .PP Here is an example of a \fBconnect_callback\fR routine: .PP .Vb 2 \& # External modules are OK, but note the caveats above. \& use Socket; \& \& sub connect_callback \& { \& my $ctx = shift; # The Milter context object. \& my $hostname = shift; # The connection\*(Aqs host name. \& my $sockaddr_in = shift; \& my ($port, $iaddr) = sockaddr_in($sockaddr_in); \& \& print "Hostname is: " . $hostname . "\en"; \& \& # Cool, a printable IP address. \& print "IP Address is: " . inet_ntoa($iaddr) . "\en"; \& \& return SMFIS_CONTINUE; # Returning a value is important! \& } .Ve .PP \&\fBNote:\fR The \f(CW$ctx\fR Milter context object is not a true Perl object. It's really a blessed reference to an opaque C structure. Only use the Milter context functions (described in a later section) with this object. (Don't touch it, it's evil.) .SS "Milter Callback Interfaces" .IX Subsection "Milter Callback Interfaces" These interfaces closely mirror their Milter callback counterparts, however there are some differences that take advantage of Perl's syntactic sugar. .PP \&\fBNote:\fR Each callback receives a Milter context object as the first argument. This context object is used in making Milter Context function calls. See \fBMilter Context Functions\fR for more details. .IP "\fBconnect_callback\fR \s-1CTX, HOSTNAME, SOCKADDR_IN\s0" 4 .IX Item "connect_callback CTX, HOSTNAME, SOCKADDR_IN" Invoked on each connection. \s-1HOSTNAME\s0 is the host domain name, as determined by a reverse lookup on the host address. \s-1SOCKADDR_IN\s0 is the \s-1AF_INET\s0 portion of the host address, as determined by a \fB\f(BIgetpeername\fB\|(2)\fR syscall on the \s-1SMTP\s0 socket. You can use \fB\f(BISocket::unpack_sockaddr_in()\fB\fR to unpack it into a port and \s-1IP\s0 address. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBhelo_callback\fR \s-1CTX, HELOHOST\s0" 4 .IX Item "helo_callback CTX, HELOHOST" Invoked on \s-1SMTP HELO/EHLO\s0 command. \s-1HELOHOST\s0 is the value passed to \s-1HELO/EHLO\s0 command, which should be the domain name of the sending host (but is, in practice, anything the sending host wants to send). .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBenvfrom_callback\fR \s-1CTX, ARG1, ARG2, ...,\s0 ARGn" 4 .IX Item "envfrom_callback CTX, ARG1, ARG2, ..., ARGn" Invoked on envelope from. \s-1ARG1, ARG2, ...\s0 ARGn are \s-1SMTP\s0 command arguments. \s-1ARG1\s0 is guaranteed to be the sender address. Later arguments are the \s-1ESMTP\s0 arguments. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBenvrcpt_callback\fR \s-1CTX, ARG1, ARG2, ...,\s0 ARGn" 4 .IX Item "envrcpt_callback CTX, ARG1, ARG2, ..., ARGn" Invoked on each envelope recipient. \s-1ARG1, ARG2, ...\s0 ARGn are \s-1SMTP\s0 command arguments. \s-1ARG1\s0 is guaranteed to be the recipient address. Later arguments are the \s-1ESMTP\s0 arguments. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBheader_callback\fR \s-1CTX, FIELD, VALUE\s0" 4 .IX Item "header_callback CTX, FIELD, VALUE" Invoked on each message header. The content of the header may have folded white space (that is, multiple lines with following white space) included. \s-1FIELD\s0 is the header field name, \s-1VALUE\s0 is the header field value. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBeoh_callback\fR \s-1CTX\s0" 4 .IX Item "eoh_callback CTX" Invoked at end of header. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBbody_callback\fR \s-1CTX, BODY, LEN\s0" 4 .IX Item "body_callback CTX, BODY, LEN" Invoked for each body chunk. There may be multiple body chunks passed to the filter. End-of-lines are represented as received from \s-1SMTP \s0(normally Carriage\-Return/Line\-Feed). \s-1BODY\s0 contains the body data, \s-1LEN\s0 contains the length of the body data. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBeom_callback\fR \s-1CTX\s0" 4 .IX Item "eom_callback CTX" Invoked at end of message. This routine can perform special operations such as modifying the message header, body, or envelope. See the section on \&\fBeom_callback\fR in \fBMilter Context Functions\fR. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBabort_callback\fR \s-1CTX\s0" 4 .IX Item "abort_callback CTX" Invoked if message is aborted outside of the control of the filter, for example, if the \s-1SMTP\s0 sender issues an \s-1RSET\s0 command. If \fBabort_callback\fR is called, \fBeom_callback\fR will not be called and vice versa. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .IP "\fBclose_callback\fR \s-1CTX\s0" 4 .IX Item "close_callback CTX" Invoked at end of the connection. This is called on close even if the previous mail transaction was aborted. .Sp This callback should return one of the \fBSMFIS_*\fR result codes. .SS "Milter Context Functions" .IX Subsection "Milter Context Functions" These routines are object methods that are part of the \&\fBSendmail::Milter::Context\fR pseudo-package for use by \fBSendmail::Milter\fR callback functions. Any attempts to use them without a properly blessed Milter context object will fail miserably. Please see restrictions on when these routines may be called. .PP \&\fBContext routines available to all Milter callback functions:\fR .PP These functions are available to all types of Milter callback functions. It is worth noting that passing connection-private data by reference is probably more efficient than passing by value. .IP "\fB\f(CB$ctx\fB\fR\->setpriv \s-1DATA\s0" 4 .IX Item "$ctx->setpriv DATA" Each \fB\f(CB$ctx\fB\fR can contain connection-private data (specific to an \s-1SMTP\s0 connection). This routine can be used to allocate this private data. Calling this function with \s-1DATA\s0 set to the undefined value will clear Milter's pointer to this private data. You should always do this to decrement the private data's reference count. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "\fB\f(CB$ctx\fB\fR\->getpriv" 4 .IX Item "$ctx->getpriv" Each \fB\f(CB$ctx\fB\fR can contain connection-private data (specific to an \s-1SMTP\s0 connection). This routine can be used to retrieve this private data. .Sp This function returns a scalar containing \fB\f(CB$ctx\fB\fR's private data. .IP "\fB\f(CB$ctx\fB\fR\->getsymval \s-1SYMNAME\s0" 4 .IX Item "$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. \s-1SYMNAME\s0 is the name of the symbol to access. .Sp This function returns the value of the symbol name \s-1SYMNAME. \s0 .IP "\fB\f(CB$ctx\fB\fR\->setreply \s-1RCODE, XCODE, MESSAGE\s0" 4 .IX Item "$ctx->setreply RCODE, XCODE, MESSAGE" Set the specific reply code to be used in response to the active command. If not specified, a generic reply code is used. \&\s-1RCODE\s0 is the three-digit (\fB\s-1RFC 821\s0\fR) \s-1SMTP\s0 reply code to be returned, e.g. \f(CW551\fR. \&\s-1XCODE\s0 is the extended (\fB\s-1RFC 2034\s0\fR) reply code, e.g., \f(CW5.7.6\fR. \&\s-1MESSAGE\s0 is the text part of the \s-1SMTP\s0 reply. .Sp This function returns nonzero upon success, the undefined value otherwise. .PP \&\fBContext routines available only to the eom_callback function:\fR .PP The \fBeom_callback\fR Milter callback is called at the end of a message (essentially, after the final \s-1DATA\s0 dot). This routine can call some special routines to modify the envelope, header, or body of the message before the message is enqueued. These routines must not be called from any vendor routine other than \fBeom_callback\fR. .IP "\fB\f(CB$ctx\fB\fR\->addheader \s-1FIELD, VALUE\s0" 4 .IX Item "$ctx->addheader FIELD, VALUE" Add a header to the message. \s-1FIELD\s0 is the header field name. \s-1VALUE\s0 is the header field value. This header is not passed to other filters. It is not checked for standards compliance; the mail filter must ensure that no protocols are violated as a result of adding this header. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "\fB\f(CB$ctx\fB\fR\->chgheader \s-1FIELD, INDEX, VALUE\s0" 4 .IX Item "$ctx->chgheader FIELD, INDEX, VALUE" Change/delete a header in the message. \s-1FIELD\s0 is the header field name. \s-1INDEX\s0 is the Nth occurence of the header field name. \s-1VALUE\s0 is the new header field value (empty for delete header). It is not checked for standards compliance; the mail filter must ensure that no protocols are violated as a result of adding this header. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "\fB\f(CB$ctx\fB\fR\->addrcpt \s-1RCPT\s0" 4 .IX Item "$ctx->addrcpt RCPT" Add a recipient to the envelope. \s-1RCPT\s0 is the recipient to be added. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "\fB\f(CB$ctx\fB\fR\->delrcpt \s-1RCPT\s0" 4 .IX Item "$ctx->delrcpt RCPT" Delete a recipient from the envelope. \s-1RCPT\s0 is the envelope recipient to be deleted. This should be in exactly the same form passed to \fBenvrcpt_callback\fR or the address may not be deleted. .Sp This function returns nonzero upon success, the undefined value otherwise. .IP "\fB\f(CB$ctx\fB\fR\->replacebody \s-1DATA\s0" 4 .IX Item "$ctx->replacebody DATA" Replace the body of the message. \s-1DATA\s0 is the scalar containing the block of message body information to insert. This routine may be called multiple times if the body is longer than convenient to send in one call. End of line should be represented as Carriage\-Return/Line Feed. .Sp This function returns nonzero upon success, the undefined value otherwise. .ie n .SH "@EXPORT" .el .SH "\f(CW@EXPORT\fP" .IX Header "@EXPORT" \&\fBSendmail::Milter\fR exports the following constants: .SS "Callback Result Codes" .IX Subsection "Callback Result Codes" These are the possible result codes that may be returned by the Milter callback functions. If you do not specify a return value, \fBSendmail::Milter\fR will send a default result code of \fB\s-1SMFIS_CONTINUE\s0\fR back to Milter. .IP "\s-1SMFIS_CONTINUE\s0" 4 .IX Item "SMFIS_CONTINUE" Continue processing message/connection .IP "\s-1SMFIS_REJECT\s0" 4 .IX Item "SMFIS_REJECT" Reject the message/connection. No further routines will be called for this message (or connection, if returned from a connection-oriented routine). .IP "\s-1SMFIS_DISCARD\s0" 4 .IX Item "SMFIS_DISCARD" Accept the message, but silently discard the message. No further routines will be called for this message. This is only meaningful from message-oriented routines. .IP "\s-1SMFIS_ACCEPT\s0" 4 .IX Item "SMFIS_ACCEPT" Accept the message/connection. No further routines will be called for this message (or connection, if returned from a connection-oriented routine; in this case, it causes all messages on this connection to be accepted without filtering). .IP "\s-1SMFIS_TEMPFAIL\s0" 4 .IX Item "SMFIS_TEMPFAIL" Return a temporary failure, i.e., the corresponding \s-1SMTP\s0 command will return a 4xx status code. In some cases this may prevent further routines from being called on this message or connection, although in other cases (e.g., when processing an envelope recipient) processing of the message will continue. .SS "Capability Flags" .IX Subsection "Capability Flags" These are possible capability flags for what a mail filter can do. Normally, you should specify each capability explicitly as needed. .IP "\s-1SMFIF_ADDHDRS\s0" 4 .IX Item "SMFIF_ADDHDRS" Allows a mail filter to add headers. .IP "\s-1SMFIF_CHGBODY\s0" 4 .IX Item "SMFIF_CHGBODY" Allows a mail filter to change the message body. .IP "\s-1SMFIF_ADDRCPT\s0" 4 .IX Item "SMFIF_ADDRCPT" Allows a mail filter to add recipients. .IP "\s-1SMFIF_DELRCPT\s0" 4 .IX Item "SMFIF_DELRCPT" Allows a mail filter to delete recipients. .IP "\s-1SMFIF_CHGHDRS\s0" 4 .IX Item "SMFIF_CHGHDRS" Allows a mail filter to change headers. .IP "\s-1SMFIF_MODBODY\s0" 4 .IX Item "SMFIF_MODBODY" Allows a mail filter to change the message body. (Provided only for backwards compatibility) .SS "Capability Flag Sets" .IX Subsection "Capability Flag Sets" These provide sets of capability flags that indicate all of the capabilities in a particular version of Milter. \fB\s-1SMFI_CURR_ACTS\s0\fR is set to the capabilities in the current version of Milter. .IP "\s-1SMFI_CURR_ACTS\s0" 4 .IX Item "SMFI_CURR_ACTS" Enables the set of capabilities available to mail filters in the current version of Milter. .IP "\s-1SMFI_V1_ACTS\s0" 4 .IX Item "SMFI_V1_ACTS" Enables the set of capabilities available to mail filters in V1 of Milter. .IP "\s-1SMFI_V2_ACTS\s0" 4 .IX Item "SMFI_V2_ACTS" Enables the set of capabilities available to mail filters in V2 of Milter. .SH "EXAMPLES" .IX Header "EXAMPLES" .SS "Appending a line to the message body" .IX Subsection "Appending a line to the message body" .Vb 1 \& use Sendmail::Milter; \& \& my %my_milter_callbacks = \& ( \& \*(Aqeoh\*(Aq => \e&my_eoh_callback, \& \*(Aqbody\*(Aq => \e&my_body_callback, \& \*(Aqeom\*(Aq => \e&my_eom_callback, \& \*(Aqabort\*(Aq => \e&my_abort_callback, \& ); \& \& sub my_eoh_callback \& { \& my $ctx = shift; \& my $body = ""; \& \& $ctx\->setpriv(\e$body); \& \& return SMFIS_CONTINUE; \& } \& \& sub my_body_callback \& { \& my $ctx = shift; \& my $body_chunk = shift; \& my $body_ref = $ctx\->getpriv(); \& \& ${$body_ref} .= $body_chunk; \& \& # This is crucial, the reference to the body may have \& # changed. \& \& $ctx\->setpriv($body_ref); \& \& return SMFIS_CONTINUE; \& } \& \& sub my_eom_callback \& { \& my $ctx = shift; \& my $body_ref = $ctx\->getpriv(); \& \& # Note: This doesn\*(Aqt support messages with MIME data. \& \& ${$body_ref} .= "\-\-\-> Append me to this message body!\en"; \& \& $ctx\->replacebody(${$body_ref}); \& \& $ctx\->setpriv(undef); \& \& return SMFIS_ACCEPT; \& } \& \& sub my_abort_callback \& { \& my $ctx = shift; \& \& $ctx\->setpriv(undef); \& \& return SMFIS_CONTINUE; \& } \& \& \& # The following code does not necessarily need to be in a \& # BEGIN block. It just looks funny without it. :) \& \& BEGIN: \& { \& Sendmail::Milter::auto_setconn("myfilter"); \& Sendmail::Milter::register("myfilter", \& \e%my_milter_callbacks, SMFI_CURR_ACTS); \& \& Sendmail::Milter::main(); \& \& # Never reaches here, callbacks are called from Milter. \& } .Ve .PP See the \fBtest.pl\fR sample test case for more callback examples. .SH "AUTHOR" .IX Header "AUTHOR" Charles Ying, cying@cpan.org. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2000\-2001 Charles Ying. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as sendmail itself. .PP The interpreter pools portion (found in the intpools.c, intpools.h, and test.pl files) of this code is also available under the same terms as perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIperl\fR\|(1), \fIsendmail\fR\|(8).