Back to index

courier  0.68.2
Functions
msgbodystructure.c File Reference
#include "imaptoken.h"
#include "imapwrite.h"
#include "rfc822/rfc822.h"
#include "rfc2045/rfc2045.h"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

void msgenvelope (void(*)(const char *, size_t), FILE *, struct rfc2045 *)
void msgappends (void(*)(const char *, size_t), const char *, size_t)
static void do_param_list (void(*writefunc)(const char *, size_t), struct rfc2045attr *a)
static void contentstr (void(*writefunc)(const char *, size_t), const char *s)
static void do_disposition (void(*writefunc)(const char *, size_t), const char *disposition_s, struct rfc2045attr *disposition_a)
void msgbodystructure (void(*writefunc)(const char *, size_t), int dox, FILE *fp, struct rfc2045 *mimep)

Function Documentation

static void contentstr ( void(*)(const char *, size_t)  writefunc,
const char *  s 
) [static]

Definition at line 70 of file msgbodystructure.c.

{
       if (!s || !*s)
       {
              (*writefunc)("NIL", 3);
              return;
       }

       (*writefunc)("\"", 1);
       msgappends(writefunc, s, strlen(s));
       (*writefunc)("\"", 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_disposition ( void(*)(const char *, size_t)  writefunc,
const char *  disposition_s,
struct rfc2045attr disposition_a 
) [static]

Definition at line 84 of file msgbodystructure.c.

{
       if ( (disposition_s == 0 || *disposition_s == 0) &&
              disposition_a == 0)
       {
              (*writefunc)("NIL", 3);
              return;
       }
       (*writefunc)("(", 1);

       if (disposition_s && *disposition_s)
       {
              (*writefunc)("\"", 1);
              msgappends(writefunc, disposition_s,
                     strlen(disposition_s));
              (*writefunc)("\"", 1);
       }
       else
              (*writefunc)("\"\"", 2);

       (*writefunc)(" ", 1);
       do_param_list(writefunc, disposition_a);
       (*writefunc)(")", 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_param_list ( void(*)(const char *, size_t)  writefunc,
struct rfc2045attr a 
) [static]

Definition at line 24 of file msgbodystructure.c.

{
int    flag;
char   *p;

       flag=0;
       p="(";
       for (; a; a=a->next)
       {
              (*writefunc)(p, strlen(p));
              (*writefunc)("\"", 1);
              if (a->name)
                     msgappends(writefunc, a->name, strlen(a->name));
              (*writefunc)("\" \"", 3);
              if (a->value)
              {
#if    IMAP_CLIENT_BUGS

              /* NETSCAPE */

              char *u, *v, *w;

                     u=strdup(a->value);
                     if (!u)       write_error_exit(0);
                     strcpy(u, a->value);
                     for (v=w=u; *v; v++)
                            if (*v != '\\')      *w++ = *v;
                     *w=0;
                     msgappends(writefunc, u, strlen(u));
                     free(u);

#else
                     msgappends(writefunc, a->value, strlen(a->value));
#endif
              }
              (*writefunc)("\"", 1);
              flag=1;
              p=" ";
       }
       if (flag)
              (*writefunc)(")", 1);
       else
              (*writefunc)("NIL", 3);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void msgappends ( void(*)(const char *, size_t)  ,
const char *  ,
size_t   
)

Definition at line 58 of file msgenvelope.c.

{
       size_t i,j;
       char *q=0;

       for (i=0; i<l; i++)
              if (s[i] & 0x80)     /* Illegal 8-bit header content */
              {
                     char *p=malloc(l+1);

                     if (!p)
                            write_error_exit(0);
                     if (l)
                            memcpy(p, s, l);
                     p[l]=0;

                     /* Assume UTF-8, if not, well, GIGO */
                     q=rfc2047_encode_str(p, "utf-8",
                                        rfc2047_qp_allow_any);
                     free(p);
                     if (!q)
                            write_error_exit(0);
                     s=q;
                     l=strlen(s);
              }

       for (i=j=0; i<l; i++)
       {
              if (s[i] == '"' || s[i] == '\\')
              {
                     (*writefunc)(s+j, i-j);
                     (*writefunc)("\\", 1);
                     j=i;
              }
       }
       (*writefunc)(s+j, i-j);
       if (q)
              free(q);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void msgbodystructure ( void(*)(const char *, size_t)  writefunc,
int  dox,
FILE *  fp,
struct rfc2045 mimep 
)

Definition at line 111 of file msgbodystructure.c.

{
const char *content_type_s;
const char *content_transfer_encoding_s;
const char *charset_s;
off_t start_pos, end_pos, start_body;
off_t nlines, nbodylines;
const char *disposition_s;

char   *p, *q;

       rfc2045_mimeinfo(mimep, &content_type_s, &content_transfer_encoding_s,
              &charset_s);
       rfc2045_mimepos(mimep, &start_pos, &end_pos, &start_body,
              &nlines, &nbodylines);

       disposition_s=mimep->content_disposition;

       (*writefunc)("(", 1);

       if (mimep->firstpart && mimep->firstpart->isdummy &&
              mimep->firstpart->next)
              /* MULTIPART */
       {
       struct rfc2045       *childp;

              for (childp=mimep->firstpart; (childp=childp->next) != 0; )
                     msgbodystructure(writefunc, dox, fp, childp);

              (*writefunc)(" \"", 2);
              p=strchr(content_type_s, '/');
              if (p)
                     msgappends(writefunc, p+1, strlen(p+1));
              (*writefunc)("\"", 1);

              if (dox)
              {
                     (*writefunc)(" ", 1);
                     do_param_list(writefunc, mimep->content_type_attr);

                     (*writefunc)(" ", 1);
                     do_disposition(writefunc, disposition_s,
                            mimep->content_disposition_attr);

                     (*writefunc)(" ", 1);
                     contentstr(writefunc, rfc2045_content_language(mimep));
              }
       }
       else
       {
       char   *mybuf;
       char   buf[40];
       const  char *cp;

              mybuf=my_strdup(content_type_s);
              q=strtok(mybuf, " /");
              (*writefunc)("\"", 1);
              if (q)
                     msgappends(writefunc, q, strlen(q));
              (*writefunc)("\" \"", 3);
              if (q) q=strtok(0, " /");
              if (q)
                     msgappends(writefunc, q, strlen(q));
              free(mybuf);
              (*writefunc)("\" ", 2);

              do_param_list(writefunc, mimep->content_type_attr);

              (*writefunc)(" ", 1);
              cp=rfc2045_content_id(mimep);
              if (!cp || !*cp)
                     contentstr(writefunc, cp);
              else
              {
                     (*writefunc)("\"<", 2);
                     msgappends(writefunc, cp, strlen(cp));
                     (*writefunc)(">\"", 2);
              }
              (*writefunc)(" ", 1);
              contentstr(writefunc, rfc2045_content_description(mimep));

              (*writefunc)(" \"", 2);
              msgappends(writefunc, content_transfer_encoding_s,
                     strlen(content_transfer_encoding_s));
              (*writefunc)("\" ", 2);

              sprintf(buf, "%lu", (unsigned long)
                     (end_pos-start_body+nbodylines));
                     /* nbodylines added for CRs */
              (*writefunc)(buf, strlen(buf));

              if (
              (content_type_s[0] == 't' || content_type_s[0] == 'T') &&
              (content_type_s[1] == 'e' || content_type_s[1] == 'E') &&
              (content_type_s[2] == 'x' || content_type_s[2] == 'X') &&
              (content_type_s[3] == 't' || content_type_s[3] == 'T') &&
                     (content_type_s[4] == '/' ||
                      content_type_s[4] == 0))
              {
                     (*writefunc)(" ", 1);
                     sprintf(buf, "%lu", (unsigned long)nbodylines);
                     (*writefunc)(buf, strlen(buf));
              }

              if (mimep->firstpart && !mimep->firstpart->isdummy)
                     /* message/rfc822 */
              {
                     (*writefunc)(" ", 1);
                     msgenvelope(writefunc, fp, mimep->firstpart);
                     (*writefunc)(" ", 1);
                     msgbodystructure(writefunc, dox, fp, mimep->firstpart);
                     (*writefunc)(" ", 1);
                     sprintf(buf, "%lu", (unsigned long)nbodylines);
                     (*writefunc)(buf, strlen(buf));
              }

              if (dox)
              {
                     (*writefunc)(" ", 1);
                     contentstr(writefunc, rfc2045_content_md5(mimep));

                     (*writefunc)(" ", 1);
                     do_disposition(writefunc, disposition_s,
                            mimep->content_disposition_attr);

                     (*writefunc)(" NIL", 4);
                            /* TODO Content-Language: */
              }
       }
       (*writefunc)(")", 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void msgenvelope ( void(*)(const char *, size_t)  ,
FILE *  ,
struct rfc2045  
)

Definition at line 215 of file msgenvelope.c.

{
char   *date=0, *subject=0;
char   *from=0, *sender=0, *replyto=0, *to=0, *cc=0, *bcc=0;
char   *inreplyto=0, *msgid=0;

off_t start_pos, end_pos, start_body;
off_t nlines, nbodylines;

char   *p, *q, *r;

       rfc2045_mimepos(mimep, &start_pos, &end_pos, &start_body,
              &nlines, &nbodylines);

       if (fseek(fp, start_pos, SEEK_SET) < 0)
       {
              perror("fseek");
              exit(0);
       }

       while ((p=read_header(fp, &start_pos, &start_body)) != 0)
       {
       char   **hdrp=0;
       size_t oldl, newl;
       size_t c;

              if ((q=strchr(p, ':')) != 0)
                     *q++=0;
              for (r=p; *r; r++)
                     *r=tolower((int)(unsigned char)*r);
              if (strcmp(p, "date") == 0) hdrp= &date;
              if (strcmp(p, "subject") == 0)     hdrp= &subject;
              if (strcmp(p, "from") == 0) hdrp= &from;
              if (strcmp(p, "sender") == 0)      hdrp= &sender;
              if (strcmp(p, "reply-to") == 0)    hdrp= &replyto;
              if (strcmp(p, "to") == 0)   hdrp= &to;
              if (strcmp(p, "cc") == 0)   hdrp= &cc;
              if (strcmp(p, "bcc") == 0)  hdrp= &bcc;
              if (strcmp(p, "in-reply-to") == 0) hdrp= &inreplyto;
              if (strcmp(p, "message-id") == 0) hdrp= &msgid;
              if (!hdrp)    continue;
              if (!q)       q="";
              oldl= *hdrp ? strlen(*hdrp):0;
              newl= strlen(q);
              c=oldl+newl+1;
              if (c > 8192) c=8192;
              r= (char *)(*hdrp ? realloc(*hdrp, c+1):malloc(c+1));
              if (!r)
              {
                     perror("malloc");
                     exit(1);
              }
              if (oldl && oldl < c)
                     r[oldl++]=',';
              newl=c-oldl;
              if (newl)     memcpy(r+oldl, q, newl);
              r[oldl+newl]=0;
              *hdrp= r;
       }

#if 1
       if (!replyto)
              replyto=strdup(from ? from:"");
       if (!sender)
              sender=strdup(from ? from:"");

       if (!replyto || !sender)
       {
              perror("malloc");
              exit(1);
       }
#endif

       (*writefunc)("(", 1);
       doenvs(writefunc, date);
       (*writefunc)(" ", 1);
       doenvs(writefunc, subject);
       (*writefunc)(" ", 1);
       doenva(writefunc, from);
       (*writefunc)(" ", 1);
       doenva(writefunc, sender);
       (*writefunc)(" ", 1);
       doenva(writefunc, replyto);
       (*writefunc)(" ", 1);
       doenva(writefunc, to);
       (*writefunc)(" ", 1);
       doenva(writefunc, cc);
       (*writefunc)(" ", 1);
       doenva(writefunc, bcc);
       (*writefunc)(" ", 1);
       doenvs(writefunc, inreplyto);
       (*writefunc)(" ", 1);
       doenvs(writefunc, msgid);
       (*writefunc)(")", 1);
}

Here is the call graph for this function: