Save an email.
798{
800 return -1;
801
802 int rc = -1;
803 int tagged_progress_count = 0;
804 unsigned int msg_count = 0;
806
808 struct stat st = { 0 };
810
812 {
813 msg_count++;
814 }
816
818 const bool is_passphrase_needed = security_flags &
SEC_ENCRYPT;
819
820 const char *prompt = NULL;
821 const char *progress_msg = NULL;
822
823
824 switch (save_opt)
825 {
827
828 progress_msg = (msg_count > 1) ?
_(
"Copying tagged messages...") : NULL;
829 switch (transform_opt)
830 {
832 prompt = (msg_count > 1) ?
_(
"Copy tagged to mailbox") :
_(
"Copy to mailbox");
833 break;
835 prompt = (msg_count > 1) ?
_(
"Decrypt-copy tagged to mailbox") :
836 _(
"Decrypt-copy to mailbox");
837 break;
839 prompt = (msg_count > 1) ?
_(
"Decode-copy tagged to mailbox") :
840 _(
"Decode-copy to mailbox");
841 break;
842 }
843 break;
844
846
847 progress_msg = (msg_count > 1) ?
_(
"Saving tagged messages...") : NULL;
848 switch (transform_opt)
849 {
851 prompt = (msg_count > 1) ?
_(
"Save tagged to mailbox") :
_(
"Save to mailbox");
852 break;
854 prompt = (msg_count > 1) ?
_(
"Decrypt-save tagged to mailbox") :
855 _(
"Decrypt-save to mailbox");
856 break;
858 prompt = (msg_count > 1) ?
_(
"Decode-save tagged to mailbox") :
859 _(
"Decode-save to mailbox");
860 break;
861 }
862 break;
863 }
864
869
872 {
873 goto cleanup;
874 }
875
877 if (pathlen == 0)
878 goto cleanup;
879
880
881 if (buf->
data[pathlen - 1] ==
'/')
882 buf->
data[pathlen - 1] =
'\0';
883
884
885
890 else
892
894
895
897 goto cleanup;
898
901 {
902 rc = -1;
903 goto errcleanup;
904 }
905
907
908#ifdef USE_IMAP
911 {
913 switch (rc)
914 {
915
916 case 0:
918 rc = 0;
919 goto cleanup;
920
921 case 1:
922 break;
923
924 case -1:
925 goto errcleanup;
926 }
927 }
928#endif
929
932 bool old_append = m_save->
append;
934
935
936 if (msg_count > 1)
939 {
940 rc = -1;
942 goto errcleanup;
943 }
945
946#ifdef USE_COMP_MBOX
947
948
951 {
953 }
954
956 m_comp = NULL;
957#endif
959 {
961 if (rc != 0)
962 {
964 m_save->
append = old_append;
965 goto errcleanup;
966 }
967#ifdef USE_COMP_MBOX
968 if (m_comp)
969 {
972 {
976 }
979 }
980#endif
981 }
982 else
983 {
984 rc = 0;
985
986#ifdef USE_NOTMUCH
989#endif
992 {
996 if (rc != 0)
997 break;
998#ifdef USE_COMP_MBOX
999 if (m_comp)
1000 {
1004 {
1008 }
1011 }
1012#endif
1013 }
1015
1016#ifdef USE_NOTMUCH
1019#endif
1020 if (rc != 0)
1021 {
1023 m_save->
append = old_append;
1024 goto errcleanup;
1025 }
1026 }
1027
1028 const bool need_mailbox_cleanup = ((m_save->
type ==
MUTT_MBOX) ||
1030
1032 m_save->
append = old_append;
1033
1034 if (need_mailbox_cleanup)
1036
1038 rc = 0;
1039
1040errcleanup:
1041 if (rc != 0)
1042 {
1043 switch (save_opt)
1044 {
1046 if (msg_count > 1)
1047 {
1048
1050 }
1051 else
1052 {
1053
1055 }
1056 break;
1058 if (msg_count > 1)
1059 {
1060
1062 }
1063 else
1064 {
1065
1067 }
1068 break;
1069 }
1070 }
1071
1073
1074cleanup:
1076 return rc;
1077}
#define MUTT_SEL_NO_FLAGS
No flags are set.
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
int mutt_buffer_enter_fname(const char *prompt, struct Buffer *fname, bool mailbox, struct Mailbox *m, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
Ask the user to select a file.
int mutt_save_message_ctx(struct Mailbox *m_src, struct Email *e, enum MessageSaveOpt save_opt, enum MessageTransformOpt transform_opt, struct Mailbox *m_dst)
Save a message to a given mailbox.
@ SAVE_COPY
Copy message, making a duplicate in another mailbox.
void mutt_file_resolve_symlink(struct Buffer *buf)
Resolve a symlink in place.
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
void mutt_default_save(char *path, size_t pathlen, struct Email *e)
Find the default save path for an email.
int imap_copy_messages(struct Mailbox *m, struct EmailList *el, const char *dest, enum MessageSaveOpt save_opt)
Server COPY messages to another folder.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
MailboxType
Supported mailbox formats.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_IMAP
'IMAP' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
void mutt_mailbox_cleanup(const char *path, struct stat *st)
Restore the timestamp of a mailbox.
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
int mutt_save_confirm(const char *s, struct stat *st)
Ask the user to save.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND, but uses mutt_file_fopen() with mode "w" for mbox-style fo...
#define MUTT_QUIET
Do not print any messages.
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
#define SEC_NO_FLAGS
No flags are set.
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
void progress_free(struct Progress **ptr)
Free a Progress Bar.
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
The envelope/body of an email.
bool old
Email is seen, but unread.
bool flagged
Marked important?
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
bool append
Mailbox is opened in append mode.
int msg_new
Number of new messages.
int msg_count
Total number of messages.
enum MailboxType type
Mailbox type.
int msg_flagged
Number of flagged messages.
void * compress_info
Compressed mbox module private data.
int msg_unread
Number of unread messages.