Back to index

courier  0.68.2
testsuite.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2006 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "rfc822.h"
00007 #include      "rfc2047.h"
00008 #include      <stdio.h>
00009 #include      <stdlib.h>
00010 
00011 
00012 static void print_func(char c, void *p)
00013 {
00014        p=p;
00015        putchar(c);
00016 }
00017 
00018 static void print_separator(const char *s, void *p)
00019 {
00020        p=p;
00021        printf("%s", s);
00022 }
00023 
00024 static struct rfc822t *tokenize(const char *p)
00025 {
00026 struct rfc822t       *tp;
00027 int    i;
00028 char   buf[2];
00029 
00030        printf("Tokenize: %s\n", p);
00031        tp=rfc822t_alloc_new(p, NULL, NULL);
00032        if (!tp)      exit(0);
00033        buf[1]=0;
00034        for (i=0; i<tp->ntokens; i++)
00035        {
00036               buf[0]=tp->tokens[i].token;
00037               if (buf[0] == '\0' || buf[0] == '"' || buf[0] == '(')
00038               {
00039                      printf("%s: ", buf[0] == '"' ? "Quote":
00040                             buf[0] == '(' ? "Comment":"Atom");
00041                      if (fwrite(tp->tokens[i].ptr, tp->tokens[i].len, 1,
00042                                stdout) != 1)
00043                             exit(1);
00044 
00045                      printf("\n");
00046               }
00047               else   printf("Token: %s\n", buf[0] ? buf:"atom");
00048        }
00049        return (tp);
00050 }
00051 
00052 static struct rfc822a *doaddr(struct rfc822t *t)
00053 {
00054 struct rfc822a *a=rfc822a_alloc(t);
00055 
00056        if (!a)       exit(0);
00057        printf("----\n");
00058        rfc822_print(a, print_func, print_separator, NULL);
00059        printf("\n");
00060        return (a);
00061 }
00062 
00063 int main()
00064 {
00065        struct rfc822t *t1, *t2, *t3, *t4, *t5;
00066        struct rfc822a *a1, *a2, *a3, *a4, *a5;
00067 
00068        t1=tokenize("nobody@example.com (Nobody (is) here\\) right)");
00069        t2=tokenize("Distribution  list: nobody@example.com daemon@example.com");
00070        t3=tokenize("Mr Nobody <nobody@example.com>, Mr. Nobody <nobody@example.com>");
00071        t4=tokenize("nobody@example.com, <nobody@example.com>, Mr. Nobody <nobody@example.com>");
00072 
00073        t5=tokenize("=?UTF-8?Q?Test?= <nobody@example.com>, foo=bar <nobody@example.com>");
00074 
00075        a1=doaddr(t1);
00076        a2=doaddr(t2);
00077        a3=doaddr(t3);
00078        a4=doaddr(t4);
00079        a5=doaddr(t5);
00080 
00081        rfc822a_free(a5);
00082        rfc822a_free(a4);
00083        rfc822a_free(a3);
00084        rfc822a_free(a2);
00085        rfc822a_free(a1);
00086        rfc822t_free(t5);
00087        rfc822t_free(t4);
00088        rfc822t_free(t3);
00089        rfc822t_free(t2);
00090        rfc822t_free(t1);
00091 
00092 #define FIVEUTF8 "\xe2\x85\xa4"
00093 
00094 #define FIVETIMES4 FIVEUTF8 FIVEUTF8 FIVEUTF8 FIVEUTF8
00095 
00096 #define FIVETIMES16 FIVETIMES4 FIVETIMES4 FIVETIMES4 FIVETIMES4
00097 
00098 #define FIVEMAX FIVETIMES16 FIVETIMES4 FIVETIMES4
00099 
00100        {
00101               char *p=rfc2047_encode_str(FIVEMAX, "utf-8",
00102                                       rfc2047_qp_allow_any);
00103 
00104               if (p)
00105               {
00106                      printf("%s\n", p);
00107                      free(p);
00108               }
00109        }
00110 
00111        {
00112               char *p=rfc2047_encode_str(FIVEMAX FIVEUTF8, "utf-8",
00113                                       rfc2047_qp_allow_any);
00114 
00115               if (p)
00116               {
00117                      printf("%s\n", p);
00118                      free(p);
00119               }
00120        }
00121 
00122        {
00123               char *p=rfc2047_encode_str(FIVEMAX "\xcc\x80", "utf-8",
00124                                       rfc2047_qp_allow_any);
00125 
00126               if (p)
00127               {
00128                      printf("%s\n", p);
00129                      free(p);
00130               }
00131        }
00132 
00133        return (0);
00134 }