X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mx%2Fcompress.c;h=ec4db2b33514006d17862006f84261e34683456b;hp=1b6d4f007da017182e9658db5af40b5edbe450c3;hb=6b4475312b058043257fba4526817f60d9e26baf;hpb=68fabfdd78a08d3896ef25fe99e76c32beb56761 diff --git a/lib-mx/compress.c b/lib-mx/compress.c index 1b6d4f0..ec4db2b 100644 --- a/lib-mx/compress.c +++ b/lib-mx/compress.c @@ -59,14 +59,29 @@ static void mbox_unlock_compressed (CONTEXT * ctx, FILE * fp) static int is_new (const char *path) { - return (access (path, W_OK) && errno == ENOENT); + return access (path, W_OK) && errno == ENOENT; } 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) @@ -87,7 +102,7 @@ int mutt_can_append_compressed (const char *path) int magic; if (is_new (path)) - return (find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0); + return find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0; magic = mx_get_magic (path); @@ -292,9 +307,7 @@ int mutt_open_append_compressed (CONTEXT * ctx) m_fclose(&fh); ctx->path = p_dupstr(tmppath, m_strlen(tmppath)); - - ctx->magic = DefaultMagic; - + ctx->magic = M_MBOX; if (is_new (ctx->realpath) || ctx->magic != M_MBOX) unlink(tmppath); @@ -457,4 +470,5 @@ mx_t const compress_mx = { NULL, NULL, NULL, + NULL, };