s/qmail 4.3.20
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(buffer *b,void (*dohf)(),void (*hdone)(),void (*dobl)())
22{
23 int match;
24 int flaglineok;
25 match = 1;
26 flaglineok = 0;
27
28 for (;;) {
29 switch (getsa(b,&nextline,&match)) {
30 case -1:
31 return -1;
32 case 0:
33 if (flaglineok) dohf(&line);
34 hdone();
35 /* no message body; could insert blank line here */
36 return 0;
37 }
38
39 if (flaglineok) {
40 if ((nextline.s[0] == ' ') || (nextline.s[0] == '\t')) {
41 if (!stralloc_cat(&line,&nextline)) return -1;
42 continue;
43 }
44 dohf(&line);
45 }
46
47 if (nextline.len == 1) {
48 hdone();
49 dobl(&nextline);
50 break;
51 }
52
53 if (stralloc_starts(&nextline,"From ")) {
54 if (!stralloc_copys(&line,"MBOX-Line: ")) return -1;
55 if (!stralloc_cat(&line,&nextline)) return -1;
56 } else if (hfield_valid(nextline.s,nextline.len)) {
57 if (!stralloc_copy(&line,&nextline)) return -1;
58 } else {
59 hdone();
60 if (!stralloc_copys(&line,"\n")) return -1;
61 dobl(&line);
62 dobl(&nextline);
63 break;
64 }
65 flaglineok = 1;
66 }
67
68 for (;;)
69 switch (getsa(b,&nextline,&match)) {
70 case -1: return -1;
71 case 0: return 0;
72 case 1: dobl(&nextline);
73 }
74}
buffer b
Definition: auto-gid.c:10
int stralloc_copys(stralloc *, char const *)
stralloc sa
Definition: dnscname.c:11
int headerbody(buffer *b, void(*dohf)(), void(*hdone)(), void(*dobl)())
Definition: headerbody.c:21
int hfield_valid(char *s, int len)
Definition: hfield.c:69
int match
Definition: matchup.c:196