Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 812370e8e4f8ac698e01b21e53db774d > files > 56

maildrop-1.7.0-17mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><link rel='stylesheet' type='text/css' href='manpage.css'>
  <!-- $Id: rfc2045.sgml,v 1.3 2002/09/22 02:32:57 mrsam Exp $ -->
  <!-- Copyright 2001 Double Precision, Inc.  See COPYING for -->
  <!-- distribution information. -->
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<link rel="icon" href="icon.gif" type="image/gif" />
<TITLE
>rfc2045</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><H1
><A
NAME="RFC2045"
></A
>rfc2045</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN10"
></A
><H2
>Name</H2
>rfc2045&nbsp;--&nbsp;RFC 2045 (MIME) parsing library</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN13"
></A
><H2
>Synopsis</H2
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN14"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#include &#60;rfc822.h&#62;
#include &#60;rfc2045.h&#62;

cc ... -lrfc2045 -lrfc822</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN16"
></A
><H2
>DESCRIPTION</H2
><P
>The rfc2045 library parses MIME-formatted messages.
The rfc2045 library is used to:</P
><P
>1) Parse the structure of a MIME formatted message</P
><P
>2) Examine the contents of each MIME section</P
><P
>3) Optionally rewrite and reformat the message.</P
><DIV
CLASS="REFSECT2"
><A
NAME="AEN22"
></A
><H3
>Creating an rfc2045 structure</H3
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN24"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#include &#60;rfc2045.h&#62;

struct rfc2045 *ptr=rfc2045_alloc();
void rfc2045_parse(struct rfc2045 *ptr, const char *txt, size_t cnt);

struct rfc2045 *ptr=rfc2045_fromfd(int fd);
struct rfc2045 *ptr=rfc2045_fromfp(FILE *fp);

void rfc2045_free(struct rfc2045 *ptr);

