smfi_insheader.html revision 168515
1168515Sgshapiro<HTML> 2168515Sgshapiro<HEAD><TITLE>smfi_insheader</TITLE></HEAD> 3168515Sgshapiro<BODY> 4132943Sgshapiro<!-- 5168515Sgshapiro$Id: smfi_insheader.html,v 1.9 2006/12/21 18:30:35 ca Exp $ 6132943Sgshapiro--> 7168515Sgshapiro<H1>smfi_insheader</H1> 8132943Sgshapiro 9168515Sgshapiro<TABLE border="0" cellspacing=4 cellpadding=4> 10132943Sgshapiro<!---------- Synopsis -----------> 11168515Sgshapiro<TR><TH valign="top" align=left width=100>SYNOPSIS</TH><TD> 12168515Sgshapiro<PRE> 13132943Sgshapiro#include <libmilter/mfapi.h> 14132943Sgshapiroint smfi_insheader( 15132943Sgshapiro SMFICTX *ctx, 16132943Sgshapiro int hdridx, 17132943Sgshapiro char *headerf, 18132943Sgshapiro char *headerv 19132943Sgshapiro); 20168515Sgshapiro</PRE> 21132943SgshapiroPrepend a header to the current message. 22168515Sgshapiro</TD></TR> 23132943Sgshapiro 24132943Sgshapiro<!----------- Description ----------> 25168515Sgshapiro<TR><TH valign="top" align=left>DESCRIPTION</TH><TD> 26168515Sgshapiro<TABLE border="1" cellspacing=1 cellpadding=4> 27168515Sgshapiro<TR align="left" valign=top> 28168515Sgshapiro<TH width="80">Called When</TH> 29168515Sgshapiro<TD>Called only from <A href="xxfi_eom.html">xxfi_eom</A>.</TD> 30168515Sgshapiro</TR> 31168515Sgshapiro<TR align="left" valign=top> 32168515Sgshapiro<TH width="80">Effects</TH> 33168515Sgshapiro<TD>Prepends a header to the current message.</TD> 34168515Sgshapiro</TR> 35168515Sgshapiro</TABLE> 36132943Sgshapiro 37132943Sgshapiro<!----------- Arguments ----------> 38168515Sgshapiro<TR><TH valign="top" align=left>ARGUMENTS</TH><TD> 39168515Sgshapiro <TABLE border="1" cellspacing=0> 40168515Sgshapiro <TR bgcolor="#dddddd"><TH>Argument</TH><TH>Description</TH></TR> 41168515Sgshapiro <TR valign="top"><TD>ctx</TD> 42168515Sgshapiro <TD>Opaque context structure. 43168515Sgshapiro </TD></TR> 44168515Sgshapiro <TR valign="top"><TD>hdridx</TD> 45168515Sgshapiro <TD>The location in the internal header list where this header should 46132943Sgshapiro be inserted; 0 makes it the topmost header, etc. 47168515Sgshapiro </TD></TR> 48168515Sgshapiro <TR valign="top"><TD>headerf</TD> 49168515Sgshapiro <TD>The header name, a non-NULL, null-terminated string. 50168515Sgshapiro </TD></TR> 51168515Sgshapiro <TR valign="top"><TD>headerv</TD> 52168515Sgshapiro <TD>The header value to be added, a non-NULL, null-terminated string. This may be the empty string. 53168515Sgshapiro </TD></TR> 54168515Sgshapiro </TABLE> 55168515Sgshapiro</TD></TR> 56132943Sgshapiro 57132943Sgshapiro<!----------- Return values ----------> 58168515Sgshapiro<TR> 59168515Sgshapiro<TH valign="top" align=left>RETURN VALUES</TH> 60132943Sgshapiro 61168515Sgshapiro<TD>smfi_insheader returns MI_FAILURE if: 62168515Sgshapiro<UL><LI>headerf or headerv is NULL. 63168515Sgshapiro <LI>Adding headers in the current connection state is invalid. 64168515Sgshapiro <LI>Memory allocation fails. 65168515Sgshapiro <LI>A network error occurs. 66168515Sgshapiro <LI>SMFIF_ADDHDRS was not set when <A href="smfi_register.html">smfi_register</A> was called. 67168515Sgshapiro</UL> 68132943SgshapiroOtherwise, it returns MI_SUCCESS. 69168515Sgshapiro</TD> 70168515Sgshapiro</TR> 71132943Sgshapiro 72132943Sgshapiro<!----------- Notes ----------> 73168515Sgshapiro<TR align="left" valign=top> 74168515Sgshapiro<TH>NOTES</TH> 75168515Sgshapiro<TD> 76168515Sgshapiro<UL> 77168515Sgshapiro <LI>smfi_insheader does not change a message's existing headers. 78168515Sgshapiro To change a header's current value, use 79168515Sgshapiro <A HREF="smfi_chgheader.html">smfi_chgheader</A>. 80168515Sgshapiro <LI>A filter which calls smfi_insheader must have set the SMFIF_ADDHDRS 81168515Sgshapiro flag in the smfiDesc_str passed to 82168515Sgshapiro <A href="smfi_register.html">smfi_register</A>. 83168515Sgshapiro <LI>For smfi_insheader, filter order is important. 84168515Sgshapiro <B>Later filters will see the header changes made by earlier ones.</B> 85168515Sgshapiro <LI>A filter will receive <EM>only</EM> headers that have been sent 86168515Sgshapiro by the SMTP client and those header modifications by earlier filters. 87168515Sgshapiro It will <EM>not</EM> receive the headers that are inserted by sendmail 88168515Sgshapiro itself. 89168515Sgshapiro This makes the header insertion position highly dependent on 90168515Sgshapiro the headers that exist in the incoming message 91168515Sgshapiro and those that are configured to be added by sendmail. 92168515Sgshapiro For example, sendmail will always add a 93168515Sgshapiro <CODE>Received:</CODE> header to the beginning of the headers. 94168515Sgshapiro Setting <CODE>hdridx</CODE> to 0 will actually insert the header 95168515Sgshapiro before this <CODE>Received:</CODE> header. 96168515Sgshapiro However, later filters can be easily confused as they receive 97168515Sgshapiro the added header, but not the <CODE>Received:</CODE> header, 98168515Sgshapiro thus making it hard to insert a header at a fixed position. 99168515Sgshapiro <LI>If hdridx is a number larger than the number of headers in the message, 100168515Sgshapiro the header will simply be appended. 101168515Sgshapiro <LI>Neither the name nor the value of the header is checked for 102168515Sgshapiro standards compliance. 103168515Sgshapiro However, each line of the header must be under 2048 characters 104168515Sgshapiro and should be under 998 characters. 105168515Sgshapiro If longer headers are needed, make them multi-line. 106168515Sgshapiro To make a multi-line header, 107168515Sgshapiro insert a line feed (ASCII 0x0a, or <TT>\n</TT> in C) 108168515Sgshapiro followed by at least one whitespace character 109168515Sgshapiro such as a space (ASCII 0x20) or tab (ASCII 0x09, or <TT>\t</TT> in C). 110168515Sgshapiro The line feed should NOT be preceded by a carriage return (ASCII 0x0d); 111168515Sgshapiro the MTA will add this automatically. 112168515Sgshapiro <B>It is the filter writer's responsibility to ensure that no standards 113168515Sgshapiro are violated.</B> 114168515Sgshapiro</UL> 115168515Sgshapiro</TD> 116168515Sgshapiro</TR> 117132943Sgshapiro 118132943Sgshapiro<!----------- Example code ----------> 119168515Sgshapiro<TR> 120168515Sgshapiro<TH valign="top" align=left>EXAMPLE</TH> 121132943Sgshapiro 122168515Sgshapiro<TD> 123168515Sgshapiro <PRE> 124132943Sgshapiro int ret; 125132943Sgshapiro SMFICTX *ctx; 126132943Sgshapiro 127132943Sgshapiro ... 128132943Sgshapiro 129132943Sgshapiro ret = smfi_insheader(ctx, 0, "First", "See me?"); 130168515Sgshapiro </PRE> 131168515Sgshapiro</TD> 132168515Sgshapiro</TR> 133132943Sgshapiro 134168515Sgshapiro</TABLE> 135132943Sgshapiro 136168515Sgshapiro<HR size="1"> 137168515Sgshapiro<FONT size="-1"> 138168515SgshapiroCopyright (c) 2004, 2006 Sendmail, Inc. and its suppliers. 139132943SgshapiroAll rights reserved. 140168515Sgshapiro<BR> 141132943SgshapiroBy using this file, you agree to the terms and conditions set 142132943Sgshapiroforth in the LICENSE. 143168515Sgshapiro</FONT> 144168515Sgshapiro</BODY> 145168515Sgshapiro</HTML> 146