Back to index

courier  0.68.2
rfc822_getaddr.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2008 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 /*
00007 */
00008 #include      "rfc822.h"
00009 #include      <stdlib.h>
00010 
00011 static void cntlen(char c, void *p)
00012 {
00013        if (c != '\n')
00014               ++ *(size_t *)p;
00015 }
00016 
00017 static void saveaddr(char c, void *p)
00018 {
00019        if (c != '\n')
00020        {
00021        char **cp=(char **)p;
00022 
00023               *(*cp)++=c;
00024        }
00025 }
00026 
00027 char *rfc822_getaddr(const struct rfc822a *rfc, int n)
00028 {
00029        return rfc822_display_addr_tobuf(rfc, n, NULL);
00030 }
00031 
00032 char *rfc822_gettok(const struct rfc822token *t)
00033 {
00034 size_t addrbuflen=0;
00035 char   *addrbuf, *ptr;
00036 
00037        rfc822tok_print(t, &cntlen, &addrbuflen);
00038 
00039        if (!(addrbuf=malloc(addrbuflen+1)))
00040               return (0);
00041 
00042        ptr=addrbuf;
00043        rfc822tok_print(t, &saveaddr, &ptr);
00044        addrbuf[addrbuflen]=0;
00045        return (addrbuf);
00046 }