Back to index

courier  0.68.2
Classes | Defines | Functions
rfc2045.h File Reference
#include "../rfc2045/rfc2045_config.h"
#include "../numlib/numlib.h"
#include <sys/types.h>
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  rfc2045
struct  rfc2045attr
struct  rfc2045id
struct  rfc2045src
struct  rfc2045ac
struct  rfc2045_mkreplyinfo
struct  rfc2045_decodemsgtoutf8_cb
struct  rfc2231param
 NON-PUBLIC DATA. More...

Defines

#define RFC2045_ISMIME1(p)   ((p) && atoi(p) == 1)
#define RFC2045_ISMIME1DEF(p)   (!(p) || atoi(p) == 1)
#define RFC2045_ERR8BITHEADER   1 /* 8 bit characters in headers */
#define RFC2045_ERR8BITCONTENT
#define RFC2045_ERR2COMPLEX   4 /* Too many nested contents */
#define RFC2045_ERRBADBOUNDARY   8 /* Overlapping MIME boundaries */
#define RFC2045_RW_7BIT   1
#define RFC2045_RW_8BIT   2
#define rfc2045_fromfp(f)   (rfc2045_fromfd(fileno((f))))
#define rfc2045header_fromfp(f)   (rfc2045header_fromfd(fileno((f))))
#define RFC2045H_NOLC   1 /* Do not convert header to lowercase */
#define RFC2045H_KEEPNL
#define RFC2045_DECODEMSG_NOBODY   0x01
#define RFC2045_DECODEMSG_NOHEADERS   0x02
#define RFC2045_DECODEMSG_NOHEADERNAME   0x04

Functions

struct rfc2045rfc2045_alloc ()
void rfc2045_parse (struct rfc2045 *, const char *, size_t)
void rfc2045_parse_partial (struct rfc2045 *)
void rfc2045_free (struct rfc2045 *)
void rfc2045_mimeinfo (const struct rfc2045 *, const char **, const char **, const char **)
const char * rfc2045_boundary (const struct rfc2045 *)
int rfc2045_isflowed (const struct rfc2045 *)
int rfc2045_isdelsp (const struct rfc2045 *)
char * rfc2045_related_start (const struct rfc2045 *)
const char * rfc2045_content_id (const struct rfc2045 *)
const char * rfc2045_content_description (const struct rfc2045 *)
const char * rfc2045_content_language (const struct rfc2045 *)
const char * rfc2045_content_md5 (const struct rfc2045 *)
void rfc2045_mimepos (const struct rfc2045 *, off_t *, off_t *, off_t *, off_t *, off_t *)
unsigned rfc2045_mimepartcount (const struct rfc2045 *)
void rfc2045_xdump (struct rfc2045 *)
void rfc2045_decode (struct rfc2045 *, void(*)(struct rfc2045 *, struct rfc2045id *, void *), void *)
struct rfc2045rfc2045_find (struct rfc2045 *, const char *)
struct rfc2045srcrfc2045src_init_fd (int fd)
void rfc2045src_deinit (struct rfc2045src *)
void rfc2045_cdecode_start (struct rfc2045 *, int(*)(const char *, size_t, void *), void *)
int rfc2045_cdecode (struct rfc2045 *, const char *, size_t)
int rfc2045_cdecode_end (struct rfc2045 *)
const char * rfc2045_getdefaultcharset ()
void rfc2045_setdefaultcharset (const char *)
struct rfc2045rfc2045_fromfd (int)
struct rfc2045rfc2045header_fromfd (int)
void rfc2045_error (const char *)
struct rfc2045rfc2045_alloc_ac ()
int rfc2045_ac_check (struct rfc2045 *, int)
int rfc2045_rewrite (struct rfc2045 *p, struct rfc2045src *src, int fdout_arg, const char *appname)
int rfc2045_rewrite_func (struct rfc2045 *p, struct rfc2045src *src, int(*funcarg)(const char *, int, void *), void *funcargarg, const char *appname)
int rfc2045_try_boundary (struct rfc2045 *, struct rfc2045src *, const char *)
char * rfc2045_mk_boundary (struct rfc2045 *, struct rfc2045src *)
const char * rfc2045_getattr (const struct rfc2045attr *, const char *)
int rfc2045_attrset (struct rfc2045attr **, const char *, const char *)
char * rfc2045_content_base (struct rfc2045 *p)
char * rfc2045_append_url (const char *, const char *)
struct rfc2045rfc2045_searchcontenttype (struct rfc2045 *, const char *)
int rfc2045_decodemimesection (struct rfc2045src *, struct rfc2045 *, int(*)(const char *, size_t, void *), void *)
int rfc2045_decodetextmimesection (struct rfc2045src *, struct rfc2045 *, const char *, int *, int(*)(const char *, size_t, void *), void *)
struct rfc2045headerinforfc2045header_start (struct rfc2045src *, struct rfc2045 *)
int rfc2045header_get (struct rfc2045headerinfo *, char **, char **, int)
void rfc2045header_end (struct rfc2045headerinfo *)
int rfc2045_parse_mime_header (const char *header, void(*header_type_cb)(const char *, void *), void(*header_param_cb)(const char *, const char *, void *), void *void_arg)
int rfc2045_makereply (struct rfc2045_mkreplyinfo *)
int rfc2045_decodemsgtoutf8 (struct rfc2045src *src, struct rfc2045 *p, struct rfc2045_decodemsgtoutf8_cb *callback)
int rfc2231_decodeType (struct rfc2045 *rfc, const char *name, char **chsetPtr, char **langPtr, char **textPtr)
int rfc2231_decodeDisposition (struct rfc2045 *rfc, const char *name, char **chsetPtr, char **langPtr, char **textPtr)
int rfc2231_udecodeType (struct rfc2045 *rfc, const char *name, const char *myChset, char **textPtr)
int rfc2231_udecodeDisposition (struct rfc2045 *rfc, const char *name, const char *myChset, char **textPtr)
int rfc2231_attrCreate (const char *name, const char *value, const char *charset, const char *language, int(*cb_func)(const char *param, const char *value, void *void_arg), void *cb_arg)
void rfc2231_paramDestroy (struct rfc2231param *paramList)
int rfc2231_buildAttrList (struct rfc2231param **paramList, const char *name, const char *attrName, const char *attrValue)
void rfc2231_paramDecode (struct rfc2231param *paramList, char *charsetPtr, char *langPtr, char *textPtr, int *charsetLen, int *langLen, int *textLen)

