NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Postponed Emails. More...

#include <stdbool.h>
#include "ncrypt/lib.h"
#include <stdio.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_postponed (struct Mailbox *m)
 Create a Menu to select a postponed message -.
 
int mutt_get_postponed (struct Mailbox *m_cur, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
 Recall a postponed message.
 
int mutt_num_postponed (struct Mailbox *m, bool force)
 Return the number of postponed messages.
 
SecurityFlags mutt_parse_crypt_hdr (const char *p, bool set_empty_signas, SecurityFlags crypt_app)
 Parse a crypto header string.
 
int mutt_prepare_template (FILE *fp, struct Mailbox *m, struct Email *e_new, struct Email *e, bool resend)
 Prepare a message template.
 
void mutt_update_num_postponed (void)
 Force the update of the number of postponed messages.
 
struct MailboxViewpostponed_get_mailbox_view (struct MuttWindow *dlg)
 Extract the Mailbox from the Postponed Dialog.
 

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

◆ 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 661 of file postpone.c.

663{
664 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
665 if (!c_postponed)
666 return -1;
667
668 struct Email *e = NULL;
669 int rc = SEND_POSTPONED;
670 const char *p = NULL;
671
672 struct Mailbox *m = mx_path_resolve(c_postponed);
673 if (m_cur != m)
674 {
675 if (!mx_mbox_open(m, MUTT_NOSORT))
676 {
677 PostCount = 0;
678 mutt_error(_("No postponed messages"));
679 mailbox_free(&m);
680 return -1;
681 }
682 }
683
684 mx_mbox_check(m);
685
686 if (m->msg_count == 0)
687 {
688 PostCount = 0;
689 mutt_error(_("No postponed messages"));
690 if (m_cur != m)
691 {
692 mx_fastclose_mailbox(m, false);
693 mailbox_free(&m);
694 }
695 return -1;
696 }
697
698 /* avoid the "purge deleted messages" prompt */
699 const enum QuadOption c_delete = cs_subset_quad(NeoMutt->sub, "delete");
700 cs_subset_str_native_set(NeoMutt->sub, "delete", MUTT_YES, NULL);
701
702 if (m->msg_count == 1)
703 {
704 /* only one message, so just use that one. */
705 e = m->emails[0];
706 }
707 else if (!(e = dlg_postponed(m)))
708 {
709 rc = -1;
710 goto cleanup;
711 }
712
713 if (mutt_prepare_template(NULL, m, hdr, e, false) < 0)
714 {
715 rc = -1;
716 goto cleanup;
717 }
718
719 /* finished with this message, so delete it. */
720 mutt_set_flag(m, e, MUTT_DELETE, true, true);
721 mutt_set_flag(m, e, MUTT_PURGE, true, true);
722
723 /* update the count for the status display */
725
726 struct ListNode *np = NULL, *tmp = NULL;
727 STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp)
728 {
729 size_t plen = 0;
730 // Check for header names: most specific first
731 if ((plen = mutt_istr_startswith(np->data, "X-Mutt-References:")) ||
732 (plen = mutt_istr_startswith(np->data, "Mutt-References:")))
733 {
734 /* if a mailbox is currently open, look to see if the original message
735 * the user attempted to reply to is in this mailbox */
736 if (m_cur)
737 {
738 p = mutt_str_skip_email_wsp(np->data + plen);
739 if (!m_cur->id_hash)
740 m_cur->id_hash = mutt_make_id_hash(m_cur);
741 *cur = mutt_hash_find(m_cur->id_hash, p);
742
743 if (*cur)
744 rc |= SEND_REPLY;
745 }
746 }
747 // Check for header names: most specific first
748 else if ((plen = mutt_istr_startswith(np->data, "X-Mutt-Fcc:")) ||
749 (plen = mutt_istr_startswith(np->data, "Mutt-Fcc:")))
750 {
751 p = mutt_str_skip_email_wsp(np->data + plen);
752 buf_strcpy(fcc, p);
754
755 /* note that mutt-fcc was present. we do this because we want to add a
756 * default fcc if the header was missing, but preserve the request of the
757 * user to not make a copy if the header field is present, but empty. */
758 rc |= SEND_POSTPONED_FCC;
759 }
760 // Check for header names: most specific first
761 else if (((WithCrypto & APPLICATION_PGP) != 0) &&
762 ((plen = mutt_istr_startswith(np->data, "X-Mutt-PGP:")) ||
763 (plen = mutt_istr_startswith(np->data, "Mutt-PGP:")) ||
764 (plen = mutt_istr_startswith(np->data, "Pgp:"))))
765 {
766 hdr->security = mutt_parse_crypt_hdr(np->data + plen, true, APPLICATION_PGP);
768 }
769 // Check for header names: most specific first
770 else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
771 ((plen = mutt_istr_startswith(np->data, "X-Mutt-SMIME:")) ||
772 (plen = mutt_istr_startswith(np->data, "Mutt-SMIME:"))))
773 {
774 hdr->security = mutt_parse_crypt_hdr(np->data + plen, true, APPLICATION_SMIME);
776 }
777 else
778 {
779 // skip header removal
780 continue;
781 }
782
783 // remove the header
784 STAILQ_REMOVE(&hdr->env->userhdrs, np, ListNode, entries);
785 FREE(&np->data);
786 FREE(&np);
787 }
788
789 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(NeoMutt->sub, "crypt_opportunistic_encrypt");
790 if (c_crypt_opportunistic_encrypt)
792
793cleanup:
794 if (m_cur != m)
795 {
796 hardclose(m);
797 mailbox_free(&m);
798 }
799
800 cs_subset_str_native_set(NeoMutt->sub, "delete", c_delete, NULL);
801 return rc;
802}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:192
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:89
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1045
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:57
struct Email * dlg_postponed(struct Mailbox *m)
Create a Menu to select a postponed message -.
Definition: dlg_postpone.c:210
#define mutt_error(...)
Definition: logging2.h:93
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
#define FREE(x)
Definition: memory.h:55
#define _(a)
Definition: message.h:28
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:609
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:243
@ MUTT_PURGE
Messages to be purged (bypass trash)
Definition: mutt.h:77
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:75
struct HashTable * mutt_make_id_hash(struct Mailbox *m)
Create a Hash Table for message-ids.
Definition: mutt_thread.c:1702
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:519
void mx_fastclose_mailbox(struct Mailbox *m, bool keep_account)
Free up memory associated with the Mailbox.
Definition: mx.c:414
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:288
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1641
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1110
#define MUTT_NOSORT
Do not sort the mailbox after opening it.
Definition: mxapi.h:41
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:96
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:97
#define WithCrypto
Definition: lib.h:122
SecurityFlags mutt_parse_crypt_hdr(const char *p, bool set_empty_signas, SecurityFlags crypt_app)
Parse a crypto header string.
Definition: postpone.c:204
short PostCount
Number of postponed (draft) emails.
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:487
static void hardclose(struct Mailbox *m)
Try hard to close a mailbox.
Definition: postpone.c:186
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:441
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:400
#define SEND_POSTPONED_FCC
Used by mutt_get_postponed() to signal that the Mutt-Fcc header field was present.
Definition: send.h:50
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:46
#define SEND_REPLY
Reply to sender.
Definition: send.h:42
The envelope/body of an email.
Definition: email.h:39
struct Envelope * env
Envelope information.
Definition: email.h:68
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
struct ListHead userhdrs
user defined headers
Definition: envelope.h:85
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
struct HashTable * id_hash
Hash Table: "message-id" -> Email.
Definition: mailbox.h:123
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
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:299
+ 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 70 of file postpone.c.

71{
72 struct stat st = { 0 };
73
74 static time_t LastModify = 0;
75 static char *OldPostponed = NULL;
76
78 {
79 UpdateNumPostponed = false;
80 force = true;
81 }
82
83 const char *const c_postponed = cs_subset_string(NeoMutt->sub, "postponed");
84 if (!mutt_str_equal(c_postponed, OldPostponed))
85 {
86 FREE(&OldPostponed);
87 OldPostponed = mutt_str_dup(c_postponed);
88 LastModify = 0;
89 force = true;
90 }
91
92 if (!c_postponed)
93 return 0;
94
95 // We currently are in the `$postponed` mailbox so just pick the current status
96 if (m && mutt_str_equal(c_postponed, m->realpath))
97 {
99 return PostCount;
100 }
101
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
123 if (stat(c_postponed, &st) == -1)
124 {
125 PostCount = 0;
126 LastModify = 0;
127 return 0;
128 }
129
130 if (S_ISDIR(st.st_mode))
131 {
132 /* if we have a maildir mailbox, we need to stat the "new" dir */
133 struct Buffer *buf = buf_pool_get();
134
135 buf_printf(buf, "%s/new", c_postponed);
136 if ((access(buf_string(buf), F_OK) == 0) && (stat(buf_string(buf), &st) == -1))
137 {
138 PostCount = 0;
139 LastModify = 0;
140 buf_pool_release(&buf);
141 return 0;
142 }
143 buf_pool_release(&buf);
144 }
145
146 if (LastModify < st.st_mtime)
147 {
148 int optnews = OptNews;
149 LastModify = st.st_mtime;
150
151 if (access(c_postponed, R_OK | F_OK) != 0)
152 return PostCount = 0;
153 if (optnews)
154 OptNews = false;
155 struct Mailbox *m_post = mx_path_resolve(c_postponed);
156 if (mx_mbox_open(m_post, MUTT_NOSORT | MUTT_QUIET))
157 {
158 PostCount = m_post->msg_count;
159 mx_fastclose_mailbox(m_post, false);
160 }
161 else
162 {
163 PostCount = 0;
164 }
165 mailbox_free(&m_post);
166
167 if (optnews)
168 OptNews = true;
169 }
170
171 return PostCount;
172}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:64
#define mutt_debug(LEVEL,...)
Definition: logging2.h:90
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2348
int imap_path_status(const char *path, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1175
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:46
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:254
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
#define MUTT_QUIET
Do not print any messages.
Definition: mxapi.h:44
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
static bool UpdateNumPostponed
When true, force a recount of the postponed (draft) emails.
Definition: postpone.c:60
String manipulation buffer.
Definition: buffer.h:36
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 204 of file postpone.c.

205{
206 char smime_cryptalg[1024] = { 0 };
207 char sign_as[1024] = { 0 };
208 char *q = NULL;
210
211 if (!WithCrypto)
212 return SEC_NO_FLAGS;
213
215 for (; p[0] != '\0'; p++)
216 {
217 switch (p[0])
218 {
219 case 'c':
220 case 'C':
221 q = smime_cryptalg;
222
223 if (p[1] == '<')
224 {
225 for (p += 2; (p[0] != '\0') && (p[0] != '>') &&
226 (q < (smime_cryptalg + sizeof(smime_cryptalg) - 1));
227 *q++ = *p++)
228 {
229 }
230
231 if (p[0] != '>')
232 {
233 mutt_error(_("Illegal S/MIME header"));
234 return SEC_NO_FLAGS;
235 }
236 }
237
238 *q = '\0';
239 break;
240
241 case 'e':
242 case 'E':
243 flags |= SEC_ENCRYPT;
244 break;
245
246 case 'i':
247 case 'I':
248 flags |= SEC_INLINE;
249 break;
250
251 /* This used to be the micalg parameter.
252 *
253 * It's no longer needed, so we just skip the parameter in order
254 * to be able to recall old messages. */
255 case 'm':
256 case 'M':
257 if (p[1] != '<')
258 break;
259
260 for (p += 2; (p[0] != '\0') && (p[0] != '>'); p++)
261 ; // do nothing
262
263 if (p[0] != '>')
264 {
265 mutt_error(_("Illegal crypto header"));
266 return SEC_NO_FLAGS;
267 }
268 break;
269
270 case 'o':
271 case 'O':
272 flags |= SEC_OPPENCRYPT;
273 break;
274
275 case 'a':
276 case 'A':
277#ifdef USE_AUTOCRYPT
278 flags |= SEC_AUTOCRYPT;
279#endif
280 break;
281
282 case 'z':
283 case 'Z':
284#ifdef USE_AUTOCRYPT
285 flags |= SEC_AUTOCRYPT_OVERRIDE;
286#endif
287 break;
288
289 case 's':
290 case 'S':
291 flags |= SEC_SIGN;
292 q = sign_as;
293
294 if (p[1] == '<')
295 {
296 for (p += 2;
297 (p[0] != '\0') && (*p != '>') && (q < (sign_as + sizeof(sign_as) - 1));
298 *q++ = *p++)
299 {
300 }
301
302 if (p[0] != '>')
303 {
304 mutt_error(_("Illegal crypto header"));
305 return SEC_NO_FLAGS;
306 }
307 }
308
309 q[0] = '\0';
310 break;
311
312 default:
313 mutt_error(_("Illegal crypto header"));
314 return SEC_NO_FLAGS;
315 }
316 }
317
318 /* the cryptalg field must not be empty */
319 if (((WithCrypto & APPLICATION_SMIME) != 0) && *smime_cryptalg)
320 {
321 struct Buffer *errmsg = buf_pool_get();
322 int rc = cs_subset_str_string_set(NeoMutt->sub, "smime_encrypt_with",
323 smime_cryptalg, errmsg);
324
325 if ((CSR_RESULT(rc) != CSR_SUCCESS) && !buf_is_empty(errmsg))
326 mutt_error("%s", buf_string(errmsg));
327
328 buf_pool_release(&errmsg);
329 }
330
331 /* Set {Smime,Pgp}SignAs, if desired. */
332
333 if (((WithCrypto & APPLICATION_PGP) != 0) && (crypt_app == APPLICATION_PGP) &&
334 (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
335 {
336 cs_subset_str_string_set(NeoMutt->sub, "pgp_sign_as", sign_as, NULL);
337 }
338
339 if (((WithCrypto & APPLICATION_SMIME) != 0) && (crypt_app == APPLICATION_SMIME) &&
340 (flags & SEC_SIGN) && (set_empty_signas || *sign_as))
341 {
342 cs_subset_str_string_set(NeoMutt->sub, "smime_sign_as", sign_as, NULL);
343 }
344
345 return flags;
346}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
#define CSR_RESULT(x)
Definition: set.h:50
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:91
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:93
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:82
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:92
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:83
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:84
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
Definition: lib.h:94
#define SEC_SIGN
Email is signed.
Definition: lib.h:85
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:388
+ 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 487 of file postpone.c.

489{
490 struct Message *msg = NULL;
491 struct Body *b = NULL;
492 FILE *fp_body = NULL;
493 int rc = -1;
494 struct Envelope *protected_headers = NULL;
495 struct Buffer *file = NULL;
496
497 if (!fp && !(msg = mx_msg_open(m, e)))
498 return -1;
499
500 if (!fp)
501 fp = msg->fp;
502
503 fp_body = fp;
504
505 /* parse the message header and MIME structure */
506
507 if (!mutt_file_seek(fp, e->offset, SEEK_SET))
508 {
509 return -1;
510 }
511 e_new->offset = e->offset;
512 /* enable header weeding for resent messages */
513 e_new->env = mutt_rfc822_read_header(fp, e_new, true, resend);
514 e_new->body->length = e->body->length;
515 mutt_parse_part(fp, e_new->body);
516
517 /* If resending a message, don't keep message_id or mail_followup_to.
518 * Otherwise, we are resuming a postponed message, and want to keep those
519 * headers if they exist. */
520 if (resend)
521 {
522 FREE(&e_new->env->message_id);
524 }
525
526 SecurityFlags sec_type = SEC_NO_FLAGS;
527 if (((WithCrypto & APPLICATION_PGP) != 0) && sec_type == SEC_NO_FLAGS)
528 sec_type = mutt_is_multipart_encrypted(e_new->body);
529 if (((WithCrypto & APPLICATION_SMIME) != 0) && sec_type == SEC_NO_FLAGS)
530 sec_type = mutt_is_application_smime(e_new->body);
531 if (sec_type != SEC_NO_FLAGS)
532 {
533 e_new->security |= sec_type;
534 if (!crypt_valid_passphrase(sec_type))
535 goto bail;
536
537 mutt_message(_("Decrypting message..."));
538 int ret = -1;
539 if (sec_type & APPLICATION_PGP)
540 ret = crypt_pgp_decrypt_mime(fp, &fp_body, e_new->body, &b);
541 else if (sec_type & APPLICATION_SMIME)
542 ret = crypt_smime_decrypt_mime(fp, &fp_body, e_new->body, &b);
543 if ((ret == -1) || !b)
544 {
545 mutt_error(_("Could not decrypt postponed message"));
546 goto bail;
547 }
548
549 /* throw away the outer layer and keep only the (now decrypted) inner part
550 * with its headers. */
551 mutt_body_free(&e_new->body);
552 e_new->body = b;
553
554 if (b->mime_headers)
555 {
556 protected_headers = b->mime_headers;
557 b->mime_headers = NULL;
558 }
559
561 }
562
563 /* remove a potential multipart/signed layer - useful when
564 * resending messages */
565 if ((WithCrypto != 0) && mutt_is_multipart_signed(e_new->body))
566 {
567 e_new->security |= SEC_SIGN;
568 if (((WithCrypto & APPLICATION_PGP) != 0) &&
569 mutt_istr_equal(mutt_param_get(&e_new->body->parameter, "protocol"), "application/pgp-signature"))
570 {
571 e_new->security |= APPLICATION_PGP;
572 }
573 else if (WithCrypto & APPLICATION_SMIME)
574 {
575 e_new->security |= APPLICATION_SMIME;
576 }
577
578 /* destroy the signature */
579 mutt_body_free(&e_new->body->parts->next);
580 e_new->body = mutt_remove_multipart(e_new->body);
581
582 if (e_new->body->mime_headers)
583 {
584 mutt_env_free(&protected_headers);
585 protected_headers = e_new->body->mime_headers;
586 e_new->body->mime_headers = NULL;
587 }
588 }
589
590 /* We don't need no primary multipart/mixed. */
591 if ((e_new->body->type == TYPE_MULTIPART) && mutt_istr_equal(e_new->body->subtype, "mixed"))
592 e_new->body = mutt_remove_multipart(e_new->body);
593
594 file = buf_pool_get();
595
596 /* create temporary files for all attachments */
597 if (create_tmp_files_for_attachments(fp_body, file, e_new, e_new->body, protected_headers) < 0)
598 {
599 goto bail;
600 }
601
602 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
603 if (c_crypt_protected_headers_read && protected_headers && protected_headers->subject &&
604 !mutt_str_equal(e_new->env->subject, protected_headers->subject))
605 {
606 mutt_env_set_subject(e_new->env, protected_headers->subject);
607 }
608 mutt_env_free(&protected_headers);
609
610 /* Fix encryption flags. */
611
612 /* No inline if multipart. */
613 if ((WithCrypto != 0) && (e_new->security & SEC_INLINE) && e_new->body->next)
614 e_new->security &= ~SEC_INLINE;
615
616 /* Do we even support multiple mechanisms? */
618
619 /* Theoretically, both could be set. Take the one the user wants to set by default. */
620 if ((e_new->security & APPLICATION_PGP) && (e_new->security & APPLICATION_SMIME))
621 {
622 const bool c_smime_is_default = cs_subset_bool(NeoMutt->sub, "smime_is_default");
623 if (c_smime_is_default)
624 e_new->security &= ~APPLICATION_PGP;
625 else
626 e_new->security &= ~APPLICATION_SMIME;
627 }
628
630
631 rc = 0;
632
633bail:
634
635 /* that's it. */
636 buf_pool_release(&file);
637 if (fp_body != fp)
638 mutt_file_fclose(&fp_body);
639 if (msg)
640 mx_msg_close(m, &msg);
641
642 if (rc == -1)
643 {
644 mutt_env_free(&e_new->env);
645 mutt_body_free(&e_new->body);
646 }
647
648 return rc;
649}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:408
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:609
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:132
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:443
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:210
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:432
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition: parse.c:1822
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
Definition: parse.c:1205
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition: envelope.c:69
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:655
#define mutt_file_fclose(FP)
Definition: file.h:139
#define mutt_message(...)
Definition: logging2.h:92
@ 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:673
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
Definition: mx.c:1185
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition: mx.c:1139
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:85
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:358
void mutt_rfc3676_space_unstuff(struct Email *e)
Remove RFC3676 space stuffing.
Definition: rfc3676.c:499
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:76
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:63
struct Body * next
next attachment in the list
Definition: body.h:72
char * subtype
content-type subtype
Definition: body.h:61
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
struct Body * body
List of MIME parts.
Definition: email.h:69
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:71
The header of an Email.
Definition: envelope.h:57
char *const subject
Email's subject.
Definition: envelope.h:70
char * message_id
Message ID.
Definition: envelope.h:73
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
Definition: envelope.h:65
A local copy of an email.
Definition: message.h:34
FILE * fp
pointer to the message data
Definition: message.h:35
+ 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 177 of file postpone.c.

178{
179 UpdateNumPostponed = true;
180}
+ Here is the caller graph for this function:

◆ postponed_get_mailbox_view()

struct MailboxView * postponed_get_mailbox_view ( struct MuttWindow dlg)

Extract the Mailbox from the Postponed Dialog.

Parameters
dlgPostponed Dialog
Return values
ptrMailbox view

Definition at line 212 of file functions.c.

213{
214 if (!dlg)
215 return NULL;
216
217 struct Menu *menu = dlg->wdata;
218 struct PostponeData *pd = menu->mdata;
219 if (!pd)
220 return NULL;
221
222 return pd->mailbox_view;
223}
Definition: lib.h:79
void * mdata
Private data.
Definition: lib.h:147
void * wdata
Private data.
Definition: mutt_window.h:145
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct MailboxView * mailbox_view
Postponed Mailbox view.
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:36
+ Here is the caller graph for this function: