NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Postponed Emails. More...

#include <stdbool.h>
#include "ncrypt/lib.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct Emaildlg_select_postponed_email (struct Mailbox *m)
 Create a Menu to select a postponed message. More...
 
int mutt_get_postponed (struct Mailbox *m_cur, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
 Recall a postponed message. More...
 
int mutt_num_postponed (struct Mailbox *m, bool force)
 Return the number of postponed messages. More...
 
SecurityFlags mutt_parse_crypt_hdr (const char *p, bool set_empty_signas, SecurityFlags crypt_app)
 Parse a crypto header string. More...
 
int mutt_prepare_template (FILE *fp, struct Mailbox *m, struct Email *e_new, struct Email *e, bool resend)
 Prepare a message template. More...
 
void mutt_update_num_postponed (void)
 Force the update of the number of postponed messages. More...
 

Detailed Description

Postponed Emails.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Function Documentation

◆ dlg_select_postponed_email()

struct Email * dlg_select_postponed_email ( struct Mailbox m)

Create a Menu to select a postponed message.

Parameters
mMailbox
Return values
ptrEmail

Definition at line 190 of file dlg_postpone.c.

191{
193
194 struct Menu *menu = dlg->wdata;
196 menu->color = post_color;
197 menu->max = m->msg_count;
198 menu->mdata = m;
199 menu->mdata_free = NULL; // Menu doesn't own the data
200 menu->custom_search = true;
201
202 struct PostponeData pd = { false, m, menu, NULL };
203 dlg->wdata = &pd;
204
205 // NT_COLOR is handled by the SimpleDialog
208
209 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
210 sbar_set_title(sbar, _("Postponed Messages"));
211
212 /* The postponed mailbox is setup to have sorting disabled, but the global
213 * `$sort` variable may indicate something different. Sorting has to be
214 * disabled while the postpone menu is being displayed. */
215 const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
217
218 // ---------------------------------------------------------------------------
219 // Event Loop
220 int op = OP_NULL;
221 do
222 {
223 menu_tagging_dispatcher(menu->win, op);
224 window_redraw(NULL);
225
227 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
228 if (op < 0)
229 continue;
230 if (op == OP_NULL)
231 {
233 continue;
234 }
236
237 int rc = postpone_function_dispatcher(dlg, op);
238
239 if (rc == FR_UNKNOWN)
240 rc = menu_function_dispatcher(menu->win, op);
241 if (rc == FR_UNKNOWN)
242 rc = global_function_dispatcher(NULL, op);
243 } while (!pd.done);
244 // ---------------------------------------------------------------------------
245
246 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
247 simple_dialog_free(&dlg);
248
249 return pd.email;
250}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping PostponeHelp[]
Help Bar for the Postponed email selection dialog.
Definition: dlg_postpone.c:89
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:129
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static struct AttrColor * post_color(struct Menu *menu, int line)
Calculate the colour for a line of the postpone index - Implements Menu::color() -.
Definition: dlg_postpone.c:168
static void post_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the email list - Implements Menu::make_entry() -.
Definition: dlg_postpone.c:102
static int postponed_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_postpone.c:142
static int postponed_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_postpone.c:116
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:797
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1065
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
#define _(a)
Definition: message.h:28
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_select_postponed_email()
Definition: mutt_window.h:89
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:44
int msg_count
Total number of messages.
Definition: mailbox.h:88
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:134
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
bool custom_search
The menu implements its own non-Menusearch()-compatible search, trickle OP_SEARCH*.
Definition: lib.h:85
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:38
bool done
Should we close the Dialog?
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:37
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:305
@ MENU_POSTPONE
Select a postponed email.
Definition: type.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_postponed()

int mutt_get_postponed ( struct Mailbox m_cur,
struct Email hdr,
struct Email **  cur,
struct Buffer fcc 
)

Recall a postponed message.

Parameters
[in]m_curCurrent mailbox
[in]hdrenvelope/attachment info for recalled message
[out]curif message was a reply, 'cur' is set to the message which 'hdr' is in reply to
[in]fccfcc for the recalled message
Return values
-1Error/no messages
0Normal exit
SEND_REPLYRecalled message is a reply

Definition at line 663 of file postpone.c.

665{
666 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
667 if (!c_postponed)
668 return -1;
669
670 struct Email *e = NULL;
671 int rc = SEND_POSTPONED;
672 const char *p = NULL;
673
674 struct Mailbox *m = mx_path_resolve(c_postponed);
675 if (m_cur != m)
676 {
677 if (!mx_mbox_open(m, MUTT_NOSORT))
678 {
679 PostCount = 0;
680 mutt_error(_("No postponed messages"));
681 mailbox_free(&m);
682 return -1;
683 }
684 }
685
686 mx_mbox_check(m);
687
688 if (m->msg_count == 0)
689 {
690 PostCount = 0;
691 mutt_error(_("No postponed messages"));
692 if (m_cur != m)
693 {
694 mx_fastclose_mailbox(m, false);
695 mailbox_free(&m);
696 }
697 return -1;
698 }
699
700 /* avoid the "purge deleted messages" prompt */
701 const enum QuadOption c_delete = cs_subset_quad(NeoMutt->sub, "delete");
702 cs_subset_str_native_set(NeoMutt->sub, "delete", MUTT_YES, NULL);
703
704 struct MailboxView *mv = (m_cur != m) ? mview_new(m) : NULL;
705 if (m->msg_count == 1)
706 {
707 /* only one message, so just use that one. */
708 e = m->emails[0];
709 }
710 else if (!(e = dlg_select_postponed_email(m)))
711 {
712 rc = -1;
713 goto cleanup;
714 }
715
716 if (mutt_prepare_template(NULL, m, hdr, e, false) < 0)
717 {
718 rc = -1;
719 goto cleanup;
720 }
721
722 /* finished with this message, so delete it. */
723 mutt_set_flag(m, e, MUTT_DELETE, true);
724 mutt_set_flag(m, e, MUTT_PURGE, true);
725
726 /* update the count for the status display */
728
729 struct ListNode *np = NULL, *tmp = NULL;
730 STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp)
731 {
732 size_t plen = 0;
733 // Check for header names: most specific first
734 if ((plen = mutt_istr_startswith(np->data, "X-Mutt-References:")) ||
735 (plen = mutt_istr_startswith(np->data, "Mutt-References:")))
736 {
737 /* if a mailbox is currently open, look to see if the original message
738 * the user attempted to reply to is in this mailbox */
739 if (m_cur)
740 {
742 if (!m_cur->id_hash)
743 m_cur->id_hash = mutt_make_id_hash(m_cur);
744 *cur = mutt_hash_find(m_cur->id_hash, p);
745
746 if (*cur)
747 rc |= SEND_REPLY;
748 }
749 }
750 // Check for header names: most specific first
751 else if ((plen = mutt_istr_startswith(np->data, "X-Mutt-Fcc:")) ||
752 (plen = mutt_istr_startswith(np->data, "Mutt-Fcc:")))
753 {
755 mutt_buffer_strcpy(fcc, p);
757
758 /* note that mutt-fcc was present. we do this because we want to add a
759 * default fcc if the header was missing, but preserve the request of the
760 * user to not make a copy if the header field is present, but empty.
761 * see http://dev.mutt.org/trac/ticket/3653 */
762 rc |= SEND_POSTPONED_FCC;
763 }
764 // Check for header names: most specific first
765 else if (((WithCrypto & APPLICATION_PGP) != 0) &&
766 ((plen = mutt_istr_startswith(np->data, "X-Mutt-PGP:")) ||
767 (plen = mutt_istr_startswith(np->data, "Mutt-PGP:")) ||
768 (plen = mutt_istr_startswith(np->data, "Pgp:"))))
769 {
772 }
773 // Check for header names: most specific first
774 else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
775 ((plen = mutt_istr_startswith(np->data, "X-Mutt-SMIME:")) ||
776 (plen = mutt_istr_startswith(np->data, "Mutt-SMIME:"))))
777 {
780 }
781#ifdef MIXMASTER
782 // Check for header names: most specific first
783 else if ((plen = mutt_istr_startswith(np->data, "X-Mutt-Mix:")) ||
784 (plen = mutt_istr_startswith(np->data, "Mutt-Mix:")))
785 {
786 mutt_list_free(&hdr->chain);
787
788 char *t = strtok(np->data + plen, " \t\n");
789 while (t)
790 {
792 t = strtok(NULL, " \t\n");
793 }
794 }
795#endif
796 else
797 {
798 // skip header removal
799 continue;
800 }
801
802 // remove the header
803 STAILQ_REMOVE(&hdr->env->userhdrs, np, ListNode, entries);
804 FREE(&np->data);
805 FREE(&np);
806 }
807
808 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(NeoMutt->sub, "crypt_opportunistic_encrypt");
809 if (c_crypt_opportunistic_encrypt)
811
812cleanup:
813 if (m_cur != m)
814 {
815 hardclose(m);
816 mview_free(&mv);
817 mailbox_free(&m);
818 }
819
820 cs_subset_str_native_set(NeoMutt->sub, "delete", c_delete, NULL);
821 return rc;
822}
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:365
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1024
struct Email * dlg_select_postponed_email(struct Mailbox *m)
Create a Menu to select a postponed message.
Definition: dlg_postpone.c:190
#define mutt_error(...)
Definition: logging.h:87
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:87
#define FREE(x)
Definition: memory.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:679
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
@ MUTT_PURGE
Messages to be purged (bypass trash)
Definition: mutt.h:85
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:83
struct HashTable * mutt_make_id_hash(struct Mailbox *m)
Create a Hash Table for message-ids.
Definition: mutt_thread.c:1669
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:546
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition: mview.c:49
struct MailboxView * mview_new(struct Mailbox *m)
Create a new MailboxView.
Definition: mview.c:77
void mx_fastclose_mailbox(struct Mailbox *m, bool keep_account)
Free up memory associated with the Mailbox.
Definition: mx.c:431
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:305
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1684
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1133
#define MUTT_NOSORT
Do not sort the mailbox after opening it.
Definition: mxapi.h:62
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define WithCrypto
Definition: lib.h:116
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
SecurityFlags mutt_parse_crypt_hdr(const char *p, bool set_empty_signas, SecurityFlags crypt_app)
Parse a crypto header string.
Definition: postpone.c:212
short PostCount
Definition: postpone.c:58
int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *e_new, struct Email *e, bool resend)
Prepare a message template.
Definition: postpone.c:491
static void hardclose(struct Mailbox *m)
Try hard to close a mailbox.
Definition: postpone.c:194
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:63
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
#define SEND_POSTPONED_FCC
Used by mutt_get_postponed() to signal that the Mutt-Fcc header field was present.
Definition: send.h:48
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:44
#define SEND_REPLY
Reply to sender.
Definition: send.h:40
The envelope/body of an email.
Definition: email.h:37
struct Envelope * env
Envelope information.
Definition: email.h:66
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:41
struct ListHead chain
Mixmaster chain.
Definition: email.h:89
struct ListHead userhdrs
user defined headers
Definition: envelope.h:87
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
The "current" mailbox.
Definition: mview.h:38
A mailbox.
Definition: mailbox.h:79
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
struct HashTable * id_hash
Hash Table by msg id.
Definition: mailbox.h:123
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_num_postponed()

