diff options
author | June McEnroe <june@causal.agency> | 2019-12-21 07:41:14 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-21 07:41:14 -0500 |
commit | 3dfd663c98d1f7586e95ce5d82a92c9059ab46c1 (patch) | |
tree | 0d36393b132264e38a8c2ea2d895feaf95807a32 /imbox.c | |
parent | Convert CRLF to LF (diff) | |
download | imbox-3dfd663c98d1f7586e95ce5d82a92c9059ab46c1.tar.gz imbox-3dfd663c98d1f7586e95ce5d82a92c9059ab46c1.zip |
Clean up mboxrd code
Diffstat (limited to '')
-rw-r--r-- | imbox.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/imbox.c b/imbox.c index 22bb36a..5ab23c1 100644 --- a/imbox.c +++ b/imbox.c @@ -55,35 +55,34 @@ static void printLines(const char *lines) { } static void mboxrd(const char *headers, const char *body) { - static regex_t fromRegex; - compile(&fromRegex, "^From: .*<([^>]+)>"); +#define MATCH(str, match) \ + (int)((match).rm_eo - (match).rm_so), &(str)[(match).rm_so] + static regex_t fromRegex, dateRegex; + compile(&fromRegex, "^From: .*<([^>]+)>"); regmatch_t from[2]; int error = regexec(&fromRegex, headers, 2, from, 0); if (error) errx(EX_DATAERR, "missing From header"); - printf( - "From %.*s ", - (int)(from[1].rm_eo - from[1].rm_so), &headers[from[1].rm_so] - ); + printf("From %.*s ", MATCH(headers, from[1])); - static regex_t dateRegex; + // Day, Date Month Year Time -> Day Month Date Time Year compile(&dateRegex, "^Date: (...), (..) (...) (....) (.{8})"); - regmatch_t date[6]; error = regexec(&dateRegex, headers, 6, date, 0); if (error) errx(EX_DATAERR, "missing Date header"); printf( "%.*s %.*s %.*s %.*s %.*s\n", - (int)(date[1].rm_eo - date[1].rm_so), &headers[date[1].rm_so], - (int)(date[3].rm_eo - date[3].rm_so), &headers[date[3].rm_so], - (int)(date[2].rm_eo - date[2].rm_so), &headers[date[2].rm_so], - (int)(date[5].rm_eo - date[5].rm_so), &headers[date[5].rm_so], - (int)(date[4].rm_eo - date[4].rm_so), &headers[date[4].rm_so] + MATCH(headers, date[1]), + MATCH(headers, date[3]), + MATCH(headers, date[2]), + MATCH(headers, date[5]), + MATCH(headers, date[4]) ); printLines(headers); printLines(body); printf("\n"); +#undef MATCH } static bool verbose; |