2 * Mailbox Parser (so far very primitive)
4 * (c) 2010 Martin Mares <mj@ucw.cz>
14 const char progname[] = "mparse";
18 static char buf[BUFSIZE];
19 static char *bpos=buf, *bend=buf;
21 static char *getline(void)
28 int remains = bend - bpos;
31 char *nl = memchr(bpos, '\n', remains);
35 if (nl > p && nl[-1] == '\r')
41 memmove(buf, bpos, remains);
46 int space = BUFSIZE - remains;
49 int len = read(0, bend, space);
51 die("Read error: %m");
73 main(int argc UNUSED, char **argv UNUSED)
76 enum state state = S_INITIAL;
80 // printf("<%s>\n", c);
81 if (state == S_INITIAL || state == S_BODY)
83 if (!strncmp(c, "From ", 5))
96 else if (*c == ' ' || *c == '\t')
98 while (*c == ' ' || *c == '\t')
111 if (state == S_HEADER)
112 printf("\nX-Warning: Incomplete mail\n\n");