NeoMutt  2024-04-25-91-gb0e085
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
send.h File Reference

Prepare and send an email. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for send.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SEND_NO_FLAGS   0
 No flags are set.
 
#define SEND_REPLY   (1 << 0)
 Reply to sender.
 
#define SEND_GROUP_REPLY   (1 << 1)
 Reply to all.
 
#define SEND_LIST_REPLY   (1 << 2)
 Reply to mailing list.
 
#define SEND_FORWARD   (1 << 3)
 Forward email.
 
#define SEND_POSTPONED   (1 << 4)
 Recall a postponed email.
 
#define SEND_BATCH   (1 << 5)
 Send email in batch mode (without user interaction)
 
#define SEND_KEY   (1 << 6)
 Mail a PGP public key.
 
#define SEND_RESEND   (1 << 7)
 Reply using the current email as a template.
 
#define SEND_POSTPONED_FCC   (1 << 8)
 Used by mutt_get_postponed() to signal that the Mutt-Fcc header field was present.
 
#define SEND_NO_FREE_HEADER   (1 << 9)
 Used by the -E flag.
 
#define SEND_DRAFT_FILE   (1 << 10)
 Used by the -H flag.
 
#define SEND_TO_SENDER   (1 << 11)
 Compose new email to sender.
 
#define SEND_GROUP_CHAT_REPLY   (1 << 12)
 Reply to all recipients preserving To/Cc.
 
#define SEND_NEWS   (1 << 13)
 Reply to a news article.
 
#define SEND_REVIEW_TO   (1 << 14)
 Allow the user to edit the To field.
 
#define SEND_CONSUMED_STDIN   (1 << 15)
 stdin has been read; don't read it twice
 
#define SEND_CLI_CRYPTO   (1 << 16)
 Enable message security in modes that by default don't enable it.
 

Typedefs

typedef uint32_t SendFlags
 Flags for mutt_send_message(), e.g. SEND_REPLY.
 

Functions

void mutt_add_to_reference_headers (struct Envelope *env, struct Envelope *env_cur, struct ConfigSubset *sub)
 Generate references for a reply email.
 
struct Addressmutt_default_from (struct ConfigSubset *sub)
 Get a default 'from' Address.
 
int mutt_edit_address (struct AddressList *al, const char *field, bool expand_aliases)
 Edit an email address.
 
void mutt_encode_descriptions (struct Body *b, bool recurse, struct ConfigSubset *sub)
 RFC2047 encode the content-descriptions.
 
int mutt_fetch_recips (struct Envelope *out, struct Envelope *in, SendFlags flags, struct ConfigSubset *sub)
 Generate recpients for a reply email.
 
void mutt_fix_reply_recipients (struct Envelope *env, struct ConfigSubset *sub)
 Remove duplicate recipients.
 
void mutt_forward_intro (struct Email *e, FILE *fp, struct ConfigSubset *sub)
 Add the "start of forwarded message" text.
 
void mutt_forward_trailer (struct Email *e, FILE *fp, struct ConfigSubset *sub)
 Add a "end of forwarded message" text.
 
void mutt_make_attribution_intro (struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
 Add "on DATE, PERSON wrote" header.
 
void mutt_make_attribution_trailer (struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
 Add suffix to replied email text.
 
void mutt_make_forward_subject (struct Envelope *env, struct Email *e, struct ConfigSubset *sub)
 Create a subject for a forwarded email.
 
void mutt_make_misc_reply_headers (struct Envelope *env, struct Envelope *env_cur, struct ConfigSubset *sub)
 Set subject for a reply.
 
int mutt_resend_message (FILE *fp, struct Mailbox *m, struct Email *e_cur, struct ConfigSubset *sub)
 Resend an email.
 
int mutt_send_message (SendFlags flags, struct Email *e_templ, const char *tempfile, struct Mailbox *m, struct EmailArray *ea, struct ConfigSubset *sub)
 Send an email.
 
void mutt_set_followup_to (struct Envelope *env, struct ConfigSubset *sub)
 Set followup-to field.
 
bool mutt_send_list_subscribe (struct Mailbox *m, struct Email *e)
 Send a mailing-list subscription email.
 
bool mutt_send_list_unsubscribe (struct Mailbox *m, struct Email *e)
 Send a mailing-list unsubscription email.
 

Detailed Description

Prepare and send an email.

Authors
  • Richard Russon
  • Pietro Cerutti
  • Alejandro Colomar

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 send.h.

Macro Definition Documentation

◆ SEND_NO_FLAGS

#define SEND_NO_FLAGS   0

No flags are set.

Definition at line 41 of file send.h.

◆ SEND_REPLY

#define SEND_REPLY   (1 << 0)

Reply to sender.

Definition at line 42 of file send.h.

◆ SEND_GROUP_REPLY

#define SEND_GROUP_REPLY   (1 << 1)

Reply to all.

Definition at line 43 of file send.h.

◆ SEND_LIST_REPLY

#define SEND_LIST_REPLY   (1 << 2)

Reply to mailing list.

Definition at line 44 of file send.h.

◆ SEND_FORWARD

#define SEND_FORWARD   (1 << 3)

Forward email.

Definition at line 45 of file send.h.

◆ SEND_POSTPONED

#define SEND_POSTPONED   (1 << 4)

Recall a postponed email.

Definition at line 46 of file send.h.

◆ SEND_BATCH

#define SEND_BATCH   (1 << 5)

Send email in batch mode (without user interaction)

Definition at line 47 of file send.h.

◆ SEND_KEY

#define SEND_KEY   (1 << 6)

Mail a PGP public key.

Definition at line 48 of file send.h.

◆ SEND_RESEND

#define SEND_RESEND   (1 << 7)

Reply using the current email as a template.

Definition at line 49 of file send.h.

◆ SEND_POSTPONED_FCC

#define SEND_POSTPONED_FCC   (1 << 8)

Used by mutt_get_postponed() to signal that the Mutt-Fcc header field was present.

Definition at line 50 of file send.h.

◆ SEND_NO_FREE_HEADER

#define SEND_NO_FREE_HEADER   (1 << 9)

Used by the -E flag.

Definition at line 51 of file send.h.

◆ SEND_DRAFT_FILE

#define SEND_DRAFT_FILE   (1 << 10)

Used by the -H flag.

Definition at line 52 of file send.h.

◆ SEND_TO_SENDER

#define SEND_TO_SENDER   (1 << 11)

Compose new email to sender.

Definition at line 53 of file send.h.

◆ SEND_GROUP_CHAT_REPLY

#define SEND_GROUP_CHAT_REPLY   (1 << 12)

Reply to all recipients preserving To/Cc.

Definition at line 54 of file send.h.

◆ SEND_NEWS

#define SEND_NEWS   (1 << 13)

Reply to a news article.

Definition at line 55 of file send.h.

◆ SEND_REVIEW_TO

#define SEND_REVIEW_TO   (1 << 14)

Allow the user to edit the To field.

Definition at line 56 of file send.h.

◆ SEND_CONSUMED_STDIN

#define SEND_CONSUMED_STDIN   (1 << 15)

stdin has been read; don't read it twice

Definition at line 57 of file send.h.

◆ SEND_CLI_CRYPTO

#define SEND_CLI_CRYPTO   (1 << 16)

Enable message security in modes that by default don't enable it.

Definition at line 58 of file send.h.

Typedef Documentation

◆ SendFlags

typedef uint32_t SendFlags

Flags for mutt_send_message(), e.g. SEND_REPLY.

Definition at line 40 of file send.h.

Function Documentation

◆ mutt_add_to_reference_headers()

void mutt_add_to_reference_headers ( struct Envelope env,
struct Envelope env_cur,
struct ConfigSubset sub 
)

Generate references for a reply email.

Parameters
envEnvelope for result
env_curEnvelope of source email
subConfig Subset

Definition at line 1097 of file send.c.

1099{
1100 add_references(&env->references, env_cur);
1101 add_message_id(&env->references, env_cur);
1102 add_message_id(&env->in_reply_to, env_cur);
1103
1104 const bool c_x_comment_to = cs_subset_bool(sub, "x_comment_to");
1105 if (OptNewsSend && c_x_comment_to && !TAILQ_EMPTY(&env_cur->from))
1107}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: globals.c:71
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_EMPTY(head)
Definition: queue.h:721
static void add_message_id(struct ListHead *head, struct Envelope *env)
Add the email's message ID to a list.
Definition: send.c:1006
static void add_references(struct ListHead *head, struct Envelope *env)
Add the email's references to a list.
Definition: send.c:995
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:134
char * x_comment_to
List of 'X-comment-to' fields.
Definition: envelope.h:81
struct ListHead references
message references (in reverse order)
Definition: envelope.h:83
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:84
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_default_from()

struct Address * mutt_default_from ( struct ConfigSubset sub)

Get a default 'from' Address.

Parameters
subConfig Subset
Return values
ptrNewly allocated Address

Definition at line 1458 of file send.c.

1459{
1460 /* Note: We let $from override $real_name here.
1461 * Is this the right thing to do?
1462 */
1463
1464 const struct Address *c_from = cs_subset_address(sub, "from");
1465 if (c_from)
1466 {
1467 return mutt_addr_copy(c_from);
1468 }
1469
1470 char domain[1024] = { 0 };
1471 const char *mailbox = Username;
1472 const bool c_use_domain = cs_subset_bool(sub, "use_domain");
1473 if (c_use_domain)
1474 {
1475 snprintf(domain, sizeof(domain), "%s@%s", NONULL(Username),
1476 NONULL(mutt_fqdn(true, sub)));
1477 mailbox = domain;
1478 }
1479
1480 return mutt_addr_create(NULL, mailbox);
1481}
struct Address * mutt_addr_create(const char *personal, const char *mailbox)
Create and populate a new Address.
Definition: address.c:414
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:745
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: config_type.c:272
char * Username
User's login name.
Definition: globals.c:41
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:707
#define NONULL(x)
Definition: string2.h:37
An email address.
Definition: address.h:36
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_edit_address()

int mutt_edit_address ( struct AddressList *  al,
const char *  field,
bool  expand_aliases 
)

Edit an email address.

Parameters
[in,out]alAddressList to edit
[in]fieldPrompt for user
[in]expand_aliasesIf true, expand Address aliases
Return values
0Success
-1Failure

Definition at line 191 of file send.c.

192{
193 int rc = 0;
194 struct Buffer *buf = buf_pool_get();
195 buf_alloc(buf, 8192);
196 char *err = NULL;
197 int idna_ok = 0;
198
199 do
200 {
202 buf_reset(buf);
203 mutt_addrlist_write(al, buf, false);
204 if (mw_get_field(field, buf, MUTT_COMP_NO_FLAGS, HC_ALIAS, &CompleteAliasOps, NULL) != 0)
205 {
206 rc = -1;
207 goto done;
208 }
211 if (expand_aliases)
213 idna_ok = mutt_addrlist_to_intl(al, &err);
214 if (idna_ok != 0)
215 {
216 mutt_error(_("Bad IDN: '%s'"), err);
217 FREE(&err);
218 }
219 } while (idna_ok != 0);
220
221done:
222 buf_pool_release(&buf);
223 return rc;
224}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1378
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition: address.c:1206
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:644
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1293
const struct CompleteOps CompleteAliasOps
Auto-Completion of Aliases.
Definition: complete.c:108
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:295
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
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
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition: window.c:274
#define mutt_error(...)
Definition: logging2.h:92
@ HC_ALIAS
Aliases.
Definition: lib.h:52
#define FREE(x)
Definition: memory.h:45
#define _(a)
Definition: message.h:28
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_encode_descriptions()

void mutt_encode_descriptions ( struct Body b,
bool  recurse,
struct ConfigSubset sub 
)

RFC2047 encode the content-descriptions.

Parameters
bBody of email
recurseIf true, encode children parts
subConfig Subset

Definition at line 1554 of file send.c.

1555{
1556 const struct Slist *const c_send_charset = cs_subset_slist(sub, "send_charset");
1557 for (struct Body *t = b; t; t = t->next)
1558 {
1559 if (t->description)
1560 {
1561 rfc2047_encode(&t->description, NULL, sizeof("Content-Description:"), c_send_charset);
1562 }
1563 if (recurse && t->parts)
1564 mutt_encode_descriptions(t->parts, recurse, sub);
1565 }
1566}
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:242
void rfc2047_encode(char **pd, const char *specials, int col, const struct Slist *charsets)
RFC-2047-encode a string.
Definition: rfc2047.c:628
void mutt_encode_descriptions(struct Body *b, bool recurse, struct ConfigSubset *sub)
RFC2047 encode the content-descriptions.
Definition: send.c:1554
The body of an email.
Definition: body.h:36
struct Body * next
next attachment in the list
Definition: body.h:72
String list.
Definition: slist.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_fetch_recips()

int mutt_fetch_recips ( struct Envelope out,
struct Envelope in,
SendFlags  flags,
struct ConfigSubset sub 
)

Generate recpients for a reply email.

Parameters
outEnvelope to populate
inEnvelope of source email
flagsFlags, see SendFlags
subConfig Subset
Return values
0Success
-1Failure

Definition at line 936 of file send.c.

938{
939 enum QuadOption hmfupto = MUTT_ABORT;
940 const struct Address *followup_to = TAILQ_FIRST(&in->mail_followup_to);
941
942 if ((flags & (SEND_LIST_REPLY | SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY)) && followup_to)
943 {
944 char prompt[256] = { 0 };
945 snprintf(prompt, sizeof(prompt), _("Follow-up to %s%s?"),
946 buf_string(followup_to->mailbox),
947 TAILQ_NEXT(TAILQ_FIRST(&in->mail_followup_to), entries) ? ",..." : "");
948
949 hmfupto = query_quadoption(prompt, sub, "honor_followup_to");
950 if (hmfupto == MUTT_ABORT)
951 return -1;
952 }
953
954 if (flags & SEND_LIST_REPLY)
955 {
956 add_mailing_lists(&out->to, &in->to, &in->cc);
957
958 if (followup_to && (hmfupto == MUTT_YES) &&
959 (default_to(&out->cc, in, flags & SEND_LIST_REPLY, (hmfupto == MUTT_YES), sub) == MUTT_ABORT))
960 {
961 return -1; /* abort */
962 }
963 }
964 else if (flags & SEND_TO_SENDER)
965 {
966 mutt_addrlist_copy(&out->to, &in->from, false);
967 }
968 else
969 {
970 if (default_to(&out->to, in, flags & (SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY),
971 (hmfupto == MUTT_YES), sub) == -1)
972 {
973 return -1; /* abort */
974 }
975
976 if ((flags & (SEND_GROUP_REPLY | SEND_GROUP_CHAT_REPLY)) &&
977 (!followup_to || (hmfupto != MUTT_YES)))
978 {
979 /* if(!mutt_addr_is_user(in->to)) */
980 if (flags & SEND_GROUP_REPLY)
981 mutt_addrlist_copy(&out->cc, &in->to, true);
982 else
983 mutt_addrlist_copy(&out->to, &in->to, true);
984 mutt_addrlist_copy(&out->cc, &in->cc, true);
985 }
986 }
987 return 0;
988}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
Definition: quad.h:37
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
Definition: question.c:365
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
static void add_mailing_lists(struct AddressList *out, const struct AddressList *t, const struct AddressList *c)
Search Address lists for mailing lists.
Definition: send.c:164
static int default_to(struct AddressList *to, struct Envelope *env, SendFlags flags, int hmfupto, struct ConfigSubset *sub)
Generate default email addresses.
Definition: send.c:850
#define SEND_GROUP_CHAT_REPLY
Reply to all recipients preserving To/Cc.
Definition: send.h:54
#define SEND_GROUP_REPLY
Reply to all.
Definition: send.h:43
#define SEND_LIST_REPLY
Reply to mailing list.
Definition: send.h:44
#define SEND_TO_SENDER
Compose new email to sender.
Definition: send.h:53
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
Definition: envelope.h:65
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_fix_reply_recipients()

void mutt_fix_reply_recipients ( struct Envelope env,
struct ConfigSubset sub 
)

Remove duplicate recipients.

Parameters
envEnvelope to fix
subConfig Subset

Definition at line 1019 of file send.c.

1020{
1021 const bool c_me_too = cs_subset_bool(sub, "me_too");
1022 if (!c_me_too)
1023 {
1024 const bool c_reply_self = cs_subset_bool(sub, "reply_self");
1025
1026 /* the order is important here. do the CC: first so that if the
1027 * the user is the only recipient, it ends up on the TO: field */
1028 remove_user(&env->cc, TAILQ_EMPTY(&env->to));
1029 remove_user(&env->to, TAILQ_EMPTY(&env->cc) || c_reply_self);
1030 }
1031
1032 /* the CC field can get cluttered, especially with lists */
1033 mutt_addrlist_dedupe(&env->to);
1034 mutt_addrlist_dedupe(&env->cc);
1035 mutt_addrlist_remove_xrefs(&env->to, &env->cc);
1036
1037 if (!TAILQ_EMPTY(&env->cc) && TAILQ_EMPTY(&env->to))
1038 {
1039 TAILQ_SWAP(&env->to, &env->cc, Address, entries);
1040 }
1041}
void mutt_addrlist_remove_xrefs(const struct AddressList *a, struct AddressList *b)
Remove cross-references.
Definition: address.c:1433
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
Definition: address.c:1397
#define TAILQ_SWAP(head1, head2, type, field)
Definition: queue.h:859
static void remove_user(struct AddressList *al, bool leave_only)
Remove any address which matches the current user.
Definition: send.c:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_forward_intro()

void mutt_forward_intro ( struct Email e,
FILE *  fp,
struct ConfigSubset sub 
)

Add the "start of forwarded message" text.

Parameters
eEmail
subConfig Subset
fpFile to write to

Definition at line 452 of file send.c.

453{
454 const struct Expando *c_forward_attribution_intro = cs_subset_expando(sub, "forward_attribution_intro");
455 if (!c_forward_attribution_intro || !fp)
456 return;
457
458 const char *const c_attribution_locale = cs_subset_string(sub, "attribution_locale");
459
460 struct Buffer *buf = buf_pool_get();
461 setlocale(LC_TIME, NONULL(c_attribution_locale));
462 mutt_make_string(buf, -1, c_forward_attribution_intro, NULL, -1, e,
464 setlocale(LC_TIME, "");
465 fputs(buf_string(buf), fp);
466 fputs("\n\n", fp);
467 buf_pool_release(&buf);
468}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:357
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1796
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
Parsed Expando trees.
Definition: expando.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_forward_trailer()

void mutt_forward_trailer ( struct Email e,
FILE *  fp,
struct ConfigSubset sub 
)

Add a "end of forwarded message" text.

Parameters
eEmail
subConfig Subset
fpFile to write to

Definition at line 476 of file send.c.

477{
478 const struct Expando *c_forward_attribution_trailer = cs_subset_expando(sub, "forward_attribution_trailer");
479 if (!c_forward_attribution_trailer || !fp)
480 return;
481
482 const char *const c_attribution_locale = cs_subset_string(sub, "attribution_locale");
483
484 struct Buffer *buf = buf_pool_get();
485 setlocale(LC_TIME, NONULL(c_attribution_locale));
486 mutt_make_string(buf, -1, c_forward_attribution_trailer, NULL, -1, e,
488 setlocale(LC_TIME, "");
489 fputc('\n', fp);
490 fputs(buf_string(buf), fp);
491 fputc('\n', fp);
492 buf_pool_release(&buf);
493}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_attribution_intro()

void mutt_make_attribution_intro ( struct Email e,
FILE *  fp_out,
struct ConfigSubset sub 
)

Add "on DATE, PERSON wrote" header.

Parameters
eEmail
fp_outFile to write to
subConfig Subset

Definition at line 660 of file send.c.

661{
662 format_attribution(cs_subset_expando(sub, "attribution_intro"), e, fp_out, sub);
663}
static void format_attribution(const struct Expando *exp, struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Format an attribution prefix/suffix.
Definition: send.c:637
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_attribution_trailer()

void mutt_make_attribution_trailer ( struct Email e,
FILE *  fp_out,
struct ConfigSubset sub 
)

Add suffix to replied email text.

Parameters
eEmail
fp_outFile to write to
subConfig Subset

Definition at line 671 of file send.c.

672{
673 format_attribution(cs_subset_expando(sub, "attribution_trailer"), e, fp_out, sub);
674}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_forward_subject()

void mutt_make_forward_subject ( struct Envelope env,
struct Email e,
struct ConfigSubset sub 
)

Create a subject for a forwarded email.

Parameters
envEnvelope for result
eEmail
subConfig Subset

Definition at line 1049 of file send.c.

1050{
1051 if (!env)
1052 return;
1053
1054 const struct Expando *c_forward_format = cs_subset_expando(sub, "forward_format");
1055
1056 struct Buffer *buf = buf_pool_get();
1057 /* set the default subject for the message. */
1058 mutt_make_string(buf, -1, c_forward_format, NULL, -1, e, MUTT_FORMAT_NO_FLAGS, NULL);
1060 buf_pool_release(&buf);
1061}
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition: envelope.c:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_misc_reply_headers()

void mutt_make_misc_reply_headers ( struct Envelope env,
struct Envelope env_cur,
struct ConfigSubset sub 
)

Set subject for a reply.

Parameters
envEnvelope for result
env_curEnvelope of source email
subConfig Subset

Definition at line 1069 of file send.c.

1071{
1072 if (!env || !env_cur)
1073 return;
1074
1075 /* This takes precedence over a subject that might have
1076 * been taken from a List-Post header. Is that correct? */
1077 if (env_cur->real_subj)
1078 {
1079 char *subj = NULL;
1080 mutt_str_asprintf(&subj, "Re: %s", env_cur->real_subj);
1081 mutt_env_set_subject(env, subj);
1082 FREE(&subj);
1083 }
1084 else if (!env->subject)
1085 {
1086 const char *const c_empty_subject = cs_subset_string(sub, "empty_subject");
1087 mutt_env_set_subject(env, c_empty_subject);
1088 }
1089}
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:803
char *const subject
Email's subject.
Definition: envelope.h:70
char *const real_subj
Offset of the real subject.
Definition: envelope.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_resend_message()

int mutt_resend_message ( FILE *  fp,
struct Mailbox m,
struct Email e_cur,
struct ConfigSubset sub 
)

Resend an email.

Parameters
fpFile containing email
mMailbox
e_curEmail to resend
subConfig Subset
Return values
0Message was successfully sent
-1Message was aborted or an error occurred
1Message was postponed

Definition at line 1614 of file send.c.

1616{
1617 struct Email *e_new = email_new();
1618
1619 if (mutt_prepare_template(fp, m, e_new, e_cur, true) < 0)
1620 {
1621 email_free(&e_new);
1622 return -1;
1623 }
1624
1625 if (WithCrypto)
1626 {
1627 /* mutt_prepare_template doesn't always flip on an application bit.
1628 * so fix that here */
1629 if (!(e_new->security & (APPLICATION_SMIME | APPLICATION_PGP)))
1630 {
1631 const bool c_smime_is_default = cs_subset_bool(sub, "smime_is_default");
1632 if (((WithCrypto & APPLICATION_SMIME) != 0) && c_smime_is_default)
1633 e_new->security |= APPLICATION_SMIME;
1634 else if (WithCrypto & APPLICATION_PGP)
1635 e_new->security |= APPLICATION_PGP;
1636 else
1637 e_new->security |= APPLICATION_SMIME;
1638 }
1639
1640 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(sub, "crypt_opportunistic_encrypt");
1641 if (c_crypt_opportunistic_encrypt)
1642 {
1643 e_new->security |= SEC_OPPENCRYPT;
1645 }
1646 }
1647
1648 struct EmailArray ea = ARRAY_HEAD_INITIALIZER;
1649 ARRAY_ADD(&ea, e_cur);
1650 int rc = mutt_send_message(SEND_RESEND, e_new, NULL, m, &ea, sub);
1651 ARRAY_FREE(&ea);
1652
1653 return rc;
1654}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:58
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1045
struct Email * email_new(void)
Create a new Email.
Definition: email.c:77
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:46
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:86
#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
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:484
int mutt_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Mailbox *m, struct EmailArray *ea, struct ConfigSubset *sub)
Send an email.
Definition: send.c:2099
#define SEND_RESEND
Reply using the current email as a template.
Definition: send.h:49
The envelope/body of an email.
Definition: email.h:39
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_send_message()

int mutt_send_message ( SendFlags  flags,
struct Email e_templ,
const char *  tempfile,
struct Mailbox m,
struct EmailArray *  ea,
struct ConfigSubset sub 
)

Send an email.

Parameters
flagsSend mode, see SendFlags
e_templTemplate to use for new message
tempfileFile specified by -i or -H
mCurrent mailbox
eaArray of Emails to send
subConfig Subset
Return values
0Message was successfully sent
-1Message was aborted or an error occurred
1Message was postponed

Definition at line 2099 of file send.c.

2101{
2102 struct Buffer *fcc = buf_pool_get(); /* where to copy this message */
2103 FILE *fp_tmp = NULL;
2104 struct Body *pbody = NULL;
2105 int i;
2106 bool free_clear_content = false;
2107
2108 struct Body *clear_content = NULL;
2109 char *pgpkeylist = NULL;
2110 /* save current value of "pgp_sign_as" and "smime_default_key" */
2111 char *pgp_sign_as = NULL;
2112 char *smime_sign_as = NULL;
2113 const char *tag = NULL;
2114 char *err = NULL;
2115 const char *ctype = NULL;
2116 char *finalpath = NULL;
2117 struct Email *e_cur = NULL;
2118
2119 if (ea && (ARRAY_SIZE(ea) == 1))
2120 e_cur = *ARRAY_GET(ea, 0);
2121
2122 int rc = -1;
2123
2124 if (flags & SEND_NEWS)
2125 OptNewsSend = true;
2126 else
2127 OptNewsSend = false;
2128
2129 const enum QuadOption c_recall = cs_subset_quad(sub, "recall");
2130
2131 if (!flags && !e_templ && (c_recall != MUTT_NO) && mutt_num_postponed(m, true))
2132 {
2133 /* If the user is composing a new message, check to see if there
2134 * are any postponed messages first. */
2135 enum QuadOption ans = query_quadoption(_("Recall postponed message?"), sub, "recall");
2136 if (ans == MUTT_ABORT)
2137 return rc;
2138
2139 if (ans == MUTT_YES)
2140 flags |= SEND_POSTPONED;
2141 }
2142
2143 if (flags & SEND_POSTPONED)
2144 {
2146 {
2147 const char *const c_pgp_sign_as = cs_subset_string(sub, "pgp_sign_as");
2148 pgp_sign_as = mutt_str_dup(c_pgp_sign_as);
2149 }
2151 {
2152 const char *const c_smime_sign_as = cs_subset_string(sub, "smime_sign_as");
2153 smime_sign_as = mutt_str_dup(c_smime_sign_as);
2154 }
2155 }
2156
2157 /* Delay expansion of aliases until absolutely necessary--shouldn't
2158 * be necessary unless we are prompting the user or about to execute a
2159 * send-hook. */
2160
2161 if (!e_templ)
2162 {
2163 e_templ = email_new();
2164
2165 if (flags == SEND_POSTPONED)
2166 {
2167 rc = mutt_get_postponed(m, e_templ, &e_cur, fcc);
2168 if (rc < 0)
2169 {
2170 flags = SEND_POSTPONED;
2171 goto cleanup;
2172 }
2173 flags = rc;
2174 /* If postponed message is a news article, it have
2175 * a "Newsgroups:" header line, then set appropriate flag. */
2176 if (e_templ->env->newsgroups)
2177 {
2178 flags |= SEND_NEWS;
2179 OptNewsSend = true;
2180 }
2181 else
2182 {
2183 flags &= ~SEND_NEWS;
2184 OptNewsSend = false;
2185 }
2186 }
2187
2188 if (flags & (SEND_POSTPONED | SEND_RESEND))
2189 {
2190 struct Body *b = e_templ->body;
2191 while (b->parts)
2192 b = b->parts;
2193 fp_tmp = mutt_file_fopen(b->filename, "a+");
2194 if (!fp_tmp)
2195 {
2196 mutt_perror("%s", b->filename);
2197 goto cleanup;
2198 }
2199 }
2200
2201 if (!e_templ->env)
2202 e_templ->env = mutt_env_new();
2203 }
2204
2205 /* Parse and use an eventual list-post header */
2206 if ((flags & SEND_LIST_REPLY) && e_cur && e_cur->env && e_cur->env->list_post)
2207 {
2208 /* Use any list-post header as a template */
2209 mutt_parse_mailto(e_templ->env, NULL, e_cur->env->list_post);
2210 /* We don't let them set the sender's address. */
2211 mutt_addrlist_clear(&e_templ->env->from);
2212 }
2213
2214 if (!(flags & (SEND_KEY | SEND_POSTPONED | SEND_RESEND)))
2215 {
2216 /* When SEND_DRAFT_FILE is set, the caller has already
2217 * created the "parent" body structure. */
2218 if (!(flags & SEND_DRAFT_FILE))
2219 {
2220 pbody = mutt_body_new();
2221 pbody->next = e_templ->body; /* don't kill command-line attachments */
2222 e_templ->body = pbody;
2223
2224 const char *const c_content_type = cs_subset_string(sub, "content_type");
2225 ctype = c_content_type;
2226 if (!ctype)
2227 ctype = "text/plain";
2228 mutt_parse_content_type(ctype, e_templ->body);
2229 e_templ->body->unlink = true;
2230 e_templ->body->use_disp = false;
2231 e_templ->body->disposition = DISP_INLINE;
2232
2233 if (tempfile)
2234 {
2235 fp_tmp = mutt_file_fopen(tempfile, "a+");
2236 e_templ->body->filename = mutt_str_dup(tempfile);
2237 if (flags & SEND_NO_FREE_HEADER)
2238 e_templ->body->unlink = false;
2239 }
2240 else
2241 {
2242 struct Buffer *buf = buf_pool_get();
2243 buf_mktemp(buf);
2244 fp_tmp = mutt_file_fopen(buf_string(buf), "w+");
2245 e_templ->body->filename = buf_strdup(buf);
2246 buf_pool_release(&buf);
2247 }
2248 }
2249 else
2250 {
2251 struct Body *b = e_templ->body;
2252 while (b->parts)
2253 b = b->parts;
2254 fp_tmp = mutt_file_fopen(b->filename, "a+");
2255 }
2256
2257 if (!fp_tmp)
2258 {
2259 mutt_debug(LL_DEBUG1, "can't create tempfile %s (errno=%d)\n",
2260 e_templ->body->filename, errno);
2261 mutt_perror("%s", e_templ->body->filename);
2262 goto cleanup;
2263 }
2264 }
2265
2266 const bool c_reverse_name = cs_subset_bool(sub, "reverse_name");
2267 /* this is handled here so that the user can match ~f in send-hook */
2268 if (e_cur && c_reverse_name && !(flags & (SEND_POSTPONED | SEND_RESEND)))
2269 {
2270 /* We shouldn't have to worry about alias expansion here since we are
2271 * either replying to a real or postponed message, therefore no aliases
2272 * should exist since the user has not had the opportunity to add
2273 * addresses to the list. We just have to ensure the postponed messages
2274 * have their aliases expanded. */
2275
2276 if (!TAILQ_EMPTY(&e_templ->env->from))
2277 {
2278 mutt_debug(LL_DEBUG5, "e_templ->env->from before set_reverse_name: %s\n",
2279 buf_string(TAILQ_FIRST(&e_templ->env->from)->mailbox));
2280 mutt_addrlist_clear(&e_templ->env->from);
2281 }
2282 set_reverse_name(&e_templ->env->from, e_cur->env, sub);
2283 }
2284
2285 const bool c_reply_with_xorig = cs_subset_bool(sub, "reply_with_xorig");
2286 if (e_cur && c_reply_with_xorig && !(flags & (SEND_POSTPONED | SEND_RESEND | SEND_FORWARD)))
2287 {
2288 /* We shouldn't have to worry about freeing 'e_templ->env->from' before
2289 * setting it here since this code will only execute when doing some
2290 * sort of reply. The pointer will only be set when using the -H command
2291 * line option.
2292 *
2293 * If there is already a from address recorded in 'e_templ->env->from',
2294 * then it theoretically comes from `$reverse_name` handling, and we don't use
2295 * the 'X-Original-To header'. */
2296 if (!TAILQ_EMPTY(&e_cur->env->x_original_to) && TAILQ_EMPTY(&e_templ->env->from))
2297 {
2298 mutt_addrlist_copy(&e_templ->env->from, &e_cur->env->x_original_to, false);
2299 mutt_debug(LL_DEBUG5, "e_templ->env->from extracted from X-Original-To: header: %s\n",
2300 buf_string(TAILQ_FIRST(&e_templ->env->from)->mailbox));
2301 }
2302 }
2303
2304 const bool c_resume_draft_files = cs_subset_bool(sub, "resume_draft_files");
2305 if (!(flags & (SEND_POSTPONED | SEND_RESEND)) &&
2306 !((flags & SEND_DRAFT_FILE) && c_resume_draft_files))
2307 {
2308 if ((flags & (SEND_REPLY | SEND_FORWARD | SEND_TO_SENDER)) &&
2309 (envelope_defaults(e_templ->env, ea, flags, sub) == -1))
2310 {
2311 goto cleanup;
2312 }
2313
2314 const bool c_hdrs = cs_subset_bool(sub, "hdrs");
2315 if (c_hdrs)
2316 process_user_recips(e_templ->env);
2317
2318 /* Expand aliases and remove duplicates/crossrefs */
2319 mutt_expand_aliases_env(e_templ->env);
2320
2321 if (flags & SEND_REPLY)
2322 mutt_fix_reply_recipients(e_templ->env, sub);
2323
2324 if ((flags & SEND_NEWS) && (m && m->type == MUTT_NNTP) && !e_templ->env->newsgroups)
2325 {
2326 e_templ->env->newsgroups = mutt_str_dup(((struct NntpMboxData *) m->mdata)->group);
2327 }
2328
2329 const bool c_auto_edit = cs_subset_bool(sub, "auto_edit");
2330 const bool c_edit_headers = cs_subset_bool(sub, "edit_headers");
2331 const bool c_fast_reply = cs_subset_bool(sub, "fast_reply");
2332 if (!(flags & SEND_BATCH) && !(c_auto_edit && c_edit_headers) &&
2333 !((flags & SEND_REPLY) && c_fast_reply))
2334 {
2335 if (edit_envelope(e_templ->env, flags, sub) == -1)
2336 goto cleanup;
2337 }
2338
2339 /* the from address must be set here regardless of whether or not
2340 * $use_from is set so that the '~P' (from you) operator in send-hook
2341 * patterns will work. if $use_from is unset, the from address is killed
2342 * after send-hooks are evaluated */
2343
2344 const bool killfrom = TAILQ_EMPTY(&e_templ->env->from);
2345 if (killfrom)
2346 {
2348 }
2349
2350 if ((flags & SEND_REPLY) && e_cur)
2351 {
2352 /* change setting based upon message we are replying to */
2354
2355 /* set the replied flag for the message we are generating so that the
2356 * user can use ~Q in a send-hook to know when reply-hook's are also
2357 * being used. */
2358 e_templ->replied = true;
2359 }
2360
2361 /* change settings based upon recipients */
2362
2363 mutt_message_hook(NULL, e_templ, MUTT_SEND_HOOK);
2364
2365 /* Unset the replied flag from the message we are composing since it is
2366 * no longer required. This is done here because the FCC'd copy of
2367 * this message was erroneously get the 'R'eplied flag when stored in
2368 * a maildir-style mailbox. */
2369 e_templ->replied = false;
2370
2371 /* $use_from and/or $from might have changed in a send-hook */
2372 if (killfrom)
2373 {
2374 mutt_addrlist_clear(&e_templ->env->from);
2375
2376 const bool c_use_from = cs_subset_bool(sub, "use_from");
2377 if (c_use_from && !(flags & (SEND_POSTPONED | SEND_RESEND)))
2379 }
2380
2381 if (c_hdrs)
2382 process_user_header(e_templ->env);
2383
2384 if ((flags & SEND_BATCH) && !(flags & SEND_CONSUMED_STDIN))
2385 {
2386 if (mutt_file_copy_stream(stdin, fp_tmp) < 0)
2387 {
2388 mutt_error(_("Error sending message"));
2389 goto cleanup;
2390 }
2391 }
2392
2393 if (!(flags & SEND_BATCH))
2394 mutt_make_greeting(e_templ, fp_tmp, sub);
2395
2396 const bool c_sig_on_top = cs_subset_bool(sub, "sig_on_top");
2397 const char *const c_editor = cs_subset_string(sub, "editor");
2398 if (c_sig_on_top && !(flags & (SEND_KEY | SEND_BATCH)) && c_editor)
2399 {
2400 append_signature(fp_tmp, sub);
2401 }
2402
2403 /* include replies/forwarded messages, unless we are given a template */
2404 if (!tempfile && (m || !(flags & (SEND_REPLY | SEND_FORWARD))) &&
2405 (generate_body(fp_tmp, e_templ, flags, m, ea, sub) == -1))
2406 {
2407 goto cleanup;
2408 }
2409
2410 if (!c_sig_on_top && !(flags & (SEND_KEY | SEND_BATCH)) && c_editor)
2411 {
2412 append_signature(fp_tmp, sub);
2413 }
2414 }
2415
2416 /* Only set format=flowed for new messages. postponed/resent/draftfiles
2417 * should respect the original email.
2418 *
2419 * This is set here so that send-hook can be used to turn the option on. */
2420 if (!(flags & (SEND_KEY | SEND_POSTPONED | SEND_RESEND | SEND_DRAFT_FILE)))
2421 {
2422 const bool c_text_flowed = cs_subset_bool(sub, "text_flowed");
2423 if (c_text_flowed && is_text_plain(e_templ->body))
2424 {
2425 mutt_param_set(&e_templ->body->parameter, "format", "flowed");
2426 }
2427 }
2428
2429 /* This hook is even called for postponed messages, and can, e.g., be used
2430 * for setting the editor, the sendmail path, or the envelope sender. */
2431 mutt_message_hook(NULL, e_templ, MUTT_SEND2_HOOK);
2432
2433 /* wait until now to set the real name portion of our return address so
2434 * that $real_name can be set in a send-hook */
2435 {
2436 struct Address *from = TAILQ_FIRST(&e_templ->env->from);
2437 if (from && !from->personal && !(flags & (SEND_RESEND | SEND_POSTPONED)))
2438 {
2439 const char *const c_real_name = cs_subset_string(sub, "real_name");
2440 if (c_real_name)
2441 from->personal = buf_new(c_real_name);
2442 }
2443 }
2444
2445 if (!(((WithCrypto & APPLICATION_PGP) != 0) && (flags & SEND_KEY)))
2446 mutt_file_fclose(&fp_tmp);
2447
2448 if (!(flags & SEND_BATCH))
2449 {
2450 struct stat st = { 0 };
2451 time_t mtime;
2452 struct Body *b = e_templ->body;
2453 while (b->parts)
2454 b = b->parts;
2455 mtime = mutt_file_decrease_mtime(b->filename, NULL);
2456 if (mtime == (time_t) -1)
2457 {
2458 mutt_perror("%s", b->filename);
2459 goto cleanup;
2460 }
2461
2462 mutt_update_encoding(b, sub);
2463
2464 const bool c_edit_headers = cs_subset_bool(sub, "edit_headers");
2465 const bool c_auto_edit = cs_subset_bool(sub, "auto_edit");
2466
2467 /* Select whether or not the user's editor should be called now. We
2468 * don't want to do this when:
2469 * 1) we are sending a key/cert
2470 * 2) we are forwarding a message and the user doesn't want to edit it.
2471 * This is controlled by the quadoption $forward_edit. However, if
2472 * both $edit_headers and $auto_edit are set, we want to ignore the
2473 * setting of $forward_edit because the user probably needs to add the
2474 * recipients. */
2475 if (!(flags & SEND_KEY) &&
2476 (((flags & SEND_FORWARD) == 0) || (c_edit_headers && c_auto_edit) ||
2477 (query_quadoption(_("Edit forwarded message?"), sub, "forward_edit") == MUTT_YES)))
2478 {
2479 /* If the this isn't a text message, look for a mailcap edit command */
2480 const char *const c_editor = cs_subset_string(sub, "editor");
2481 b = e_templ->body;
2482 while (b->parts)
2483 b = b->parts;
2484 if (mutt_needs_mailcap(b))
2485 {
2486 if (!mutt_edit_attachment(b))
2487 goto cleanup;
2488 }
2489 else if (c_edit_headers)
2490 {
2491 mutt_env_to_local(e_templ->env);
2492 mutt_edit_headers(c_editor, b->filename, e_templ, fcc);
2493 mutt_env_to_intl(e_templ->env, NULL, NULL);
2494 }
2495 else
2496 {
2497 mutt_edit_file(c_editor, b->filename);
2498 if (stat(b->filename, &st) == 0)
2499 {
2500 if (mtime != st.st_mtime)
2502 }
2503 else
2504 {
2505 mutt_perror("%s", b->filename);
2506 }
2507 }
2508
2509 mutt_message_hook(NULL, e_templ, MUTT_SEND2_HOOK);
2510 }
2511
2513 {
2514 if (stat(e_templ->body->filename, &st) == 0)
2515 {
2516 /* if the file was not modified, bail out now */
2517 if ((mtime == st.st_mtime) && !e_templ->body->next &&
2518 (query_quadoption(_("Abort unmodified message?"), sub, "abort_unmodified") == MUTT_YES))
2519 {
2520 mutt_message(_("Aborted unmodified message"));
2521 goto cleanup;
2522 }
2523 }
2524 else
2525 {
2526 mutt_perror("%s", e_templ->body->filename);
2527 }
2528 }
2529 }
2530
2531 /* Set the message security unless:
2532 * 1) crypto support is not enabled (WithCrypto==0)
2533 * 2) pgp: header field was present during message editing with $edit_headers (e_templ->security != 0)
2534 * 3) we are resending a message
2535 * 4) we are recalling a postponed message (don't override the user's saved settings)
2536 * 5) we are in batch mode
2537 * But 3, 4, and 5, can be overridden with '-C' in the command line (flags & SEND_CLI_CRYPTO)
2538 *
2539 * This is done after allowing the user to edit the message so that security
2540 * settings can be configured with send2-hook and $edit_headers. */
2541 if ((WithCrypto != 0) && (e_templ->security == 0) &&
2542 ((flags & SEND_CLI_CRYPTO) || !(flags & (SEND_BATCH | SEND_POSTPONED | SEND_RESEND))))
2543 {
2544 bool c_autocrypt = false;
2545 bool c_autocrypt_reply = false;
2546
2547#ifdef USE_AUTOCRYPT
2548 c_autocrypt = cs_subset_bool(sub, "autocrypt");
2549 c_autocrypt_reply = cs_subset_bool(sub, "autocrypt_reply");
2550#endif
2551
2552 if (c_autocrypt && c_autocrypt_reply && e_cur && (e_cur->security & SEC_AUTOCRYPT))
2553 {
2555 }
2556 else
2557 {
2558 const bool c_crypt_auto_sign = cs_subset_bool(sub, "crypt_auto_sign");
2559 const bool c_crypt_auto_encrypt = cs_subset_bool(sub, "crypt_auto_encrypt");
2560 const bool c_crypt_reply_encrypt = cs_subset_bool(sub, "crypt_reply_encrypt");
2561 const bool c_crypt_reply_sign = cs_subset_bool(sub, "crypt_reply_sign");
2562 const bool c_crypt_reply_sign_encrypted = cs_subset_bool(sub, "crypt_reply_sign_encrypted");
2563
2564 if (c_crypt_auto_sign)
2565 e_templ->security |= SEC_SIGN;
2566 if (c_crypt_auto_encrypt)
2567 e_templ->security |= SEC_ENCRYPT;
2568 if (c_crypt_reply_encrypt && e_cur && (e_cur->security & SEC_ENCRYPT))
2569 e_templ->security |= SEC_ENCRYPT;
2570 if (c_crypt_reply_sign && e_cur && (e_cur->security & SEC_SIGN))
2571 e_templ->security |= SEC_SIGN;
2572 if (c_crypt_reply_sign_encrypted && e_cur && (e_cur->security & SEC_ENCRYPT))
2573 e_templ->security |= SEC_SIGN;
2574
2575 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(sub, "crypt_opportunistic_encrypt");
2576
2577 if (((WithCrypto & APPLICATION_PGP) != 0) &&
2578 ((e_templ->security & (SEC_ENCRYPT | SEC_SIGN)) || c_crypt_opportunistic_encrypt))
2579 {
2580 const bool c_pgp_auto_inline = cs_subset_bool(sub, "pgp_auto_inline");
2581 const bool c_pgp_reply_inline = cs_subset_bool(sub, "pgp_reply_inline");
2582
2583 if (c_pgp_auto_inline)
2584 e_templ->security |= SEC_INLINE;
2585 if (c_pgp_reply_inline && e_cur && (e_cur->security & SEC_INLINE))
2586 e_templ->security |= SEC_INLINE;
2587 }
2588 }
2589
2590 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(sub, "crypt_opportunistic_encrypt");
2591
2592 if (e_templ->security || c_crypt_opportunistic_encrypt)
2593 {
2594 const bool c_crypt_auto_pgp = cs_subset_bool(sub, "crypt_auto_pgp");
2595 const bool c_crypt_auto_smime = cs_subset_bool(sub, "crypt_auto_smime");
2596
2597 /* When replying / forwarding, use the original message's
2598 * crypto system. According to the documentation,
2599 * smime_is_default should be disregarded here.
2600 *
2601 * Problem: At least with forwarding, this doesn't really
2602 * make much sense. Should we have an option to completely
2603 * disable individual mechanisms at run-time? */
2604 if (e_cur)
2605 {
2606 if (((WithCrypto & APPLICATION_PGP) != 0) && c_crypt_auto_pgp &&
2607 (e_cur->security & APPLICATION_PGP))
2608 {
2609 e_templ->security |= APPLICATION_PGP;
2610 }
2611 else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
2612 c_crypt_auto_smime && (e_cur->security & APPLICATION_SMIME))
2613 {
2614 e_templ->security |= APPLICATION_SMIME;
2615 }
2616 }
2617
2618 const bool c_smime_is_default = cs_subset_bool(sub, "smime_is_default");
2619
2620 /* No crypto mechanism selected? Use availability + smime_is_default
2621 * for the decision. */
2622 if (!(e_templ->security & (APPLICATION_SMIME | APPLICATION_PGP)))
2623 {
2624 if (((WithCrypto & APPLICATION_SMIME) != 0) && c_crypt_auto_smime && c_smime_is_default)
2625 {
2626 e_templ->security |= APPLICATION_SMIME;
2627 }
2628 else if (((WithCrypto & APPLICATION_PGP) != 0) && c_crypt_auto_pgp)
2629 {
2630 e_templ->security |= APPLICATION_PGP;
2631 }
2632 else if (((WithCrypto & APPLICATION_SMIME) != 0) && c_crypt_auto_smime)
2633 {
2634 e_templ->security |= APPLICATION_SMIME;
2635 }
2636 }
2637 }
2638
2639 /* opportunistic encrypt relies on SMIME or PGP already being selected */
2640 if (c_crypt_opportunistic_encrypt)
2641 {
2642 /* If something has already enabled encryption, e.g. `$crypt_auto_encrypt`
2643 * or `$crypt_reply_encrypt`, then don't enable opportunistic encrypt for
2644 * the message. */
2645 if (!(e_templ->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)))
2646 {
2647 e_templ->security |= SEC_OPPENCRYPT;
2649 }
2650 }
2651
2652 /* No permissible mechanisms found. Don't sign or encrypt. */
2653 if (!(e_templ->security & (APPLICATION_SMIME | APPLICATION_PGP)))
2654 e_templ->security = SEC_NO_FLAGS;
2655 }
2656
2657 /* Deal with the corner case where the crypto module backend is not available.
2658 * This can happen if configured without PGP/SMIME and with GPGME, but
2659 * $crypt_use_gpgme is unset. */
2660 if (e_templ->security && !crypt_has_module_backend(e_templ->security))
2661 {
2662 mutt_error(_("No crypto backend configured. Disabling message security setting."));
2663 e_templ->security = SEC_NO_FLAGS;
2664 }
2665
2666 /* specify a default fcc. if we are in batchmode, only save a copy of
2667 * the message if the value of $copy is yes or ask-yes */
2668
2669 const enum QuadOption c_copy = cs_subset_quad(sub, "copy");
2670
2671 if (buf_is_empty(fcc) && !(flags & SEND_POSTPONED_FCC) &&
2672 (!(flags & SEND_BATCH) || (c_copy & 0x1)))
2673 {
2674 /* set the default FCC */
2675 const bool killfrom = TAILQ_EMPTY(&e_templ->env->from);
2676 if (killfrom)
2677 {
2679 }
2680 mutt_select_fcc(fcc, e_templ);
2681 if (killfrom)
2682 {
2683 mutt_addrlist_clear(&e_templ->env->from);
2684 }
2685 }
2686
2687 mutt_rfc3676_space_stuff(e_templ);
2688
2689 mutt_update_encoding(e_templ->body, sub);
2690
2691 if (!(flags & SEND_BATCH))
2692 {
2693 main_loop:
2694
2695 buf_pretty_mailbox(fcc);
2696 i = dlg_compose(e_templ, fcc,
2697 ((flags & SEND_NO_FREE_HEADER) ? MUTT_COMPOSE_NOFREEHEADER : 0), sub);
2698 if (i == -1)
2699 {
2700 /* abort */
2701 if (flags & SEND_NEWS)
2702 mutt_message(_("Article not posted"));
2703 else
2704 mutt_message(_("Mail not sent"));
2705 goto cleanup;
2706 }
2707 else if (i == 1)
2708 {
2709 if (postpone_message(e_templ, e_cur, buf_string(fcc), flags, sub) != 0)
2710 goto main_loop;
2711 mutt_message(_("Message postponed"));
2712 rc = 1;
2713 goto cleanup;
2714 }
2715 }
2716
2717 if (!(flags & SEND_NEWS))
2718 {
2719 if ((mutt_addrlist_count_recips(&e_templ->env->to) == 0) &&
2720 (mutt_addrlist_count_recips(&e_templ->env->cc) == 0) &&
2721 (mutt_addrlist_count_recips(&e_templ->env->bcc) == 0))
2722 {
2723 if (flags & SEND_BATCH)
2724 {
2725 puts(_("No recipients specified"));
2726 goto cleanup;
2727 }
2728
2729 mutt_warning(_("No recipients specified"));
2730 goto main_loop;
2731 }
2732 }
2733
2734 if (mutt_env_to_intl(e_templ->env, &tag, &err))
2735 {
2736 mutt_error(_("Bad IDN in '%s': '%s'"), tag, err);
2737 FREE(&err);
2738 if (flags & SEND_BATCH)
2739 goto cleanup;
2740 goto main_loop;
2741 }
2742
2743 const enum QuadOption c_abort_nosubject = cs_subset_quad(sub, "abort_nosubject");
2744
2745 if (!e_templ->env->subject && !(flags & SEND_BATCH) &&
2746 (query_quadoption(_("No subject, abort sending?"), sub, "abort_nosubject") != MUTT_NO))
2747 {
2748 /* if the abort is automatic, print an error message */
2749 if (c_abort_nosubject == MUTT_YES)
2750 mutt_error(_("No subject specified"));
2751 goto main_loop;
2752 }
2753
2754 if ((flags & SEND_NEWS) && !e_templ->env->subject)
2755 {
2756 mutt_error(_("No subject specified"));
2757 goto main_loop;
2758 }
2759
2760 if ((flags & SEND_NEWS) && !e_templ->env->newsgroups)
2761 {
2762 mutt_error(_("No newsgroup specified"));
2763 goto main_loop;
2764 }
2765
2766 if (!(flags & SEND_BATCH) && abort_for_missing_attachments(e_templ->body, sub))
2767 {
2768 goto main_loop;
2769 }
2770
2771 if (e_templ->body->next)
2772 e_templ->body = mutt_make_multipart(e_templ->body);
2773
2774 /* Ok, we need to do it this way instead of handling all fcc stuff in
2775 * one place in order to avoid going to main_loop with encoded "env"
2776 * in case of error. Ugh. */
2777
2778 mutt_encode_descriptions(e_templ->body, true, sub);
2779
2780 /* Make sure that clear_content and free_clear_content are
2781 * properly initialized -- we may visit this particular place in
2782 * the code multiple times, including after a failed call to
2783 * mutt_protect(). */
2784
2785 clear_content = NULL;
2786 free_clear_content = false;
2787
2788 if (WithCrypto)
2789 {
2790 if (e_templ->security & (SEC_ENCRYPT | SEC_SIGN | SEC_AUTOCRYPT))
2791 {
2792 /* save the decrypted attachments */
2793 clear_content = e_templ->body;
2794
2795 if ((crypt_get_keys(e_templ, &pgpkeylist, false) == -1) ||
2796 (mutt_protect(e_templ, pgpkeylist, false) == -1))
2797 {
2798 if (mutt_istr_equal(e_templ->body->subtype, "mixed"))
2799 e_templ->body = mutt_remove_multipart(e_templ->body);
2800
2801 FREE(&pgpkeylist);
2802
2803 decode_descriptions(e_templ->body);
2804
2805 if (flags & SEND_BATCH)
2806 {
2807 mutt_message(_("Missing encryption key; mail not sent"));
2808 rc = -1;
2809 goto cleanup;
2810 }
2811
2812 goto main_loop;
2813 }
2814 mutt_encode_descriptions(e_templ->body, false, sub);
2815 }
2816
2817 /* at this point, e_templ->body is one of the following three things:
2818 * - multipart/signed. In this case, clear_content is a child
2819 * - multipart/encrypted. In this case, clear_content exists independently
2820 * - application/pgp. In this case, clear_content exists independently
2821 * - something else. In this case, it's the same as clear_content */
2822
2823 /* This is ugly -- lack of "reporting back" from mutt_protect(). */
2824
2825 if (clear_content && (e_templ->body != clear_content) &&
2826 (e_templ->body->parts != clear_content))
2827 free_clear_content = true;
2828 }
2829
2830 if (!OptNoCurses)
2831 mutt_message(_("Sending message..."));
2832
2833 mutt_prepare_envelope(e_templ->env, true, sub);
2834
2835 const bool c_fcc_before_send = cs_subset_bool(sub, "fcc_before_send");
2836 if (c_fcc_before_send)
2837 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2838
2839 i = invoke_mta(m, e_templ, sub);
2840 if (i < 0)
2841 {
2842 if (!(flags & SEND_BATCH))
2843 {
2844 if (!WithCrypto)
2845 ; // do nothing
2846 else if ((e_templ->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) ||
2847 ((e_templ->security & SEC_SIGN) && (e_templ->body->type == TYPE_APPLICATION)))
2848 {
2849 if (e_templ->body != clear_content)
2850 {
2851 mutt_body_free(&e_templ->body); /* destroy PGP data */
2852 e_templ->body = clear_content; /* restore clear text. */
2853 }
2854 }
2855 else if ((e_templ->security & SEC_SIGN) && (e_templ->body->type == TYPE_MULTIPART))
2856 {
2857 mutt_body_free(&e_templ->body->parts->next); /* destroy sig */
2858 if (mutt_istr_equal(e_templ->body->subtype, "mixed") ||
2859 mutt_istr_equal(e_templ->body->subtype, "signed"))
2860 {
2861 e_templ->body = mutt_remove_multipart(e_templ->body);
2862 }
2863 }
2864
2865 FREE(&pgpkeylist);
2866 mutt_env_free(&e_templ->body->mime_headers); /* protected headers */
2867 mutt_param_delete(&e_templ->body->parameter, "protected-headers");
2868 if (mutt_istr_equal(e_templ->body->subtype, "mixed"))
2869 e_templ->body = mutt_remove_multipart(e_templ->body);
2870 decode_descriptions(e_templ->body);
2871 mutt_unprepare_envelope(e_templ->env);
2872 FREE(&finalpath);
2873 goto main_loop;
2874 }
2875 else
2876 {
2877 puts(_("Could not send the message"));
2878 goto cleanup;
2879 }
2880 }
2881
2882 if (!c_fcc_before_send)
2883 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2884
2885 if (!OptNoCurses)
2886 {
2887 mutt_message((i != 0) ? _("Sending in background") :
2888 (flags & SEND_NEWS) ? _("Article posted") :
2889 _("Mail sent"));
2890#ifdef USE_NOTMUCH
2891 const bool c_nm_record = cs_subset_bool(sub, "nm_record");
2892 if (c_nm_record)
2893 nm_record_message(m, finalpath, e_cur);
2894#endif
2895 mutt_sleep(0);
2896 }
2897
2898 if (WithCrypto)
2899 FREE(&pgpkeylist);
2900
2901 if ((WithCrypto != 0) && free_clear_content)
2902 mutt_body_free(&clear_content);
2903
2904 /* set 'replied' flag only if the user didn't change/remove
2905 * In-Reply-To: and References: headers during edit */
2906 if (flags & SEND_REPLY)
2907 {
2908 if (!(flags & SEND_POSTPONED) && m)
2909 {
2910 struct Email **ep = NULL;
2911 ARRAY_FOREACH(ep, ea)
2912 {
2913 struct Email *e = *ep;
2914 mutt_set_flag(m, e, MUTT_REPLIED, is_reply(e, e_templ), true);
2915 }
2916 }
2917 }
2918
2919 rc = 0;
2920
2921cleanup:
2922 buf_pool_release(&fcc);
2923
2924 if (flags & SEND_POSTPONED)
2925 {
2927 {
2928 cs_subset_str_string_set(sub, "pgp_sign_as", pgp_sign_as, NULL);
2929 FREE(&pgp_sign_as);
2930 }
2932 {
2933 cs_subset_str_string_set(sub, "smime_sign_as", smime_sign_as, NULL);
2934 FREE(&smime_sign_as);
2935 }
2936 }
2937
2938 mutt_file_fclose(&fp_tmp);
2939 if (!(flags & SEND_NO_FREE_HEADER))
2940 email_free(&e_templ);
2941
2942 FREE(&finalpath);
2943 return rc;
2944}
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1480
int mutt_addrlist_count_recips(const struct AddressList *al)
Count the number of Addresses with valid recipients.
Definition: address.c:872
void mutt_expand_aliases_env(struct Envelope *env)
Expand aliases in all the fields of an Envelope.
Definition: alias.c:309
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:304
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
#define MUTT_COMPOSE_NOFREEHEADER
Definition: lib.h:50
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:192
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition: crypt.c:157
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:961
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition: cryptglue.c:170
void mutt_edit_file(const char *editor, const char *file)
Let the user edit a file.
Definition: curs_lib.c:116
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:44
void mutt_parse_content_type(const char *s, struct Body *b)
Parse a content type.
Definition: parse.c:463
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition: parse.c:1749
int mutt_env_to_intl(struct Envelope *env, const char **tag, char **err)
Convert an Envelope's Address fields to Punycode format.
Definition: envelope.c:355
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:46
void mutt_env_to_local(struct Envelope *env)
Convert an Envelope's Address fields to local format.
Definition: envelope.c:317
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition: file.c:287
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file's modification time by 1 second.
Definition: file.c:1028
#define mutt_file_fclose(FP)
Definition: file.h:149
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:148
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
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
int dlg_compose(struct Email *e, struct Buffer *fcc, uint8_t flags, struct ConfigSubset *sub)
Allow the user to edit the message envelope -.
Definition: dlg_compose.c:305
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
void mutt_select_fcc(struct Buffer *path, struct Email *e)
Select the FCC path for an email.
Definition: hook.c:808
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:692
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:39
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:48
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:47
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
@ DISP_INLINE
Content is inline.
Definition: mime.h:62
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: multipart.c:126
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
Definition: multipart.c:100
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
@ MUTT_REPLIED
Messages that have been replied to.
Definition: mutt.h:72
bool mutt_edit_attachment(struct Body *b)
Edit an attachment.
Definition: mutt_attach.c:265
void mutt_edit_headers(const char *editor, const char *body, struct Email *e, struct Buffer *fcc)
Let the user edit the message header and body.
Definition: mutt_header.c:182
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:843
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:519
bool mutt_needs_mailcap(struct Body *b)
Does this type need a mailcap entry do display.
Definition: muttlib.c:379
#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
#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 nm_record_message(struct Mailbox *m, char *path, struct Email *e)
Add a message to the Notmuch database.
Definition: notmuch.c:1896
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:143
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:111
int mutt_num_postponed(struct Mailbox *m, bool force)
Return the number of postponed messages.
Definition: postpone.c:71
int mutt_get_postponed(struct Mailbox *m_cur, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
Recall a postponed message.
Definition: postpone.c:658
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:38
void mutt_rfc3676_space_stuff(struct Email *e)
Perform RFC3676 space stuffing on an Email.
Definition: rfc3676.c:486
static int postpone_message(struct Email *e_post, struct Email *e_cur, const char *fcc, SendFlags flags, struct ConfigSubset *sub)
Save an Email for another day.
Definition: send.c:1922
static bool is_reply(struct Email *reply, struct Email *orig)
Is one email a reply to another?
Definition: send.c:1663
static int save_fcc(struct Mailbox *m, struct Email *e, struct Buffer *fcc, struct Body *clear_content, char *pgpkeylist, SendFlags flags, char **finalpath, struct ConfigSubset *sub)
Save an Email to a 'sent mail' folder.
Definition: send.c:1727
static int envelope_defaults(struct Envelope *env, struct EmailArray *ea, SendFlags flags, struct ConfigSubset *sub)
Fill in some defaults for a new email.
Definition: send.c:1147
void mutt_fix_reply_recipients(struct Envelope *env, struct ConfigSubset *sub)
Remove duplicate recipients.
Definition: send.c:1019
static int generate_body(FILE *fp_tmp, struct Email *e, SendFlags flags, struct Mailbox *m, struct EmailArray *ea, struct ConfigSubset *sub)
Create a new email body.
Definition: send.c:1220
static void mutt_make_greeting(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add greetings string.
Definition: send.c:751
static int invoke_mta(struct Mailbox *m, struct Email *e, struct ConfigSubset *sub)
Send an email.
Definition: send.c:1491
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
Definition: send.c:1458
static void process_user_recips(struct Envelope *env)
Process the user headers.
Definition: send.c:376
static void process_user_header(struct Envelope *env)
Process the user headers.
Definition: send.c:401
static int edit_envelope(struct Envelope *en, SendFlags flags, struct ConfigSubset *sub)
Edit Envelope fields.
Definition: send.c:234
static bool abort_for_missing_attachments(const struct Body *b, struct ConfigSubset *sub)
Should we abort sending because of missing attachments?
Definition: send.c:2047
static void set_reverse_name(struct AddressList *al, struct Envelope *env, struct ConfigSubset *sub)
Try to set the 'from' field from the recipients.
Definition: send.c:1405
static void fix_end_of_file(const char *data)
Ensure a file ends with a linefeed.
Definition: send.c:1589
static bool is_text_plain(const struct Body *b)
Is a Body a text/plain MIME part?
Definition: send.c:2036
static void decode_descriptions(struct Body *b)
RFC2047 decode them in case of an error.
Definition: send.c:1572
static void append_signature(FILE *fp, struct ConfigSubset *sub)
Append a signature to an email.
Definition: send.c:108
#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_BATCH
Send email in batch mode (without user interaction)
Definition: send.h:47
#define SEND_NO_FREE_HEADER
Used by the -E flag.
Definition: send.h:51
#define SEND_DRAFT_FILE
Used by the -H flag.
Definition: send.h:52
#define SEND_KEY
Mail a PGP public key.
Definition: send.h:48
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:46
#define SEND_CONSUMED_STDIN
stdin has been read; don't read it twice
Definition: send.h:57
#define SEND_CLI_CRYPTO
Enable message security in modes that by default don't enable it.
Definition: send.h:58
#define SEND_REPLY
Reply to sender.
Definition: send.h:42
#define SEND_NEWS
Reply to a news article.
Definition: send.h:55
#define SEND_FORWARD
Forward email.
Definition: send.h:45
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
Definition: sendlib.c:422
void mutt_unprepare_envelope(struct Envelope *env)
Undo the encodings of mutt_prepare_envelope()
Definition: sendlib.c:819
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition: sendlib.c:780
struct Buffer * personal
Real name of address.
Definition: address.h:37
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:68
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:76
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:63
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:47
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:42
char * subtype
content-type subtype
Definition: body.h:61
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:59
struct Envelope * env
Envelope information.
Definition: email.h:68
struct Body * body
List of MIME parts.
Definition: email.h:69
bool replied
Email has been replied to.
Definition: email.h:51
struct AddressList x_original_to
Email's 'X-Original-to'.
Definition: envelope.h:66
char * newsgroups
List of newsgroups.
Definition: envelope.h:78
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
char * list_post
This stores a mailto URL, or nothing.
Definition: envelope.h:67
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
void * mdata
Driver specific data.
Definition: mailbox.h:132
NNTP-specific Mailbox data -.
Definition: mdata.h:34
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:386
#define buf_mktemp(buf)
Definition: tmp.h:33
+ Here is the caller graph for this function:

◆ mutt_set_followup_to()

void mutt_set_followup_to ( struct Envelope env,
struct ConfigSubset sub 
)

Set followup-to field.

Parameters
envEnvelope to modify
subConfig Subset

Definition at line 1334 of file send.c.

1335{
1336 /* Only generate the Mail-Followup-To if the user has requested it, and
1337 * it hasn't already been set */
1338
1339 const bool c_followup_to = cs_subset_bool(sub, "followup_to");
1340 if (!c_followup_to)
1341 return;
1342 if (OptNewsSend)
1343 {
1344 if (!env->followup_to && env->newsgroups && (strrchr(env->newsgroups, ',')))
1345 env->followup_to = mutt_str_dup(env->newsgroups);
1346 return;
1347 }
1348
1349 if (TAILQ_EMPTY(&env->mail_followup_to))
1350 {
1351 if (mutt_is_list_recipient(false, env))
1352 {
1353 /* this message goes to known mailing lists, so create a proper
1354 * mail-followup-to header */
1355
1356 mutt_addrlist_copy(&env->mail_followup_to, &env->to, false);
1357 mutt_addrlist_copy(&env->mail_followup_to, &env->cc, true);
1358 }
1359
1360 /* remove ourselves from the mail-followup-to header */
1361 remove_user(&env->mail_followup_to, false);
1362
1363 /* If we are not subscribed to any of the lists in question, re-add
1364 * ourselves to the mail-followup-to header. The mail-followup-to header
1365 * generated is a no-op with group-reply, but makes sure list-reply has the
1366 * desired effect. */
1367
1368 if (!TAILQ_EMPTY(&env->mail_followup_to) &&
1370 {
1371 struct AddressList *al = NULL;
1372 if (!TAILQ_EMPTY(&env->reply_to))
1373 al = &env->reply_to;
1374 else if (!TAILQ_EMPTY(&env->from))
1375 al = &env->from;
1376
1377 if (al)
1378 {
1379 struct Address *a = NULL;
1380 TAILQ_FOREACH_REVERSE(a, al, AddressList, entries)
1381 {
1383 }
1384 }
1385 else
1386 {
1388 }
1389 }
1390
1392 }
1393}
void mutt_addrlist_prepend(struct AddressList *al, struct Address *a)
Prepend an Address to an AddressList.
Definition: address.c:1491
bool mutt_is_subscribed_list_recipient(bool all_addr, struct Envelope *env)
Matches subscribed mailing lists.
Definition: exec.c:478
bool mutt_is_list_recipient(bool all_addr, struct Envelope *env)
Matches known mailing lists.
Definition: exec.c:491
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:745
char * followup_to
List of 'followup-to' fields.
Definition: envelope.h:80
struct AddressList reply_to
Email's 'reply-to'.
Definition: envelope.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_send_list_subscribe()

bool mutt_send_list_subscribe ( struct Mailbox m,
struct Email e 
)

Send a mailing-list subscription email.

Parameters
mMailbox
eEmail carrying mailing-list subscription headers
Return values
trueSuccess
falseFailure

Definition at line 3007 of file send.c.

3008{
3009 if (!e || !e->env)
3010 {
3011 return false;
3012 }
3013
3014 const char *mailto = e->env->list_subscribe;
3015 if (!mailto)
3016 {
3017 mutt_warning(_("No List-Subscribe header found"));
3018 return false;
3019 }
3020
3021 struct EmailArray ea = ARRAY_HEAD_INITIALIZER;
3022 ARRAY_ADD(&ea, e);
3023 bool rc = send_simple_email(m, &ea, mailto, "Subscribe", "subscribe");
3024 ARRAY_FREE(&ea);
3025
3026 return rc;
3027}
static bool send_simple_email(struct Mailbox *m, struct EmailArray *ea, const char *mailto, const char *subj, const char *body)
Compose an email given a few basic ingredients.
Definition: send.c:2956
char * list_subscribe
This stores a mailto URL, or nothing.
Definition: envelope.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_send_list_unsubscribe()

bool mutt_send_list_unsubscribe ( struct Mailbox m,
struct Email e 
)

Send a mailing-list unsubscription email.

Parameters
mMailbox
eEmail carrying mailing-list unsubscription headers
Return values
trueSuccess
falseFailure

Definition at line 3036 of file send.c.

3037{
3038 if (!e || !e->env)
3039 {
3040 return false;
3041 }
3042
3043 const char *mailto = e->env->list_unsubscribe;
3044 if (!mailto)
3045 {
3046 mutt_warning(_("No List-Unsubscribe header found"));
3047 return false;
3048 }
3049
3050 struct EmailArray ea = ARRAY_HEAD_INITIALIZER;
3051 ARRAY_ADD(&ea, e);
3052 bool rc = send_simple_email(m, &ea, mailto, "Unsubscribe", "unsubscribe");
3053 ARRAY_FREE(&ea);
3054
3055 return rc;
3056}
char * list_unsubscribe
This stores a mailto URL, or nothing.
Definition: envelope.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function: