From af590a81d7a2985e70e6fa17da6cdebe4cd07ca2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 22 Jul 2014 17:55:45 +0200 Subject: [PATCH 1/1] Use seek to skip mail body if possible --- cm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cm.c b/cm.c index 642c5e5..1b65717 100644 --- a/cm.c +++ b/cm.c @@ -1,7 +1,7 @@ /* * Incoming Mail Checker * - * (c) 2005--2010 Martin Mares + * (c) 2005--2014 Martin Mares */ #define _GNU_SOURCE @@ -293,7 +293,7 @@ build_snippet(char *buf, char *term, struct mbox *b) add_snippet(&buf, term, b->subject_snippet); } -static int mb_fd, mb_pos; +static int mb_fd, mb_pos, mb_seekable; static unsigned char mb_buf[4096], *mb_cc, *mb_end; static void @@ -366,6 +366,13 @@ mb_skip(int len) int avail = mb_end - mb_cc; if (!avail) { + if (mb_seekable && len >= (int) sizeof(mb_buf)) + { + int next = len - len % sizeof(mb_buf); + mb_seek(mb_tell() + next); + len -= next; + continue; + } if (mb_ll_get() < 0) return; len--; @@ -403,6 +410,7 @@ scan_mbox(struct mbox *b, struct stat *st) b->total = b->new = b->flagged = -1; return; } + mb_seekable = 1; char signature[2]; c = read(mb_fd, signature, 2); @@ -431,11 +439,12 @@ scan_mbox(struct mbox *b, struct stat *st) close(mb_fd); mb_fd = fds[0]; compressed = 1; + mb_seekable = 0; } mb_reset(0); int incremental = 0; - if (b->last_size && b->last_pos && st->st_size > b->last_size && !b->force_refresh && !compressed) + if (b->last_size && b->last_pos && st->st_size > b->last_size && !b->force_refresh && mb_seekable) { mb_seek(b->last_pos); if (mb_check(from, 6)) -- 2.39.5