Back to index

courier  0.68.2
Functions
mimegpgheader.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "mimegpgheader.h"

Go to the source code of this file.

Functions

void libmail_readheader_init (struct read_header_context *cts)
int libmail_readheader (struct read_header_context *cts, const char *buf)
struct headerlibmail_readheader_finish (struct read_header_context *cts)
void libmail_header_free (struct header *p)
struct headerlibmail_header_find (struct header *p, const char *n)
const char * libmail_header_find_txt (struct header *p, const char *n)
void libmail_mimeheader_free (struct mime_header *m)
static void striptrlspc (char *p)
struct mime_headerlibmail_mimeheader_parse (const char *field)
const char * libmail_mimeheader_getattr (struct mime_header *m, const char *name)

Function Documentation

struct header* libmail_header_find ( struct header p,
const char *  n 
) [read]

Definition at line 104 of file mimegpgheader.c.

{
       int l=strlen(n);

       while (p)
       {
              if (p->header && strncasecmp(p->header, n, l) == 0)
                     return (p);
              p=p->next;
       }
       return (p);
}

Here is the caller graph for this function:

const char* libmail_header_find_txt ( struct header p,
const char *  n 
)

Definition at line 117 of file mimegpgheader.c.

{
       p=libmail_header_find(p, n);
       if (p)
              return (p->header+strlen(n));
       return (NULL);
}

Here is the call graph for this function:

void libmail_header_free ( struct header p)

Definition at line 90 of file mimegpgheader.c.

{
       struct header *q;

       while (p)
       {
              q=p->next;
              if (p->header)
                     free(p->header);
              free(p);
              p=q;
       }
}

Here is the caller graph for this function:

void libmail_mimeheader_free ( struct mime_header m)

Definition at line 125 of file mimegpgheader.c.

{
       struct mime_attribute *a;

       while ((a=m->attr_list) != 0)
       {
              m->attr_list=a->next;
              if (a->name)
                     free(a->name);
              if (a->value)
                     free(a->value);
              free(a);
       }
       free(m->header_name);
       free(m);
}

Here is the caller graph for this function:

const char* libmail_mimeheader_getattr ( struct mime_header m,
const char *  name 
)

Definition at line 292 of file mimegpgheader.c.

{
       struct mime_attribute *a;

       for (a=m->attr_list; a; a=a->next)
       {
              if (strcasecmp(a->name, name) == 0)
                     return (a->value);
       }
       return (0);
}

Here is the caller graph for this function:

struct mime_header* libmail_mimeheader_parse ( const char *  field) [read]

Definition at line 152 of file mimegpgheader.c.

{
       struct mime_header *header=0;
       struct mime_attribute *last_attr=0;

       while (*field || header == 0)
       {
              const char *p;

              if (*field && isspace((int)(unsigned char)*field))
              {
                     ++field;
                     continue;
              }
              for (p=field; *p; p++)
              {
                     if (*p == ';')
                            break;
                     if (*p == '=' && header)
                            break;
              }

              if (!header)
              {
                     if ((header=(struct mime_header *)
                          malloc(sizeof(*header))) == 0)
                            return NULL;

                     if ((header->header_name=malloc(p-field+1)) == 0)
                     {
                            free(header);
                            return (NULL);
                     }
                     memcpy(header->header_name, field, p-field);
                     header->header_name[p-field]=0;
                     header->attr_list=NULL;
                     striptrlspc(header->header_name);
                     field=p;
              }
              else
              {
                     struct mime_attribute *a=(struct mime_attribute *)
                            malloc(sizeof(struct mime_attribute));
                     int pass, len;
                     char *s=0;

                     if (!a)
                     {
                            libmail_mimeheader_free(header);
                            return NULL;
                     }
                     if ((a->name=malloc(p-field+1)) == NULL)
                     {
                            free(a);
                            libmail_mimeheader_free(header);
                            return NULL;
                     }
                     memcpy(a->name, field, p-field);
                     a->name[p-field]=0;
                     striptrlspc(a->name);
                     a->value=0;
                     a->next=0;
                     if (last_attr)
                     {
                            last_attr->next=a;
                     }
                     else
                     {
                            header->attr_list=a;
                     }
                     last_attr=a;

                     if (*p == '=')
                            ++p;

                     while (*p && isspace((int)(unsigned char)*p))
                     {
                            ++p;
                     }

                     field=p;

                     len=0;
                     for (pass=0; pass<2; pass++)
                     {
                            int quote=0;

                            if (pass)
                            {
                                   s=a->value=malloc(len);
                                   if (!s)
                                   {
                                          libmail_mimeheader_free(header);
                                          return NULL;
                                   }
                            }
                            len=0;

                            for (p=field; *p; )
                            {
                                   if (*p == ';' && !quote)
                                   {
                                          break;
                                   }

                                   if (*p == '"')
                                   {
                                          quote= !quote;
                                          ++p;
                                          continue;
                                   }

                                   if (*p == '\\' && p[1])
                                          ++p;

                                   if (pass)
                                          s[len]= *p;
                                   ++len;
                                   ++p;
                            }
                            if (pass)
                                   s[len]=0;
                            ++len;
                     }

                     striptrlspc(a->value);
                     field=p;
                     if (a->value[0] == 0)
                     {
                            free(a->value);
                            a->value=0;
                     }
              }
              if (*field == ';')
                     ++field;
       }

       return (header);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int libmail_readheader ( struct read_header_context cts,
const char *  buf 
)

Definition at line 23 of file mimegpgheader.c.

{
       int l;
       char *s;
       struct header *p;

       l=strlen(buf);
       p=0;

       if (cts->continue_header)
              p=cts->last;
       else if (isspace((int)(unsigned char)buf[0]))
              p=cts->last;

       if (!p)
       {
              p=(struct header *)malloc(sizeof(*p));
              if (!p)
                     return -1;

              p->next=0;
              p->header=0;
              cts->header_len=0;
              if (cts->last)
                     cts->last->next=p;
              else
                     cts->first=p;
              cts->last=p;
       }

       s=p->header ? realloc(p->header, cts->header_len + l + 1)
              :malloc(l+1);

       if (!s)
              return (-1);

       strcpy(s+cts->header_len, buf);
       cts->header_len += l;
       p->header=s;

       cts->continue_header=!l || buf[l-1] != '\n';

       return 0;
}

Here is the caller graph for this function:

struct header* libmail_readheader_finish ( struct read_header_context cts) [read]

Definition at line 68 of file mimegpgheader.c.

{
       struct header *last;

       for (last=cts->first; last; last=last->next)
       {
              char *q, *r;

              if (!last->header)
                     continue;

              for (q=r=last->header; *r; r++)
              {
                     if (*r == '\r')
                            continue;
                     *q++ = *r;
              }
              *q=0;
       }
       return (cts->first);
}

Here is the caller graph for this function:

Definition at line 15 of file mimegpgheader.c.

{
       cts->continue_header=0;
       cts->header_len=0;
       cts->first=0;
       cts->last=0;
}

Here is the caller graph for this function:

static void striptrlspc ( char *  p) [static]

Definition at line 142 of file mimegpgheader.c.

{
       char *q;

       for (q=p; *p; p++)
              if (!isspace((int)(unsigned char)*p))
                     q=p+1;
       *q=0;
}

Here is the caller graph for this function: