1 diff -udprP mutt-1.5.21.orig/compress.c mutt-1.5.21/compress.c
2 --- mutt-1.5.21.orig/compress.c 1970-01-01 03:00:00.000000000 +0300
3 +++ mutt-1.5.21/compress.c 2010-09-16 13:09:15.000000000 +0300
6 + * Copyright (C) 1997 Alain Penders <Alain@Finale-Dev.com>
8 + * This program is free software; you can redistribute it and/or modify
9 + * it under the terms of the GNU General Public License as published by
10 + * the Free Software Foundation; either version 2 of the License, or
11 + * (at your option) any later version.
13 + * This program is distributed in the hope that it will be useful,
14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 + * GNU General Public License for more details.
18 + * You should have received a copy of the GNU General Public License
19 + * along with this program; if not, write to the Free Software
20 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 +#ifdef USE_COMPRESSED
33 +#include "mutt_curses.h"
38 +#include <sys/stat.h>
42 + const char *close; /* close-hook command */
43 + const char *open; /* open-hook command */
44 + const char *append; /* append-hook command */
45 + off_t size; /* size of real folder */
48 +char echo_cmd[HUGE_STRING];
51 + * ctx - context to lock
52 + * excl - exclusive lock?
53 + * retry - should retry if unable to lock?
55 +int mbox_lock_compressed (CONTEXT *ctx, FILE *fp, int excl, int retry)
59 + if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, 1, retry)) == 0)
61 + else if (retry && !excl)
70 +void mbox_unlock_compressed (CONTEXT *ctx, FILE *fp)
76 + mx_unlock_file (ctx->realpath, fileno (fp), 1);
81 +static int is_new (const char *path)
83 + return (access (path, W_OK) != 0 && errno == ENOENT) ? 1 : 0;
86 +static const char* find_compress_hook (int type, const char *path)
88 + const char* c = mutt_find_hook (type, path);
89 + return (!c || !*c) ? NULL : c;
92 +int mutt_can_read_compressed (const char *path)
94 + return find_compress_hook (M_OPENHOOK, path) ? 1 : 0;
97 +/* if the file is new, we really do not append, but create, and so use
98 + * close-hook, and not append-hook
100 +static const char* get_append_command (const char *path, const CONTEXT* ctx)
102 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
103 + return (is_new (path)) ? ci->close : ci->append;
106 +int mutt_can_append_compressed (const char *path)
111 + return (find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0);
113 + magic = mx_get_magic (path);
115 + if (magic != 0 && magic != M_COMPRESSED)
118 + return (find_compress_hook (M_APPENDHOOK, path)
119 + || (find_compress_hook (M_OPENHOOK, path)
120 + && find_compress_hook (M_CLOSEHOOK, path))) ? 1 : 0;
123 +/* open a compressed mailbox */
124 +static COMPRESS_INFO *set_compress_info (CONTEXT *ctx)
128 + /* Now lets uncompress this thing */
129 + ci = safe_malloc (sizeof (COMPRESS_INFO));
130 + ctx->compressinfo = (void*) ci;
131 + ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
132 + ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
133 + ci->close = find_compress_hook (M_CLOSEHOOK, ctx->path);
137 +static void set_path (CONTEXT* ctx)
139 + char tmppath[_POSIX_PATH_MAX];
141 + /* Setup the right paths */
142 + ctx->realpath = ctx->path;
144 + /* Uncompress to /tmp */
145 + mutt_mktemp (tmppath, sizeof(tmppath));
146 + ctx->path = safe_malloc (strlen (tmppath) + 1);
147 + strcpy (ctx->path, tmppath);
150 +static int get_size (const char* path)
153 + if (stat (path, &sb) != 0)
155 + return (sb.st_size);
158 +static void store_size (CONTEXT* ctx)
160 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
161 + ci->size = get_size (ctx->realpath);
165 +compresshook_format_str (char *dest, size_t destlen, size_t col, char op,
166 + const char *src, const char *fmt, const char *ifstring,
167 + const char *elsestring, unsigned long data,
170 + char tmp[SHORT_STRING];
172 + CONTEXT *ctx = (CONTEXT *) data;
176 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
177 + snprintf (dest, destlen, tmp, ctx->realpath);
180 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
181 + snprintf (dest, destlen, tmp, ctx->path);
187 +/* check that the command has both %f and %t
188 + * 0 means OK, -1 means error
190 +int mutt_test_compress_command (const char* cmd)
192 + return (strstr (cmd, "%f") && strstr (cmd, "%t")) ? 0 : -1;
195 +static char *get_compression_cmd (const char* cmd, const CONTEXT* ctx)
197 + char expanded[_POSIX_PATH_MAX];
198 + mutt_FormatString (expanded, sizeof (expanded), 0, cmd, compresshook_format_str,
199 + (unsigned long) ctx, 0);
200 + return safe_strdup (expanded);
203 +int mutt_check_mailbox_compressed (CONTEXT* ctx)
205 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
206 + if (ci->size != get_size (ctx->realpath))
208 + FREE (&ctx->compressinfo);
209 + FREE (&ctx->realpath);
210 + mutt_error _("Mailbox was corrupted!");
216 +int mutt_open_read_compressed (CONTEXT *ctx)
222 + COMPRESS_INFO *ci = set_compress_info (ctx);
225 + FREE (ctx->compressinfo);
228 + if (!ci->close || access (ctx->path, W_OK) != 0)
235 + mutt_message (_("Decompressing %s..."), ctx->realpath);
237 + cmd = get_compression_cmd (ci->open, ctx);
240 + dprint (2, (debugfile, "DecompressCmd: '%s'\n", cmd));
242 + if ((fp = fopen (ctx->realpath, "r")) == NULL)
244 + mutt_perror (ctx->realpath);
248 + mutt_block_signals ();
249 + if (mbox_lock_compressed (ctx, fp, 0, 1) == -1)
252 + mutt_unblock_signals ();
253 + mutt_error _("Unable to lock mailbox!");
260 + sprintf(echo_cmd,_("echo Decompressing %s..."),ctx->realpath);
261 + mutt_system(echo_cmd);
262 + rc = mutt_system (cmd);
263 + mbox_unlock_compressed (ctx, fp);
264 + mutt_unblock_signals ();
269 + mutt_any_key_to_continue (NULL);
271 + FREE (ctx->compressinfo);
272 + mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), cmd);
278 + if (mutt_check_mailbox_compressed (ctx))
281 + ctx->magic = mx_get_magic (ctx->path);
286 +void restore_path (CONTEXT* ctx)
289 + ctx->path = ctx->realpath;
292 +/* remove the temporary mailbox */
293 +void remove_file (CONTEXT* ctx)
295 + if (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
296 + remove (ctx->path);
299 +int mutt_open_append_compressed (CONTEXT *ctx)
302 + COMPRESS_INFO *ci = set_compress_info (ctx);
304 + if (!get_append_command (ctx->path, ctx))
306 + if (ci->open && ci->close)
307 + return (mutt_open_read_compressed (ctx));
310 + FREE (&ctx->compressinfo);
316 + ctx->magic = DefaultMagic;
318 + if (!is_new (ctx->realpath))
319 + if (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
320 + if ((fh = fopen (ctx->path, "w")))
322 + /* No error checking - the parent function will catch it */
327 +/* close a compressed mailbox */
328 +void mutt_fast_close_compressed (CONTEXT *ctx)
330 + dprint (2, (debugfile, "mutt_fast_close_compressed called on '%s'\n",
333 + if (ctx->compressinfo)
338 + /* if the folder was removed, remove the gzipped folder too */
339 + if (access (ctx->path, F_OK) != 0 && ! option (OPTSAVEEMPTY))
340 + remove (ctx->realpath);
344 + restore_path (ctx);
345 + FREE (&ctx->compressinfo);
349 +/* return 0 on success, -1 on failure */
350 +int mutt_sync_compressed (CONTEXT* ctx)
355 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
358 + mutt_message (_("Compressing %s..."), ctx->realpath);
360 + cmd = get_compression_cmd (ci->close, ctx);
364 + if ((fp = fopen (ctx->realpath, "a")) == NULL)
366 + mutt_perror (ctx->realpath);
370 + mutt_block_signals ();
371 + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1)
374 + mutt_unblock_signals ();
375 + mutt_error _("Unable to lock mailbox!");
383 + dprint (2, (debugfile, "CompressCommand: '%s'\n", cmd));
387 + sprintf(echo_cmd,_("echo Compressing %s..."), ctx->realpath);
388 + mutt_system(echo_cmd);
389 + if (mutt_system (cmd))
391 + mutt_any_key_to_continue (NULL);
392 + mutt_error (_("%s: Error compressing mailbox! Original mailbox deleted, uncompressed one kept!\n"), ctx->path);
396 + mbox_unlock_compressed (ctx, fp);
397 + mutt_unblock_signals ();
407 +int mutt_slow_close_compressed (CONTEXT *ctx)
410 + const char *append;
412 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
414 + dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n",
418 + && ((append = get_append_command (ctx->realpath, ctx))
419 + || (append = ci->close))))
420 + { /* if we can not or should not append,
421 + * we only have to remove the compressed info, because sync was already
424 + mutt_fast_close_compressed (ctx);
434 + if (append == ci->close)
435 + mutt_message (_("Compressing %s..."), ctx->realpath);
437 + mutt_message (_("Compressed-appending to %s..."), ctx->realpath);
440 + cmd = get_compression_cmd (append, ctx);
444 + if ((fp = fopen (ctx->realpath, "a")) == NULL)
446 + mutt_perror (ctx->realpath);
450 + mutt_block_signals ();
451 + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1)
454 + mutt_unblock_signals ();
455 + mutt_error _("Unable to lock mailbox!");
460 + dprint (2, (debugfile, "CompressCmd: '%s'\n", cmd));
465 + if (append == ci->close)
466 + sprintf(echo_cmd,_("echo Compressing %s..."), ctx->realpath);
468 + sprintf(echo_cmd,_("echo Compressed-appending to %s..."), ctx->realpath);
469 + mutt_system(echo_cmd);
471 + if (mutt_system (cmd))
473 + mutt_any_key_to_continue (NULL);
474 + mutt_error (_(" %s: Error compressing mailbox! Uncompressed one kept!\n"),
477 + mbox_unlock_compressed (ctx, fp);
478 + mutt_unblock_signals ();
483 + mbox_unlock_compressed (ctx, fp);
484 + mutt_unblock_signals ();
487 + restore_path (ctx);
489 + FREE (&ctx->compressinfo);
494 +#endif /* USE_COMPRESSED */
495 diff -udprP mutt-1.5.21.orig/compress.h mutt-1.5.21/compress.h
496 --- mutt-1.5.21.orig/compress.h 1970-01-01 03:00:00.000000000 +0300
497 +++ mutt-1.5.21/compress.h 2010-09-16 13:09:15.000000000 +0300
500 + * Copyright (C) 1997 Alain Penders <Alain@Finale-Dev.com>
502 + * This program is free software; you can redistribute it and/or modify
503 + * it under the terms of the GNU General Public License as published by
504 + * the Free Software Foundation; either version 2 of the License, or
505 + * (at your option) any later version.
507 + * This program is distributed in the hope that it will be useful,
508 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
509 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
510 + * GNU General Public License for more details.
512 + * You should have received a copy of the GNU General Public License
513 + * along with this program; if not, write to the Free Software
514 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
517 +int mutt_can_read_compressed (const char *);
518 +int mutt_can_append_compressed (const char *);
519 +int mutt_open_read_compressed (CONTEXT *);
520 +int mutt_open_append_compressed (CONTEXT *);
521 +int mutt_slow_close_compressed (CONTEXT *);
522 +int mutt_sync_compressed (CONTEXT *);
523 +int mutt_test_compress_command (const char *);
524 +int mutt_check_mailbox_compressed (CONTEXT *);
525 +void mutt_fast_close_compressed (CONTEXT *);
526 diff -udprP mutt-1.5.21.orig/config.h.in mutt-1.5.21/config.h.in
527 --- mutt-1.5.21.orig/config.h.in 2010-08-25 19:32:03.000000000 +0300
528 +++ mutt-1.5.21/config.h.in 2010-09-16 13:09:15.000000000 +0300
531 /* Define to enable Sun mailtool attachments support. */
532 #undef SUN_ATTACHMENT
534 +/* The compressed mailboxes support */
535 +#undef USE_COMPRESSED
537 /* Define to use dotlocking for mailboxes. */
539 diff -udprP mutt-1.5.21.orig/configure mutt-1.5.21/configure
540 --- mutt-1.5.21.orig/configure 2010-08-25 19:31:47.000000000 +0300
541 +++ mutt-1.5.21/configure 2010-09-16 13:09:15.000000000 +0300
542 @@ -1434,6 +1434,7 @@ Optional Features:
543 --disable-warnings Turn off compiler warnings (not recommended)
544 --enable-nfs-fix Work around an NFS with broken attributes caching
545 --enable-mailtool Enable Sun mailtool attachments support
546 + --enable-compressed Enable compressed folders support
547 --enable-locales-fix The result of isprint() is unreliable
548 --enable-exact-address Enable regeneration of email addresses
549 --enable-hcache Enable header caching
550 @@ -8650,6 +8651,18 @@ $as_echo "$mutt_cv_regex_broken" >&6; }
555 +# Check whether --enable-compressed or --disable-compressed was given.
556 +if test "${enable_compressed+set}" = set; then
557 + enableval="$enable_compressed"
558 + if test x$enableval = xyes; then
559 + cat >> confdefs.h <<\EOF
560 +#define USE_COMPRESSED 1
566 if test $mutt_cv_regex = yes; then
568 $as_echo "#define USE_GNU_REGEX 1" >>confdefs.h
569 diff -udprP mutt-1.5.21.orig/configure.ac mutt-1.5.21/configure.ac
570 --- mutt-1.5.21.orig/configure.ac 2010-08-24 19:34:21.000000000 +0300
571 +++ mutt-1.5.21/configure.ac 2010-09-16 13:09:15.000000000 +0300
572 @@ -806,6 +806,11 @@ AC_ARG_ENABLE(mailtool, AC_HELP_STRING([
573 AC_DEFINE(SUN_ATTACHMENT,1,[ Define to enable Sun mailtool attachments support. ])
576 +AC_ARG_ENABLE(compressed, AC_HELP_STRING([--enable-compressed], [Enable compressed folders support]),
577 + [if test x$enableval = xyes; then
578 + AC_DEFINE(USE_COMPRESSED,1,[ Define to enable compressed folders support. ])
581 AC_ARG_ENABLE(locales-fix, AC_HELP_STRING([--enable-locales-fix], [The result of isprint() is unreliable]),
582 [if test x$enableval = xyes; then
583 AC_DEFINE(LOCALES_HACK,1,[ Define if the result of isprint() is unreliable. ])
584 diff -udprP mutt-1.5.21.orig/curs_main.c mutt-1.5.21/curs_main.c
585 --- mutt-1.5.21.orig/curs_main.c 2010-09-13 20:19:55.000000000 +0300
586 +++ mutt-1.5.21/curs_main.c 2010-09-16 13:09:15.000000000 +0300
587 @@ -1133,6 +1133,11 @@ int mutt_index_menu (void)
591 +#ifdef USE_COMPRESSED
592 + if (Context->compressinfo && Context->realpath)
593 + mutt_str_replace (&LastFolder, Context->realpath);
596 mutt_str_replace (&LastFolder, Context->path);
597 oldcount = Context ? Context->msgcount : 0;
599 diff -udprP mutt-1.5.21.orig/doc/Makefile.am mutt-1.5.21/doc/Makefile.am
600 --- mutt-1.5.21.orig/doc/Makefile.am 2009-08-25 22:08:52.000000000 +0300
601 +++ mutt-1.5.21/doc/Makefile.am 2010-09-16 13:09:15.000000000 +0300
602 @@ -32,7 +32,8 @@ EXTRA_DIST = dotlock.man \
604 CHUNKED_DOCFILES = index.html intro.html gettingstarted.html \
605 configuration.html mimesupport.html advancedusage.html \
606 - optionalfeatures.html security.html tuning.html reference.html miscellany.html
607 + optionalfeatures.html security.html tuning.html reference.html miscellany.html \
608 + compressed-folders.html
610 HTML_DOCFILES = manual.html $(CHUNKED_DOCFILES)
612 diff -udprP mutt-1.5.21.orig/doc/Makefile.in mutt-1.5.21/doc/Makefile.in
613 --- mutt-1.5.21.orig/doc/Makefile.in 2010-08-25 19:31:48.000000000 +0300
614 +++ mutt-1.5.21/doc/Makefile.in 2010-09-16 13:09:15.000000000 +0300
615 @@ -237,7 +237,8 @@ EXTRA_DIST = dotlock.man \
617 CHUNKED_DOCFILES = index.html intro.html gettingstarted.html \
618 configuration.html mimesupport.html advancedusage.html \
619 - optionalfeatures.html security.html tuning.html reference.html miscellany.html
620 + optionalfeatures.html security.html tuning.html reference.html miscellany.html \
621 + compressed-folders.html
623 HTML_DOCFILES = manual.html $(CHUNKED_DOCFILES)
624 BUILT_DISTFILES = stamp-doc-xml stamp-doc-chunked manual.txt $(HTML_DOCFILES)
625 diff -udprP mutt-1.5.21.orig/doc/manual.xml.head mutt-1.5.21/doc/manual.xml.head
626 --- mutt-1.5.21.orig/doc/manual.xml.head 2010-08-24 19:34:21.000000000 +0300
627 +++ mutt-1.5.21/doc/manual.xml.head 2010-09-16 13:09:15.000000000 +0300
628 @@ -5163,6 +5163,24 @@ search patterns:
629 () — logical grouping operator
635 +<link linkend="open-hook">open-hook</link>
641 +<link linkend="close-hook">close-hook</link>
647 +<link linkend="append-hook">append-hook</link>
653 @@ -6094,6 +6112,254 @@ selection. Highest priority has the mail
657 +<chapter id="compressed-folders">
658 +<title>Compressed folders Support (OPTIONAL)</title>
661 +If Mutt was compiled with compressed folders support (by running the
662 +<emphasis>configure</emphasis> script with the
663 +<emphasis>--enable-compressed</emphasis> flag), Mutt can open folders
664 +stored in an arbitrary format, provided that the user has a script to
665 +convert from/to this format to one of the accepted.
669 +The most common use is to open compressed archived folders e.g. with
674 +In addition, the user can provide a script that gets a folder in an
675 +accepted format and appends its context to the folder in the
676 +user-defined format, which may be faster than converting the entire
677 +folder to the accepted format, appending to it and converting back to
678 +the user-defined format.
682 +There are three hooks defined
683 +(<link linkend="open-hook">open-hook</link>,
684 +<link linkend="close-hook">close-hook</link> and
685 +<link linkend="append-hook">append-hook</link>) which define commands
686 +to uncompress and compress a folder and to append messages to an
687 +existing compressed folder respectively.
694 +open-hook \\.gz$ "gzip -cd %f > %t"
695 +close-hook \\.gz$ "gzip -c %t > %f"
696 +append-hook \\.gz$ "gzip -c %t >> %f"
701 +You do not have to specify all of the commands. If you omit
702 +<link linkend="append-hook">append-hook</link>, the folder will be open
703 +and closed again each time you will add to it. If you omit
704 +<link linkend="close-hook">close-hook</link> (or give empty command),
705 +the folder will be open in the mode. If you specify
706 +<link linkend="append-hook">append-hook</link> though you'll be able to
707 +append to the folder.
711 +Note that Mutt will only try to use hooks if the file is not in one of
712 +the accepted formats. In particular, if the file is empty, mutt
713 +supposes it is not compressed. This is important because it allows the
714 +use of programs that do not have well defined extensions. Just use
715 +``.'' as a regexp. But this may be surprising if your compressing
716 +script produces empty files. In this situation, unset
717 +<link linkend="save-empty">$save_empty</link>, so that
718 +the compressed file will be removed if you delete all of the messages.
721 +<sect1 id="open-hook">
722 +<title>Open a compressed mailbox for reading</title>
725 +Usage: <literal>open-hook</literal> <emphasis>regexp</emphasis> <emphasis>command</emphasis>
729 +The <emphasis>command</emphasis> is the command that can be used for
730 +opening the folders whose names match <emphasis>regexp</emphasis>.
734 +The <emphasis>command</emphasis> string is the printf-like format
735 +string, and it should accept two parameters: %f, which is
736 +replaced with the (compressed) folder name, and %t which is
737 +replaced with the name of the temporary folder to which to write.
741 +%f and %t can be repeated any number of times in the
742 +command string, and all of the entries are replaced with the
743 +appropriate folder name. In addition, %% is replaced by
744 +%, as in printf, and any other %anything is left as is.
748 +The <emphasis>command</emphasis> should <emphasis role="bold">not</emphasis>
749 +remove the original compressed file. The <emphasis>command</emphasis>
750 +should return non-zero exit status if it fails, so mutt knows
758 +open-hook \\.gz$ "gzip -cd %f > %t"
763 +If the <emphasis>command</emphasis> is empty, this operation is
764 +disabled for this file type.
769 +<sect1 id="close-hook">
770 +<title>Write a compressed mailbox</title>
773 +Usage: <literal>close-hook</literal> <emphasis>regexp</emphasis> <emphasis>command</emphasis>
777 +This is used to close the folder that was open with the
778 +<link linkend="open-hook">open-hook</link> command after some changes
783 +The <emphasis>command</emphasis> string is the command that can be
784 +used for closing the folders whose names match <emphasis>regexp</emphasis>.
785 +It has the same format as in the <link linkend="open-hook">open-hook</link>
786 +command. Temporary folder in this case is the folder previously
787 +produced by the <link linkend="open-hook">open-hook</link> command.
791 +The <emphasis>command</emphasis> should <emphasis role="bold">not</emphasis>
792 +remove the decompressed file. The <emphasis>command</emphasis> should
793 +return non-zero exit status if it fails, so mutt knows something's
801 +close-hook \\.gz$ "gzip -c %t > %f"
806 +If the <emphasis>command</emphasis> is empty, this operation is
807 +disabled for this file type, and the file can only be open in the
812 +<link linkend="close-hook">close-hook</link> is not called when you
813 +exit from the folder if the folder was not changed.
818 +<sect1 id="append-hook">
819 +<title>Append a message to a compressed mailbox</title>
822 +Usage: <literal>append-hook</literal> <emphasis>regexp</emphasis> <emphasis>command</emphasis>
826 +This command is used for saving to an existing compressed folder.
827 +The <emphasis>command</emphasis> is the command that can be used for
828 +appending to the folders whose names match <emphasis>regexp</emphasis>.
829 +It has the same format as in the <link linkend="open-hook">open-hook</link>
830 +command. The temporary folder in this case contains the messages that
835 +The <emphasis>command</emphasis> should <emphasis role="bold">not</emphasis>
836 +remove the decompressed file. The <emphasis>command</emphasis> should
837 +return non-zero exit status if it fails, so mutt knows something's
845 +append-hook \\.gz$ "gzip -c %t >> %f"
850 +When <link linkend="append-hook">append-hook</link> is used, the folder
851 +is not opened, which saves time, but this means that we can not find
852 +out what the folder type is. Thus the default
853 +(<link linkend="mbox-type">$mbox_type</link>) type is
854 +always supposed (i.e. this is the format used for the temporary
859 +If the file does not exist when you save to it,
860 +<link linkend="close-hook">close-hook</link> is called, and not
861 +<link linkend="append-hook">append-hook</link>.
862 +<link linkend="append-hook">append-hook</link> is only for appending
863 +to existing folders.
867 +If the <emphasis>command</emphasis> is empty, this operation is
868 +disabled for this file type. In this case, the folder will be open and
869 +closed again (using <link linkend="open-hook">open-hook</link> and
870 +<link linkend="close-hook">close-hook</link> respectively) each time
877 +<title>Encrypted folders</title>
880 +The compressed folders support can also be used to handle encrypted
881 +folders. If you want to encrypt a folder with PGP, you may want to use
882 +the following hooks:
885 +open-hook \\.pgp$ "pgp -f < %f > %t"
886 +close-hook \\.pgp$ "pgp -fe YourPgpUserIdOrKeyId < %t > %f"
891 +Please note, that PGP does not support appending to an encrypted
892 +folder, so there is no append-hook defined.
896 +<emphasis role="bold">Note:</emphasis> the folder is temporary stored
897 +decrypted in the /tmp directory, where it can be read by your system
898 +administrator. So think about the security aspects of this.
905 <chapter id="mimesupport">
906 <title>Mutt's MIME Support</title>
908 @@ -8428,6 +8694,18 @@ The following are the commands understoo
912 +<command><link linkend="append-hook">append-hook</link></command>
913 +<arg choice="plain">
914 +<replaceable class="parameter">pattern</replaceable>
916 +<arg choice="plain">
917 +<replaceable class="parameter">command</replaceable>
924 <command><link linkend="auto-view">auto_view</link></command>
926 <replaceable>mimetype</replaceable>
927 @@ -8489,6 +8767,18 @@ The following are the commands understoo
931 +<command><link linkend="close-hook">close-hook</link></command>
932 +<arg choice="plain">
933 +<replaceable class="parameter">pattern</replaceable>
935 +<arg choice="plain">
936 +<replaceable class="parameter">command</replaceable>
943 <command><link linkend="color">color</link></command>
945 <replaceable class="parameter">object</replaceable>
946 @@ -8558,6 +8848,18 @@ The following are the commands understoo
950 +<command><link linkend="open-hook">open-hook</link></command>
951 +<arg choice="plain">
952 +<replaceable class="parameter">pattern</replaceable>
954 +<arg choice="plain">
955 +<replaceable class="parameter">command</replaceable>
962 <command><link linkend="crypt-hook">crypt-hook</link></command>
964 <replaceable class="parameter">pattern</replaceable>
965 diff -udprP mutt-1.5.21.orig/doc/Muttrc.head mutt-1.5.21/doc/Muttrc.head
966 --- mutt-1.5.21.orig/doc/Muttrc.head 2009-08-25 22:08:52.000000000 +0300
967 +++ mutt-1.5.21/doc/Muttrc.head 2010-09-16 13:09:15.000000000 +0300
968 @@ -29,6 +29,11 @@ macro generic,pager <F1> "<shell-escape>
969 macro index,pager y "<change-folder>?<toggle-mailboxes>" "show incoming mailboxes list"
972 +# Use folders which match on \\.gz$ as gzipped folders:
973 +# open-hook \\.gz$ "gzip -cd %f > %t"
974 +# close-hook \\.gz$ "gzip -c %t > %f"
975 +# append-hook \\.gz$ "gzip -c %t >> %f"
977 # If Mutt is unable to determine your site's domain name correctly, you can
978 # set the default here.
980 diff -udprP mutt-1.5.21.orig/doc/muttrc.man.head mutt-1.5.21/doc/muttrc.man.head
981 --- mutt-1.5.21.orig/doc/muttrc.man.head 2010-03-24 23:41:46.000000000 +0200
982 +++ mutt-1.5.21/doc/muttrc.man.head 2010-09-16 13:09:15.000000000 +0300
983 @@ -346,6 +346,24 @@ specify the ID of the public key to be u
984 to a certain recipient. The meaning of "key ID" is to be taken
985 broadly: This can be a different e-mail address, a numerical key ID,
986 or even just an arbitrary search string.
989 +\fBopen-hook\fP \fIregexp\fP "\fIcommand\fP"
990 +\fBclose-hook\fP \fIregexp\fP "\fIcommand\fP"
991 +\fBappend-hook\fP \fIregexp\fP "\fIcommand\fP"
994 +These commands provide a way to handle compressed folders. The given
995 +\fBregexp\fP specifies which folders are taken as compressed (e.g.
996 +"\fI\\\\.gz$\fP"). The commands tell Mutt how to uncompress a folder
997 +(\fBopen-hook\fP), compress a folder (\fBclose-hook\fP) or append a
998 +compressed mail to a compressed folder (\fBappend-hook\fP). The
999 +\fIcommand\fP string is the
1001 +like format string, and it should accept two parameters: \fB%f\fP,
1002 +which is replaced with the (compressed) folder name, and \fB%t\fP
1003 +which is replaced with the name of the temporary folder to which to
1006 \fBpush\fP \fIstring\fP
1007 This command adds the named \fIstring\fP to the keyboard buffer.
1008 diff -udprP mutt-1.5.21.orig/hook.c mutt-1.5.21/hook.c
1009 --- mutt-1.5.21.orig/hook.c 2010-08-25 19:31:40.000000000 +0300
1010 +++ mutt-1.5.21/hook.c 2010-09-16 13:09:15.000000000 +0300
1012 #include "mailbox.h"
1013 #include "mutt_crypt.h"
1015 +#ifdef USE_COMPRESSED
1016 +#include "compress.h"
1022 @@ -92,6 +96,16 @@ int mutt_parse_hook (BUFFER *buf, BUFFER
1023 memset (&pattern, 0, sizeof (pattern));
1024 pattern.data = safe_strdup (path);
1026 +#ifdef USE_COMPRESSED
1027 + else if (data & (M_APPENDHOOK | M_OPENHOOK | M_CLOSEHOOK))
1029 + if (mutt_test_compress_command (command.data))
1031 + strfcpy (err->data, _("bad formatted command string"), err->dsize);
1036 else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ICONVHOOK | M_ACCOUNTHOOK))
1037 && (!WithCrypto || !(data & M_CRYPTHOOK))
1039 diff -udprP mutt-1.5.21.orig/init.h mutt-1.5.21/init.h
1040 --- mutt-1.5.21.orig/init.h 2010-09-15 18:39:31.000000000 +0300
1041 +++ mutt-1.5.21/init.h 2010-09-16 13:09:15.000000000 +0300
1042 @@ -3486,6 +3486,11 @@ struct command_t Commands[] = {
1043 { "fcc-hook", mutt_parse_hook, M_FCCHOOK },
1044 { "fcc-save-hook", mutt_parse_hook, M_FCCHOOK | M_SAVEHOOK },
1045 { "folder-hook", mutt_parse_hook, M_FOLDERHOOK },
1046 +#ifdef USE_COMPRESSED
1047 + { "open-hook", mutt_parse_hook, M_OPENHOOK },
1048 + { "close-hook", mutt_parse_hook, M_CLOSEHOOK },
1049 + { "append-hook", mutt_parse_hook, M_APPENDHOOK },
1051 { "group", parse_group, M_GROUP },
1052 { "ungroup", parse_group, M_UNGROUP },
1053 { "hdr_order", parse_list, UL &HeaderOrderList },
1054 diff -udprP mutt-1.5.21.orig/main.c mutt-1.5.21/main.c
1055 --- mutt-1.5.21.orig/main.c 2010-09-13 20:19:55.000000000 +0300
1056 +++ mutt-1.5.21/main.c 2010-09-16 13:09:15.000000000 +0300
1057 @@ -310,6 +310,12 @@ static void show_version (void)
1061 +#ifdef USE_COMPRESSED
1070 diff -udprP mutt-1.5.21.orig/Makefile.am mutt-1.5.21/Makefile.am
1071 --- mutt-1.5.21.orig/Makefile.am 2010-08-24 19:34:21.000000000 +0300
1072 +++ mutt-1.5.21/Makefile.am 2010-09-16 13:09:15.000000000 +0300
1073 @@ -22,6 +22,7 @@ BUILT_SOURCES = keymap_defs.h patchlist.
1074 bin_PROGRAMS = mutt @DOTLOCK_TARGET@ @PGPAUX_TARGET@
1076 addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c \
1078 crypt.c cryptglue.c \
1079 commands.c complete.c compose.c copy.c curs_lib.c curs_main.c date.c \
1080 edit.c enter.c flags.c init.c filter.c from.c \
1081 @@ -62,6 +63,7 @@ EXTRA_mutt_SOURCES = account.c bcache.c
1083 EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
1084 configure account.h \
1086 attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \
1087 globals.h hash.h history.h init.h keymap.h mutt_crypt.h \
1088 mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \
1089 diff -udprP mutt-1.5.21.orig/Makefile.in mutt-1.5.21/Makefile.in
1090 --- mutt-1.5.21.orig/Makefile.in 2010-08-25 19:31:48.000000000 +0300
1091 +++ mutt-1.5.21/Makefile.in 2010-09-16 13:09:15.000000000 +0300
1096 +mutt_SOURCES += compress.c
1097 +EXTRA_DIST += compress.h
1098 +mutt_OBJECTS += compress.o
1102 pkgdatadir = $(datadir)/@PACKAGE@
1103 diff -udprP mutt-1.5.21.orig/mbox.c mutt-1.5.21/mbox.c
1104 --- mutt-1.5.21.orig/mbox.c 2010-09-13 20:19:55.000000000 +0300
1105 +++ mutt-1.5.21/mbox.c 2010-09-16 13:09:15.000000000 +0300
1108 #include "mutt_curses.h"
1110 +#ifdef USE_COMPRESSED
1111 +#include "compress.h"
1114 #include <sys/stat.h>
1117 @@ -1070,6 +1074,12 @@ bail: /* Come here in case of disaster
1118 int mbox_close_mailbox (CONTEXT *ctx)
1120 mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
1122 +#ifdef USE_COMPRESSED
1123 + if (ctx->compressinfo)
1124 + mutt_slow_close_compressed (ctx);
1127 mutt_unblock_signals ();
1128 mx_fastclose_mailbox (ctx);
1130 diff -udprP mutt-1.5.21.orig/mutt.h mutt-1.5.21/mutt.h
1131 --- mutt-1.5.21.orig/mutt.h 2010-09-13 20:19:55.000000000 +0300
1132 +++ mutt-1.5.21/mutt.h 2010-09-16 13:09:15.000000000 +0300
1133 @@ -146,6 +146,11 @@ typedef enum
1134 #define M_ACCOUNTHOOK (1<<9)
1135 #define M_REPLYHOOK (1<<10)
1136 #define M_SEND2HOOK (1<<11)
1137 +#ifdef USE_COMPRESSED
1138 +#define M_OPENHOOK (1<<12)
1139 +#define M_APPENDHOOK (1<<13)
1140 +#define M_CLOSEHOOK (1<<14)
1143 /* tree characters for linearize_tree and print_enriched_string */
1144 #define M_TREE_LLCORNER 1
1145 @@ -885,6 +890,11 @@ typedef struct _context
1147 unsigned char rights[(RIGHTSMAX + 7)/8]; /* ACL bits */
1149 +#ifdef USE_COMPRESSED
1150 + void *compressinfo; /* compressed mbox module private data */
1151 + char *realpath; /* path to compressed mailbox */
1152 +#endif /* USE_COMPRESSED */
1154 unsigned int locked : 1; /* is the mailbox locked? */
1155 unsigned int changed : 1; /* mailbox has been modified */
1156 unsigned int readonly : 1; /* don't allow changes to the mailbox */
1157 diff -udprP mutt-1.5.21.orig/mx.c mutt-1.5.21/mx.c
1158 --- mutt-1.5.21.orig/mx.c 2010-09-13 20:19:55.000000000 +0300
1159 +++ mutt-1.5.21/mx.c 2010-09-16 13:09:15.000000000 +0300
1164 +#ifdef USE_COMPRESSED
1165 +#include "compress.h"
1171 @@ -414,6 +418,11 @@ int mx_get_magic (const char *path)
1175 +#ifdef USE_COMPRESSED
1176 + if (magic == 0 && mutt_can_read_compressed (path))
1177 + return M_COMPRESSED;
1183 @@ -453,6 +462,13 @@ static int mx_open_mailbox_append (CONTE
1187 +#ifdef USE_COMPRESSED
1188 + /* special case for appending to compressed folders -
1189 + * even if we can not open them for reading */
1190 + if (mutt_can_append_compressed (ctx->path))
1191 + mutt_open_append_compressed (ctx);
1197 @@ -617,6 +633,11 @@ CONTEXT *mx_open_mailbox (const char *pa
1199 ctx->magic = mx_get_magic (path);
1201 +#ifdef USE_COMPRESSED
1202 + if (ctx->magic == M_COMPRESSED)
1203 + mutt_open_read_compressed (ctx);
1207 mutt_error (_("%s is not a mailbox."), path);
1209 @@ -721,6 +742,10 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
1210 mutt_free_header (&ctx->hdrs[i]);
1213 +#ifdef USE_COMPRESSED
1214 + if (ctx->compressinfo)
1215 + mutt_fast_close_compressed (ctx);
1218 FREE (&ctx->pattern);
1219 if (ctx->limit_pattern)
1220 @@ -773,6 +798,12 @@ static int sync_mailbox (CONTEXT *ctx, i
1222 if (tmp && tmp->new == 0)
1223 mutt_update_mailbox (tmp);
1225 +#ifdef USE_COMPRESSED
1226 + if (rc == 0 && ctx->compressinfo)
1227 + return mutt_sync_compressed (ctx);
1233 @@ -981,6 +1012,11 @@ int mx_close_mailbox (CONTEXT *ctx, int
1234 !mutt_is_spool(ctx->path) && !option (OPTSAVEEMPTY))
1235 mx_unlink_empty (ctx->path);
1237 +#ifdef USE_COMPRESSED
1238 + if (ctx->compressinfo && mutt_slow_close_compressed (ctx))
1242 mx_fastclose_mailbox (ctx);
1245 @@ -1293,6 +1329,11 @@ int mx_check_mailbox (CONTEXT *ctx, int
1249 +#ifdef USE_COMPRESSED
1250 + if (ctx->compressinfo)
1251 + return mutt_check_mailbox_compressed (ctx);
1256 if (ctx->locked) lock = 0;
1257 diff -udprP mutt-1.5.21.orig/mx.h mutt-1.5.21/mx.h
1258 --- mutt-1.5.21.orig/mx.h 2009-08-25 22:08:52.000000000 +0300
1259 +++ mutt-1.5.21/mx.h 2010-09-16 13:09:15.000000000 +0300
1260 @@ -36,6 +36,9 @@ enum
1264 +#ifdef USE_COMPRESSED
1269 WHERE short DefaultMagic INITVAL (M_MBOX);
1270 diff -udprP mutt-1.5.21.orig/PATCHES mutt-1.5.21/PATCHES
1271 --- mutt-1.5.21.orig/PATCHES 2008-03-19 22:07:06.000000000 +0200
1272 +++ mutt-1.5.21/PATCHES 2010-09-16 13:09:15.000000000 +0300
1275 diff -udprP mutt-1.5.21.orig/po/POTFILES.in mutt-1.5.21/po/POTFILES.in
1276 --- mutt-1.5.21.orig/po/POTFILES.in 2008-03-19 22:07:57.000000000 +0200
1277 +++ mutt-1.5.21/po/POTFILES.in 2010-09-16 13:09:15.000000000 +0300
1278 @@ -8,6 +8,7 @@ charset.c
1286 diff -udprP mutt-1.5.21.orig/status.c mutt-1.5.21/status.c
1287 --- mutt-1.5.21.orig/status.c 2010-08-24 19:34:21.000000000 +0300
1288 +++ mutt-1.5.21/status.c 2010-09-16 13:09:15.000000000 +0300
1289 @@ -96,6 +96,14 @@ status_format_str (char *buf, size_t buf
1292 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
1293 +#ifdef USE_COMPRESSED
1294 + if (Context && Context->compressinfo && Context->realpath)
1296 + strfcpy (tmp, Context->realpath, sizeof (tmp));
1297 + mutt_pretty_mailbox (tmp, sizeof (tmp));
1301 if (Context && Context->path)
1303 strfcpy (tmp, Context->path, sizeof (tmp));