]> mj.ucw.cz Git - checkmail.git/commitdiff
Added support for gzipped mailboxes.
authorMartin Mares <mj@ucw.cz>
Wed, 13 Feb 2008 18:46:45 +0000 (19:46 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 13 Feb 2008 18:46:45 +0000 (19:46 +0100)
ChangeLog
cm.c

index 6116cedfd0accc182f1717549ede227c38ae7d25..b7fac2409ee53d8fce46b142a47ca343223fcdb1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-13  Martin Mares <mj@ucw.cz>
+
+       * Added support for gzipped mailboxes, based on a patch by
+         Michal Vaner.
+
+       * Released as 1.2.
+
 2008-01-16  Martin Mares <mj@ucw.cz>
 
        * Non-ASCII characters are displayed properly in UTF-8 locale.
@@ -6,6 +13,8 @@
          parts do not look printable. This mode is now enabled by default,
          tweak the Makefile if you do not have libncursesw.
 
+       * Released as 1.1.
+
 2007-06-25  Martin Mares <mj@ucw.cz>
 
        * Non-ASCII characters encoded as per RFC 2047 are now deciphered
diff --git a/cm.c b/cm.c
index a112a005c74556e349889c50286616b4dadc7814..e56b4637127bd853721ea3c60de1ca1fd7701c1c 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -18,6 +18,8 @@
 #include <unistd.h>
 #include <pwd.h>
 #include <time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #ifdef CONFIG_WIDE_CURSES
 #include <ncursesw/ncurses.h>
@@ -313,6 +315,7 @@ scan_mbox(struct mbox *b, struct stat *st)
 {
   char buf[1024], sender[1024], subject[1024];
   int c;
+  int compressed = 0;
   const char from[] = "\nFrom ";
 
   if (!st->st_size)
@@ -331,10 +334,39 @@ scan_mbox(struct mbox *b, struct stat *st)
       b->total = b->new = b->flagged = -1;
       return;
     }
+
+  char signature[2];
+  c = read(mb_fd, signature, 2);
+  lseek(mb_fd, 0, SEEK_SET);
+
+  if (c == 2 && !memcmp(signature, "\037\213", 2)) //gzip
+    {
+      debug("[decompressing] ");
+      int fds[2];
+      if (pipe(fds))
+       die("pipe failed: %m");
+      int pid = fork();
+      if (pid < 0)
+       die("fork failed: %m");
+      if (!pid)
+       {
+         if (dup2(mb_fd, 0) < 0 || dup2(fds[1], 1) < 0)
+           die("dup2 failed: %m");
+         close(fds[0]);
+         close(fds[1]);
+         close(mb_fd);
+         execlp("gzip", "gzip", "-cd", NULL);
+         die("Cannot execute gzip: %m");
+       }
+      close(fds[1]);
+      close(mb_fd);
+      mb_fd = fds[0];
+      compressed = 1;
+    }
   mb_reset(0);
 
   int incremental = 0;
-  if (b->last_size && b->last_pos && st->st_size > b->last_size && !b->force_refresh)
+  if (b->last_size && b->last_pos && st->st_size > b->last_size && !b->force_refresh && !compressed)
     {
       mb_seek(b->last_pos);
       if (mb_check(from, 6))
@@ -449,6 +481,12 @@ scan_mbox(struct mbox *b, struct stat *st)
 
  done:
   close(mb_fd);
+  if (compressed)
+    {
+      int status;
+      if (wait(&status) < 0 || !WIFEXITED(status) || WEXITSTATUS(status))
+       b->total = b->new = b->flagged = -1;
+    }
 }
 
 static void