From: Martin Mares Date: Tue, 22 Jul 2014 15:14:03 +0000 (+0200) Subject: Use Content-Length to determine mail length if available X-Git-Tag: v1.8~5 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f790f8303362f85c84b46f2f98bdfdce2df793bf;p=checkmail.git Use Content-Length to determine mail length if available Some programs do not escape "From " lines in the body of the mail, so just seeking for "From " (even with proper date format) does not work in general. However, in such cases, Content-Length is present. --- diff --git a/cm.c b/cm.c index e14c8fa..9a38a1d 100644 --- a/cm.c +++ b/cm.c @@ -354,6 +354,27 @@ mb_check(const char *p, int len) return 1; } +static void +mb_skip(int len) +{ + while (len) + { + int avail = mb_end - mb_cc; + if (!avail) + { + if (mb_ll_get() < 0) + return; + len--; + } + else + { + int next = (avail < len) ? avail : len; + len -= next; + mb_cc += next; + } + } +} + static void scan_mbox(struct mbox *b, struct stat *st) { @@ -454,6 +475,7 @@ scan_mbox(struct mbox *b, struct stat *st) while ((c = mb_get()) >= 0 && c != '\n') ; + int content_length = -1; int new = 1; int flagged = 0; sender[0] = 0; @@ -499,6 +521,8 @@ scan_mbox(struct mbox *b, struct stat *st) strcpy(sender, buf+5); else if (!strncasecmp(buf, "Subject:", 8)) strcpy(subject, buf+8); + else if (!strncasecmp(buf, "Content-Length:", 15)) + content_length = atoi(buf + 15); } b->total++; @@ -507,13 +531,16 @@ scan_mbox(struct mbox *b, struct stat *st) if (flagged) b->flagged++; if (debug_mode > 1) - debug("new=%d flagged=%d sender=<%s> subject=<%s>\n", new, flagged, sender, subject); + debug("new=%d flagged=%d len=%d sender=<%s> subject=<%s>\n", new, flagged, content_length, sender, subject); if (new || (flagged && !b->snippet_is_new)) { b->snippet_is_new = new; prepare_snippets(b, sender, subject); } + if (content_length >= 0) + mb_skip(content_length); + int ct = 1; while (from[ct]) {