summaryrefslogtreecommitdiff
path: root/headerbody.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-02 01:58:45 (GMT)
committerJohn Denker <jsd@av8n.com>2012-06-02 01:58:45 (GMT)
commitb732a73bc773789894466b0e5320b2f1fe42c7e9 (patch)
tree385358983f064a1f10a5080b33a3ba13010886db /headerbody.c
parent634d365a03cb0581a062cd3cf4db9ae69f1cde26 (diff)
original, as downloaded from http://www.qmail.org/netqmail-1.06.tar.gz
Diffstat (limited to 'headerbody.c')
-rw-r--r--headerbody.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/headerbody.c b/headerbody.c
new file mode 100644
index 0000000..91965c0
--- /dev/null
+++ b/headerbody.c
@@ -0,0 +1,87 @@
+#include "stralloc.h"
+#include "substdio.h"
+#include "getln.h"
+#include "hfield.h"
+#include "headerbody.h"
+
+static int getsa(ss,sa,match)
+substdio *ss;
+stralloc *sa;
+int *match;
+{
+ if (!*match) return 0;
+ if (getln(ss,sa,match,'\n') == -1) return -1;
+ if (*match) return 1;
+ if (!sa->len) return 0;
+ if (!stralloc_append(sa,"\n")) return -1;
+ return 1;
+}
+
+static stralloc line = {0};
+static stralloc nextline = {0};
+
+int headerbody(ss,dohf,hdone,dobl)
+substdio *ss;
+void (*dohf)();
+void (*hdone)();
+void (*dobl)();
+{
+ int match;
+ int flaglineok;
+ match = 1;
+ flaglineok = 0;
+ for (;;)
+ {
+ switch(getsa(ss,&nextline,&match))
+ {
+ case -1:
+ return -1;
+ case 0:
+ if (flaglineok) dohf(&line);
+ hdone();
+ /* no message body; could insert blank line here */
+ return 0;
+ }
+ if (flaglineok)
+ {
+ if ((nextline.s[0] == ' ') || (nextline.s[0] == '\t'))
+ {
+ if (!stralloc_cat(&line,&nextline)) return -1;
+ continue;
+ }
+ dohf(&line);
+ }
+ if (nextline.len == 1)
+ {
+ hdone();
+ dobl(&nextline);
+ break;
+ }
+ if (stralloc_starts(&nextline,"From "))
+ {
+ if (!stralloc_copys(&line,"MBOX-Line: ")) return -1;
+ if (!stralloc_cat(&line,&nextline)) return -1;
+ }
+ else
+ if (hfield_valid(nextline.s,nextline.len))
+ {
+ if (!stralloc_copy(&line,&nextline)) return -1;
+ }
+ else
+ {
+ hdone();
+ if (!stralloc_copys(&line,"\n")) return -1;
+ dobl(&line);
+ dobl(&nextline);
+ break;
+ }
+ flaglineok = 1;
+ }
+ for (;;)
+ switch(getsa(ss,&nextline,&match))
+ {
+ case -1: return -1;
+ case 0: return 0;
+ case 1: dobl(&nextline);
+ }
+}