int mutt_num_postponed ( struct Mailbox m,
bool  force 
)

Return the number of postponed messages.

Parameters
mcurrently selected mailbox
force
  • false Use a cached value if costly to get a fresh count (IMAP)
  • true Force check
Return values
numPostponed messages

Definition at line 69 of file postpone.c.

70{
71 struct stat st = { 0 };
72
73 static time_t LastModify = 0;
74 static char *OldPostponed = NULL;
75
77 {
78 UpdateNumPostponed = false;
79 force = true;
80 }
81
82 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
83 if (!mutt_str_equal(c_postponed, OldPostponed))
84 {
85 FREE(&OldPostponed);
86 OldPostponed = mutt_str_dup(c_postponed);
87 LastModify = 0;
88 force = true;
89 }
90
91 if (!c_postponed)
92 return 0;
93
94 // We currently are in the `$postponed` mailbox so just pick the current status
95 if (m && mutt_str_equal(c_postponed, m->realpath))
96 {
98 return PostCount;
99 }
100
101#ifdef USE_IMAP
102 /* LastModify is useless for IMAP */
103 if (imap_path_probe(c_postponed, NULL) == MUTT_IMAP)
104 {
105 if (force)
106 {
107 short newpc;
108
109 newpc = imap_path_status(c_postponed, false);
110 if (newpc >= 0)
111 {
112 PostCount = newpc;
113 mutt_debug(LL_DEBUG3, "%d postponed IMAP messages found\n", PostCount);
114 }
115 else
116 {
117 mutt_debug(LL_DEBUG3, "using old IMAP postponed count\n");
118 }
119 }
120 return PostCount;
121 }
122#endif
123
124 if (stat(c_postponed, &st) == -1)
125 {
126 PostCount = 0;
127 LastModify = 0;
128 return 0;
129 }
130
131 if (S_ISDIR(st.st_mode))
132 {
133 /* if we have a maildir mailbox, we need to stat the "new" dir */
134 struct Buffer *buf = mutt_buffer_pool_get();
135
136 mutt_buffer_printf(buf, "%s/new", c_postponed);
137 if ((access(mutt_buffer_string(buf), F_OK) == 0) &&
138 (stat(mutt_buffer_string(buf), &st) == -1))
139 {
140 PostCount = 0;
141 LastModify = 0;
143 return 0;
144 }
146 }
147
148 if (LastModify < st.st_mtime)
149 {
150#ifdef USE_NNTP
151 int optnews = OptNews;
152#endif
153 LastModify = st.st_mtime;
154
155 if (access(c_postponed, R_OK | F_OK) != 0)
156 return PostCount = 0;
157#ifdef USE_NNTP
158 if (optnews)
159 OptNews = false;
160#endif
161 struct Mailbox *m_post = mx_path_resolve(c_postponed);
162 if (mx_mbox_open(m_post, MUTT_NOSORT | MUTT_QUIET))
163 {
164 PostCount = m_post->msg_count;
165 mx_fastclose_mailbox(m_post, false);
166 }
167 else
168 {
169 PostCount = 0;
170 }
171 mailbox_free(&m_post);
172
173#ifdef USE_NNTP
174 if (optnews)
175 OptNews = true;
176#endif
177 }
178
179 return PostCount;
180}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:78
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2425
int imap_path_status(const char *path, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1249
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
#define MUTT_QUIET
Do not print any messages.
Definition: mxapi.h:65
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
static bool UpdateNumPostponed
Definition: postpone.c:59
String manipulation buffer.
Definition: buffer.h:34
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_crypt_hdr()

SecurityFlags mutt_parse_crypt_hdr ( const char *  p,
bool  set_empty_signas,
SecurityFlags  crypt_app 
)

Parse a crypto header string.

Parameters
pHeader string to parse
set_empty_signasAllow an empty "Sign as"
crypt_appApp, e.g. APPLICATION_PGP
Return values
numSecurityFlags, see SecurityFlags

Definition at line 212 of file postpone.c.

213{
214 char smime_cryptalg[1024] = { 0 };
215 char sign_as[1024] = { 0 };
216 char *q = NULL;
218
219 if (!WithCrypto)
220 return SEC_NO_FLAGS;
221
223 for (; p[0] != '\0'; p++)
224 {
225 switch (p[0])
226 {
227 case 'c':
228 case 'C':
229 q = smime_cryptalg;
230
231 if (p[1] == '<')
232 {
233 for (p += 2; (p[0] != '\0') && (p[0] != '>') &&
234 (q < (smime_cryptalg + sizeof(smime_cryptalg) - 1));
235 *q++ = *p++)
236 {
237 }
238
239 if (p[0] != '>')
240 {
241 mutt_error(_("Illegal S/MIME header"));
242 return SEC_NO_FLAGS;
243 }
244 }
245
246 *q = '\0';
247 break;
248
249 case 'e':
250 case 'E':
251 flags |= SEC_ENCRYPT;
252 break;
253
254 case 'i':
255 case 'I':
256 flags |= SEC_INLINE;
257 break;
258
259 /* This used to be the micalg parameter.
260 *
261 * It's no longer needed, so we just skip the parameter in order
262 * to be able to recall old messages. */
263 case 'm':
264 case 'M':
265 if (p[1] != '<')
266 break;
267
268 for (p += 2; (p[0] != '\0') && (p[0] != '>'); p++)
269 ; // do nothing
270
271 if (p[0] != '>')
272 {
273 mutt_error(_("Illegal crypto header"));
274 return SEC_NO_FLAGS;
275 }
276 break;
277
278 case 'o':
279 case 'O':
280 flags |= SEC_OPPENCRYPT;
281 break;
282
283 case 'a':
284 case 'A':
285#ifdef USE_AUTOCRYPT
286 flags |= SEC_AUTOCRYPT;
287#endif
288 break;
289
290 case 'z':
291 case 'Z':
292#ifdef USE_AUTOCRYPT
293 flags |= SEC_AUTOCRYPT_OVERRIDE;
294#endif
295 break;
296
297 case 's':
298 case 'S':
299 flags |= SEC_SIGN;
300 q = sign_as;
301
302 if (p[1] == '<')
303 {
304 for (p += 2;
305 (p[0] != '\0') && (*p != '>') && (q < (sign_as + sizeof(sign_as) - 1));
306 *q++ = *p++)
307 {
308 }
309
310 if (p[0] != '>')
311 {
312 mutt_error(_("Illegal crypto header"));
313 return SEC_NO_FLAGS;
314 }
315 }
316
317 q[0] = '\0';
318 break;
319
320 default:
321 mutt_error(_("Illegal crypto header"));
322 return SEC_NO_FLAGS;
323 }
324 }
325
326 /* the cryptalg field must not be empty */
327 if (((WithCrypto & APPLICATION_SMIME) != 0) && *smime_cryptalg)
328 {
329 struct Buffer errmsg = mutt_buffer_make(0);
330 int rc = cs_subset_str_string_set(NeoMutt->sub, "smime_encrypt_with",
331 smime_cryptalg, &errmsg);
332
333 if ((CSR_RESULT(rc) != CSR_SUCCESS) && !mutt_buffer_is_empty(&errmsg))
334 mutt_error("%s", mutt_buffer_string(&errmsg));
335
336 mutt_buffer_dealloc(&errmsg);
337 }
338
339 /* Set {Smime,Pgp}SignAs, if desired. */
340
341 if (((WithCrypto & APPLICATION_PGP) != 0) && (crypt_app == APPLICATION_PGP) &&
342 (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
343 {
344 cs_subset_str_string_set(NeoMutt->sub, "pgp_sign_as", sign_as, NULL);
345 }
346
347 if (((WithCrypto & APPLICATION_SMIME) != 0) && (crypt_app == APPLICATION_SMIME) &&
348 (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
349 {
350 cs_subset_str_string_set(NeoMutt->sub, "smime_sign_as", sign_as, NULL);
351 }
352
353 return flags;
354}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:298
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:347
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:85
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:87
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:76
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:86
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:77
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:78
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
Definition: lib.h:88
#define SEC_SIGN
Email is signed.
Definition: lib.h:79
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: subset.c:408
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_prepare_template()

int mutt_prepare_template ( FILE *  fp,
struct Mailbox m,
struct Email e_new,
struct Email e,
bool  resend 
)

Prepare a message template.

Parameters
fpIf not NULL, file containing the template
mIf fp is NULL, the Mailbox containing the header with the template
e_newThe template is read into this Header
eEmail to recall/resend
resendSet if resending (as opposed to recalling a postponed msg) Resent messages enable header weeding, and also discard any existing Message-ID and Mail-Followup-To
Return values
0Success
-1Error

Definition at line 491 of file postpone.c.

493{
494 struct Message *msg = NULL;
495 struct Body *b = NULL;
496 FILE *fp_body = NULL;
497 int rc = -1;
498 struct Envelope *protected_headers = NULL;
499 struct Buffer *file = NULL;
500
501 if (!fp && !(msg = mx_msg_open(m, e->msgno)))
502 return -1;
503
504 if (!fp)
505 fp = msg->fp;
506
507 fp_body = fp;
508
509 /* parse the message header and MIME structure */
510
511 if (!mutt_file_seek(fp, e->offset, SEEK_SET))
512 {
513 return -1;
514 }
515 e_new->offset = e->offset;
516 /* enable header weeding for resent messages */
517 e_new->env = mutt_rfc822_read_header(fp, e_new, true, resend);
518 e_new->body->length = e->body->length;
519 mutt_parse_part(fp, e_new->body);
520
521 /* If resending a message, don't keep message_id or mail_followup_to.
522 * Otherwise, we are resuming a postponed message, and want to keep those
523 * headers if they exist. */
524 if (resend)
525 {
526 FREE(&e_new->env->message_id);
528 }
529
530 SecurityFlags sec_type = SEC_NO_FLAGS;
531 if (((WithCrypto & APPLICATION_PGP) != 0) && sec_type == SEC_NO_FLAGS)
532 sec_type = mutt_is_multipart_encrypted(e_new->body);
533 if (((WithCrypto & APPLICATION_SMIME) != 0) && sec_type == SEC_NO_FLAGS)
534 sec_type = mutt_is_application_smime(e_new->body);
535 if (sec_type != SEC_NO_FLAGS)
536 {
537 e_new->security |= sec_type;
538 if (!crypt_valid_passphrase(sec_type))
539 goto bail;
540
541 mutt_message(_("Decrypting message..."));
542 int ret = -1;
543 if (sec_type & APPLICATION_PGP)
544 ret = crypt_pgp_decrypt_mime(fp, &fp_body, e_new->body, &b);
545 else if (sec_type & APPLICATION_SMIME)
546 ret = crypt_smime_decrypt_mime(fp, &fp_body, e_new->body, &b);
547 if ((ret == -1) || !b)
548 {
549 mutt_error(_("Could not decrypt postponed message"));
550 goto bail;
551 }
552
553 /* throw away the outer layer and keep only the (now decrypted) inner part
554 * with its headers. */
555 mutt_body_free(&e_new->body);
556 e_new->body = b;
557
558 if (b->mime_headers)
559 {
560 protected_headers = b->mime_headers;
561 b->mime_headers = NULL;
562 }
563
565 }
566
567 /* remove a potential multipart/signed layer - useful when
568 * resending messages */
569 if ((WithCrypto != 0) && mutt_is_multipart_signed(e_new->body))
570 {
571 e_new->security |= SEC_SIGN;
572 if (((WithCrypto & APPLICATION_PGP) != 0) &&
573 mutt_istr_equal(mutt_param_get(&e_new->body->parameter, "protocol"), "application/pgp-signature"))
574 {
575 e_new->security |= APPLICATION_PGP;
576 }
577 else if (WithCrypto & APPLICATION_SMIME)
578 e_new->security |= APPLICATION_SMIME;
579
580 /* destroy the signature */
581 mutt_body_free(&e_new->body->parts->next);
582 e_new->body = mutt_remove_multipart(e_new->body);
583
584 if (e_new->body->mime_headers)
585 {
586 mutt_env_free(&protected_headers);
587 protected_headers = e_new->body->mime_headers;
588 e_new->body->mime_headers = NULL;
589 }
590 }
591
592 /* We don't need no primary multipart/mixed. */
593 if ((e_new->body->type == TYPE_MULTIPART) && mutt_istr_equal(e_new->body->subtype, "mixed"))
594 e_new->body = mutt_remove_multipart(e_new->body);
595
596 file = mutt_buffer_pool_get();
597
598 /* create temporary files for all attachments */
599 if (create_tmp_files_for_attachments(fp_body, file, e_new, e_new->body, protected_headers) < 0)
600 {
601 goto bail;
602 }
603
604 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
605 if (c_crypt_protected_headers_read && protected_headers && protected_headers->subject &&
606 !mutt_str_equal(e_new->env->subject, protected_headers->subject))
607 {
608 mutt_str_replace(&e_new->env->subject, protected_headers->subject);
609 }
610 mutt_env_free(&protected_headers);
611
612 /* Fix encryption flags. */
613
614 /* No inline if multipart. */
615 if ((WithCrypto != 0) && (e_new->security & SEC_INLINE) && e_new->body->next)
616 e_new->security &= ~SEC_INLINE;
617
618 /* Do we even support multiple mechanisms? */
620
621 /* Theoretically, both could be set. Take the one the user wants to set by default. */
622 if ((e_new->security & APPLICATION_PGP) && (e_new->security & APPLICATION_SMIME))
623 {
624 const bool c_smime_is_default = cs_subset_bool(NeoMutt->sub, "smime_is_default");
625 if (c_smime_is_default)
626 e_new->security &= ~APPLICATION_PGP;
627 else
628 e_new->security &= ~APPLICATION_SMIME;
629 }
630
632
633 rc = 0;
634
635bail:
636
637 /* that's it. */
639 if (fp_body != fp)
640 mutt_file_fclose(&fp_body);
641 if (msg)
642 mx_msg_close(m, &msg);
643
644 if (rc == -1)
645 {
646 mutt_env_free(&e_new->env);
647 mutt_body_free(&e_new->body);
648 }
649
650 return rc;
651}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1443
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:401
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:598
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:133
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:436
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:433
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:211
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:708
#define mutt_message(...)
Definition: logging.h:86
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: multipart.c:126
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1200
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
Return a stream pointer for a message.
Definition: mx.c:1154
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition: parse.c:1745
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition: parse.c:1162
static int create_tmp_files_for_attachments(FILE *fp_body, struct Buffer *file, struct Email *e_new, struct Body *body, struct Envelope *protected_headers)
Create temporary files for all attachments.
Definition: postpone.c:366
void mutt_rfc3676_space_unstuff(struct Email *e)
Remove RFC3676 space stuffing.
Definition: rfc3676.c:496
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
struct Body * next
next attachment in the list
Definition: body.h:71
char * subtype
content-type subtype
Definition: body.h:60
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
struct Body * body
List of MIME parts.
Definition: email.h:67
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:69
int msgno
Number displayed to the user.
Definition: email.h:110
The header of an Email.
Definition: envelope.h:57
char * message_id
Message ID.
Definition: envelope.h:73
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
Definition: envelope.h:65
char * subject
Email's subject.
Definition: envelope.h:70
A local copy of an email.
Definition: mxapi.h:43
FILE * fp
pointer to the message data
Definition: mxapi.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_update_num_postponed()

void mutt_update_num_postponed ( void  )

Force the update of the number of postponed messages.

Definition at line 185 of file postpone.c.

186{
187 UpdateNumPostponed = true;
188}
+ Here is the caller graph for this function: