Back to index

courier  0.68.2
Classes | Defines | Functions
rfc822hdr.h File Reference
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rfc822hdr

Defines

#define rfc822hdr_init(h, s)   do { memset((h), 0, sizeof(*h)); (h)->maxsize=(s); } while(0)
#define rfc822hdr_free(h)   do { if ((h)->header) free ((h)->header); } while (0)

Functions

int rfc822hdr_read (struct rfc822hdr *, FILE *, off_t *, off_t)
void rfc822hdr_fixname (struct rfc822hdr *)
void rfc822hdr_collapse (struct rfc822hdr *)
int rfc822hdr_namecmp (const char *a, const char *b)
int rfc822hdr_is_addr (const char *hdr)

Class Documentation

struct rfc822hdr

Definition at line 24 of file rfc822hdr.h.

Class Members
size_t hdrsize
char * header
size_t maxsize
char * value

Define Documentation

#define rfc822hdr_free (   h)    do { if ((h)->header) free ((h)->header); } while (0)

Definition at line 35 of file rfc822hdr.h.

#define rfc822hdr_init (   h,
 
)    do { memset((h), 0, sizeof(*h)); (h)->maxsize=(s); } while(0)

Definition at line 32 of file rfc822hdr.h.


Function Documentation

void rfc822hdr_collapse ( struct rfc822hdr )

Definition at line 113 of file rfc822hdr.c.

{
       char *p, *q;

       for (p=q=h->value; *p; )
       {
              if (*p == '\n')
              {
                     while (*p && isspace((int)(unsigned char)*p))
                            ++p;
                     *q++=' ';
                     continue;
              }
              *q++ = *p++;
       }
       *q=0;
}

Here is the caller graph for this function:

void rfc822hdr_fixname ( struct rfc822hdr )

Definition at line 103 of file rfc822hdr.c.

{
       char *p;

       for (p=h->header; *p; p++)
       {
              *p=tolower((int)(unsigned char)*p);
       }
}

Here is the caller graph for this function:

int rfc822hdr_is_addr ( const char *  hdr)

Definition at line 150 of file rfc822hdr.c.

{
       return rfc822hdr_namecmp(hdr, "from") == 0 ||
              rfc822hdr_namecmp(hdr, "to") == 0 ||
              rfc822hdr_namecmp(hdr, "cc") == 0 ||
              rfc822hdr_namecmp(hdr, "bcc") == 0 ||
              rfc822hdr_namecmp(hdr, "resent-from") == 0 ||
              rfc822hdr_namecmp(hdr, "resent-to") == 0 ||
              rfc822hdr_namecmp(hdr, "resent-cc") == 0 ||
              rfc822hdr_namecmp(hdr, "resent-bcc") == 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc822hdr_namecmp ( const char *  a,
const char *  b 
)

Definition at line 135 of file rfc822hdr.c.

{
       int rc;

       while ((rc=(int)(unsigned char)lc(*a) - (int)(unsigned char)lc(*b))==0)
       {
              if (!*a)
                     return 0;
              ++a;
              ++b;
       }

       return rc;
}

Here is the caller graph for this function:

int rfc822hdr_read ( struct rfc822hdr ,
FILE *  ,
off_t *  ,
off_t   
)

Definition at line 18 of file rfc822hdr.c.

{
       size_t n=0;
       int c;

       for (;;)
       {
              if ( n >= h->hdrsize)
              {
                     size_t hn=h->hdrsize + 1024;
                     char *p= h->header ? realloc(h->header, hn):
                            malloc(hn);

                     if (!p)
                            return (-1);

                     h->header=p;
                     h->hdrsize=hn;
              }

              if (pos && *pos >= epos)
              {
                     h->header[n]=0;
                     break;
              }

              c=getc(f);
              if (c == EOF)
              {
                     if (pos)
                            *pos=epos;
                     h->header[n]=0;
                     break;
              }
              if (pos)
                     ++*pos;

              h->header[n]=c;
              if (c == '\n')
              {
                     if (n == 0)
                     {
                            if (pos)
                                   *pos=epos;
                            h->header[n]=0;
                            break;
                     }

                     c=getc(f);
                     if (c != EOF)
                            ungetc(c, f);
                     if (c == '\n' || c == '\r' ||
                         !isspace((int)(unsigned char)c))
                     {
                            h->header[n]=0;
                            break;
                     }
              }
              n++;
              if (h->maxsize && n + 2 > h->maxsize)
                     --n;
       }

       if (n == 0)
       {
              if (pos)
                     *pos=epos;
              h->value=h->header;
              return (1);
       }

       for (h->value=h->header; *h->value; ++h->value)
       {
              if (*h->value == ':')
              {
                     *h->value++=0;
                     while (*h->value &&
                            isspace((int)(unsigned char)*h->value))
                            ++h->value;
                     break;
              }
       }
       return (0);
}

Here is the caller graph for this function: