NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mbox_open_append()

Open a Mailbox for appending. More...

+ Collaboration diagram for mbox_open_append():

Functions

static bool comp_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
 
static bool imap_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
 
bool maildir_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
 
static bool mbox_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
 
static bool mh_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
 

Detailed Description

Open a Mailbox for appending.

Parameters
mMailbox to open
flagsFlags, see OpenMailboxFlags
Return values
trueSuccess
falseFailure
Precondition
m is not NULL

Function Documentation

◆ comp_mbox_open_append()

static bool comp_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)
static

Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.

flags may also contain MUTT_NEWFOLDER

To append to a compressed mailbox we need an append-hook (or both open- and close-hooks).

Definition at line 503 of file compress.c.

504{
505 /* If this succeeds, we know there's an open-hook */
506 struct CompressInfo *ci = set_compress_info(m);
507 if (!ci)
508 return false;
509
510 /* To append we need an append-hook or a close-hook */
511 if (!ci->cmd_append && !ci->cmd_close)
512 {
513 mutt_error(_("Can't append without an append-hook or close-hook : %s"),
514 mailbox_path(m));
515 goto cmoa_fail1;
516 }
517
518 if (setup_paths(m) != 0)
519 goto cmoa_fail2;
520
521 /* Lock the realpath for the duration of the append.
522 * It will be unlocked in the close */
523 if (!lock_realpath(m, true))
524 {
525 mutt_error(_("Unable to lock mailbox"));
526 goto cmoa_fail2;
527 }
528
529 /* Open the existing mailbox, unless we are appending */
530 if (!ci->cmd_append && (mutt_file_get_size(m->realpath) > 0))
531 {
532 if (!execute_command(m, ci->cmd_open, _("Decompressing %s")))
533 {
534 mutt_error(_("Compress command failed: %s"), ci->cmd_open->string);
535 goto cmoa_fail2;
536 }
538 }
539 else
540 {
541 m->type = cs_subset_enum(NeoMutt->sub, "mbox_type");
542 }
543
544 /* We can only deal with mbox and mmdf mailboxes */
545 if ((m->type != MUTT_MBOX) && (m->type != MUTT_MMDF))
546 {
547 mutt_error(_("Unsupported mailbox type for appending"));
548 goto cmoa_fail2;
549 }
550
551 ci->child_ops = mx_get_ops(m->type);
552 if (!ci->child_ops)
553 {
554 mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
555 goto cmoa_fail2;
556 }
557
558 if (!ci->child_ops->mbox_open_append(m, flags))
559 goto cmoa_fail2;
560
561 return true;
562
563cmoa_fail2:
564 /* remove the partial uncompressed file */
565 (void) remove(mailbox_path(m));
566cmoa_fail1:
567 /* Free the compress_info to prevent close from trying to recompress */
569
570 return false;
571}
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:174
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the Mailbox.realpath.
Definition: compress.c:107
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition: compress.c:323
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:71
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1519
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
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:1321
Private data for compress.
Definition: lib.h:58
struct Expando * cmd_open
open-hook command
Definition: lib.h:61
struct Expando * cmd_append
append-hook command
Definition: lib.h:59
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:63
struct Expando * cmd_close
close-hook command
Definition: lib.h:60
const char * string
Pointer to the parsed string.
Definition: expando.h:42
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
bool(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Definition: mxapi.h:150
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:

◆ imap_mbox_open_append()

static bool imap_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)
static

Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.

Definition at line 2074 of file imap.c.

2075{
2076 if (!m->account)
2077 return false;
2078
2079 /* in APPEND mode, we appear to hijack an existing IMAP connection -
2080 * mailbox is brand new and mostly empty */
2082 struct ImapMboxData *mdata = imap_mdata_get(m);
2083
2084 int rc = imap_mailbox_status(m, false);
2085 if (rc >= 0)
2086 return true;
2087 if (rc == -1)
2088 return false;
2089
2090 char buf[PATH_MAX + 64];
2091 snprintf(buf, sizeof(buf), _("Create %s?"), mdata->name);
2092 const bool c_confirm_create = cs_subset_bool(NeoMutt->sub, "confirm_create");
2093 if (c_confirm_create &&
2094 (query_yesorno_help(buf, MUTT_YES, NeoMutt->sub, "confirm_create") != MUTT_YES))
2095 return false;
2096
2097 if (imap_create_mailbox(adata, mdata->name) < 0)
2098 return false;
2099
2100 return true;
2101}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:123
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1207
int imap_create_mailbox(struct ImapAccountData *adata, const char *mailbox)
Create a new mailbox.
Definition: imap.c:436
#define PATH_MAX
Definition: mutt.h:42
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
enum QuadOption query_yesorno_help(const char *prompt, enum QuadOption def, struct ConfigSubset *sub, const char *name)
Ask the user a Yes/No question offering help.
Definition: question.c:341
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
IMAP-specific Account data -.
Definition: adata.h:40
IMAP-specific Mailbox data -.
Definition: mdata.h:40
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
+ Here is the call graph for this function:

◆ maildir_mbox_open_append()

bool maildir_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)

Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.

Definition at line 748 of file mailbox.c.

749{
750 if (!(flags & (MUTT_APPEND | MUTT_APPENDNEW | MUTT_NEWFOLDER)))
751 {
752 return true;
753 }
754
755 errno = 0;
756 if ((mutt_file_mkdir(mailbox_path(m), S_IRWXU) != 0) && (errno != EEXIST))
757 {
758 mutt_perror("%s", mailbox_path(m));
759 return false;
760 }
761
762 char tmp[PATH_MAX] = { 0 };
763 snprintf(tmp, sizeof(tmp), "%s/cur", mailbox_path(m));
764 errno = 0;
765 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
766 {
767 mutt_perror("%s", tmp);
768 rmdir(mailbox_path(m));
769 return false;
770 }
771
772 snprintf(tmp, sizeof(tmp), "%s/new", mailbox_path(m));
773 errno = 0;
774 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
775 {
776 mutt_perror("%s", tmp);
777 snprintf(tmp, sizeof(tmp), "%s/cur", mailbox_path(m));
778 rmdir(tmp);
779 rmdir(mailbox_path(m));
780 return false;
781 }
782
783 snprintf(tmp, sizeof(tmp), "%s/tmp", mailbox_path(m));
784 errno = 0;
785 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
786 {
787 mutt_perror("%s", tmp);
788 snprintf(tmp, sizeof(tmp), "%s/cur", mailbox_path(m));
789 rmdir(tmp);
790 snprintf(tmp, sizeof(tmp), "%s/new", mailbox_path(m));
791 rmdir(tmp);
792 rmdir(mailbox_path(m));
793 return false;
794 }
795
796 return true;
797}
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:974
#define mutt_perror(...)
Definition: logging2.h:93
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND, but uses mutt_file_fopen() with mode "w" for mbox-style fo...
Definition: mxapi.h:45
#define MUTT_APPEND
Open mailbox for appending messages.
Definition: mxapi.h:42
#define MUTT_APPENDNEW
Set in mx_open_mailbox_append if the mailbox doesn't exist.
Definition: mxapi.h:49
+ Here is the call graph for this function:

◆ mbox_mbox_open_append()

static bool mbox_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)
static

Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.

Definition at line 878 of file mbox.c.

879{
880 if (init_mailbox(m) != 0)
881 return false;
882
884 if (!adata)
885 return false;
886
887 if (!adata->fp)
888 {
889 // create dir recursively
890 char *tmp_path = mutt_path_dirname(mailbox_path(m));
891 if (mutt_file_mkdir(tmp_path, S_IRWXU) == -1)
892 {
893 mutt_perror("%s", mailbox_path(m));
894 FREE(&tmp_path);
895 return false;
896 }
897 FREE(&tmp_path);
898
899 adata->fp = mutt_file_fopen(mailbox_path(m), (flags & MUTT_NEWFOLDER) ? "w+" : "a+");
900 if (!adata->fp)
901 {
902 mutt_perror("%s", mailbox_path(m));
903 return false;
904 }
905
906 if (mbox_lock_mailbox(m, true, true) != false)
907 {
908 mutt_error(_("Couldn't lock %s"), mailbox_path(m));
910 return false;
911 }
912 }
913
914 if (!mutt_file_seek(adata->fp, 0, SEEK_END))
915 {
917 return false;
918 }
919
920 return true;
921}
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:778
#define mutt_file_fclose(FP)
Definition: file.h:149
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:148
static int mbox_lock_mailbox(struct Mailbox *m, bool excl, bool retry)
Lock a mailbox.
Definition: mbox.c:140
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:125
static int init_mailbox(struct Mailbox *m)
Add Mbox data to the Mailbox.
Definition: mbox.c:106
#define FREE(x)
Definition: memory.h:45
char * mutt_path_dirname(const char *path)
Return a path up to, but not including, the final '/'.
Definition: path.c:312
Mbox-specific Account data -.
Definition: lib.h:49
+ Here is the call graph for this function:

◆ mh_mbox_open_append()

static bool mh_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)
static

Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.

Definition at line 825 of file mh.c.

826{
827 if (!(flags & (MUTT_APPENDNEW | MUTT_NEWFOLDER)))
828 return true;
829
830 if (mutt_file_mkdir(mailbox_path(m), S_IRWXU))
831 {
832 mutt_perror("%s", mailbox_path(m));
833 return false;
834 }
835
836 char tmp[PATH_MAX] = { 0 };
837 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", mailbox_path(m));
838 const int i = creat(tmp, S_IRWXU);
839 if (i == -1)
840 {
841 mutt_perror("%s", tmp);
842 rmdir(mailbox_path(m));
843 return false;
844 }
845 close(i);
846
847 return true;
848}
+ Here is the call graph for this function: