s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
headerbody.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "buffer.h"
3#include "getln.h"
4#include "hfield.h"
5#include "headerbody.h"
6
7static int getsa(buffer *b,stralloc *sa,int *match)
8{
9 if (!*match) return 0;
10 if (getln(b,sa,match,'\n') == -1) return -1;
11 if (*match) return 1;
12 if (!sa->len) return 0;
13 if (!stralloc_append(sa,"\n")) return -1;
14
15 return 1;
16}
17
18static stralloc line = {0};
19static stralloc nextline = {0};
20
21int headerbody(b,dohf,hdone,dobl)
22buffer *b;
23void (*dohf)();
24void (*hdone)();
25void (*dobl)();
26{
27 int match;
28 int flaglineok;
29 match = 1;
30 flaglineok = 0;
31
32 for (;;) {
33 switch (getsa(b,&nextline,&match)) {
34 case -1:
35 return -1;
36 case 0:
37 if (flaglineok) dohf(&line);
38 hdone();
39 /* no message body; could insert blank line here */
40 return 0;
41 }
42
43 if (flaglineok) {
44 if ((nextline.s[0] == ' ') || (nextline.s[0] == '\t')) {
45 if (!stralloc_cat(&line,&nextline)) return -1;
46 continue;
47 }
48 dohf(&line);
49 }
50
51 if (nextline.len == 1) {
52 hdone();
53 dobl(&nextline);
54 break;
55 }
56
57 if (stralloc_starts(&nextline,"From ")) {
58 if (!stralloc_copys(&line,"MBOX-Line: ")) return -1;
59 if (!stralloc_cat(&line,&nextline)) return -1;
60 } else if (hfield_valid(nextline.s,nextline.len)) {
61 if (!stralloc_copy(&line,&nextline)) return -1;
62 } else {
63 hdone();
64 if (!stralloc_copys(&line,"\n")) return -1;
65 dobl(&line);
66 dobl(&nextline);
67 break;
68 }
69 flaglineok = 1;
70 }
71
72 for (;;)
73 switch (getsa(b,&nextline,&match)) {
74 case -1: return -1;
75 case 0: return 0;
76 case 1: dobl(&nextline);
77 }
78}
buffer b
Definition: auto-gid.c:10
int stralloc_copys(stralloc *, char const *)
stralloc sa
Definition: dnscname.c:11
int headerbody()
int hfield_valid()
int match
Definition: matchup.c:195