void rfc2045_error(const char *errmsg)
{
        perror(errmsg);
        exit(0);
}</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>The <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure is created from an existing
message.
The function <TT
CLASS="FUNCTION"
>rfc2045_alloc</TT
>() allocates the structure,
then <TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>() is
called to initialize the structure based on the contents of a message.
<TT
CLASS="PARAMETER"
><I
>txt</I
></TT
> points to the contents of the message, and
<TT
CLASS="PARAMETER"
><I
>cnt</I
></TT
> contains the number of bytes in the message.</P
><P
>Large messages are parsed by calling <TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>()
multiple number of times, each time passing a portion of the overall message.
There is no need to call a separate function after the entire message is
parsed -- the <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure is created
dynamically, on the fly.</P
><P
><TT
CLASS="FUNCTION"
>rfc2045_alloc</TT
>() returns NULL if there was insufficient
memory to allocate the structure. The <TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>()
also allocates memory, internally, however
no error indication is return in the event of a memory allocation failure.
Instead, the function <TT
CLASS="FUNCTION"
>rfc2045_error</TT
>() is called,
with <TT
CLASS="PARAMETER"
><I
>errmsg</I
></TT
> set to
<TT
CLASS="LITERAL"
>"Out of memory"</TT
>.
<TT
CLASS="FUNCTION"
>rfc2045_error</TT
>() is also called by
<TT
CLASS="FUNCTION"
>rfc2045_alloc</TT
>() - it also
calls <TT
CLASS="FUNCTION"
>rfc2045_error</TT
>(), before returning a
NULL pointer.</P
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_error</TT
>() function is not included in the
rfc2045 library, it must be defined by the application to report the error in
some appropriate way. All functions below will use
<TT
CLASS="FUNCTION"
>rfc2045_error</TT
>() to report an error condition
(currently only insufficient memory is reported), in addition to returning any
kind of an error indicator.  Some functions do not return an error indicator,
so <TT
CLASS="FUNCTION"
>rfc2045_error</TT
>() is the only reliable way to detect a
failure.</P
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_fromfd</TT
>() function initializes an
<CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure from
a file descriptor. It is equivalent to calling
<TT
CLASS="FUNCTION"
>rfc2045_alloc</TT
>(), then reading
the contents of the given file descriptor, and calling
<TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>(). The
rfc2045_fromfp() function initializes an <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
>
structure from a FILE.</P
><P
>After the <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure is initialized, the
functions described
below may be used to access and work with the contents of the structure. When
the <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure is no longer needed, the
function <TT
CLASS="FUNCTION"
>rfc2045_free</TT
>() deallocates and destroys the
structure.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN58"
></A
><H3
>Structure of a MIME message</H3
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN60"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;struct rfc2045 {

        struct rfc2045 *parent;

        struct rfc2045 *firstpart;
        struct rfc2045 *next;
        int             isdummy;
        int             rfcviolation;
} ;</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>The <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure has many fields,
only some are publicly documented. A
MIME message is represented by a recursive tree of linked
<CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
>
structures. Each instance of the <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure
represents a single
MIME section of a MIME-formatted message.</P
><P
>The top-level structure that represents the entire message is created by the
<TT
CLASS="FUNCTION"
>rfc2045_alloc</TT
>() function.  The remaining structures are
created dynamically by
<TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>().  Any <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
>
structure, except ones whose
<CODE
CLASS="STRUCTFIELD"
>isdummy</CODE
> flag is set, may be used as an argument to
any function described in the following chapters.</P
><P
>The <CODE
CLASS="STRUCTFIELD"
>rfcviolation</CODE
> field in the top-level
<CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
>
indicates any errors found while parsing the MIME message.
<CODE
CLASS="STRUCTNAME"
>rfcviolation</CODE
> is a bitmask of the following
flags:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="ERRORCODE"
>RFC2045_ERR8BITHEADER</SPAN
></DT
><DD
><P
>Illegal 8-bit characters in MIME headers.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>RFC2045_ERR8BITCONTENT</SPAN
></DT
><DD
><P
>Illegal 8-bit contents of a MIME section that declared a 7bit transfer
encoding.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>RFC2045_ERR2COMPLEX</SPAN
></DT
><DD
><P
>The message has too many MIME sections, this is a potential denial-of-service
attack.</P
></DD
><DT
><SPAN
CLASS="ERRORCODE"
>RFC2045_ERRBADBOUNDARY</SPAN
></DT
><DD
><P
>Ambiguous nested multipart MIME boundary strings.
(Nested MIME boundary strings where one string is a prefix of another
string).</P
></DD
></DL
></DIV
><P
>In each <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure that represents a
multipart MIME section (or one that contains <TT
CLASS="LITERAL"
>message/rfc822</TT
>
content) the <CODE
CLASS="STRUCTFIELD"
>firstpart</CODE
> pointer points to
the first MIME section in the multipart MIME section (or the included
"message/rfc822" MIME section).  If there are more than one MIME sections in a
multipart MIME section <CODE
CLASS="STRUCTFIELD"
>firstpart-&#62;next</CODE
> gets you
the second MIME section, <CODE
CLASS="STRUCTFIELD"
>firstpart-&#62;next-&#62;next</CODE
>
gets you the third MIME section, and so on.  <CODE
CLASS="STRUCTFIELD"
>parent</CODE
>
points to the parent MIME section, which is NULL for the top-level MIME
section.</P
><P
>Not all MIME sections are created equal.  In a multipart MIME section,
there is an initial, unused, "filler" section before the first MIME delimiter
(see
<A
HREF="http://www.rfc-editor.org/rfc/rfc2045.txt"
TARGET="_top"
>RFC 2045</A
>
for more information).  This filler section typically contains a
terse message saying that this is a MIME-formatted message.
This is not considered to be a "real" MIME section, and
all MIME-aware software must ignore those.  These filler sections are
designated by setting the <CODE
CLASS="STRUCTFIELD"
>isdummy</CODE
> field
to a non-zero value.  All <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
>
structures that have <CODE
CLASS="STRUCTFIELD"
>isdummy</CODE
> set should be
ignored, and skipped over, when traversing the
<CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> tree.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN109"
></A
><H3
>Basic MIME information</H3
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN111"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;const char *content_type, *content_transfer_encoding,
           *content_character_set;

