18
* Function: rfc822db_parse_stanza
19
* Input: a FILE pointer to an open readable file containing a stanza in rfc822
21
* Output: a pointer to a dynamically allocated rfc822_header structure
22
* Description: parse a stanza from file into the returned header struct
23
* Assumptions: no lines are over 8192 bytes long.
26
struct rfc822_header* rfc822_parse_stanza(FILE *file)
28
struct rfc822_header *head, **tail, *cur;
35
/* fprintf(stderr,"rfc822db_parse_stanza(file)\n");*/
36
while (fgets(buf, sizeof(buf), file))
43
if (buf[strlen(buf)-1] == '\n')
44
buf[strlen(buf)-1] = '\0';
48
*(tmp+1) != 0 && *(tmp+1) == '.' &&
51
gchar *now = cur->value;
52
cur->value = g_strconcat(now, "\n", NULL);
55
else if (isspace(*tmp))
57
gchar *now = cur->value;
58
if(strlen(now) == 0 || g_str_has_suffix(now, " ") || g_str_has_suffix(now, "\n"))
59
cur->value = g_strconcat(now, g_strstrip(tmp), NULL);
61
cur->value = g_strconcat(now, " ", g_strstrip(tmp), NULL);
66
while (*tmp != 0 && *tmp != ':')
70
cur = g_new0(struct rfc822_header,1);
73
cur->header = strdup(buf);
77
cur->value = strdup(tmp);
88
char *rfc822_header_lookup(struct rfc822_header *list, const char* key)
90
/* fprintf(stderr,"rfc822db_header_lookup(list,key=%s)\n",key);*/
91
while (list && (strcasecmp(key, list->header) != 0))
95
/* fprintf(stderr,"rfc822db_header_lookup returning: '%s'\n", list->value);*/
100
void rfc822_header_free_all(struct rfc822_header *list)
103
struct rfc822_header *now = list;
104
g_free(list->header);