X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mx%2Fcompress.c;h=01e4a07c725d5e986eb2dc393b13a2e1af20d9e2;hp=c28eee69edc33da00a0e8e11b47e7840fe255cb7;hb=2c0e197ef42e4cdff1eff705c8b1b1d07336bf24;hpb=9946738a6a1c27a5602a14d1afe2eea2389732b2 diff --git a/lib-mx/compress.c b/lib-mx/compress.c index c28eee6..01e4a07 100644 --- a/lib-mx/compress.c +++ b/lib-mx/compress.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include "mutt.h" @@ -38,7 +38,7 @@ static int mbox_lock_compressed (CONTEXT * ctx, FILE * fp, int excl, int retry) { int r; - if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, 1, retry)) == 0) + if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, retry)) == 0) ctx->locked = 1; else if (retry && !excl) { ctx->readonly = 1; @@ -52,8 +52,7 @@ static void mbox_unlock_compressed (CONTEXT * ctx, FILE * fp) { if (ctx->locked) { fflush (fp); - - mx_unlock_file (ctx->realpath, fileno (fp), 1); + mx_unlock_file(ctx->realpath, fileno(fp)); ctx->locked = 0; } } @@ -65,9 +64,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)