NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
compress.c
Go to the documentation of this file.
1
39#include "config.h"
40#include <errno.h>
41#include <stdbool.h>
42#include <stdio.h>
43#include <string.h>
44#include <sys/stat.h>
45#include <unistd.h>
46#include "mutt/lib.h"
47#include "config/lib.h"
48#include "core/lib.h"
49#include "gui/lib.h"
50#include "lib.h"
51#include "expando/lib.h"
52#include "expando.h"
53#include "globals.h"
54#include "hook.h"
55#include "mx.h"
56#include "protos.h"
57
58struct Email;
59
63static const struct Command CompCommands[] = {
64 // clang-format off
65 { "append-hook", mutt_parse_hook, MUTT_APPEND_HOOK },
66 { "close-hook", mutt_parse_hook, MUTT_CLOSE_HOOK },
67 { "open-hook", mutt_parse_hook, MUTT_OPEN_HOOK },
68 // clang-format on
69};
70
80 // clang-format off
81 { "f", "from", ED_COMPRESS, ED_CMP_FROM, NULL },
82 { "t", "to", ED_COMPRESS, ED_CMP_TO, NULL },
83 { NULL, NULL, 0, -1, NULL }
84 // clang-format on
85};
86
91{
93}
94
106static bool lock_realpath(struct Mailbox *m, bool excl)
107{
108 if (!m || !m->compress_info)
109 return false;
110
111 struct CompressInfo *ci = m->compress_info;
112
113 if (ci->locked)
114 return true;
115
116 if (excl)
117 ci->fp_lock = mutt_file_fopen(m->realpath, "a");
118 else
119 ci->fp_lock = mutt_file_fopen(m->realpath, "r");
120 if (!ci->fp_lock)
121 {
122 mutt_perror("%s", m->realpath);
123 return false;
124 }
125
126 int r = mutt_file_lock(fileno(ci->fp_lock), excl, true);
127 if (r == 0)
128 {
129 ci->locked = true;
130 }
131 else if (excl)
132 {
134 m->readonly = true;
135 return true;
136 }
137
138 return r == 0;
139}
140
147static void unlock_realpath(struct Mailbox *m)
148{
149 if (!m || !m->compress_info)
150 return;
151
152 struct CompressInfo *ci = m->compress_info;
153
154 if (!ci->locked)
155 return;
156
157 mutt_file_unlock(fileno(ci->fp_lock));
158
159 ci->locked = false;
161}
162
173static int setup_paths(struct Mailbox *m)
174{
175 if (!m)
176 return -1;
177
178 /* Setup the right paths */
180
181 /* We will uncompress to TMPDIR */
182 struct Buffer *buf = buf_pool_get();
183 buf_mktemp(buf);
184 buf_copy(&m->pathbuf, buf);
185 buf_pool_release(&buf);
186
187 return mutt_file_touch(mailbox_path(m)) ? 0 : -1;
188}
189
196static void store_size(const struct Mailbox *m)
197{
198 if (!m || !m->compress_info)
199 return;
200
201 struct CompressInfo *ci = m->compress_info;
202
204}
205
211static struct Expando *validate_compress_expando(const char *s)
212{
213 struct Buffer *err = buf_pool_get();
214
215 struct Expando *exp = expando_parse(s, CompressFormatDef, err);
216 if (!exp)
217 {
218 mutt_error(_("Expando parse error: %s"), buf_string(err));
219 }
220
221 buf_pool_release(&err);
222 return exp;
223}
224
233static struct CompressInfo *set_compress_info(struct Mailbox *m)
234{
235 if (!m)
236 return NULL;
237
238 if (m->compress_info)
239 return m->compress_info;
240
241 /* Open is compulsory */
242 const char *o = mutt_find_hook(MUTT_OPEN_HOOK, mailbox_path(m));
243 if (!o)
244 return NULL;
245
246 const char *c = mutt_find_hook(MUTT_CLOSE_HOOK, mailbox_path(m));
247 const char *a = mutt_find_hook(MUTT_APPEND_HOOK, mailbox_path(m));
248
249 struct CompressInfo *ci = MUTT_MEM_CALLOC(1, struct CompressInfo);
250 m->compress_info = ci;
251
255
256 return ci;
257}
258
263static void compress_info_free(struct Mailbox *m)
264{
265 if (!m || !m->compress_info)
266 return;
267
268 struct CompressInfo *ci = m->compress_info;
272
274
275 FREE(&m->compress_info);
276}
277
289static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
290{
291 if (!m || !exp || !progress)
292 return false;
293
294 if (m->verbose)
295 mutt_message(progress, m->realpath);
296
297 bool rc = true;
298 struct Buffer *sys_cmd = buf_pool_get();
299 buf_alloc(sys_cmd, STR_COMMAND);
300
302 mutt_endwin();
303 fflush(stdout);
304
306 sys_cmd->dsize, sys_cmd);
307
308 if (mutt_system(buf_string(sys_cmd)) != 0)
309 {
310 rc = false;
312 mutt_error(_("Error running \"%s\""), buf_string(sys_cmd));
313 }
314
316
317 buf_pool_release(&sys_cmd);
318 return rc;
319}
320
333{
334 if (!m)
335 return false;
336
337 /* If this succeeds, we know there's an open-hook */
338 struct CompressInfo *ci = set_compress_info(m);
339 if (!ci)
340 return false;
341
342 /* We have an open-hook, so to append we need an append-hook,
343 * or a close-hook. */
344 if (ci->cmd_append || ci->cmd_close)
345 return true;
346
347 mutt_error(_("Can't append without an append-hook or close-hook : %s"), mailbox_path(m));
348 return false;
349}
350
361bool mutt_comp_can_read(const char *path)
362{
363 if (!path)
364 return false;
365
367 return true;
368
369 return false;
370}
371
381int mutt_comp_valid_command(const char *cmd)
382{
383 if (!cmd)
384 return 0;
385
386 return strstr(cmd, "%f") && strstr(cmd, "%t");
387}
388
392static bool comp_ac_owns_path(struct Account *a, const char *path)
393{
394 return false;
395}
396
400static bool comp_ac_add(struct Account *a, struct Mailbox *m)
401{
402 return true;
403}
404
414{
415 struct CompressInfo *ci = set_compress_info(m);
416 if (!ci)
417 return MX_OPEN_ERROR;
418
419 /* If there's no close-hook, or the file isn't writable */
420 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
421 m->readonly = true;
422
423 if (setup_paths(m) != 0)
424 goto cmo_fail;
425 store_size(m);
426
427 if (!lock_realpath(m, false))
428 {
429 mutt_error(_("Unable to lock mailbox"));
430 goto cmo_fail;
431 }
432
433 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
434 goto cmo_fail;
435
437
439 if (m->type == MUTT_UNKNOWN)
440 {
441 mutt_error(_("Can't identify the contents of the compressed file"));
442 goto cmo_fail;
443 }
444
445 ci->child_ops = mx_get_ops(m->type);
446 if (!ci->child_ops)
447 {
448 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
449 goto cmo_fail;
450 }
451
452 m->account->type = m->type;
453 return ci->child_ops->mbox_open(m);
454
455cmo_fail:
456 /* remove the partial uncompressed file */
457 (void) remove(mailbox_path(m));
459 return MX_OPEN_ERROR;
460}
461
468static bool comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
469{
470 /* If this succeeds, we know there's an open-hook */
471 struct CompressInfo *ci = set_compress_info(m);
472 if (!ci)
473 return false;
474
475 /* To append we need an append-hook or a close-hook */
476 if (!ci->cmd_append && !ci->cmd_close)
477 {
478 mutt_error(_("Can't append without an append-hook or close-hook : %s"),
479 mailbox_path(m));
480 goto cmoa_fail1;
481 }
482
483 if (setup_paths(m) != 0)
484 goto cmoa_fail2;
485
486 /* Lock the realpath for the duration of the append.
487 * It will be unlocked in the close */
488 if (!lock_realpath(m, true))
489 {
490 mutt_error(_("Unable to lock mailbox"));
491 goto cmoa_fail2;
492 }
493
494 /* Open the existing mailbox, unless we are appending */
495 if (!ci->cmd_append && (mutt_file_get_size(m->realpath) > 0))
496 {
497 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
498 {
499 mutt_error(_("Compress command failed: %s"), ci->cmd_open->string);
500 goto cmoa_fail2;
501 }
503 }
504 else
505 {
506 m->type = cs_subset_enum(NeoMutt->sub, "mbox_type");
507 }
508
509 /* We can only deal with mbox and mmdf mailboxes */
510 if ((m->type != MUTT_MBOX) && (m->type != MUTT_MMDF))
511 {
512 mutt_error(_("Unsupported mailbox type for appending"));
513 goto cmoa_fail2;
514 }
515
516 ci->child_ops = mx_get_ops(m->type);
517 if (!ci->child_ops)
518 {
519 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
520 goto cmoa_fail2;
521 }
522
523 if (!ci->child_ops->mbox_open_append(m, flags))
524 goto cmoa_fail2;
525
526 return true;
527
528cmoa_fail2:
529 /* remove the partial uncompressed file */
530 (void) remove(mailbox_path(m));
531cmoa_fail1:
532 /* Free the compress_info to prevent close from trying to recompress */
534
535 return false;
536}
537
548static enum MxStatus comp_mbox_check(struct Mailbox *m)
549{
550 if (!m->compress_info)
551 return MX_STATUS_ERROR;
552
553 struct CompressInfo *ci = m->compress_info;
554
555 const struct MxOps *ops = ci->child_ops;
556 if (!ops)
557 return MX_STATUS_ERROR;
558
559 int size = mutt_file_get_size(m->realpath);
560 if (size == ci->size)
561 return MX_STATUS_OK;
562
563 if (!lock_realpath(m, false))
564 {
565 mutt_error(_("Unable to lock mailbox"));
566 return MX_STATUS_ERROR;
567 }
568
569 bool rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
570 store_size(m);
572 if (!rc)
573 return MX_STATUS_ERROR;
574
575 return ops->mbox_check(m);
576}
577
584static enum MxStatus comp_mbox_sync(struct Mailbox *m)
585{
586 if (!m->compress_info)
587 return MX_STATUS_ERROR;
588
589 struct CompressInfo *ci = m->compress_info;
590
591 if (!ci->cmd_close)
592 {
593 mutt_error(_("Can't sync a compressed file without a close-hook"));
594 return MX_STATUS_ERROR;
595 }
596
597 const struct MxOps *ops = ci->child_ops;
598 if (!ops)
599 return MX_STATUS_ERROR;
600
601 if (!lock_realpath(m, true))
602 {
603 mutt_error(_("Unable to lock mailbox"));
604 return MX_STATUS_ERROR;
605 }
606
607 enum MxStatus check = comp_mbox_check(m);
608 if (check != MX_STATUS_OK)
609 goto sync_cleanup;
610
611 check = ops->mbox_sync(m);
612 if (check != MX_STATUS_OK)
613 goto sync_cleanup;
614
615 if (!execute_command(m, ci->cmd_close, _("Compressing %s")))
616 {
617 check = MX_STATUS_ERROR;
618 goto sync_cleanup;
619 }
620
621 check = MX_STATUS_OK;
622
623sync_cleanup:
624 store_size(m);
626 return check;
627}
628
635static enum MxStatus comp_mbox_close(struct Mailbox *m)
636{
637 if (!m->compress_info)
638 return MX_STATUS_ERROR;
639
640 struct CompressInfo *ci = m->compress_info;
641
642 const struct MxOps *ops = ci->child_ops;
643 if (!ops)
644 {
646 return MX_STATUS_ERROR;
647 }
648
649 ops->mbox_close(m);
650
651 /* sync has already been called, so we only need to delete some files */
652 if (m->append)
653 {
654 const struct Expando *append = NULL;
655 const char *msg = NULL;
656
657 /* The file exists and we can append */
658 if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
659 {
660 append = ci->cmd_append;
661 msg = _("Compressed-appending to %s...");
662 }
663 else
664 {
665 append = ci->cmd_close;
666 msg = _("Compressing %s");
667 }
668
669 if (!execute_command(m, append, msg))
670 {
672 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
673 }
674 else
675 {
676 if (remove(mailbox_path(m)) < 0)
677 {
678 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
679 mailbox_path(m), strerror(errno), errno);
680 }
681 }
682
684 }
685 else
686 {
687 /* If the file was removed, remove the compressed folder too */
688 if (access(mailbox_path(m), F_OK) != 0)
689 {
690 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
691 if (!c_save_empty)
692 {
693 if (remove(m->realpath) < 0)
694 {
695 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
696 m->realpath, strerror(errno), errno);
697 }
698 }
699 }
700 else
701 {
702 if (remove(mailbox_path(m)) < 0)
703 {
704 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
705 mailbox_path(m), strerror(errno), errno);
706 }
707 }
708 }
709
711
712 return MX_STATUS_OK;
713}
714
718static bool comp_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
719{
720 if (!m->compress_info)
721 return false;
722
723 struct CompressInfo *ci = m->compress_info;
724
725 const struct MxOps *ops = ci->child_ops;
726 if (!ops)
727 return false;
728
729 /* Delegate */
730 return ops->msg_open(m, msg, e);
731}
732
736static bool comp_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
737{
738 if (!m->compress_info)
739 return false;
740
741 struct CompressInfo *ci = m->compress_info;
742
743 const struct MxOps *ops = ci->child_ops;
744 if (!ops)
745 return false;
746
747 /* Delegate */
748 return ops->msg_open_new(m, msg, e);
749}
750
754static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
755{
756 if (!m->compress_info)
757 return -1;
758
759 struct CompressInfo *ci = m->compress_info;
760
761 const struct MxOps *ops = ci->child_ops;
762 if (!ops)
763 return -1;
764
765 /* Delegate */
766 return ops->msg_commit(m, msg);
767}
768
772static int comp_msg_close(struct Mailbox *m, struct Message *msg)
773{
774 if (!m->compress_info)
775 return -1;
776
777 struct CompressInfo *ci = m->compress_info;
778
779 const struct MxOps *ops = ci->child_ops;
780 if (!ops)
781 return -1;
782
783 /* Delegate */
784 return ops->msg_close(m, msg);
785}
786
790static int comp_msg_padding_size(struct Mailbox *m)
791{
792 if (!m->compress_info)
793 return 0;
794
795 struct CompressInfo *ci = m->compress_info;
796
797 const struct MxOps *ops = ci->child_ops;
798 if (!ops || !ops->msg_padding_size)
799 return 0;
800
801 return ops->msg_padding_size(m);
802}
803
807static int comp_msg_save_hcache(struct Mailbox *m, struct Email *e)
808{
809 if (!m->compress_info)
810 return 0;
811
812 struct CompressInfo *ci = m->compress_info;
813
814 const struct MxOps *ops = ci->child_ops;
815 if (!ops || !ops->msg_save_hcache)
816 return 0;
817
818 return ops->msg_save_hcache(m, e);
819}
820
824static int comp_tags_edit(struct Mailbox *m, const char *tags, struct Buffer *buf)
825{
826 if (!m->compress_info)
827 return 0;
828
829 struct CompressInfo *ci = m->compress_info;
830
831 const struct MxOps *ops = ci->child_ops;
832 if (!ops || !ops->tags_edit)
833 return 0;
834
835 return ops->tags_edit(m, tags, buf);
836}
837
841static int comp_tags_commit(struct Mailbox *m, struct Email *e, const char *buf)
842{
843 if (!m->compress_info)
844 return 0;
845
846 struct CompressInfo *ci = m->compress_info;
847
848 const struct MxOps *ops = ci->child_ops;
849 if (!ops || !ops->tags_commit)
850 return 0;
851
852 return ops->tags_commit(m, e, buf);
853}
854
858static enum MailboxType comp_path_probe(const char *path, const struct stat *st)
859{
860 if (!st || !S_ISREG(st->st_mode))
861 return MUTT_UNKNOWN;
862
863 if (mutt_comp_can_read(path))
864 return MUTT_COMPRESSED;
865
866 return MUTT_UNKNOWN;
867}
868
872static int comp_path_canon(struct Buffer *path)
873{
874 mutt_path_canon(path, HomeDir, false);
875 return 0;
876}
877
884const struct MxOps MxCompOps = {
885 // clang-format off
887 .name = "compressed",
888 .is_local = true,
889 .ac_owns_path = comp_ac_owns_path,
890 .ac_add = comp_ac_add,
891 .mbox_open = comp_mbox_open,
892 .mbox_open_append = comp_mbox_open_append,
893 .mbox_check = comp_mbox_check,
894 .mbox_check_stats = NULL,
895 .mbox_sync = comp_mbox_sync,
896 .mbox_close = comp_mbox_close,
897 .msg_open = comp_msg_open,
898 .msg_open_new = comp_msg_open_new,
899 .msg_commit = comp_msg_commit,
900 .msg_close = comp_msg_close,
901 .msg_padding_size = comp_msg_padding_size,
902 .msg_save_hcache = comp_msg_save_hcache,
903 .tags_edit = comp_tags_edit,
904 .tags_commit = comp_tags_commit,
905 .path_probe = comp_path_probe,
906 .path_canon = comp_path_canon,
907 .path_is_empty = NULL,
908 // clang-format on
909};
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:601
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:337
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:233
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:263
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:173
const struct ExpandoDefinition CompressFormatDef[]
Expando definitions.
Definition: compress.c:79
void mutt_comp_init(void)
Setup feature commands.
Definition: compress.c:90
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:196
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition: compress.c:106
bool mutt_comp_can_append(struct Mailbox *m)
Can we append to this path?
Definition: compress.c:332
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:147
static const struct Command CompCommands[]
Compression Commands.
Definition: compress.c:63
int mutt_comp_valid_command(const char *cmd)
Is this command string allowed?
Definition: compress.c:381
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition: compress.c:289
static struct Expando * validate_compress_expando(const char *s)
Validate the Compress hooks.
Definition: compress.c:211
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:361
const struct ExpandoRenderCallback CompressRenderCallbacks[]
Callbacks for Compression Hook Expandos.
Definition: expando.c:70
@ ED_CMP_FROM
'from' path
Definition: lib.h:50
@ ED_CMP_TO
'to' path
Definition: lib.h:51
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:71
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
char * HomeDir
User's home directory.
Definition: globals.c:37
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition: mailbox.h:53
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:174
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:152
@ ED_COMPRESS
Compress ED_CMP_ ExpandoDataCompress.
Definition: domain.h:40
struct Expando * expando_parse(const char *str, const struct ExpandoDefinition *defs, struct Buffer *err)
Parse an Expando string.
Definition: expando.c:81
void expando_free(struct Expando **ptr)
Free an Expando object.
Definition: expando.c:61
int expando_render(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando + data into a string.
Definition: expando.c:118
Parse Expando string.
bool mutt_file_touch(const char *path)
Make sure a file exists.
Definition: file.c:981
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition: file.c:1095
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1142
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1412
#define mutt_file_fclose(FP)
Definition: file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:138
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'hook' family of commands - Implements Command::parse() -.
Definition: hook.c:166
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
static bool comp_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
Definition: compress.c:400
static bool comp_ac_owns_path(struct Account *a, const char *path)
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path() -.
Definition: compress.c:392
const struct MxOps MxCompOps
Compressed Mailbox - Implements MxOps -.
Definition: compress.c:884
static enum MxStatus comp_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
Definition: compress.c:548
static enum MxStatus comp_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
Definition: compress.c:635
static bool comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
Definition: compress.c:468
static enum MxOpenReturns comp_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
Definition: compress.c:413
static enum MxStatus comp_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
Definition: compress.c:584
static int comp_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition: compress.c:772
static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition: compress.c:754
static bool comp_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
Definition: compress.c:736
static bool comp_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
Definition: compress.c:718
static int comp_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Implements MxOps::msg_padding_size() -.
Definition: compress.c:790
static int comp_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
Definition: compress.c:807
static int comp_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition: compress.c:872
static enum MailboxType comp_path_probe(const char *path, const struct stat *st)
Is this a compressed Mailbox? - Implements MxOps::path_probe() -.
Definition: compress.c:858
static int comp_tags_commit(struct Mailbox *m, struct Email *e, const char *buf)
Save the tags to a message - Implements MxOps::tags_commit() -.
Definition: compress.c:841
static int comp_tags_edit(struct Mailbox *m, const char *tags, struct Buffer *buf)
Prompt and validate new messages tags - Implements MxOps::tags_edit() -.
Definition: compress.c:824
Convenience wrapper for the gui headers.
char * mutt_find_hook(HookFlags type, const char *pat)
Find a matching hook.
Definition: hook.c:678
Parse and execute user-defined hooks.
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:49
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:51
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:50
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
#define mutt_array_size(x)
Definition: memory.h:38
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool mutt_path_canon(struct Buffer *path, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:248
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:281
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:127
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1325
API for mailboxes.
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mxapi.h:39
MxOpenReturns
Return values for mbox_open()
Definition: mxapi.h:73
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mxapi.h:75
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_sync(), and mbox_close()
Definition: mxapi.h:60
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:61
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:62
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
Prototypes for many functions.
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:52
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
Sidebar Expando definitions.
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:217
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:235
Key value store.
#define STR_COMMAND
Enough space for a long command line.
Definition: string2.h:35
A group of associated Mailboxes.
Definition: account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:37
String manipulation buffer.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:39
Private data for compress.
Definition: lib.h:60
struct Expando * cmd_open
open-hook command
Definition: lib.h:63
FILE * fp_lock
fp used for locking
Definition: lib.h:67
struct Expando * cmd_append
append-hook command
Definition: lib.h:61
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:65
bool locked
if realpath is locked
Definition: lib.h:66
long size
size of the compressed file
Definition: lib.h:64
struct Expando * cmd_close
close-hook command
Definition: lib.h:62
The envelope/body of an email.
Definition: email.h:39
Definition of a format string.
Definition: definition.h:44
Parsed Expando trees.
Definition: expando.h:41
const char * string
Pointer to the parsed string.
Definition: expando.h:42
A mailbox.
Definition: mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:109
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:121
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:116
bool verbose
Display status messages?
Definition: mailbox.h:117
A local copy of an email.
Definition: message.h:34
Definition: mxapi.h:88
bool(* msg_open)(struct Mailbox *m, struct Message *msg, struct Email *e)
Definition: mxapi.h:213
int(* tags_commit)(struct Mailbox *m, struct Email *e, const char *buf)
Definition: mxapi.h:320
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Definition: mxapi.h:286
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mxapi.h:89
int(* msg_padding_size)(struct Mailbox *m)
Definition: mxapi.h:271
int(* tags_edit)(struct Mailbox *m, const char *tags, struct Buffer *buf)
Definition: mxapi.h:303
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Definition: mxapi.h:244
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition: mxapi.h:133
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Definition: mxapi.h:259
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition: mxapi.h:229
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition: mxapi.h:196
enum MxStatus(* mbox_sync)(struct Mailbox *m)
Definition: mxapi.h:184
bool(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Definition: mxapi.h:147
enum MxStatus(* mbox_check)(struct Mailbox *m)
Definition: mxapi.h:159
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
#define buf_mktemp(buf)
Definition: tmp.h:33