Class Documentation

struct rfc2045attr

Definition at line 96 of file rfc2045.h.

Collaboration diagram for rfc2045attr:
Class Members
char * name
struct rfc2045attr * next
char * value
struct rfc2045id

Definition at line 127 of file rfc2045.h.

Collaboration diagram for rfc2045id:
Class Members
int idnum
struct rfc2045id * next
struct rfc2231param

NON-PUBLIC DATA.

Definition at line 623 of file rfc2045.h.

Collaboration diagram for rfc2231param:
Class Members
int encoded
struct rfc2231param * next
int paramnum
const char * value

Define Documentation

#define RFC2045_DECODEMSG_NOBODY   0x01

Definition at line 532 of file rfc2045.h.

#define RFC2045_DECODEMSG_NOHEADERNAME   0x04

Definition at line 541 of file rfc2045.h.

#define RFC2045_DECODEMSG_NOHEADERS   0x02

Definition at line 535 of file rfc2045.h.

#define RFC2045_ERR2COMPLEX   4 /* Too many nested contents */

Definition at line 64 of file rfc2045.h.

Value:
2      /* 8 bit contents, but no 8bit
                                   content-transfer-encoding */

Definition at line 63 of file rfc2045.h.

#define RFC2045_ERR8BITHEADER   1 /* 8 bit characters in headers */

Definition at line 62 of file rfc2045.h.

#define RFC2045_ERRBADBOUNDARY   8 /* Overlapping MIME boundaries */

Definition at line 65 of file rfc2045.h.

#define rfc2045_fromfp (   f)    (rfc2045_fromfd(fileno((f))))

Definition at line 169 of file rfc2045.h.

#define RFC2045_ISMIME1 (   p)    ((p) && atoi(p) == 1)

Definition at line 25 of file rfc2045.h.

#define RFC2045_ISMIME1DEF (   p)    (!(p) || atoi(p) == 1)

Definition at line 26 of file rfc2045.h.

#define RFC2045_RW_7BIT   1

Definition at line 71 of file rfc2045.h.

#define RFC2045_RW_8BIT   2

Definition at line 72 of file rfc2045.h.

#define RFC2045H_KEEPNL
Value:
2      /* Preserve newlines in the value string
                            ** of multiline headers.
                            */

Definition at line 267 of file rfc2045.h.

#define RFC2045H_NOLC   1 /* Do not convert header to lowercase */

Definition at line 266 of file rfc2045.h.

#define rfc2045header_fromfp (   f)    (rfc2045header_fromfd(fileno((f))))

Definition at line 171 of file rfc2045.h.


Function Documentation

int rfc2045_ac_check ( struct rfc2045 ,
int   
)

Definition at line 20 of file rfc2045acchk.c.

{
int    flag=0;              /* Flag - rewriting suggested */
struct rfc2045 *c;
int    hasnon7bit=p->has8bitchars;
              /* hasnon7bit: 8bit chars in this section or subsections */
const char *te;
int    is8bitte;

       for (c=p->firstpart; c; c=c->next)
              if (!c->isdummy)
              {
                     if (rfc2045_ac_check(c, rwmode))   flag=1;
                     if (c->content_transfer_encoding &&
                         strcmp(c->content_transfer_encoding, "7bit") &&
                         strcmp(c->content_transfer_encoding, "uuencode") &&
                            strcmp(c->content_transfer_encoding, "quoted-printable"))
                            hasnon7bit=1;
                     if (c->has8bitchars)
                            p->has8bitchars=1;
              }

       if (RFC2045_ISMIME1DEF(p->mime_version) && !p->content_type)
       {
              if ((p->content_type=strdup("text/plain")) == 0)
                     rfc2045_enomem();
              if (p->mime_version)
              {
                     flag=1;
              }
       }

       if (RFC2045_ISMIME1DEF(p->mime_version)
              && !rfc2045_getattr(p->content_type_attr, "charset")
              && strncasecmp(p->content_type, "text/", 5) == 0)
       {
              if (rfc2045_attrset(&p->content_type_attr, "charset",
                                rfc2045_getdefaultcharset()) < 0)
                     rfc2045_enomem();

              if (p->mime_version

                     && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */

                     )
              {
                     flag=1;
              }
       }

       if (RFC2045_ISMIME1DEF(p->mime_version)
              && !p->content_transfer_encoding)
       {
              if ((p->content_transfer_encoding=strdup(
                     hasnon7bit ? "8bit":"7bit")) == 0)
                     rfc2045_enomem();
              if (p->mime_version

                     && p->firstpart == 0 /* sam - don't trigger rewrites on changes to multipart headers */
                     )
              {
                     flag=1;
              }
       }

#if 0
       if (RFC2045_ISMIME1DEF(p->mime_version)
              && strncmp(p->content_type, "text/", 5) == 0 && !hasnon7bit
              && strcmp(p->content_transfer_encoding, "7bit"))
       {
              if (p->mime_version)
              {
                     flag=1;
              }
       }
#endif

       if (RFC2045_ISMIME1DEF(p->mime_version))
       {
              /* Check for conversions */

              te=p->content_transfer_encoding;
              is8bitte=strcasecmp(te, "base64") &&
                     strcasecmp(te, "quoted-printable") &&
                     strcasecmp(te, "uuencode") &&
                     strcasecmp(te, "7bit");     /* 8 bit contents */

              if (is8bitte && !p->has8bitchars && !p->haslongline)
              {
                     if (p->rw_transfer_encoding)
                            free(p->rw_transfer_encoding);
                     if ((p->rw_transfer_encoding=strdup("7bit")) == 0)
                            rfc2045_enomem();
                     flag=1;
                     is8bitte=0;
              }

              if (rwmode == RFC2045_RW_7BIT && (is8bitte || p->haslongline))
              {
                     if (p->rw_transfer_encoding)
                            free(p->rw_transfer_encoding);
                     if ((p->rw_transfer_encoding=strdup("quoted-printable"))
                            == 0)
                            rfc2045_enomem();
                     flag=1;
              }
              else if (rwmode == RFC2045_RW_8BIT &&
                     strcasecmp(te, "quoted-printable") == 0 &&
                     !p->haslongline)
              {
                     if (p->rw_transfer_encoding)
                            free(p->rw_transfer_encoding);
                     if ((p->rw_transfer_encoding=strdup(hasnon7bit
                                   ? "8bit":"7bit")) == 0)
                            rfc2045_enomem();
                     flag=1;
              }
       }

       if (!p->mime_version)
       {
              if ((p->mime_version=strdup("1.0")) == 0)
                     rfc2045_enomem();
       }
       return (flag);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc2045* rfc2045_alloc ( ) [read]

Definition at line 35 of file rfc2045.c.

{
struct rfc2045 *p=(struct rfc2045 *)malloc(sizeof(struct rfc2045));

       if (!p)
       {
              rfc2045_enomem();
              return (0);
       }

       /* Initialize everything to nulls, except for one thing */

       memset(p, '\0', sizeof(*p));

       p->pindex=1;  /* Start with part #1 */
       p->workinheader=1;
       /* Most of the time, we're about to read a header */

       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc2045* rfc2045_alloc_ac ( ) [read]

Definition at line 36 of file rfc2045acprep.c.

{
struct rfc2045 *p=rfc2045_alloc();

       if (p) p->rfc2045acptr= &rfc2045acprep;
       currwp=0;
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2045_append_url ( const char *  ,
const char *   
)

Definition at line 55 of file rfc2045appendurl.c.

{
const char *base_method;
unsigned base_method_l;
const char *base_path;

const char *loc_method;
unsigned loc_method_l;
const char *loc_path;
char *buf, *q;

       get_method_path(base, &base_method, &base_method_l, &base_path);
       get_method_path(loc, &loc_method, &loc_method_l, &loc_path);

       if (loc_method_l)
       {
              buf=malloc(strlen(loc)+1);
              if (!buf)
                     return NULL;
              else
                     strcpy(buf, loc);
              return (buf);
       }

       loc_method=base_method;
       loc_method_l=base_method_l;

       if (!base_path)      base_path="";
       if (!loc_path)       loc_path="";

       buf=malloc(loc_method_l + strlen(base_path)+strlen(loc_path) + 3);

       if (!buf)
       {
              return NULL;
       }

       if (loc_method_l)
              memcpy(buf, loc_method, loc_method_l);
       buf[loc_method_l]=0;

       q=buf + loc_method_l;

       strcat(strcpy(q, base_path), "/");

       if ( loc_path[0] == '/')
       {
       char *r;

              if (loc_path[1] == '/')
                     /* Location is absolute */
              {
                     *q=0;
              }

              /* Relative to top of base */

              else if ( q[0] == '/' && q[1] == '/' &&
                     (r=strchr(q+2, '/')) != 0)
              {
                     *r=0;
              }
              else
                     *q=0;  /* No sys in base, just start with / */
       }

       strcat(q, loc_path);

       return (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_attrset ( struct rfc2045attr **  ,
const char *  ,
const char *   
)

Definition at line 67 of file rfc2045.c.

{
char   *v;

       while (*p)
       {
              if (strcmp( (*p)->name, name) == 0)       break;
              p=&(*p)->next;
       }
       if (val == 0)
       {
       struct rfc2045attr *q= *p;

              if (q)
              {
                     *p=q->next;
                     if (q->name)  free(q->name);
                     if (q->value) free(q->value);
                     free(q);
              }
              return 0;
       }

       v=strdup(val);
       if (!v)
              return -1;

       if (!*p)
       {
              if (((*p)=(struct rfc2045attr *)malloc(sizeof(**p))) == 0)
              {
                     free(v);
                     return -1;
              }
              memset( (*p), 0, sizeof(**p));
              if ( ((*p)->name=strdup(name)) == 0)
              {
                     free( *p );
                     *p=0;
                     free(v);
                     return -1;
              }
       }
       if ( (*p)->value )   free ( (*p)->value );
       (*p)->value=v;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc2045_boundary ( const struct rfc2045 )

Definition at line 1242 of file rfc2045.c.

{
const char *cb=rfc2045_getattr( p->content_type_attr, "boundary");

       if (!cb)      cb="";
       return (cb);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_cdecode ( struct rfc2045 ,
const char *  ,
size_t   
)

Definition at line 210 of file rfc2045cdecode.c.

{
       if (s && l)   return ((*p->decode_func)(p, s, l));
       return (0);
}

Here is the caller graph for this function:

int rfc2045_cdecode_end ( struct rfc2045 )

Definition at line 205 of file rfc2045cdecode.c.

{
       return ((*p->decode_func)(p, NULL, 0));
}

Here is the caller graph for this function:

void rfc2045_cdecode_start ( struct rfc2045 ,
int(*)(const char *, size_t, void *)  ,
void *   
)

Definition at line 188 of file rfc2045cdecode.c.

{
       p->misc_decode_ptr=miscptr;
       p->udecode_func=u;
       p->decode_func= &decode_raw;
       p->workbuflen=0;
       if (p->content_transfer_encoding)
       {
              if (strcmp(p->content_transfer_encoding,
                            "quoted-printable") == 0)
                     p->decode_func= &decode_qp;
              else if (strcmp(p->content_transfer_encoding, "base64") == 0)
                     p->decode_func= &decode_base64;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2045_content_base ( struct rfc2045 p)

Definition at line 126 of file rfc2045appendurl.c.

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc2045_content_description ( const struct rfc2045 )

Definition at line 1269 of file rfc2045.c.

{
       return (p->content_description ? p->content_description:"");
}

Here is the caller graph for this function:

const char* rfc2045_content_id ( const struct rfc2045 )

Definition at line 1264 of file rfc2045.c.

{
       return (p->content_id ? p->content_id:"");
}

Here is the caller graph for this function:

const char* rfc2045_content_language ( const struct rfc2045 )

Definition at line 1274 of file rfc2045.c.

{
       return (p->content_language ? p->content_language:"");
}

Here is the caller graph for this function:

const char* rfc2045_content_md5 ( const struct rfc2045 )

Definition at line 1279 of file rfc2045.c.

{
       return (p->content_md5 ? p->content_md5:"");
}

Here is the caller graph for this function:

void rfc2045_decode ( struct rfc2045 ,
void(*)(struct rfc2045 *, struct rfc2045id *, void *)  ,
void *   
)

Definition at line 32 of file rfc2045decode.c.

{
struct rfc2045id topid;

       topid.idnum=1;
       decode(&topid, &topid.next, p, func, ptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_decodemimesection ( struct rfc2045src ,
struct rfc2045 ,
int(*)(const char *, size_t, void *)  ,
void *   
)

Definition at line 19 of file rfc2045decodemimesection.c.

{
       off_t  start_pos, end_pos, start_body;
       char   buf[BUFSIZ];
       ssize_t       cnt;
       off_t  dummy;
       int    rc;

       rfc2045_mimepos(rfc, &start_pos, &end_pos, &start_body,
              &dummy, &dummy);
       if (SRC_SEEK(src, start_body) == (off_t)-1) return (-1);

        rfc2045_cdecode_start(rfc, handler, voidarg);

        while (start_body < end_pos)
        {
                cnt=sizeof(buf);
                if (cnt > end_pos-start_body)
                        cnt=end_pos-start_body;
                cnt=SRC_READ(src, buf, cnt);
                if (cnt <= 0)   break;
                if ((rc=rfc2045_cdecode(rfc, buf, cnt)) != 0)
                     return (rc);
              start_body += cnt;
        }
        return (rfc2045_cdecode_end(rfc));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_decodemsgtoutf8 ( struct rfc2045src src,
struct rfc2045 p,
struct rfc2045_decodemsgtoutf8_cb callback 
)

Definition at line 87 of file rfc2045decodemsgtoutf8.c.

{
       struct rfc2045headerinfo *hi;
       int rc;

       hi=rfc2045header_start(src, p);

       if (hi)
       {
              char *header;
              char *value;

              while (rfc2045header_get(hi, &header, &value,
                                    RFC2045H_NOLC |
                                    RFC2045H_KEEPNL) == 0 && header)
              {
                     if (callback->flags & RFC2045_DECODEMSG_NOHEADERS)
                            continue;

                     if (doconvtoutf8_rfc822hdr(header, value,
                                             callback) < 0)
                            return -1;
              }
              rfc2045header_end(hi);
       }

       if (p->firstpart)
       {
              for (p=p->firstpart; p; p=p->next)
              {
                     if (!p->isdummy)
                     {
                            if ((rc=rfc2045_decodemsgtoutf8(src, p,
                                                        callback))
                                != 0)
                                   return rc;
                     }
              }
       }
       else
       {
              const char *content_type;
              const char *transfer_encoding;
              const char *charset;
              struct doconvtoutf8_info info;

              info.callback=callback;

              rfc2045_mimeinfo(p, &content_type, &transfer_encoding,
                             &charset);

              if (strncmp(content_type, "text/", 5) == 0 &&
                  (callback->flags & RFC2045_DECODEMSG_NOBODY) == 0 &&
                  (rc=rfc2045_decodetextmimesection(src, p, "utf-8", NULL,
                                                decode_handler,
                                                &info)) != 0)
                     return rc;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_decodetextmimesection ( struct rfc2045src ,
struct rfc2045 ,
const char *  ,
int *  ,
int(*)(const char *, size_t, void *)  ,
void *   
)

Definition at line 24 of file rfc2045decodemimesectionu.c.

{
       const char *dummy;
       const char *src_chset;

       libmail_u_convert_handle_t ci;
       int rc;
       int dummy_flag;

       if (!conv_err)
              conv_err= &dummy_flag;

       rfc2045_mimeinfo(rfc, &dummy, &dummy, &src_chset);

       *conv_err=0;

       if ((ci=libmail_u_convert_init(src_chset, mychset, handler, voidarg))
           == NULL)
       {
              *conv_err=1;
              return -1;
       }

       rc=rfc2045_decodemimesection(src, rfc, &myhandler, &ci);

       dummy_flag=0;
       if (libmail_u_convert_deinit(ci, &dummy_flag))
              rc= -1;

       if (dummy_flag)
              *conv_err=1;
       return (rc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_error ( const char *  )

Definition at line 126 of file esmtpclient.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc2045* rfc2045_find ( struct rfc2045 ,
const char *   
) [read]

Definition at line 41 of file rfc2045find.c.

{
struct rfc2045findstruct fs;

       fs.partnum=str;
       fs.ptr=0;
       rfc2045_decode(p, &do_decode, &fs);
       return (fs.ptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_free ( struct rfc2045 )

Definition at line 139 of file rfc2045.c.

{
struct rfc2045 *q, *r;

       for (q=p->firstpart; q; )
       {
              r=q->next;
              rfc2045_free(q);
              q=r;
       }
       rfc2045_freeattr(p->content_type_attr);
       rfc2045_freeattr(p->content_disposition_attr);

       if (p->header)              free(p->header);
       if (p->content_md5)  free(p->content_md5);
       if (p->content_base) free(p->content_base);
       if (p->content_location)    free(p->content_location);
       if (p->content_language)    free(p->content_language);
       if (p->content_id)   free(p->content_id);
       if (p->content_description) free(p->content_description);
       if (p->content_transfer_encoding) free(p->content_transfer_encoding);
       if (p->boundary) free(p->boundary);
       if (p->content_type) free(p->content_type);
       if (p->mime_version) free(p->mime_version);
       if (p->workbuf)             free(p->workbuf);
       if (p->content_disposition) free(p->content_disposition);
       if (p->rw_transfer_encoding) free(p->rw_transfer_encoding);
       free(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc2045* rfc2045_fromfd ( int  ) [read]

Definition at line 21 of file rfc2045_fromfd.c.

{
struct rfc2045       *rfc;
char   buf[BUFSIZ];
int    n;
off_t  orig_pos;

       if ((orig_pos=lseek(fd, 0L, SEEK_CUR)) == (off_t)-1) return (NULL);
       if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1)  return (NULL);
       if ((rfc=rfc2045_alloc()) == 0)    return (NULL);

       while ((n=read(fd, buf, sizeof(buf))) > 0)
              rfc2045_parse(rfc, buf, n);
       rfc2045_parse_partial(rfc);

       if (lseek(fd, orig_pos, SEEK_SET) == (off_t)-1)
       {
              rfc2045_free(rfc);
              rfc=0;
       }
       return (rfc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc2045_getattr ( const struct rfc2045attr ,
const char *   
)

Definition at line 56 of file rfc2045.c.

{
       while (p)
       {
              if (p->name && strcmp(p->name, name) == 0)
                     return (p->value);
              p=p->next;
       }
       return (0);
}

Here is the caller graph for this function:

const char* rfc2045_getdefaultcharset ( )

Definition at line 1220 of file rfc2045.c.

{
const char *p=rfc2045_defcharset;

       if (!p)       p=RFC2045CHARSET;
       return (p);
}

Here is the caller graph for this function:

int rfc2045_isdelsp ( const struct rfc2045 )

Definition at line 1257 of file rfc2045.c.

{
       const char *cb=rfc2045_getattr(p->content_type_attr, "delsp");

       return (cb && strcmp(cb, "yes") == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_isflowed ( const struct rfc2045 )

Definition at line 1250 of file rfc2045.c.

{
       const char *cb=rfc2045_getattr(p->content_type_attr, "format");

       return (cb && strcmp(cb, "flowed") == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 225 of file rfc2045reply.c.

{
       if (strcmp(ri->replymode, "forward") == 0
           || strcmp(ri->replymode, "forwardatt") == 0)
              return (mkforward(ri));

       return (mkreply(ri));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_mimeinfo ( const struct rfc2045 ,
const char **  ,
const char **  ,
const char **   
)

Definition at line 1203 of file rfc2045.c.

{
const char *c;

       *content_type_s=GETINFO(p->content_type, "text/plain");
       *content_transfer_encoding_s=GETINFO(p->content_transfer_encoding,
                                          "8bit");

       c=rfc2045_getattr(p->content_type_attr, "charset");
       if (!c)       c=rfc2045_getdefaultcharset();

       *charset_s=c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned rfc2045_mimepartcount ( const struct rfc2045 )

Definition at line 1307 of file rfc2045.c.

{
const struct rfc2045 *q;
unsigned n=0;

       for (q=p->firstpart; q; q=q->next) ++n;
       return (n);
}
void rfc2045_mimepos ( const struct rfc2045 ,
off_t *  ,
off_t *  ,
off_t *  ,
off_t *  ,
off_t *   
)

Definition at line 1284 of file rfc2045.c.

{
       *start_pos=p->startpos;
       *end_pos=p->endpos;

       *nlines=p->nlines;
       *nbodylines=p->nbodylines;
       if (p->parent)       /* MIME parts do not have the trailing CRLF */
       {
              *end_pos=p->endbody;
              if (*nlines)  --*nlines;
              if (*nbodylines) --*nbodylines;
       }
       *start_body=p->startbody;

       if (*start_body == *start_pos)     /* No header */
       {
              *start_body= *end_pos;
       }
}

Here is the caller graph for this function:

char* rfc2045_mk_boundary ( struct rfc2045 ,
struct rfc2045src  
)

Definition at line 28 of file rfc2045mkboundary.c.

{
char   hostnamebuf[256];
pid_t  mypid;
char   pidbuf[NUMBUFSIZE];
time_t mytime;
char   timebuf[NUMBUFSIZE];
static size_t cnt=0;
char   cntbuf[NUMBUFSIZE];
char   *p;
int    rc;

       hostnamebuf[sizeof(hostnamebuf)-1]=0;
       if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
              hostnamebuf[0]=0;
       mypid=getpid();
       time(&mytime);
       libmail_str_pid_t(mypid, pidbuf);
       libmail_str_time_t(mytime, timebuf);
       for (;;)
       {
              char tempbuf[NUMBUFSIZE];

              libmail_str_size_t(++cnt, tempbuf);
              sprintf(cntbuf, "%4s", tempbuf);
              for (p=cntbuf; *p == ' '; *p++ = '0')
                     ;
              p=malloc(strlen(hostnamebuf)+strlen(pidbuf)
                      +strlen(timebuf)+strlen(cntbuf)+11);
              if (!p)
              {
                     rfc2045_enomem();
                     return (NULL);
              }

              sprintf(p, "=_%-1.30s-%s-%s-%s", hostnamebuf,
                     pidbuf, timebuf, cntbuf);
              if ((rc=rfc2045_try_boundary(s, src, p)) == 0)
                     break;
              free(p);
              if (rc < 0)
                     return (NULL);
       }
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_parse ( struct rfc2045 ,
const char *  ,
size_t   
)

Definition at line 266 of file rfc2045.c.

{
       size_t l;

       while (s)
       {
              for (l=0; l<s; l++)
                     if (buf[l] == '\n')  break;
              if (l < s && buf[l] == '\n')
              {
                     ++l;
                     rfc2045_add_workbuf(h, buf, l);
                     doline(h);
                     h->workbuflen=0;
              }
              else
                     rfc2045_add_workbuf(h, buf, l);
              buf += l;
              s -= l;
       }

       if (h->workbuflen > 1024)
              rfc2045_parse_partial(h);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_parse_mime_header ( const char *  header,
void(*)(const char *, void *)  header_type_cb,
void(*)(const char *, const char *, void *)  header_param_cb,
void *  void_arg 
)

Definition at line 1330 of file rfc2045.c.

{
       struct rfc2045_parse_mime_info mi;
       struct rfc822t *h=rfc822t_alloc_new(header, NULL, NULL);

       mi.header_type_cb=header_type_cb;
       mi.header_param_cb=header_param_cb;
       mi.void_arg=void_arg;

       if (!h)
              return -1;

       parse_content_header(h, 0, parse_mime_cb, parse_param_cb, &mi);
       rfc822t_free(h);
       return 0;
}

Here is the call graph for this function:

void rfc2045_parse_partial ( struct rfc2045 )

Definition at line 291 of file rfc2045.c.

{
       /*
       ** Our buffer's getting pretty big.  Let's see if we can
       ** partially handle it.
       */

       if (h->workbuflen > 0)
       {
       struct rfc2045 *p;
       int    l, i;

              for (p=h; p->lastpart && !p->lastpart->workclosed;
                            p=p->lastpart)
                     ;

              /* If p->workinheader, we've got a mother of all headers
              ** here.  Well, that's just too bad, we'll end up garbling
              ** it.
              */

              l=h->workbuflen;

              /* We do need to make sure that the final \r\n gets
              ** stripped off, so don't gobble up everything if
              ** the last character we see is a \r
              */

              if (h->workbuf[l-1] == '\r')
                     --l;

              /* If we'll be rewriting, make sure rwprep knows about
              ** stuff that was skipped just now. */

              if (h->rfc2045acptr && !p->workinheader &&
                     (!p->lastpart || !p->lastpart->workclosed))
                     (*h->rfc2045acptr->section_contents)(h->workbuf, l);

              update_counts(p, p->endpos+l, p->endpos+l, 0);
              p->informdata=1;
              for (i=0; l<h->workbuflen; l++)
                     h->workbuf[i++]=h->workbuf[l];
              h->workbuflen=i;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2045_related_start ( const struct rfc2045 )

Definition at line 1083 of file rfc2045.c.

{
const char *cb=rfc2045_getattr( p->content_type_attr, "start");
struct rfc822t *t;
struct rfc822a       *a;
int    i;

       if (!cb || !*cb)     return (0);

       t=rfc822t_alloc_new(cb, 0, NULL);
       if (!t)
       {
              rfc2045_enomem();
              return(0);
       }

       a=rfc822a_alloc(t);
       if (!a)
       {
              rfc822t_free(t);
              rfc2045_enomem();
              return (0);
       }
       for (i=0; i<a->naddrs; i++)
              if (a->addrs[i].tokens)
              {
              char   *s=rfc822_getaddr(a, i);

                     rfc822a_free(a);
                     rfc822t_free(t);
                     if (!s)
                            rfc2045_enomem();
                     return (s);
              }

       rfc822a_free(a);
       rfc822t_free(t);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_rewrite ( struct rfc2045 p,
struct rfc2045src src,
int  fdout_arg,
const char *  appname 
)

Definition at line 396 of file rfc2045rewrite.c.

{
       fdout=fdout_arg;
       fdout_func=0;
       return (rfc2045_rewrite_common(p, src, appname));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_rewrite_func ( struct rfc2045 p,
struct rfc2045src src,
int(*)(const char *, int, void *)  funcarg,
void *  funcargarg,
const char *  appname 
)

Definition at line 404 of file rfc2045rewrite.c.

{
       fdout= -1;
       fdout_func=funcarg;
       fdout_arg=funcargarg;
       return (rfc2045_rewrite_common(p, src, appname));
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc2045* rfc2045_searchcontenttype ( struct rfc2045 ,
const char *   
) [read]

Definition at line 21 of file rfc2045searchcontenttype.c.

{
       const  char *content_type, *dummy;
       struct rfc2045 *p;

        rfc2045_mimeinfo(rfc, &content_type, &dummy, &dummy);
       if (strcmp(content_type, ct) == 0)
              return (rfc);

       for (p=rfc->firstpart; p; p=p->next)
       {
              if (p->isdummy)      continue;
              rfc2045_mimeinfo(p, &content_type, &dummy, &dummy);
              if (strcmp(content_type, ct) == 0)
                     break;
              if (strncmp(content_type, "multipart/", 10) == 0)
                     return(rfc2045_searchcontenttype(p, ct));
       }

       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_setdefaultcharset ( const char *  )

Definition at line 1228 of file rfc2045.c.

{
char   *p=strdup(charset);

       if (!p)
       {
              rfc2045_enomem();
              return;
       }

       if (rfc2045_defcharset)     free(rfc2045_defcharset);
       rfc2045_defcharset=p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2045_try_boundary ( struct rfc2045 ,
struct rfc2045src ,
const char *   
)

Definition at line 108 of file rfc2045tryboundary.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045_xdump ( struct rfc2045 )

Definition at line 44 of file rfc2045xdump.c.

{
       dodump(p, 0);
}

Here is the call graph for this function:

void rfc2045header_end ( struct rfc2045headerinfo )

Definition at line 127 of file rfc2045header.c.

{
       if (p->headerbuf)
              free(p->headerbuf);
       free(p);
}

Here is the caller graph for this function:

struct rfc2045* rfc2045header_fromfd ( int  ) [read]

Definition at line 46 of file rfc2045_fromfd.c.

{
struct        rfc2045        *rfc;
char        buf[BUFSIZ];
int        n;
off_t        orig_pos;

        if ((orig_pos=lseek(fd, 0L, SEEK_CUR)) == (off_t)-1) return (NULL);
        if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1)        return (NULL);
        if ((rfc=rfc2045_alloc()) == 0)        return (NULL);

        while (rfc->workinheader && (n=read(fd, buf, sizeof(buf))) > 0)
                rfc2045_parse(rfc, buf, n);
        if (lseek(fd, orig_pos, SEEK_SET) == (off_t)-1)
        {
                rfc2045_free(rfc);
                rfc=0;
        }
        return (rfc);
}

Here is the call graph for this function:

int rfc2045header_get ( struct rfc2045headerinfo ,
char **  ,
char **  ,
int   
)

Definition at line 170 of file rfc2045header.c.

{
       int c=PEEK(p);
       int isnl=0;
       size_t n=0;
       char *s, *t;
       int eatspace=0;

       if (c == -1 || c == '\r' || c == '\n')
       {
              *header=*value=NULL;
              return (0);
       }

       for (;;)
       {
              if (n >= p->headerbufsize)
              {
                     size_t n=p->headerbufsize += 256;
                     char *s= p->headerbuf ?
                            realloc(p->headerbuf, n):
                            malloc(n);

                     if (!s)
                            return (-1);
                     p->headerbuf=s;
                     p->headerbufsize=n;
              }

              c=PEEK(p);
              if (c < 0)
                     break;

              if (c == '\r')
              {
                     --p->readleft;
                     ++p->readptr;
                     continue;
              }

              if (isnl) /* Last char was newline */
              {
                     if (!isspace((int)(unsigned char)c) || c == '\n')
                            break;

                     isnl=0;

                     if ((flags & RFC2045H_KEEPNL) == 0)
                            eatspace=1; /* Fold headers */
              }

              if (c == '\n')
                     isnl=1;

              if (eatspace)
              {
                     if (c != '\n' && isspace((int)(unsigned char)c))
                     {
                            --p->readleft;
                            ++p->readptr;
                            continue;
                     }
                     eatspace=0;
              }

              if (c == '\n' && (flags & RFC2045H_KEEPNL) == 0)
                     c=' ';

              p->headerbuf[n++]=c;
              --p->readleft;
              ++p->readptr;
       }

       while (n > 0 && p->headerbuf[n-1] == ' ')
              --n;

       p->headerbuf[n]=0;

       *header= *value= p->headerbuf;

       while (**value)
       {
              if (**value == ':')
              {
                     **value=0;
                     ++*value;

                     while (**value && isspace((int)(unsigned char)**value))
                            ++*value;
                     break;
              }

              if (!(flags & RFC2045H_NOLC))
              {
                     if (**value >= 'A' && **value <= 'Z')
                            **value += 'a' - 'A';
              }
              ++*value;
       }

       s=strrchr( *value, '\n');

       if (s && *s && s[1] == 0)
              *s=0;

       s=strrchr( *value, '\r');

       if (s && *s && s[1] == 0)
              *s=0;

       for (s=t=*value; *s; )
              if (!isspace((int)(unsigned char)*s++))
                     t=s;
       *t=0;
       return (0);
}

Here is the caller graph for this function:

struct rfc2045headerinfo* rfc2045header_start ( struct rfc2045src ,
struct rfc2045  
) [read]

Definition at line 92 of file rfc2045header.c.

{
       off_t start_pos, dummy, start_body;
       int firstheader;
       struct rfc2045headerinfo *p;

       if (rfcp)
       {
              rfc2045_mimepos(rfcp, &start_pos, &dummy, &start_body, &dummy,
                            &dummy);
              firstheader=0;
       }
       else
       {
              start_pos=0;
              start_body=0;
              firstheader=1;
       }

       if (SRC_SEEK(src, start_pos) < 0)
              return NULL;

       p=(struct rfc2045headerinfo *)calloc(sizeof(struct rfc2045headerinfo),
                                        1);

       if (!p)
              return (NULL);
       p->src=src;

       p->headerleft=start_body - start_pos;
       p->firstheader=firstheader;
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2045src_deinit ( struct rfc2045src )

Definition at line 46 of file rfc2045header.c.

{
       (*ptr->deinit_func)(ptr->arg);
}

Here is the caller graph for this function:

struct rfc2045src* rfc2045src_init_fd ( int  fd) [read]

Definition at line 29 of file rfc2045header.c.

{
       struct rfc2045src_fd *ptr=malloc(sizeof(struct rfc2045src_fd));

       if (!ptr)
              return NULL;

       memset(ptr, 0, sizeof(*ptr));

       ptr->src.arg=ptr;
       ptr->src.deinit_func=deinit_func_fd;
       ptr->src.seek_func=seek_func_fd;
       ptr->src.read_func=read_func_fd;
       ptr->fd=fd;
       return &ptr->src;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2231_attrCreate ( const char *  name,
const char *  value,
const char *  charset,
const char *  language,
int(*)(const char *param, const char *value, void *void_arg)  cb_func,
void *  cb_arg 
)

Definition at line 31 of file rfc2231encode.c.

{
       size_t l;
       const char *cp;
       char *p, *q;
       int rc;

       if (strlen(name)>60)
       {
              errno=EINVAL;
              return -1; /* You kidding me? */
       }

       for (l=0; value[l]; l++)
              if (DOENCODE(value[l]))
                     break;

       if (value[l] == 0 && strlen(name)+strlen(value)<75) /* No need to encode */
       {
              char *p=malloc(strlen(value)+3);

              if (!p)
                     return -1;

              strcat(strcat(strcpy(p, "\""), value), "\"");

              rc=(*cb_func)(name, p, cb_arg);
              free(p);
              return rc;
       }

       if (!charset) charset="";
       if (!language) language="";

       l=strlen(charset)+strlen(language)+strlen(value)+3;

       for (cp=value; *cp; cp++)
              if (DOENCODE(*cp))
                     l += 2;

       p=malloc(l);
       if (!p)
              return -1;

       strcat(strcat(strcat(strcpy(p, charset), "'"),language), "'");
       q=p+strlen(p);
       for (cp=value; *cp; cp++)
       {
              if (DOENCODE(*cp))
              {
                     *q++='%';
                     *q++ = xdigit[ ((unsigned char)*cp / 16) & 15];
                     *q++ = xdigit[ *cp & 15];
              }
              else
                     *q++= *cp;
       }
       *q=0;

       rc=docreate(name, p, cb_func, cb_arg);
       free(p);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2231_buildAttrList ( struct rfc2231param **  paramList,
const char *  name,
const char *  attrName,
const char *  attrValue 
)

Definition at line 35 of file rfc2231.c.

{
       int nameLen=strlen(name);

       if (strncmp(attrName, name, nameLen) == 0 &&
           (attrName[nameLen] == 0 ||
            attrName[nameLen] == '*'))
       {
              struct rfc2231param *n
                     =malloc(sizeof(struct rfc2231param)), **o;

              const char *p=attrName + nameLen;

              if (!n)
              {
                     rfc2231_paramDestroy(*paramList);
                     return -1;
              }

              /*
              ** A non-rfc 2231 parameter has paramnum set to 0, an
              ** rfc 2231 parameter has paramnum set to its number, plus 1.
              */

              if (*p == 0)
              {
                     n->paramnum=0;
              }
              else
              {
                     p++;

                     n->paramnum=atoi(p)+1;

                     if (n->paramnum <= 0)
                            n->paramnum=1;
              }

              p=strrchr(attrName, '*');

              n->encoded=p && p[1] == 0;
              n->value=attrValue;

              for (o=paramList; *o; o= &(*o)->next)
                     if ( (*o)->paramnum > n->paramnum)
                            break;

              n->next= *o;
              *o=n;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2231_decodeDisposition ( struct rfc2045 rfc,
const char *  name,
char **  chsetPtr,
char **  langPtr,
char **  textPtr 
)

Definition at line 298 of file rfc2231.c.

{
       return rfc2231_decode(rfc->content_disposition_attr, name,
                           chsetPtr, langPtr, textPtr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2231_decodeType ( struct rfc2045 rfc,
const char *  name,
char **  chsetPtr,
char **  langPtr,
char **  textPtr 
)

Definition at line 289 of file rfc2231.c.

{
       return rfc2231_decode(rfc->content_type_attr, name,
                           chsetPtr, langPtr, textPtr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2231_paramDecode ( struct rfc2231param paramList,
char *  charsetPtr,
char *  langPtr,
char *  textPtr,
int *  charsetLen,
int *  langLen,
int *  textLen 
)

Definition at line 143 of file rfc2231.c.

{
       int first=1;

       *charsetLen=*langLen=*textLen=1;   /* null byte */

       if (paramList && paramList->paramnum == 0 &&
           paramList->next)
              paramList=paramList->next;
       /*
       ** Both a non-rfc2231 and an rfc2231 parameter was specified, so
       ** take the better one.
       */

       while (paramList)
       {
              const char *p=paramList->value;

              if (first && paramList->encoded)
              {
                     const char *q=strchr(p, '\'');

                     if (q && strchr(q+1, '\''))
                     {
                            while (*p != '\'')
                            {
                                   if (charsetPtr)
                                          *charsetPtr++ = *p;
                                   p++;
                                   (*charsetLen)++;
                            }
                            p++;
                            while (*p != '\'')
                            {
                                   if (langPtr)
                                          *langPtr++ = *p;
                                   p++;
                                   (*langLen)++;
                            }
                            p++;
                     }
              }

              first=0;

              while (*p)
              {
                     if (*p == '%' && p[1] && p[2] && paramList->encoded)
                     {
                            if (textPtr)
                                   *textPtr++ = nyb(p[1]) * 16 +
                                          nyb(p[2]);
                            p += 3;
                     }
                     else
                     {
                            if (textPtr)
                                   *textPtr++ = *p;

                            p++;
                     }

                     (*textLen)++;
              }

              paramList=paramList->next;
       }

       if (charsetPtr)
              *charsetPtr=0;
       if (langPtr)
              *langPtr=0;
       if (textPtr)
              *textPtr=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc2231_paramDestroy ( struct rfc2231param paramList)

Definition at line 24 of file rfc2231.c.

{
       while (p)
       {
              struct rfc2231param *q=p->next;

              free(p);
              p=q;
       }
}

Here is the caller graph for this function:

int rfc2231_udecodeDisposition ( struct rfc2045 rfc,
const char *  name,
const char *  myChset,
char **  textPtr 
)

Definition at line 356 of file rfc2231.c.

{
       char *text, *chset;

       if (rfc2231_decodeDisposition(rfc, name, &chset, NULL, &text) < 0)
              return (-1);

       if (conv_unicode(&text, chset, myCharset) < 0)
       {
              free(text);
              free(chset);
              return (-1);
       }

       *textPtr=text;
       free(chset);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2231_udecodeType ( struct rfc2045 rfc,
const char *  name,
const char *  myChset,
char **  textPtr 
)

Definition at line 335 of file rfc2231.c.

{
       char *text, *chset;

       if (rfc2231_decodeType(rfc, name, &chset, NULL, &text) < 0)
              return (-1);

       if (conv_unicode(&text, chset, myCharset) < 0)
       {
              free(text);
              free(chset);
              return (-1);
       }

       *textPtr=text;
       free(chset);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function: