2 This is the compressed folders patch by Roland Rosenfeld
5 The home page for this patch is:
7 http://www.spinnaker.de/mutt/compressed/
9 * Patch last synced with upstream:
11 - File: http://www.spinnaker.de/mutt/compressed/patch-1.5.18.rr.compressed.1.gz
14 - 2008-05-20 myon: refreshed to remove hunks in auto* files
21 + * Copyright (C) 1997 Alain Penders <Alain@Finale-Dev.com>
23 + * This program is free software; you can redistribute it and/or modify
24 + * it under the terms of the GNU General Public License as published by
25 + * the Free Software Foundation; either version 2 of the License, or
26 + * (at your option) any later version.
28 + * This program is distributed in the hope that it will be useful,
29 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 + * GNU General Public License for more details.
33 + * You should have received a copy of the GNU General Public License
34 + * along with this program; if not, write to the Free Software
35 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 +#ifdef USE_COMPRESSED
48 +#include "mutt_curses.h"
53 +#include <sys/stat.h>
57 + const char *close; /* close-hook command */
58 + const char *open; /* open-hook command */
59 + const char *append; /* append-hook command */
60 + off_t size; /* size of real folder */
65 + * ctx - context to lock
66 + * excl - exclusive lock?
67 + * retry - should retry if unable to lock?
69 +int mbox_lock_compressed (CONTEXT *ctx, FILE *fp, int excl, int retry)
73 + if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, 1, retry)) == 0)
75 + else if (retry && !excl)
84 +void mbox_unlock_compressed (CONTEXT *ctx, FILE *fp)
90 + mx_unlock_file (ctx->realpath, fileno (fp), 1);
95 +static int is_new (const char *path)
97 + return (access (path, W_OK) != 0 && errno == ENOENT) ? 1 : 0;
100 +static const char* find_compress_hook (int type, const char *path)
102 + const char* c = mutt_find_hook (type, path);
103 + return (!c || !*c) ? NULL : c;
106 +int mutt_can_read_compressed (const char *path)
108 + return find_compress_hook (M_OPENHOOK, path) ? 1 : 0;
112 + * if the file is new, we really do not append, but create, and so use
113 + * close-hook, and not append-hook
115 +static const char* get_append_command (const char *path, const CONTEXT* ctx)
117 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
118 + return (is_new (path)) ? ci->close : ci->append;
121 +int mutt_can_append_compressed (const char *path)
127 + char *dir_path = safe_strdup(path);
128 + char *aux = strrchr(dir_path, '/');
133 + if (access(dir_path, W_OK|X_OK))
136 + safe_free((void**)&dir_path);
137 + return dir_valid && (find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0);
140 + magic = mx_get_magic (path);
142 + if (magic != 0 && magic != M_COMPRESSED)
145 + return (find_compress_hook (M_APPENDHOOK, path)
146 + || (find_compress_hook (M_OPENHOOK, path)
147 + && find_compress_hook (M_CLOSEHOOK, path))) ? 1 : 0;
150 +/* open a compressed mailbox */
151 +static COMPRESS_INFO *set_compress_info (CONTEXT *ctx)
155 + /* Now lets uncompress this thing */
156 + ci = safe_malloc (sizeof (COMPRESS_INFO));
157 + ctx->compressinfo = (void*) ci;
158 + ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
159 + ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
160 + ci->close = find_compress_hook (M_CLOSEHOOK, ctx->path);
164 +static void set_path (CONTEXT* ctx)
166 + char tmppath[_POSIX_PATH_MAX];
168 + /* Setup the right paths */
169 + ctx->realpath = ctx->path;
171 + /* Uncompress to /tmp */
172 + mutt_mktemp (tmppath);
173 + ctx->path = safe_malloc (strlen (tmppath) + 1);
174 + strcpy (ctx->path, tmppath);
177 +static int get_size (const char* path)
180 + if (stat (path, &sb) != 0)
182 + return (sb.st_size);
185 +static void store_size (CONTEXT* ctx)
187 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
188 + ci->size = get_size (ctx->realpath);
192 +compresshook_format_str (char *dest, size_t destlen, size_t col, char op,
193 + const char *src, const char *fmt,
194 + const char *ifstring, const char *elsestring,
195 + unsigned long data, format_flag flags)
197 + char tmp[SHORT_STRING];
199 + CONTEXT *ctx = (CONTEXT *) data;
203 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
204 + snprintf (dest, destlen, tmp, ctx->realpath);
207 + snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
208 + snprintf (dest, destlen, tmp, ctx->path);
215 + * check that the command has both %f and %t
216 + * 0 means OK, -1 means error
218 +int mutt_test_compress_command (const char* cmd)
220 + return (strstr (cmd, "%f") && strstr (cmd, "%t")) ? 0 : -1;
223 +static char *get_compression_cmd (const char* cmd, const CONTEXT* ctx)
225 + char expanded[_POSIX_PATH_MAX];
226 + mutt_FormatString (expanded, sizeof (expanded), 0, cmd,
227 + compresshook_format_str, (unsigned long) ctx, 0);
228 + return safe_strdup (expanded);
231 +int mutt_check_mailbox_compressed (CONTEXT* ctx)
233 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
234 + if (ci->size != get_size (ctx->realpath))
236 + FREE (&ctx->compressinfo);
237 + FREE (&ctx->realpath);
238 + mutt_error _("Mailbox was corrupted!");
244 +int mutt_open_read_compressed (CONTEXT *ctx)
250 + COMPRESS_INFO *ci = set_compress_info (ctx);
253 + FREE (&ctx->compressinfo);
256 + if (!ci->close || access (ctx->path, W_OK) != 0)
263 + mutt_message (_("Decompressing %s..."), ctx->realpath);
265 + cmd = get_compression_cmd (ci->open, ctx);
268 + dprint (2, (debugfile, "DecompressCmd: '%s'\n", cmd));
270 + if ((fp = fopen (ctx->realpath, "r")) == NULL)
272 + mutt_perror (ctx->realpath);
276 + mutt_block_signals ();
277 + if (mbox_lock_compressed (ctx, fp, 0, 1) == -1)
280 + mutt_unblock_signals ();
281 + mutt_error _("Unable to lock mailbox!");
288 + fprintf (stderr, _("Decompressing %s...\n"),ctx->realpath);
289 + rc = mutt_system (cmd);
290 + mbox_unlock_compressed (ctx, fp);
291 + mutt_unblock_signals ();
296 + mutt_any_key_to_continue (NULL);
298 + FREE (&ctx->compressinfo);
299 + mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), cmd);
305 + if (mutt_check_mailbox_compressed (ctx))
308 + ctx->magic = mx_get_magic (ctx->path);
313 +void restore_path (CONTEXT* ctx)
316 + ctx->path = ctx->realpath;
319 +/* remove the temporary mailbox */
320 +void remove_file (CONTEXT* ctx)
322 + if (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
323 + remove (ctx->path);
326 +int mutt_open_append_compressed (CONTEXT *ctx)
329 + COMPRESS_INFO *ci = set_compress_info (ctx);
331 + if (!get_append_command (ctx->path, ctx))
333 + if (ci->open && ci->close)
334 + return (mutt_open_read_compressed (ctx));
337 + FREE (&ctx->compressinfo);
343 + ctx->magic = DefaultMagic;
345 + if (!is_new (ctx->realpath))
346 + if (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
347 + if ((fh = fopen (ctx->path, "w")))
349 + /* No error checking - the parent function will catch it */
354 +/* close a compressed mailbox */
355 +void mutt_fast_close_compressed (CONTEXT *ctx)
357 + dprint (2, (debugfile, "mutt_fast_close_compressed called on '%s'\n",
360 + if (ctx->compressinfo)
365 + /* if the folder was removed, remove the gzipped folder too */
366 + if ((ctx->magic > 0)
367 + && (access (ctx->path, F_OK) != 0)
368 + && ! option (OPTSAVEEMPTY))
369 + remove (ctx->realpath);
373 + restore_path (ctx);
374 + FREE (&ctx->compressinfo);
378 +/* return 0 on success, -1 on failure */
379 +int mutt_sync_compressed (CONTEXT* ctx)
384 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
387 + mutt_message (_("Compressing %s..."), ctx->realpath);
389 + cmd = get_compression_cmd (ci->close, ctx);
393 + if ((fp = fopen (ctx->realpath, "a")) == NULL)
395 + mutt_perror (ctx->realpath);
399 + mutt_block_signals ();
400 + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1)
403 + mutt_unblock_signals ();
404 + mutt_error _("Unable to lock mailbox!");
410 + dprint (2, (debugfile, "CompressCommand: '%s'\n", cmd));
414 + fprintf (stderr, _("Compressing %s...\n"), ctx->realpath);
415 + if (mutt_system (cmd))
417 + mutt_any_key_to_continue (NULL);
418 + mutt_error (_("%s: Error compressing mailbox! Original mailbox deleted, uncompressed one kept!\n"), ctx->path);
422 + mbox_unlock_compressed (ctx, fp);
423 + mutt_unblock_signals ();
433 +int mutt_slow_close_compressed (CONTEXT *ctx)
436 + const char *append;
438 + COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
440 + dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n",
444 + && ((append = get_append_command (ctx->realpath, ctx))
445 + || (append = ci->close))))
447 + /* if we can not or should not append, we only have to remove the */
448 + /* compressed info, because sync was already called */
449 + mutt_fast_close_compressed (ctx);
459 + if (append == ci->close)
460 + mutt_message (_("Compressing %s..."), ctx->realpath);
462 + mutt_message (_("Compressed-appending to %s..."), ctx->realpath);
465 + cmd = get_compression_cmd (append, ctx);
469 + if ((fp = fopen (ctx->realpath, "a")) == NULL)
471 + mutt_perror (ctx->realpath);
475 + mutt_block_signals ();
476 + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1)
479 + mutt_unblock_signals ();
480 + mutt_error _("Unable to lock mailbox!");
485 + dprint (2, (debugfile, "CompressCmd: '%s'\n", cmd));
490 + if (append == ci->close)
491 + fprintf (stderr, _("Compressing %s...\n"), ctx->realpath);
493 + fprintf (stderr, _("Compressed-appending to %s...\n"), ctx->realpath);
495 + if (mutt_system (cmd))
497 + mutt_any_key_to_continue (NULL);
498 + mutt_error (_(" %s: Error compressing mailbox! Uncompressed one kept!\n"),
501 + mbox_unlock_compressed (ctx, fp);
502 + mutt_unblock_signals ();
507 + mbox_unlock_compressed (ctx, fp);
508 + mutt_unblock_signals ();
511 + restore_path (ctx);
513 + FREE (&ctx->compressinfo);
518 +#endif /* USE_COMPRESSED */
523 + * Copyright (C) 1997 Alain Penders <Alain@Finale-Dev.com>
525 + * This program is free software; you can redistribute it and/or modify
526 + * it under the terms of the GNU General Public License as published by
527 + * the Free Software Foundation; either version 2 of the License, or
528 + * (at your option) any later version.
530 + * This program is distributed in the hope that it will be useful,
531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
533 + * GNU General Public License for more details.
535 + * You should have received a copy of the GNU General Public License
536 + * along with this program; if not, write to the Free Software
537 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
540 +int mutt_can_read_compressed (const char *);
541 +int mutt_can_append_compressed (const char *);
542 +int mutt_open_read_compressed (CONTEXT *);
543 +int mutt_open_append_compressed (CONTEXT *);
544 +int mutt_slow_close_compressed (CONTEXT *);
545 +int mutt_sync_compressed (CONTEXT *);
546 +int mutt_test_compress_command (const char *);
547 +int mutt_check_mailbox_compressed (CONTEXT *);
548 +void mutt_fast_close_compressed (CONTEXT *);
551 @@ -787,6 +787,11 @@ AC_ARG_ENABLE(locales-fix, AC_HELP_STRIN
552 AC_DEFINE(LOCALES_HACK,1,[ Define if the result of isprint() is unreliable. ])
555 +AC_ARG_ENABLE(compressed, AC_HELP_STRING([--enable-compressed], [Enable compressed folders support]),
556 + [if test x$enableval = xyes; then
557 + AC_DEFINE(USE_COMPRESSED,1, [ Define to support compressed folders. ])
560 AC_ARG_WITH(exec-shell, AC_HELP_STRING([--with-exec-shell=SHELL], [Specify alternate shell (ONLY if /bin/sh is broken)]),
561 [if test $withval != yes; then
562 AC_DEFINE_UNQUOTED(EXECSHELL, "$withval",
565 @@ -1132,6 +1132,11 @@ int mutt_index_menu (void)
569 +#ifdef USE_COMPRESSED
570 + if (Context->compressinfo && Context->realpath)
571 + mutt_str_replace (&LastFolder, Context->realpath);
574 mutt_str_replace (&LastFolder, Context->path);
575 oldcount = Context ? Context->msgcount : 0;
577 --- a/doc/manual.xml.head
578 +++ b/doc/manual.xml.head
579 @@ -4799,6 +4799,205 @@ macro pager \cb |urlview\n
583 +<sect1 id="compressedfolders">
584 +<title>Compressed folders Support (OPTIONAL)</title>
587 +If Mutt was compiled with compressed folders support (by running the
588 +<emphasis>configure</emphasis> script with the
589 +<emphasis>--enable-compressed</emphasis> flag), Mutt can open folders
590 +stored in an arbitrary format, provided that the user has a script to
591 +convert from/to this format to one of the accepted.
593 +The most common use is to open compressed archived folders e.g. with
596 +In addition, the user can provide a script that gets a folder in an
597 +accepted format and appends its context to the folder in the
598 +user-defined format, which may be faster than converting the entire
599 +folder to the accepted format, appending to it and converting back to
600 +the user-defined format.
602 +There are three hooks defined (<link
603 +linkend="open-hook">open-hook</link>, <link
604 +linkend="close-hook">close-hook</link> and <link
605 +linkend="append-hook">append-hook</link>) which define commands to
606 +uncompress and compress a folder and to append messages to an existing
607 +compressed folder respectively.
612 +open-hook \\.gz$ "gzip -cd %f > %t"
613 +close-hook \\.gz$ "gzip -c %t > %f"
614 +append-hook \\.gz$ "gzip -c %t >> %f"
617 +You do not have to specify all of the commands. If you omit <link
618 +linkend="append-hook">append-hook</link>, the folder will be open and
619 +closed again each time you will add to it. If you omit <link
620 +linkend="close-hook">close-hook</link> (or give empty command) , the
621 +folder will be open in the mode. If you specify <link
622 +linkend="append-hook">append-hook</link> though you'll be able to
623 +append to the folder.
625 +Note that Mutt will only try to use hooks if the file is not in one of
626 +the accepted formats. In particular, if the file is empty, mutt
627 +supposes it is not compressed. This is important because it allows the
628 +use of programs that do not have well defined extensions. Just use
629 +"." as a regexp. But this may be surprising if your
630 +compressing script produces empty files. In this situation, unset
631 +<link linkend="save-empty">$save_empty</link>, so that
632 +the compressed file will be removed if you delete all of the messages.
635 +<sect2 id="open-hook">
636 +<title>Open a compressed mailbox for reading</title>
639 +Usage: <literal>open-hook</literal> <emphasis>regexp</emphasis> "<emphasis>command</emphasis>"
641 +The <emphasis>command</emphasis> is the command that can be used for
642 +opening the folders whose names match <emphasis>regexp</emphasis>.
644 +The <emphasis>command</emphasis> string is the printf-like format
645 +string, and it should accept two parameters: %f, which is
646 +replaced with the (compressed) folder name, and %t which is
647 +replaced with the name of the temporary folder to which to write.
649 +%f and %t can be repeated any number of times in the
650 +command string, and all of the entries are replaced with the
651 +appropriate folder name. In addition, %% is replaced by
652 +%, as in printf, and any other %anything is left as is.
654 +The <emphasis>command</emphasis> should <emphasis
655 +role="bold">not</emphasis> remove the original compressed file. The
656 +<emphasis>command</emphasis> should return non-zero exit status if it
657 +fails, so mutt knows something's wrong.
662 +open-hook \\.gz$ "gzip -cd %f > %t"
665 +If the <emphasis>command</emphasis> is empty, this operation is
666 +disabled for this file type.
670 +<sect2 id="close-hook">
671 +<title>Write a compressed mailbox</title>
674 +Usage: <literal>close-hook</literal> <emphasis>regexp</emphasis> "<emphasis>command</emphasis>"
676 +This is used to close the folder that was open with the <link
677 +linkend="open-hook">open-hook</link> command after some changes were
680 +The <emphasis>command</emphasis> string is the command that can be
681 +used for closing the folders whose names match
682 +<emphasis>regexp</emphasis>. It has the same format as in the <link
683 +linkend="open-hook">open-hook</link> command. Temporary folder in this
684 +case is the folder previously produced by the <link
685 +linkend="open-hook">open-hook</link> command.
687 +The <emphasis>command</emphasis> should <emphasis
688 +role="bold">not</emphasis> remove the decompressed file. The
689 +<emphasis>command</emphasis> should return non-zero exit status if it
690 +fails, so mutt knows something's wrong.
695 +close-hook \\.gz$ "gzip -c %t > %f"
698 +If the <emphasis>command</emphasis> is empty, this operation is
699 +disabled for this file type, and the file can only be open in the
702 +<link linkend="close-hook">close-hook</link> is not called when you
703 +exit from the folder if the folder was not changed.
707 +<sect2 id="append-hook">
708 +<title>Append a message to a compressed mailbox</title>
711 +Usage: <literal>append-hook</literal> <emphasis>regexp</emphasis> "<emphasis>command</emphasis>"
713 +This command is used for saving to an existing compressed folder. The
714 +<emphasis>command</emphasis> is the command that can be used for
715 +appending to the folders whose names match
716 +<emphasis>regexp</emphasis>. It has the same format as in the <link
717 +linkend="open-hook">open-hook</link> command. The temporary folder in
718 +this case contains the messages that are being appended.
720 +The <emphasis>command</emphasis> should <emphasis
721 +role="bold">not</emphasis> remove the decompressed file. The
722 +<emphasis>command</emphasis> should return non-zero exit status if it
723 +fails, so mutt knows something's wrong.
728 +append-hook \\.gz$ "gzip -c %t >> %f"
731 +When <link linkend="append-hook">append-hook</link> is used, the folder
732 +is not opened, which saves time, but this means that we can not find
733 +out what the folder type is. Thus the default (<link
734 +linkend="mbox-type">$mbox_type</link>) type is always
735 +supposed (i.e. this is the format used for the temporary folder).
737 +If the file does not exist when you save to it, <link
738 +linkend="close-hook">close-hook</link> is called, and not <link
739 +linkend="append-hook">append-hook</link>. <link
740 +linkend="append-hook">append-hook</link> is only for appending to
743 +If the <emphasis>command</emphasis> is empty, this operation is
744 +disabled for this file type. In this case, the folder will be open and
745 +closed again (using <link linkend="open-hook">open-hook</link> and
746 +<link linkend="close-hook">close-hook</link>respectively) each time you
752 +<title>Encrypted folders</title>
755 +The compressed folders support can also be used to handle encrypted
756 +folders. If you want to encrypt a folder with PGP, you may want to use
757 +the following hooks:
760 +open-hook \\.pgp$ "pgp -f < %f > %t"
761 +close-hook \\.pgp$ "pgp -fe YourPgpUserIdOrKeyId < %t > %f"
764 +Please note, that PGP does not support appending to an encrypted
765 +folder, so there is no append-hook defined.
767 +If you are using GnuPG instead of PGP, you may use the following hooks
771 +open-hook \\.gpg$ "gpg --decrypt < %f > %t"
772 +close-hook \\.gpg$ "gpg --encrypt --recipient YourGpgUserIdOrKeyId < %t > %f"
775 +<emphasis role="bold">Note:</emphasis> the folder is temporary stored
776 +decrypted in the /tmp directory, where it can be read by your system
777 +administrator. So think about the security aspects of this.
782 <chapter id="mimesupport">
783 <title>Mutt's MIME Support</title>
787 @@ -24,6 +24,11 @@ macro generic,pager <F1> "<shell-escape>
788 macro index,pager y "<change-folder>?<toggle-mailboxes>" "show incoming mailboxes list"
791 +# Use folders which match on \\.gz$ as gzipped folders:
792 +# open-hook \\.gz$ "gzip -cd %f > %t"
793 +# close-hook \\.gz$ "gzip -c %t > %f"
794 +# append-hook \\.gz$ "gzip -c %t >> %f"
796 # If Mutt is unable to determine your site's domain name correctly, you can
797 # set the default here.
799 --- a/doc/Muttrc.head
800 +++ b/doc/Muttrc.head
801 @@ -24,6 +24,11 @@ macro generic,pager <F1> "<shell-escape>
802 macro index,pager y "<change-folder>?<toggle-mailboxes>" "show incoming mailboxes list"
805 +# Use folders which match on \\.gz$ as gzipped folders:
806 +# open-hook \\.gz$ "gzip -cd %f > %t"
807 +# close-hook \\.gz$ "gzip -c %t > %f"
808 +# append-hook \\.gz$ "gzip -c %t >> %f"
810 # If Mutt is unable to determine your site's domain name correctly, you can
811 # set the default here.
813 --- a/doc/muttrc.man.head
814 +++ b/doc/muttrc.man.head
815 @@ -345,6 +345,24 @@ specify the ID of the public key to be u
816 to a certain recipient. The meaning of "key ID" is to be taken
817 broadly: This can be a different e-mail address, a numerical key ID,
818 or even just an arbitrary search string.
821 +\fBopen-hook\fP \fIregexp\fP "\fIcommand\fP"
822 +\fBclose-hook\fP \fIregexp\fP "\fIcommand\fP"
823 +\fBappend-hook\fP \fIregexp\fP "\fIcommand\fP"
826 +These commands provide a way to handle compressed folders. The given
827 +\fBregexp\fP specifies which folders are taken as compressed (e.g.
828 +"\fI\\\\.gz$\fP"). The commands tell Mutt how to uncompress a folder
829 +(\fBopen-hook\fP), compress a folder (\fBclose-hook\fP) or append a
830 +compressed mail to a compressed folder (\fBappend-hook\fP). The
831 +\fIcommand\fP string is the
833 +like format string, and it should accept two parameters: \fB%f\fP,
834 +which is replaced with the (compressed) folder name, and \fB%t\fP
835 +which is replaced with the name of the temporary folder to which to
838 \fBpush\fP \fIstring\fP
839 This command adds the named \fIstring\fP to the keyboard buffer.
844 #include "mutt_crypt.h"
846 +#ifdef USE_COMPRESSED
847 +#include "compress.h"
853 @@ -92,6 +96,16 @@ int mutt_parse_hook (BUFFER *buf, BUFFER
854 memset (&pattern, 0, sizeof (pattern));
855 pattern.data = safe_strdup (path);
857 +#ifdef USE_COMPRESSED
858 + else if (data & (M_APPENDHOOK | M_OPENHOOK | M_CLOSEHOOK))
860 + if (mutt_test_compress_command (command.data))
862 + strfcpy (err->data, _("badly formatted command string"), err->dsize);
867 else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ICONVHOOK | M_ACCOUNTHOOK))
868 && (!WithCrypto || !(data & M_CRYPTHOOK))
872 @@ -3272,6 +3272,11 @@ struct command_t Commands[] = {
873 { "fcc-hook", mutt_parse_hook, M_FCCHOOK },
874 { "fcc-save-hook", mutt_parse_hook, M_FCCHOOK | M_SAVEHOOK },
875 { "folder-hook", mutt_parse_hook, M_FOLDERHOOK },
876 +#ifdef USE_COMPRESSED
877 + { "open-hook", mutt_parse_hook, M_OPENHOOK },
878 + { "close-hook", mutt_parse_hook, M_CLOSEHOOK },
879 + { "append-hook", mutt_parse_hook, M_APPENDHOOK },
881 { "group", parse_group, 0 },
882 { "ungroup", parse_ungroup, 0 },
883 { "hdr_order", parse_list, UL &HeaderOrderList },
886 @@ -403,6 +403,12 @@ static void show_version (void)
891 +#ifdef USE_COMPRESSED
901 @@ -18,7 +18,7 @@ BUILT_SOURCES = keymap_defs.h patchlist.
902 bin_PROGRAMS = mutt @DOTLOCK_TARGET@ @PGPAUX_TARGET@
904 addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c \
905 - crypt.c cryptglue.c \
906 + crypt.c cryptglue.c compress.c \
907 commands.c complete.c compose.c copy.c curs_lib.c curs_main.c date.c \
908 edit.c enter.c flags.c init.c filter.c from.c \
909 getdomain.c group.c \
910 @@ -57,7 +57,7 @@ EXTRA_mutt_SOURCES = account.c md5.c mut
913 EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
914 - configure account.h \
915 + configure account.h compress.h \
916 attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \
917 globals.h hash.h history.h init.h keymap.h mutt_crypt.h \
918 mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \
923 #include "mutt_curses.h"
925 +#ifdef USE_COMPRESSED
926 +#include "compress.h"
929 #include <sys/stat.h>
932 @@ -1037,6 +1041,12 @@ bail: /* Come here in case of disaster
933 int mbox_close_mailbox (CONTEXT *ctx)
935 mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
937 +#ifdef USE_COMPRESSED
938 + if (ctx->compressinfo)
939 + mutt_slow_close_compressed (ctx);
942 mutt_unblock_signals ();
943 mx_fastclose_mailbox (ctx);
947 @@ -160,6 +160,11 @@ typedef enum
948 #define M_ACCOUNTHOOK (1<<9)
949 #define M_REPLYHOOK (1<<10)
950 #define M_SEND2HOOK (1<<11)
951 +#ifdef USE_COMPRESSED
952 +#define M_OPENHOOK (1<<12)
953 +#define M_APPENDHOOK (1<<13)
954 +#define M_CLOSEHOOK (1<<14)
957 /* tree characters for linearize_tree and print_enriched_string */
958 #define M_TREE_LLCORNER 1
959 @@ -892,6 +897,11 @@ typedef struct _context
960 int flagged; /* how many flagged messages */
961 int msgnotreadyet; /* which msg "new" in pager, -1 if none */
963 +#ifdef USE_COMPRESSED
964 + void *compressinfo; /* compressed mbox module private data */
965 + char *realpath; /* path to compressed mailbox */
966 +#endif /* USE_COMPRESSED */
968 short magic; /* mailbox type */
970 unsigned char rights[(RIGHTSMAX + 7)/8]; /* ACL bits */
977 +#ifdef USE_COMPRESSED
978 +#include "compress.h"
984 @@ -445,6 +449,10 @@ int mx_get_magic (const char *path)
988 +#ifdef USE_COMPRESSED
989 + if (magic == 0 && mutt_can_read_compressed (path))
990 + return M_COMPRESSED;
995 @@ -484,6 +492,13 @@ static int mx_open_mailbox_append (CONTE
999 +#ifdef USE_COMPRESSED
1000 + /* special case for appending to compressed folders -
1001 + * even if we can not open them for reading */
1002 + if (mutt_can_append_compressed (ctx->path))
1003 + mutt_open_append_compressed (ctx);
1009 @@ -647,7 +662,12 @@ CONTEXT *mx_open_mailbox (const char *pa
1012 ctx->magic = mx_get_magic (path);
1015 +#ifdef USE_COMPRESSED
1016 + if (ctx->magic == M_COMPRESSED)
1017 + mutt_open_read_compressed (ctx);
1021 mutt_error (_("%s is not a mailbox."), path);
1023 @@ -748,6 +768,10 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
1024 mutt_free_header (&ctx->hdrs[i]);
1027 +#ifdef USE_COMPRESSED
1028 + if (ctx->compressinfo)
1029 + mutt_fast_close_compressed (ctx);
1032 FREE (&ctx->pattern);
1033 if (ctx->limit_pattern)
1034 @@ -800,6 +824,12 @@ static int sync_mailbox (CONTEXT *ctx, i
1036 if (tmp && tmp->new == 0)
1037 mutt_update_mailbox (tmp);
1039 +#ifdef USE_COMPRESSED
1040 + if (rc == 0 && ctx->compressinfo)
1041 + return mutt_sync_compressed (ctx);
1047 @@ -1058,6 +1088,11 @@ int mx_close_mailbox (CONTEXT *ctx, int
1048 !mutt_is_spool(ctx->path) && !option (OPTSAVEEMPTY))
1049 mx_unlink_empty (ctx->path);
1051 +#ifdef USE_COMPRESSED
1052 + if (ctx->compressinfo && mutt_slow_close_compressed (ctx))
1056 mx_fastclose_mailbox (ctx);
1059 @@ -1373,6 +1408,11 @@ int mx_check_mailbox (CONTEXT *ctx, int
1063 +#ifdef USE_COMPRESSED
1064 + if (ctx->compressinfo)
1065 + return mutt_check_mailbox_compressed (ctx);
1070 if (ctx->locked) lock = 0;
1073 @@ -40,6 +40,9 @@ enum
1077 +#ifdef USE_COMPRESSED
1082 WHERE short DefaultMagic INITVAL (M_MBOX);
1085 @@ -1289,6 +1289,48 @@ msgstr "Prüfung des Absenders fehlgeschl
1086 msgid "Failed to figure out sender"
1087 msgstr "Kann Absender nicht ermitteln"
1089 +#: compress.c:203 mbox.c:661
1090 +msgid "Mailbox was corrupted!"
1091 +msgstr "Mailbox wurde zerstört!"
1093 +#: compress.c:228 compress.c:253
1095 +msgid "Decompressing %s...\n"
1096 +msgstr "Entpacke %s...\n"
1098 +#: compress.c:246 compress.c:367 compress.c:443 mbox.c:706
1099 +msgid "Unable to lock mailbox!"
1100 +msgstr "Kann Mailbox nicht für exklusiven Zugriff sperren!"
1104 +msgid "Error executing: %s : unable to open the mailbox!\n"
1105 +msgstr "Fehler beim Ausführen von %s : Kann die Mailbox nicht öffnen!\n"
1107 +#: compress.c:350 compress.c:377 compress.c:423 compress.c:454
1109 +msgid "Compressing %s...\n"
1110 +msgstr "Komprimiere %s...\n"
1115 +"%s: Error compressing mailbox! Original mailbox deleted, uncompressed one "
1118 +"%s: Fehler beim Komprimieren der Mailbox! Ursprüngliche Mailbox gelöscht, "
1119 +"entpackte gespeichert!\n"
1121 +#: compress.c:425 compress.c:456
1123 +msgid "Compressed-appending to %s...\n"
1124 +msgstr "Hänge komprimiert an %s... an\n"
1128 +msgid " %s: Error compressing mailbox! Uncompressed one kept!\n"
1129 +msgstr " %s: Fehler beim packen der Mailbox! Entpackte Mailbox gespeichert!\n"
1133 msgid " (current time: %c)"
1134 @@ -1958,6 +2000,10 @@ msgstr "Hilfe für %s"
1135 msgid "Bad history file format (line %d)"
1136 msgstr "Falsches Format der Datei früherer Eingaben (Zeile %d)"
1139 +msgid "badly formatted command string"
1140 +msgstr "Hook enthält nicht die Muster %f und %t"
1144 msgid "unhook: Can't do unhook * from within a hook."
1145 @@ -2687,18 +2733,10 @@ msgstr "Lese %s..."
1146 msgid "Mailbox is corrupt!"
1147 msgstr "Mailbox fehlerhaft!"
1150 -msgid "Mailbox was corrupted!"
1151 -msgstr "Mailbox wurde zerstört!"
1153 #: mbox.c:719 mbox.c:975
1154 msgid "Fatal error! Could not reopen mailbox!"
1155 msgstr "Fataler Fehler, konnte Mailbox nicht erneut öffnen!"
1158 -msgid "Unable to lock mailbox!"
1159 -msgstr "Kann Mailbox nicht für exklusiven Zugriff sperren!"
1161 #. this means ctx->changed or ctx->deleted was set, but no
1162 #. * messages were found to be changed or deleted. This should
1163 #. * never happen, is we presume it is a bug in mutt.
1164 --- a/po/POTFILES.in
1165 +++ b/po/POTFILES.in
1166 @@ -8,6 +8,7 @@ charset.c
1176 @@ -96,6 +96,14 @@ status_format_str (char *buf, size_t buf
1179 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
1180 +#ifdef USE_COMPRESSED
1181 + if (Context && Context->compressinfo && Context->realpath)
1183 + strfcpy (tmp, Context->realpath, sizeof (tmp));
1184 + mutt_pretty_mailbox (tmp);
1188 if (Context && Context->path)
1190 strfcpy (tmp, Context->path, sizeof (tmp));