Back to index

courier  0.68.2
Functions
rfc2047.h File Reference
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int rfc2047_decoder (const char *text, void(*callback)(const char *chset, const char *lang, const char *content, size_t cnt, void *dummy), void *ptr)
int rfc2047_print_unicodeaddr (const struct rfc822a *a, const char *charset, void(*print_func)(char, void *), void(*print_separator)(const char *, void *), void *ptr)
char * rfc2047_encode_str (const char *str, const char *charset, int(*qp_allow)(char c))
int rfc2047_qp_allow_any (char)
int rfc2047_qp_allow_comment (char)
int rfc2047_qp_allow_word (char)
char * rfc2047_encode_header_tobuf (const char *name, const char *header, const char *charset)
char * rfc2047_encode_header_addr (const struct rfc822a *a, const char *charset)

Function Documentation

int rfc2047_decoder ( const char *  text,
void(*)(const char *chset, const char *lang, const char *content, size_t cnt, void *dummy callback,
void *  ptr 
)

Definition at line 957 of file rfc2047u.c.

{
       ssize_t rc;

       while (text && *text)
       {
              size_t i;

              for (i=0; text[i]; i++)
              {
                     if (text[i] == '=' && text[i+1] == '?')
                            break;
              }

              if (i)
                     (*callback)("iso-8859-1", "", text, i, ptr);

              text += i;

              if (!*text)
                     continue;

              rc=rfc822_decode_rfc2047_atom(text, strlen(text),
                                         callback, ptr);

              if (rc < 0)
                     return -1;

              if (rc == 0)
              {
                     (*callback)("iso-8859-1", "", text, 2, ptr);
                     text += 2;
                     continue;
              }

              text += rc;

              for (i=0; text[i]; i++)
              {
                     if (strchr(" \t\r\n", text[i]) == NULL)
                            break;
              }

              if (text[i] != '=' || text[i+1] != '?')
                     continue;

              rc=rfc822_decode_rfc2047_atom(text+i, strlen(text+i), NULL,
                                         NULL);

              if (rc < 0)
                     return -1;
              if (rc > 0)
                     text += i;
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2047_encode_header_addr ( const struct rfc822a a,
const char *  charset 
)

Definition at line 175 of file rfc2047.c.

{
size_t l;
char   *s, *p;

       l=1;
       rfc2047_encode_header_do(a, charset, &count, &counts2, &l);
       if ((s=malloc(l)) == 0)     return (0);
       p=s;
       rfc2047_encode_header_do(a, charset, &save, &saves2, &p);
       *p=0;
       return (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2047_encode_header_tobuf ( const char *  name,
const char *  header,
const char *  charset 
)

Definition at line 191 of file rfc2047.c.

{
       if (rfc822hdr_is_addr(name))
       {
              char *s=0;

              struct rfc822t *t;
              struct rfc822a *a;

              if ((t=rfc822t_alloc_new(header, NULL, NULL)) != 0)
              {
                     if ((a=rfc822a_alloc(t)) != 0)
                     {
                            s=rfc2047_encode_header_addr(a, charset);
                            rfc822a_free(a);
                     }
                     rfc822t_free(t);
              }
              return s;
       }

       return rfc2047_encode_str(header, charset, rfc2047_qp_allow_word);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc2047_encode_str ( const char *  str,
const char *  charset,
int(*)(char c)  qp_allow 
)

Definition at line 653 of file rfc2047.c.

{
       size_t i=1;
       char   *s, *p;
       unicode_char *uc;
       size_t ucsize;
       int err;

       /* Convert string to unicode */

       if (libmail_u_convert_tou_tobuf(str, strlen(str), charset,
                                   &uc, &ucsize, &err))
              return NULL;

       /*
       ** Perform two passes: calculate size of the buffer where the
       ** encoded string gets saved into, then allocate the buffer and
       ** do a second pass to actually do it.
       */

       if (rfc2047_encode_callback(uc, ucsize,
                                charset,
                                qp_allow,
                                &count_char, &i))
       {
              free(uc);
              return NULL;
       }

       if ((s=malloc(i)) == 0)
       {
              free(uc);
              return NULL;
       }

       p=s;
       (void)rfc2047_encode_callback(uc, ucsize,
                                  charset,
                                  qp_allow,
                                  &save_char, &p);
       *p=0;
       free(uc);
       return (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2047_print_unicodeaddr ( const struct rfc822a a,
const char *  charset,
void(*)(char, void *)  print_func,
void(*)(const char *, void *)  print_separator,
void *  ptr 
)

Definition at line 391 of file rfc2047u.c.

{
       const char *sep=NULL;
       int n;

       for (n=0; n<a->naddrs; ++n)
       {
              struct decode_unicode_s nbuf;
              const struct rfc822addr *addrs;
              size_t i=0;
              char *cpbuf;
              int need_braces=0;

              addrs=a->addrs+n;

              nbuf.bufptr=0;
              nbuf.bufsize=1;

              if (rfc822_display_name_int(a, n, charset,
                                       save_unicode_text, &nbuf) < 0)
                     return -1;

              nbuf.bufptr=malloc(nbuf.bufsize);
              nbuf.bufsize=0;
              if (!nbuf.bufptr)
                     return -1;

              if (rfc822_display_name_int(a, n, charset,
                                       save_unicode_text, &nbuf) < 0)
              {
                     free(nbuf.bufptr);
                     return -1;
              }
              nbuf.bufptr[nbuf.bufsize]=0;

              if (addrs->tokens == 0)
              {
                     size_t i;

                     if (nbuf.bufsize == 1) /* ; */
                            sep=0;

                     if (sep)
                            (*print_separator)(sep, ptr);

                     for (i=0; i<nbuf.bufsize; ++i)
                            (*print_func)(nbuf.bufptr[i], ptr);
                     free(nbuf.bufptr);
                     if (nbuf.bufsize > 1)
                            (*print_separator)(" ", ptr);
                     sep=NULL;
                     continue;
              }
              if (sep)
                     (*print_separator)(sep, ptr);

              if (!addrs->name)
              {
                     nbuf.bufsize=0;
                     nbuf.bufptr[0]=0;
              }

              for (i=0; i<nbuf.bufsize; i++)
                     if (strchr(RFC822_SPECIALS, nbuf.bufptr[i]))
                            break;

              cpbuf=libmail_u_convert_tobuf(nbuf.bufptr, "utf-8", charset,
                                         NULL);

              if (!cpbuf)
              {
                     const char *errmsg="\"(unknown character set)\"";

                     while (*errmsg)
                            (*print_func)(*errmsg++, ptr);
                     need_braces=1;
              }
              else
              {
                     if (i < nbuf.bufsize)
                     {
                            (*print_func)('"', ptr);

                            for (i=0; cpbuf[i]; ++i)
                            {
                                   if (cpbuf[i] == '\\' ||
                                       cpbuf[i] == '"')
                                          (*print_func)('\\', ptr);
                                   (*print_func)(cpbuf[i], ptr);
                            }
                            (*print_func)('"', ptr);
                            need_braces=1;
                     }
                        else
                        {
                                for (i=0; cpbuf[i]; ++i)
                            {
                                   need_braces=1;
                                        (*print_func)(cpbuf[i], ptr);
                            }
                        }

                     free(cpbuf);
              }
              free(nbuf.bufptr);

              if (need_braces)
              {
                     (*print_func)(' ', ptr);
                     (*print_func)('<', ptr);
              }

              nbuf.bufptr=0;
              nbuf.bufsize=1;

              if (rfc822_display_addr(a, n, charset,
                                   save_unicode_text, &nbuf) < 0)
                     return -1;

              nbuf.bufptr=malloc(nbuf.bufsize);
              nbuf.bufsize=0;
              if (!nbuf.bufptr)
                     return -1;

              if (rfc822_display_addr(a, n, charset,
                                   save_unicode_text, &nbuf) < 0)
              {
                     free(nbuf.bufptr);
                     return -1;
              }
              for (i=0; i<nbuf.bufsize; i++)
                     (*print_func)(nbuf.bufptr[i], ptr);

              free(nbuf.bufptr);

              if (need_braces)
                     (*print_func)('>', ptr);
              sep=", ";
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc2047_qp_allow_any ( char  )

Definition at line 699 of file rfc2047.c.

{
       return 1;
}

Here is the caller graph for this function:

int rfc2047_qp_allow_comment ( char  )

Definition at line 704 of file rfc2047.c.

{
       if (c == '(' || c == ')' || c == '"')
              return 0;
       return 1;
}
int rfc2047_qp_allow_word ( char  )

Definition at line 711 of file rfc2047.c.

{
       return strchr(base64tab, c) != NULL ||
              strchr("*-=_", c) != NULL;
}

Here is the caller graph for this function: