NeoMutt  2025-12-11-872-g385a04
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
compress.c
Go to the documentation of this file.
1
25
38
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 "mutt.h"
51#include "lib.h"
52#include "expando/lib.h"
53#include "hooks/lib.h"
54#include "expando.h"
55#include "mx.h"
56
57struct Email;
58
62const struct Command CompCommands[] = {
63 // clang-format off
64 { "append-hook", CMD_APPEND_HOOK, parse_compress_hook,
65 N_("Define command to append to a compressed mailbox"),
66 N_("append-hook <regex> <shell-command>"),
67 "optionalfeatures.html#append-hook" },
68 { "close-hook", CMD_CLOSE_HOOK, parse_compress_hook,
69 N_("Define command to close a compressed mailbox"),
70 N_("close-hook <regex> <shell-command>"),
71 "optionalfeatures.html#close-hook" },
72 { "open-hook", CMD_OPEN_HOOK, parse_compress_hook,
73 N_("Define command to open a compressed mailbox"),
74 N_("open-hook <regex> <shell-command>"),
75 "optionalfeatures.html#open-hook" },
76
77 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
78 // clang-format on
79};
80
90 // clang-format off
91 { "f", "from", ED_COMPRESS, ED_CMP_FROM, NULL },
92 { "t", "to", ED_COMPRESS, ED_CMP_TO, NULL },
93 { NULL, NULL, 0, -1, NULL }
94 // clang-format on
95};
96
108static bool lock_realpath(struct Mailbox *m, bool excl)
109{
110 if (!m || !m->compress_info)
111 return false;
112
113 struct CompressInfo *ci = m->compress_info;
114
115 if (ci->locked)
116 return true;
117
118 if (excl)
119 ci->fp_lock = mutt_file_fopen(m->realpath, "a");
120 else
121 ci->fp_lock = mutt_file_fopen(m->realpath, "r");
122 if (!ci->fp_lock)
123 {
124 mutt_perror("%s", m->realpath);
125 return false;
126 }
127
128 int r = mutt_file_lock(fileno(ci->fp_lock), excl, true);
129 if (r == 0)
130 {
131 ci->locked = true;
132 }
133 else if (excl)
134 {
136 m->readonly = true;
137 return true;
138 }
139 else
140 {
142 }
143
144 return r == 0;
145}
146
153static void unlock_realpath(struct Mailbox *m)
154{
155 if (!m || !m->compress_info)
156 return;
157
158 struct CompressInfo *ci = m->compress_info;
159
160 if (!ci->locked)
161 return;
162
163 mutt_file_unlock(fileno(ci->fp_lock));
164
165 ci->locked = false;
167}
168
179static int setup_paths(struct Mailbox *m)
180{
181 if (!m)
182 return -1;
183
184 /* Setup the right paths */
186
187 /* We will uncompress to TMPDIR */
188 struct Buffer *buf = buf_pool_get();
189 buf_mktemp(buf);
190 buf_copy(&m->pathbuf, buf);
191 buf_pool_release(&buf);
192
193 return mutt_file_touch(mailbox_path(m)) ? 0 : -1;
194}
195
202static void store_size(const struct Mailbox *m)
203{
204 if (!m || !m->compress_info)
205 return;
206
207 struct CompressInfo *ci = m->compress_info;
208
210}
211
217static struct Expando *validate_compress_expando(const char *s)
218{
219 struct Buffer *err = buf_pool_get();
220
221 struct Expando *exp = expando_parse(s, CompressFormatDef, err);
222 if (!exp)
223 {
224 mutt_error(_("Expando parse error: %s"), buf_string(err));
225 }
226
227 buf_pool_release(&err);
228 return exp;
229}
230
239static struct CompressInfo *set_compress_info(struct Mailbox *m)
240{
241 if (!m)
242 return NULL;
243
244 if (m->compress_info)
245 return m->compress_info;
246
247 /* Open is compulsory */
248 const char *o = mutt_find_hook(CMD_OPEN_HOOK, mailbox_path(m));
249 if (!o)
250 return NULL;
251
252 const char *c = mutt_find_hook(CMD_CLOSE_HOOK, mailbox_path(m));
253 const char *a = mutt_find_hook(CMD_APPEND_HOOK, mailbox_path(m));
254
255 struct CompressInfo *ci = MUTT_MEM_CALLOC(1, struct CompressInfo);
256 m->compress_info = ci;
257
259 ci->cmd_close = c ? validate_compress_expando(c) : NULL;
260 ci->cmd_append = a ? validate_compress_expando(a) : NULL;
261
262 return ci;
263}
264
269static void compress_info_free(struct Mailbox *m)
270{
271 if (!m || !m->compress_info)
272 return;
273
274 struct CompressInfo *ci = m->compress_info;
278
280
281 FREE(&m->compress_info);
282}
283
295static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
296{
297 if (!m || !exp || !progress)
298 return false;
299
300 if (m->verbose)
301 mutt_message(progress, m->realpath);
302
303 bool rc = true;
304 struct Buffer *sys_cmd = buf_pool_get();
305 buf_alloc(sys_cmd, STR_COMMAND);
306
308 mutt_endwin();
309 fflush(stdout);
310
312
313 if (mutt_system(buf_string(sys_cmd)) != 0)
314 {
315 rc = false;
317 mutt_error(_("Error running \"%s\""), buf_string(sys_cmd));
318 }
319
321
322 buf_pool_release(&sys_cmd);
323 return rc;
324}
325
338{
339 if (!m)
340 return false;
341
342 /* If this succeeds, we know there's an open-hook */
343 struct CompressInfo *ci = set_compress_info(m);
344 if (!ci)
345 return false;
346
347 /* We have an open-hook, so to append we need an append-hook,
348 * or a close-hook. */
349 if (ci->cmd_append || ci->cmd_close)
350 return true;
351
352 mutt_error(_("Can't append without an append-hook or close-hook : %s"), mailbox_path(m));
353 return false;
354}
355
366bool mutt_comp_can_read(const char *path)
367{
368 if (!path)
369 return false;
370
371 if (mutt_find_hook(CMD_OPEN_HOOK, path))
372 return true;
373
374 return false;
375}
376
386int mutt_comp_valid_command(const char *cmd)
387{
388 if (!cmd)
389 return 0;
390
391 return strstr(cmd, "%f") && strstr(cmd, "%t");
392}
393
397static bool comp_ac_owns_path(struct Account *a, const char *path)
398{
399 return false;
400}
401
405static bool comp_ac_add(struct Account *a, struct Mailbox *m)
406{
407 return true;
408}
409
419{
420 struct CompressInfo *ci = set_compress_info(m);
421 if (!ci)
422 return MX_OPEN_ERROR;
423
424 /* If there's no close-hook, or the file isn't writable */
425 if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
426 m->readonly = true;
427
428 if (setup_paths(m) != 0)
429 goto cmo_fail;
430 store_size(m);
431
432 if (!lock_realpath(m, false))
433 {
434 mutt_error(_("Unable to lock mailbox"));
435 goto cmo_fail;
436 }
437
438 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
439 goto cmo_fail;
440
442
444 if (m->type == MUTT_UNKNOWN)
445 {
446 mutt_error(_("Can't identify the contents of the compressed file"));
447 goto cmo_fail;
448 }
449
450 ci->child_ops = mx_get_ops(m->type);
451 if (!ci->child_ops)
452 {
453 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
454 goto cmo_fail;
455 }
456
457 m->account->type = m->type;
458 return ci->child_ops->mbox_open(m);
459
460cmo_fail:
461 /* remove the partial uncompressed file */
462 (void) remove(mailbox_path(m));
464 return MX_OPEN_ERROR;
465}
466
473static bool comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
474{
475 /* If this succeeds, we know there's an open-hook */
476 struct CompressInfo *ci = set_compress_info(m);
477 if (!ci)
478 return false;
479
480 /* To append we need an append-hook or a close-hook */
481 if (!ci->cmd_append && !ci->cmd_close)
482 {
483 mutt_error(_("Can't append without an append-hook or close-hook : %s"),
484 mailbox_path(m));
485 goto cmoa_fail1;
486 }
487
488 if (setup_paths(m) != 0)
489 goto cmoa_fail2;
490
491 /* Lock the realpath for the duration of the append.
492 * It will be unlocked in the close */
493 if (!lock_realpath(m, true))
494 {
495 mutt_error(_("Unable to lock mailbox"));
496 goto cmoa_fail2;
497 }
498
499 /* Open the existing mailbox, unless we are appending */
500 if (!ci->cmd_append && (mutt_file_get_size(m->realpath) > 0))
501 {
502 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
503 {
504 mutt_error(_("Compress command failed: %s"), ci->cmd_open->string);
505 goto cmoa_fail2;
506 }
508 }
509 else
510 {
511 m->type = cs_subset_enum(NeoMutt->sub, "mbox_type");
512 }
513
514 /* We can only deal with mbox and mmdf mailboxes */
515 if ((m->type != MUTT_MBOX) && (m->type != MUTT_MMDF))
516 {
517 mutt_error(_("Unsupported mailbox type for appending"));
518 goto cmoa_fail2;
519 }
520
521 ci->child_ops = mx_get_ops(m->type);
522 if (!ci->child_ops)
523 {
524 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
525 goto cmoa_fail2;
526 }
527
528 if (!ci->child_ops->mbox_open_append(m, flags))
529 goto cmoa_fail2;
530
531 return true;
532
533cmoa_fail2:
534 /* remove the partial uncompressed file */
535 (void) remove(mailbox_path(m));
536cmoa_fail1:
537 /* Free the compress_info to prevent close from trying to recompress */
539
540 return false;
541}
542
553static enum MxStatus comp_mbox_check(struct Mailbox *m)
554{
555 if (!m->compress_info)
556 return MX_STATUS_ERROR;
557
558 struct CompressInfo *ci = m->compress_info;
559
560 const struct MxOps *ops = ci->child_ops;
561 if (!ops)
562 return MX_STATUS_ERROR;
563
564 long size = mutt_file_get_size(m->realpath);
565 if (size == ci->size)
566 return MX_STATUS_OK;
567
568 if (!lock_realpath(m, false))
569 {
570 mutt_error(_("Unable to lock mailbox"));
571 return MX_STATUS_ERROR;
572 }
573
574 bool rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
575 store_size(m);
577 if (!rc)
578 return MX_STATUS_ERROR;
579
580 return ops->mbox_check(m);
581}
582
589static enum MxStatus comp_mbox_sync(struct Mailbox *m)
590{
591 if (!m->compress_info)
592 return MX_STATUS_ERROR;
593
594 struct CompressInfo *ci = m->compress_info;
595
596 if (!ci->cmd_close)
597 {
598 mutt_error(_("Can't sync a compressed file without a close-hook"));
599 return MX_STATUS_ERROR;
600 }
601
602 const struct MxOps *ops = ci->child_ops;
603 if (!ops)
604 return MX_STATUS_ERROR;
605
606 if (!lock_realpath(m, true))
607 {
608 mutt_error(_("Unable to lock mailbox"));
609 return MX_STATUS_ERROR;
610 }
611
612 enum MxStatus check = comp_mbox_check(m);
613 if (check != MX_STATUS_OK)
614 goto sync_cleanup;
615
616 check = ops->mbox_sync(m);
617 if (check != MX_STATUS_OK)
618 goto sync_cleanup;
619
620 if (!execute_command(m, ci->cmd_close, _("Compressing %s")))
621 {
622 check = MX_STATUS_ERROR;
623 goto sync_cleanup;
624 }
625
626 check = MX_STATUS_OK;
627
628sync_cleanup:
629 store_size(m);
631 return check;
632}
633
640static enum MxStatus comp_mbox_close(struct Mailbox *m)
641{
642 if (!m->compress_info)
643 return MX_STATUS_ERROR;
644
645 struct CompressInfo *ci = m->compress_info;
646
647 const struct MxOps *ops = ci->child_ops;
648 if (!ops)
649 {
651 return MX_STATUS_ERROR;
652 }
653
654 ops->mbox_close(m);
655
656 /* sync has already been called, so we only need to delete some files */
657 if (m->append)
658 {
659 const struct Expando *append = NULL;
660 const char *msg = NULL;
661
662 /* The file exists and we can append */
663 if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
664 {
665 append = ci->cmd_append;
666 msg = _("Compressed-appending to %s...");
667 }
668 else
669 {
670 append = ci->cmd_close;
671 msg = _("Compressing %s");
672 }
673
674 if (!execute_command(m, append, msg))
675 {
677 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
678 }
679 else
680 {
681 if (remove(mailbox_path(m)) < 0)
682 {
683 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
684 mailbox_path(m), strerror(errno), errno);
685 }
686 }
687
689 }
690 else
691 {
692 /* If the file was removed, remove the compressed folder too */
693 if (access(mailbox_path(m), F_OK) != 0)
694 {
695 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
696 if (!c_save_empty)
697 {
698 if (remove(m->realpath) < 0)
699 {
700 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
701 m->realpath, strerror(errno), errno);
702 }
703 }
704 }
705 else
706 {
707 if (remove(mailbox_path(m)) < 0)
708 {
709 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
710 mailbox_path(m), strerror(errno), errno);
711 }
712 }
713 }
714
716
717 return MX_STATUS_OK;
718}
719
723static bool comp_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
724{
725 if (!m->compress_info)
726 return false;
727
728 struct CompressInfo *ci = m->compress_info;
729
730 const struct MxOps *ops = ci->child_ops;
731 if (!ops)
732 return false;
733
734 /* Delegate */
735 return ops->msg_open(m, msg, e);
736}
737
741static bool comp_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
742{
743 if (!m->compress_info)
744 return false;
745
746 struct CompressInfo *ci = m->compress_info;
747
748 const struct MxOps *ops = ci->child_ops;
749 if (!ops)
750 return false;
751
752 /* Delegate */
753 return ops->msg_open_new(m, msg, e);
754}
755
759static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
760{
761 if (!m->compress_info)
762 return -1;
763
764 struct CompressInfo *ci = m->compress_info;
765
766 const struct MxOps *ops = ci->child_ops;
767 if (!ops)
768 return -1;
769
770 /* Delegate */
771 return ops->msg_commit(m, msg);
772}
773
777static int comp_msg_close(struct Mailbox *m, struct Message *msg)
778{
779 if (!m->compress_info)
780 return -1;
781
782 struct CompressInfo *ci = m->compress_info;
783
784 const struct MxOps *ops = ci->child_ops;
785 if (!ops)
786 return -1;
787
788 /* Delegate */
789 return ops->msg_close(m, msg);
790}
791
795static int comp_msg_padding_size(struct Mailbox *m)
796{
797 if (!m->compress_info)
798 return 0;
799
800 struct CompressInfo *ci = m->compress_info;
801
802 const struct MxOps *ops = ci->child_ops;
803 if (!ops || !ops->msg_padding_size)
804 return 0;
805
806 return ops->msg_padding_size(m);
807}
808
812static int comp_msg_save_hcache(struct Mailbox *m, struct Email *e)
813{
814 if (!m->compress_info)
815 return 0;
816
817 struct CompressInfo *ci = m->compress_info;
818
819 const struct MxOps *ops = ci->child_ops;
820 if (!ops || !ops->msg_save_hcache)
821 return 0;
822
823 return ops->msg_save_hcache(m, e);
824}
825
829static int comp_tags_edit(struct Mailbox *m, const char *tags, struct Buffer *buf)
830{
831 if (!m->compress_info)
832 return 0;
833
834 struct CompressInfo *ci = m->compress_info;
835
836 const struct MxOps *ops = ci->child_ops;
837 if (!ops || !ops->tags_edit)
838 return 0;
839
840 return ops->tags_edit(m, tags, buf);
841}
842
846static int comp_tags_commit(struct Mailbox *m, struct Email *e, const char *buf)
847{
848 if (!m->compress_info)
849 return 0;
850
851 struct CompressInfo *ci = m->compress_info;
852
853 const struct MxOps *ops = ci->child_ops;
854 if (!ops || !ops->tags_commit)
855 return 0;
856
857 return ops->tags_commit(m, e, buf);
858}
859
863static enum MailboxType comp_path_probe(const char *path, const struct stat *st)
864{
865 if (!st || !S_ISREG(st->st_mode))
866 return MUTT_UNKNOWN;
867
868 if (mutt_comp_can_read(path))
869 return MUTT_COMPRESSED;
870
871 return MUTT_UNKNOWN;
872}
873
877static int comp_path_canon(struct Buffer *path)
878{
879 mutt_path_canon(path, NeoMutt->home_dir, false);
880 return 0;
881}
882
889const struct MxOps MxCompOps = {
890 // clang-format off
891 .type = MUTT_COMPRESSED,
892 .name = "compressed",
893 .is_local = true,
894 .ac_owns_path = comp_ac_owns_path,
895 .ac_add = comp_ac_add,
896 .mbox_open = comp_mbox_open,
897 .mbox_open_append = comp_mbox_open_append,
898 .mbox_check = comp_mbox_check,
899 .mbox_check_stats = NULL,
900 .mbox_sync = comp_mbox_sync,
901 .mbox_close = comp_mbox_close,
902 .msg_open = comp_msg_open,
903 .msg_open_new = comp_msg_open_new,
904 .msg_commit = comp_msg_commit,
905 .msg_close = comp_msg_close,
906 .msg_padding_size = comp_msg_padding_size,
907 .msg_save_hcache = comp_msg_save_hcache,
908 .tags_edit = comp_tags_edit,
909 .tags_commit = comp_tags_commit,
910 .path_probe = comp_path_probe,
911 .path_canon = comp_path_canon,
912 .path_is_empty = NULL,
913 // clang-format on
914};
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
@ CF_NONE
No flags are set.
Definition command.h:49
@ CMD_CLOSE_HOOK
:close-hook
Definition command.h:73
@ CMD_NONE
No Command.
Definition command.h:62
@ CMD_OPEN_HOOK
:open-hook
Definition command.h:103
@ CMD_APPEND_HOOK
:append-hook
Definition command.h:67
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition compress.c:239
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition compress.c:269
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition compress.c:179
const struct ExpandoDefinition CompressFormatDef[]
Expando definitions.
Definition compress.c:89
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition compress.c:202
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition compress.c:108
bool mutt_comp_can_append(struct Mailbox *m)
Can we append to this path?
Definition compress.c:337
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition compress.c:153
const struct Command CompCommands[]
Compression Commands.
Definition compress.c:62
int mutt_comp_valid_command(const char *cmd)
Is this command string allowed?
Definition compress.c:386
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition compress.c:295
static struct Expando * validate_compress_expando(const char *s)
Validate the Compress hooks.
Definition compress.c:217
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition compress.c:366
const struct ExpandoRenderCallback CompressRenderCallbacks[]
Callbacks for Compression Hook Expandos.
Definition expando.c:64
Compress Expando definitions.
Compressed mbox local mailbox type.
@ ED_CMP_FROM
'from' path
Definition lib.h:51
@ ED_CMP_TO
'to' path
Definition lib.h:52
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.
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:216
MailboxType
Supported mailbox formats.
Definition mailbox.h:40
@ MUTT_MMDF
'mmdf' Mailbox type
Definition mailbox.h:45
@ MUTT_MBOX
'mbox' Mailbox type
Definition mailbox.h:44
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition mailbox.h:52
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:43
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition curs_lib.c:175
void mutt_endwin(void)
Shutdown curses.
Definition curs_lib.c:153
@ 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:974
int mutt_file_lock(int fd, bool excl, bool timeout)
(Try to) Lock a file using fcntl()
Definition file.c:1088
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition file.c:1135
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition file.c:1414
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
enum CommandResult parse_compress_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse compress hook commands - Implements Command::parse() -.
Definition parse.c:913
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
static bool comp_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
Definition compress.c:405
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:397
const struct MxOps MxCompOps
Compressed Mailbox - Implements MxOps -.
Definition compress.c:889
static enum MxStatus comp_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
Definition compress.c:553
static enum MxStatus comp_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
Definition compress.c:640
static bool comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
Definition compress.c:473
static enum MxOpenReturns comp_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
Definition compress.c:418
static enum MxStatus comp_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
Definition compress.c:589
static int comp_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition compress.c:777
static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition compress.c:759
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:741
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:723
static int comp_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Implements MxOps::msg_padding_size() -.
Definition compress.c:795
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:812
static int comp_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition compress.c:877
static enum MailboxType comp_path_probe(const char *path, const struct stat *st)
Is this a compressed Mailbox?
Definition compress.c:863
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:846
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:829
Convenience wrapper for the gui headers.
char * mutt_find_hook(enum CommandId id, const char *pat)
Find a matching hook.
Definition exec.c:115
Hook Commands.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#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:284
Many unsorted constants and some structs.
int mutt_system(const char *cmd)
Run an external command.
Definition system.c:51
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition mx.c:124
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition mx.c:1323
API for mailboxes.
uint8_t OpenMailboxFlags
Definition mxapi.h:51
MxOpenReturns
Return values for mbox_open()
Definition mxapi.h:83
@ MX_OPEN_ERROR
Open failed with an error.
Definition mxapi.h:85
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_sync(), and mbox_close()
Definition mxapi.h:70
@ MX_STATUS_ERROR
An error occurred.
Definition mxapi.h:71
@ MX_STATUS_OK
No changes.
Definition mxapi.h:72
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
@ MUTT_FORMAT_NONE
No flags are set.
Definition render.h:37
void mutt_sig_block(void)
Block signals during critical operations.
Definition signal.c:227
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition signal.c:245
#define STR_COMMAND
Enough space for a long command line.
Definition string2.h:42
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:61
struct Expando * cmd_open
open-hook command
Definition lib.h:64
FILE * fp_lock
fp used for locking
Definition lib.h:68
struct Expando * cmd_append
append-hook command
Definition lib.h:62
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
bool locked
if realpath is locked
Definition lib.h:67
long size
size of the compressed file
Definition lib.h:65
struct Expando * cmd_close
close-hook command
Definition lib.h:63
The envelope/body of an email.
Definition email.h:39
Definition of a format string.
Definition definition.h:49
Parsed Expando trees.
Definition expando.h:41
const char * string
Pointer to the parsed string.
Definition expando.h:42
A mailbox.
Definition mailbox.h:81
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:83
bool append
Mailbox is opened in append mode.
Definition mailbox.h:111
enum MailboxType type
Mailbox type.
Definition mailbox.h:104
struct Buffer pathbuf
Path of the Mailbox.
Definition mailbox.h:82
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:129
void * compress_info
Compressed mbox module private data.
Definition mailbox.h:123
bool readonly
Don't allow changes to the mailbox.
Definition mailbox.h:118
bool verbose
Display status messages?
Definition mailbox.h:119
A local copy of an email.
Definition message.h:34
Definition mxapi.h:98
bool(* msg_open)(struct Mailbox *m, struct Message *msg, struct Email *e)
Definition mxapi.h:223
int(* tags_commit)(struct Mailbox *m, struct Email *e, const char *buf)
Definition mxapi.h:330
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Definition mxapi.h:296
int(* msg_padding_size)(struct Mailbox *m)
Definition mxapi.h:281
int(* tags_edit)(struct Mailbox *m, const char *tags, struct Buffer *buf)
Definition mxapi.h:313
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Definition mxapi.h:254
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Definition mxapi.h:143
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Definition mxapi.h:269
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Definition mxapi.h:239
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition mxapi.h:206
enum MxStatus(* mbox_sync)(struct Mailbox *m)
Definition mxapi.h:194
bool(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Definition mxapi.h:157
enum MxStatus(* mbox_check)(struct Mailbox *m)
Definition mxapi.h:169
Container for Accounts, Notifications.
Definition neomutt.h:41
char * home_dir
User's home directory.
Definition neomutt.h:55
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
#define buf_mktemp(buf)
Definition tmp.h:33