Milter smfi_replacebody()

Replace the message body All sendmail versions

The SMTP DATA portion of an envelope contains two parts: headers, then an empty line, followed by the body. A Milter receives a copy of the body in its xxfi_body() function (Milter xxfi_body() on page 1207). If a Milter intends to modify or replace the body, it must first either save and then modify a copy, or create a new body.

Once the new body is prepared, you call smfi_replacebody() and, using that, replace the old body with the new. Note that you can only call smfi_replacebody() from inside the xxfi_eom() function you write. The smfi_replacebody() routine is called like this:

ret = smfi_replacebody(ctx, buf, len);

Here, ctx is the common context pointer that was passed to your xxfi_eom() function. The buf is a pointer to the location in memory where your new message body is located, and len is the size in bytes of the new body.

The returned value (the ret) will be MI_FAILURE if buf is NULL and len is greater than zero, or if the SMFIF_CHGBODY flag was not set with smfi_register() (Milter smfi_register() on page 1194) or if there is a system error. If buf is NULL and len is zero, the body becomes empty.

The data in buf does not need to be zero-terminated (like a string) because the size is set with the len argument. Each line in the new body, however, must be terminated by a carriage-return/newline combination (\r\n).

Note that the first time you call smfi_replacebody() for an envelope, the body is truncated to ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.