]> mj.ucw.cz Git - checkmail.git/commitdiff
Use seek to skip mail body if possible
authorMartin Mares <mj@ucw.cz>
Tue, 22 Jul 2014 15:55:45 +0000 (17:55 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 22 Jul 2014 15:55:45 +0000 (17:55 +0200)
cm.c

diff --git a/cm.c b/cm.c
index 642c5e54dec089b34d7ff2f26a0513b1e9e209b3..1b65717b27b6734a9d48b98c07dd33eb96425f53 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -1,7 +1,7 @@
 /*
  *     Incoming Mail Checker
  *
- *     (c) 2005--2010 Martin Mares <mj@ucw.cz>
+ *     (c) 2005--2014 Martin Mares <mj@ucw.cz>
  */
 
 #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))