Merge branch 'master' into nohook
[apps/madmutt.git] / lib-mx / compress.c
index 62a0815..67f72bc 100644 (file)
@@ -12,7 +12,7 @@
 #include <lib-sys/mutt_signal.h>
 #include <lib-sys/unix.h>
 
-#include <lib-ui/curses.h>
+#include <lib-ui/lib-ui.h>
 
 #include "mutt.h"
 
@@ -65,9 +65,24 @@ static int is_new (const char *path)
 
 static const char *find_compress_hook (int type, const char *path)
 {
-  const char *c = mutt_find_hook (type, path);
-
-  return (!c || !*c) ? NULL : c;
+  int len = strlen(path);
+  if (len > 3 && !strcmp(path + len - 3, ".gz")) {
+      switch (type) {
+        case M_OPENHOOK:   return "gzip -cd %f > %t";
+        case M_CLOSEHOOK:  return "gzip -cd %t > %f";
+        case M_APPENDHOOK: return "gzip -cd %t >> %f";
+        default: return NULL;
+      }
+  }
+  if (len > 4 && !strcmp(path + len - 4, ".bz2")) {
+      switch (type) {
+        case M_OPENHOOK:   return "bzip2 -cd %f > %t";
+        case M_CLOSEHOOK:  return "bzip2 -cd %t > %f";
+        case M_APPENDHOOK: return "bzip2 -cd %t >> %f";
+        default: return NULL;
+      }
+  }
+  return NULL;
 }
 
 int mutt_can_read_compressed (const char *path)
@@ -196,7 +211,7 @@ int mutt_open_read_compressed(CONTEXT * ctx)
   ctx->realpath = ctx->path;
 
   /* Uncompress to /tmp */
-  tmpfd = m_tempfd(tmppath, sizeof(tmppath), NONULL(MCore.tmpdir), NULL);
+  tmpfd = m_tempfd(tmppath, sizeof(tmppath), NONULL(mod_core.tmpdir), NULL);
   /* If we cannot open tempfile, that means the file already exists (!?)
    * or we are following a symlink, which is bad and insecure.
    */
@@ -289,7 +304,7 @@ int mutt_open_append_compressed (CONTEXT * ctx)
   ctx->realpath = ctx->path;
 
   /* Uncompress to /tmp */
-  fh = m_tempfile(tmppath, sizeof(tmppath), NONULL(MCore.tmpdir), NULL);
+  fh = m_tempfile(tmppath, sizeof(tmppath), NONULL(mod_core.tmpdir), NULL);
   m_fclose(&fh);
 
   ctx->path = p_dupstr(tmppath, m_strlen(tmppath));