void rfc2045_mimeinfo(const struct rfc2045 *ptr,
        &#38;content_type, &#38;content_transfer_encoding,
        &#38;content_character_set);

off_t start_pos, end_pos, start_body, nlines, nbodylines;

void rfc2045_mimepos(const struct rfc2045 *ptr,
        &#38;start_pos, &#38;end_pos, &#38;start_body, &#38;nlines,
        &#38;nbodylines);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_mimeinfo</TT
>() function returns the MIME
content type, encoding method,
and the character set of the given MIME section.  Where the MIME section does
not specify any property, <TT
CLASS="FUNCTION"
>rfc2045_mimeinfo</TT
>()
automatically supplies a default value.  The character set is only meaningful
for MIME sections with a text content type, however it is still defaulted for
other sections.  It is not permissible to supply a NULL pointer for any
argument to <TT
CLASS="FUNCTION"
>rfc2045_mimeinfo</TT
>().</P
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_mimepos</TT
>() function locates the position of
the given MIME section in the original message. It is not permissible to
supply a NULL pointer for any argument to
<TT
CLASS="FUNCTION"
>rfc2045_mimepos</TT
>().  All arguments must be used.</P
><P
><CODE
CLASS="STRUCTFIELD"
>start_pos</CODE
> and <CODE
CLASS="STRUCTFIELD"
>end_pos</CODE
>
point to the starting and the ending offset, from the beginning of the
message, of this MIME section. <CODE
CLASS="STRUCTFIELD"
>nlines</CODE
>
is initialized to the number of lines of text in this MIME section.
<CODE
CLASS="STRUCTFIELD"
>start_pos</CODE
> is the start of MIME headers for this
MIME section.
<CODE
CLASS="STRUCTFIELD"
>start_body</CODE
> is the start of the actual content of
this MIME section (after all the MIME headers, and the delimiting blank line),
and <CODE
CLASS="STRUCTFIELD"
>nbodylines</CODE
> is the number of
lines of actual content in this MIME section.</P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN127"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;const char *id=rfc2045_content_id(
                       const struct rfc2045 *ptr);

const char *desc=rfc2045_content_description(
                       const struct rfc2045 *ptr);

const char *lang=rfc2045_content_language(
                       const struct rfc2045 *ptr);

const char *md5=rfc2045_content_md5(
                       const struct rfc2045 *ptr);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>These functions return the contents of the corresponding MIME headers. If
these headers do not exist, these functions return an empty string, "", NOT a
null pointer.</P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN130"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;char *id=rfc2045_related_start(const struct rfc2045 *ptr);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>This function returns the <CODE
CLASS="STRUCTFIELD"
>start</CODE
> attribute of the
<TT
CLASS="LITERAL"
>Content-Type:</TT
>
header, which is used by <TT
CLASS="LITERAL"
>multipart/related</TT
>
MIME content. This function returns a
dynamically-allocated buffer, which must be
<TT
CLASS="FUNCTION"
>free</TT
>(3)-ed after use (a null
pointer is returned if there was insufficient memory for the buffer, and
rfc2045_error() is called).</P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN137"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;const struct rfc2045 *ptr;

const char *disposition=ptr-&#62;content_disposition;

char *charset;
char *language;
char *value;

int error;

error=rfc2231_decodeType(rfc, "name", &#38;charset,
                         &#38;language, &#38;value);
error=rfc2231_decodeDisposition(rfc, "name", &#38;charset,
                                &#38;language, &#38;value);&#13;</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>These functions and structures provide a mechanism for reading the MIME
attributes in the <TT
CLASS="LITERAL"
>Content-Type:</TT
> and
<TT
CLASS="LITERAL"
>Content-Disposition:</TT
> headers.
The MIME content type is returned by
<TT
CLASS="FUNCTION"
>rfc2045_mimeinfo</TT
>().
The MIME content disposition can be accessed in the
<CODE
CLASS="STRUCTFIELD"
>content_disposition</CODE
> directly (which may be
<TT
CLASS="LITERAL"
>NULL</TT
> if the <TT
CLASS="LITERAL"
>Content-Disposition:</TT
>
header was not specified).</P
><P
><TT
CLASS="FUNCTION"
>rfc2231_decodeType</TT
>() reads MIME attributes from the
<TT
CLASS="LITERAL"
>Content-Type:</TT
> header, and
<TT
CLASS="FUNCTION"
>rfc2231_decodeType</TT
>() reads MIME attributes from the
<TT
CLASS="LITERAL"
>Content-Disposition:</TT
> header.
These functions understand MIME attributes that are encoded according to
<A
HREF="http://www.rfc-editor.org/rfc/rfc2231.txt"
TARGET="_top"
>RFC 2231</A
>.</P
><P
>These functions initialize
<TT
CLASS="PARAMETER"
><I
>charset</I
></TT
>,
<TT
CLASS="PARAMETER"
><I
>language</I
></TT
>, and
<TT
CLASS="PARAMETER"
><I
>value</I
></TT
> parameters, allocating memory automatically.
It is the caller's responsibility to use <TT
CLASS="FUNCTION"
>free</TT
>() to return
the allocated memory.
A <TT
CLASS="LITERAL"
>NULL</TT
> may be provided in place of a parameter, indicating
that the caller does not require the corresponding information.</P
><P
><TT
CLASS="PARAMETER"
><I
>charset</I
></TT
> and
<TT
CLASS="PARAMETER"
><I
>language</I
></TT
> will be set to an empty string
(<I
CLASS="EMPHASIS"
>not</I
> <TT
CLASS="LITERAL"
>NULL</TT
>) if the MIME parameter
does not exist, or is not encoded according to
<A
HREF="http://www.rfc-editor.org/rfc/rfc2231.txt"
TARGET="_top"
>RFC 2231</A
>,
or does not specify its character set and/or language.
<TT
CLASS="PARAMETER"
><I
>value</I
></TT
> will be set to an empty string if the MIME
parameter does not exist.</P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN165"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;char *url=rfc2045_content_base(struct rfc2045 *ptr);

char *url=rfc2045_append_url(const char *base, const char *url);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>These functions are used to work with
<TT
CLASS="LITERAL"
>multipart/related</TT
> MIME content.
<TT
CLASS="FUNCTION"
>rfc2045_content_base</TT
>() returns the contents of either
the <TT
CLASS="LITERAL"
>Content-Base:</TT
> or the
<TT
CLASS="LITERAL"
>Content-Location:</TT
> header.  If both are present, they are
logically combined.
<TT
CLASS="FUNCTION"
>rfc2045_append_url()</TT
> combines two URLs,
<TT
CLASS="PARAMETER"
><I
>base</I
></TT
> and
<TT
CLASS="PARAMETER"
><I
>url</I
></TT
>, and returns the absolute URL that results from the
combination.</P
><P
>Both functions return a pointer to a dynamically-allocated buffer that must
be <TT
CLASS="FUNCTION"
>free</TT
>(3)-ed after it is no longer needed.  Both
functions return NULL if there was no sufficient memory to allocate the
buffer. <TT
CLASS="FUNCTION"
>rfc2045_content_base</TT
>()
returns an empty string in the event that there are no
<TT
CLASS="LITERAL"
>Content-Base:</TT
> or
<TT
CLASS="LITERAL"
>Content-Location:</TT
> headers. Either argument to
<TT
CLASS="FUNCTION"
>rfc2045_append_url</TT
>() may be a
NULL, or an empty string.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN181"
></A
><H3
>Decoding a MIME section</H3
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN183"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;void rfc2045_cdecode_start(struct rfc2045 *ptr,
        int (*callback_func)(const char *, size_t, void *),
        void *callback_arg);

int rfc2045_cdecode(struct rfc2045 *ptr, const char *stuff,
        size_t nstuff);

int rfc2045_cdecode_end(struct rfc2045 *ptr);&#13;</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>These functions are used to return the raw contents of the given MIME
section, transparently decoding quoted-printable or base64-encoded content.
Because the rfc2045 library does not require the message to be read from a
file (it can be stored in a memory buffer), the application is responsible for
reading the contents of the message and calling
<TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>().</P
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_cdecode_start</TT
>() function begins the process of
decoding the given MIME section. After calling
<TT
CLASS="FUNCTION"
>rfc2045_cdecode_start</TT
>(), the
application must the repeatedly call <TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>()
with the contents of the MIME message between the offsets given by the
<CODE
CLASS="STRUCTFIELD"
>start_body</CODE
> and
<CODE
CLASS="STRUCTFIELD"
>end_pos</CODE
> return values from
<TT
CLASS="FUNCTION"
>rfc2045_mimepos</TT
>(). The
<TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>() function can be called repeatedly, if
necessary, for successive portions of the MIME section. After the last call
to
<TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>(), call
<TT
CLASS="FUNCTION"
>rfc2045_cdecode_end</TT
>() to finish up
(<TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>() may have saved some undecoded content
in an internal part, and
<TT
CLASS="FUNCTION"
>rfc2045_cdecode_end</TT
>() flushes it out).</P
><P
><TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>() and
<TT
CLASS="FUNCTION"
>rfc2045_cdecode_end</TT
>() repeatedly call
<TT
CLASS="FUNCTION"
>callback_func</TT
>(), passing it the decoded contents of the
MIME section. The
first argument to <TT
CLASS="FUNCTION"
>callback_func</TT
>() is a pointer to a
portion of the decoded
content, the second argument is the number of bytes in this portion.  The
third argument is <TT
CLASS="PARAMETER"
><I
>callback_arg</I
></TT
>.</P
><P
><TT
CLASS="FUNCTION"
>callback_func</TT
>() is required to return zero, to continue
decoding. If
<TT
CLASS="FUNCTION"
>callback_func</TT
>() returns non-zero, the decoding
immediately stops and
<TT
CLASS="FUNCTION"
>rfc2045_cdecode</TT
>() or <TT
CLASS="FUNCTION"
>rfc2045_cdecode_end</TT
>() terminates with <TT
CLASS="FUNCTION"
>callback_func</TT
>'s return code.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN211"
></A
><H3
>Rewriting MIME messages</H3
><P
>This library contains functions that can be used to rewrite a MIME
message in order to convert 8-bit-encoded data to 7-bit encoding, or to
convert 7-bit encoded data to full 8-bit data, if possible.</P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><A
NAME="AEN214"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;struct rfc2045 *ptr=rfc2045_alloc_ac();
int necessary=rfc2045_ac_check(struct rfc2045 *ptr, int mode);

int error=rfc2045_rewrite(struct rfc2045 *ptr,
                int fdin,
                int fdout,
                const char *appname);

int rfc2045_rewrite_func(struct rfc2045 *p, int fdin,
        int (*funcout)(const char *, int, void *), void *funcout_arg,
        const char *appname);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>When rewriting will be used, the <TT
CLASS="FUNCTION"
>rfc2045_alloc_ac</TT
>()
function must be used
to create the initial <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure.  This
function allocates some
additional structures that are used in rewriting.
Use
<TT
CLASS="FUNCTION"
>rfc2045_parse</TT
>()
to parse the message, as usual. Use
<TT
CLASS="FUNCTION"
>rfc2045_free</TT
>() in a normal way
to destroy the <CODE
CLASS="STRUCTNAME"
>rfc2045</CODE
> structure, when all is said and
done.</P
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_ac_check</TT
>() function must be called to
determine whether
rewriting is necessary. <TT
CLASS="PARAMETER"
><I
>mode</I
></TT
> must be set to one of the
following values:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>RFC2045_RW_7BIT</DT
><DD
><P
>We want to generate 7-bit content. If the
original message contains any 8-bit content it will be converted to 7-bit
content using quoted-printable encoding.</P
></DD
><DT
>RFC2045_RW_8BIT</DT
><DD
><P
>We want to generate 8-bit content. If the
original message contains any 7-bit quoted-printable content it should be
rewritten as 8-bit content.</P
></DD
></DL
></DIV
><P
>The <TT
CLASS="FUNCTION"
>rfc2045_ac_check</TT
>() function returns non-zero if
there's any content in
the MIME message that should be converted, OR if there are any missing MIME
headers. <TT
CLASS="FUNCTION"
>rfc2045_ac_check</TT
>() returns zero if there's no
need to rewrite the
message.  However it might still be worthwhile to rewrite the message anyway.
There are some instances where it is desirable to provide defaults for some
missing MIME headers, but they are too trivial to require the message to be
rewritten.  One such case would be a missing Content-Transfer-Encoding: header
for a multipart section.</P
><P
>Either the <TT
CLASS="FUNCTION"
>rfc2045_rewrite</TT
>() or the
<TT
CLASS="FUNCTION"
>rfc2045_rewrite_func</TT
>() function is used
to rewrite the message.  The only difference is that
<TT
CLASS="FUNCTION"
>rfc2045_rewrite</TT
>() writes
the new message to a given file descriptor, <TT
CLASS="PARAMETER"
><I
>fdout</I
></TT
>, while
<TT
CLASS="FUNCTION"
>rfc2045_rewrite_func</TT
>() repeatedly calls the <TT
CLASS="PARAMETER"
><I
>funcout</I
></TT
> function. Both
function read the original message from <TT
CLASS="PARAMETER"
><I
>fdin</I
></TT
>.
<TT
CLASS="PARAMETER"
><I
>funcout</I
></TT
> receives
to a portion of the MIME message, the number of bytes in the specified
portion, and <TT
CLASS="PARAMETER"
><I
>funcout_arg</I
></TT
>. When either function rewrites
a MIME section,
an informational header gets appended, noting that the message was converted
by <TT
CLASS="PARAMETER"
><I
>appname</I
></TT
>.</P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN248"
></A
><H2
>SEE ALSO</H2
><P
><A
HREF="rfc822.html"
TARGET="_top"
><SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>rfc822</SPAN
>(3)</SPAN
></A
>,
<A
HREF="reformail.html"
TARGET="_top"
><SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>reformail</SPAN
>(1)</SPAN
></A
>,
<A
HREF="reformime.html"
TARGET="_top"
><SPAN
CLASS="CITEREFENTRY"
><SPAN
CLASS="REFENTRYTITLE"
>reformime</SPAN
>(1)</SPAN
></A
>.</P
></DIV
></BODY
></HTML
>