Send an email.
2034{
2036 FILE *fp_tmp = NULL;
2037 struct Body *pbody = NULL;
2038 int i;
2039 bool free_clear_content = false;
2040
2041 struct Body *clear_content = NULL;
2042 char *pgpkeylist = NULL;
2043
2044 char *pgp_sign_as = NULL;
2045 char *smime_sign_as = NULL;
2046 const char *tag = NULL;
2047 char *err = NULL;
2048 const char *ctype = NULL;
2049 char *finalpath = NULL;
2050 struct Email *e_cur = NULL;
2051
2054
2055 int rc = -1;
2056
2059 else
2061
2063
2065 {
2066
2067
2070 return rc;
2071
2074 }
2075
2077 {
2079 {
2082 }
2084 {
2085 const char *
const c_smime_sign_as =
cs_subset_string(sub,
"smime_sign_as");
2087 }
2088 }
2089
2090
2091
2092
2093
2094 if (!e_templ)
2095 {
2097
2099 {
2101 if (rc < 0)
2102 {
2104 goto cleanup;
2105 }
2106 flags = rc;
2107
2108
2110 {
2113 }
2114 else
2115 {
2118 }
2119 }
2120
2122 {
2127 if (!fp_tmp)
2128 {
2130 goto cleanup;
2131 }
2132 }
2133
2136 }
2137
2138
2140 {
2141
2143
2145 }
2146
2148 {
2149
2150
2152 {
2155 e_templ->
body = pbody;
2156
2158 ctype = c_content_type;
2159 if (!ctype)
2160 ctype = "text/plain";
2165
2166 if (tempfile)
2167 {
2172 }
2173 else
2174 {
2180 }
2181 }
2182 else
2183 {
2188 }
2189
2190 if (!fp_tmp)
2191 {
2195 goto cleanup;
2196 }
2197 }
2198
2200
2202 {
2203
2204
2205
2206
2207
2208
2210 {
2214 }
2216 }
2217
2218 const bool c_reply_with_xorig =
cs_subset_bool(sub,
"reply_with_xorig");
2220 {
2221
2222
2223
2224
2225
2226
2227
2228
2230 {
2234 }
2235 }
2236
2239
2240 const bool c_resume_draft_files =
cs_subset_bool(sub,
"resume_draft_files");
2243 {
2246 {
2247 goto cleanup;
2248 }
2249
2251 if (c_hdrs)
2253
2254
2256
2259
2261 {
2263 }
2264
2268 if (!(flags &
SEND_BATCH) && !(c_auto_edit && c_edit_headers) &&
2270 {
2272 goto cleanup;
2273 }
2274
2275
2276
2277
2278
2279
2281 if (killfrom)
2282 {
2284 }
2285
2287 {
2288
2290
2291
2292
2293
2295 }
2296
2297
2298
2300
2301
2302
2303
2304
2306
2307
2308 if (killfrom)
2309 {
2311
2315 }
2316
2317 if (c_hdrs)
2319
2321 {
2323 {
2325 goto cleanup;
2326 }
2327 }
2328
2331
2335 {
2337 }
2338
2339
2342 {
2343 goto cleanup;
2344 }
2345
2347 {
2349 }
2350 }
2351
2352
2353
2354
2355
2357 {
2360 {
2362 }
2363 }
2364
2365
2366
2368
2369
2370
2371 {
2374 {
2376 if (c_real_name)
2378 }
2379 }
2380
2383
2385 {
2386 struct stat st = { 0 };
2387 time_t mtime;
2392 if (mtime == (time_t) -1)
2393 {
2395 goto cleanup;
2396 }
2397
2399
2402
2403
2404
2405
2406
2407
2408
2409
2410
2412 (((flags &
SEND_FORWARD) == 0) || (c_edit_headers && c_auto_edit) ||
2414 {
2415
2421 {
2423 goto cleanup;
2424 }
2425 else if (c_edit_headers)
2426 {
2430 }
2431 else
2432 {
2435 {
2436 if (mtime != st.st_mtime)
2438 }
2439 else
2440 {
2442 }
2443 }
2444
2446 }
2447
2449 {
2451 {
2452
2453 if ((mtime == st.st_mtime) && !e_templ->
body->
next &&
2455 {
2457 goto cleanup;
2458 }
2459 }
2460 else
2461 {
2463 }
2464 }
2465 }
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2479 {
2480 bool c_autocrypt = false;
2481 bool c_autocrypt_reply = false;
2482
2483#ifdef USE_AUTOCRYPT
2486#endif
2487
2489 {
2491 }
2492 else
2493 {
2494 const bool c_crypt_auto_sign =
cs_subset_bool(sub,
"crypt_auto_sign");
2495 const bool c_crypt_auto_encrypt =
cs_subset_bool(sub,
"crypt_auto_encrypt");
2496 const bool c_crypt_reply_encrypt =
cs_subset_bool(sub,
"crypt_reply_encrypt");
2497 const bool c_crypt_reply_sign =
cs_subset_bool(sub,
"crypt_reply_sign");
2498 const bool c_crypt_reply_sign_encrypted =
cs_subset_bool(sub,
"crypt_reply_sign_encrypted");
2499
2500 if (c_crypt_auto_sign)
2502 if (c_crypt_auto_encrypt)
2510
2511 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2512
2515 {
2516 const bool c_pgp_auto_inline =
cs_subset_bool(sub,
"pgp_auto_inline");
2517 const bool c_pgp_reply_inline =
cs_subset_bool(sub,
"pgp_reply_inline");
2518
2519 if (c_pgp_auto_inline)
2523 }
2524 }
2525
2526 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2527
2528 if (e_templ->
security || c_crypt_opportunistic_encrypt)
2529 {
2530 const bool c_crypt_auto_pgp =
cs_subset_bool(sub,
"crypt_auto_pgp");
2531 const bool c_crypt_auto_smime =
cs_subset_bool(sub,
"crypt_auto_smime");
2532
2533
2534
2535
2536
2537
2538
2539
2540 if (e_cur)
2541 {
2544 {
2546 }
2549 {
2551 }
2552 }
2553
2554 const bool c_smime_is_default =
cs_subset_bool(sub,
"smime_is_default");
2555
2556
2557
2559 {
2561 {
2563 }
2565 {
2567 }
2569 {
2571 }
2572 }
2573 }
2574
2575
2576 if (c_crypt_opportunistic_encrypt)
2577 {
2578
2579
2580
2582 {
2585 }
2586 }
2587
2588
2591 }
2592
2593
2594
2595
2597 {
2598 mutt_error(
_(
"No crypto backend configured. Disabling message security setting."));
2600 }
2601
2602
2603
2604
2606
2609 {
2610
2612 if (killfrom)
2613 {
2615 }
2617 if (killfrom)
2618 {
2620 }
2621 }
2622
2624
2626
2628 {
2629 main_loop:
2630
2634 if (i == -1)
2635 {
2636
2639 else
2641 goto cleanup;
2642 }
2643 else if (i == 1)
2644 {
2646 goto main_loop;
2648 rc = 1;
2649 goto cleanup;
2650 }
2651 }
2652
2654 {
2658 {
2660 {
2661 puts(
_(
"No recipients specified"));
2662 goto cleanup;
2663 }
2664
2666 goto main_loop;
2667 }
2668 }
2669
2671 {
2675 goto cleanup;
2676 goto main_loop;
2677 }
2678
2680
2683 {
2684
2687 goto main_loop;
2688 }
2689
2691 {
2693 goto main_loop;
2694 }
2695
2697 {
2699 goto main_loop;
2700 }
2701
2703 {
2704 goto main_loop;
2705 }
2706
2707 const bool c_confirm_empty_to =
cs_subset_bool(sub,
"confirm_empty_to");
2710 {
2711 goto main_loop;
2712 }
2713
2716
2717
2718
2719
2720
2722
2723
2724
2725
2726
2727
2728 clear_content = NULL;
2729 free_clear_content = false;
2730
2732 {
2734 {
2735
2736 clear_content = e_templ->
body;
2737
2740 {
2743
2745
2747
2749 {
2751 rc = -1;
2752 goto cleanup;
2753 }
2754
2755 goto main_loop;
2756 }
2758 }
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768 if (clear_content && (e_templ->
body != clear_content) &&
2769 (e_templ->
body->
parts != clear_content))
2770 free_clear_content = true;
2771 }
2772
2775
2777
2778 const bool c_fcc_before_send =
cs_subset_bool(sub,
"fcc_before_send");
2779 if (c_fcc_before_send)
2780 {
2781 if (
save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub) &&
2783 {
2784
2785 puts(
_(
"Fcc failed. Aborting sending."));
2786 goto cleanup;
2787 }
2788 }
2789
2791 if (i < 0)
2792 {
2794 {
2796 ;
2799 {
2800 if (e_templ->
body != clear_content)
2801 {
2803 e_templ->
body = clear_content;
2804 }
2805 }
2807 {
2811 {
2813 }
2814 }
2815
2824 goto main_loop;
2825 }
2826 else
2827 {
2828 puts(
_(
"Could not send the message"));
2829 goto cleanup;
2830 }
2831 }
2832
2833 if (!c_fcc_before_send)
2834 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2835
2837 {
2841#ifdef USE_NOTMUCH
2843 if (c_nm_record)
2845#endif
2847 }
2848
2851
2854
2855
2856
2858 {
2860 {
2861 struct Email **ep = NULL;
2863 {
2864 struct Email *e = *ep;
2866 }
2867 }
2868 }
2869
2870 rc = 0;
2871
2872cleanup:
2874
2876 {
2878 {
2881 }
2883 {
2885 FREE(&smime_sign_as);
2886 }
2887 }
2888
2892
2894 return rc;
2895}
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
int mutt_addrlist_count_recips(const struct AddressList *al)
Count the number of Addresses with valid recipients.
void mutt_expand_aliases_env(struct Envelope *env)
Expand aliases in all the fields of an Envelope.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_SIZE(head)
The number of elements stored.
#define ARRAY_GET(head, idx)
Return the element at index.
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
@ CMD_SEND_HOOK
:send-hook
@ CMD_SEND2_HOOK
:send2-hook
@ CMD_REPLY_HOOK
:reply-hook
#define MUTT_COMPOSE_NOFREEHEADER
Don't free the header when closing compose dialog.
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
void mutt_edit_file(const char *editor, const char *file)
Let the user edit a file.
void mutt_body_free(struct Body **ptr)
Free a Body.
struct Body * mutt_body_new(void)
Create a new Body.
void mutt_parse_content_type(const char *s, struct Body *b)
Parse a content type.
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
int mutt_env_to_intl(struct Envelope *env, const char **tag, char **err)
Convert an Envelope's Address fields to Punycode format.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
struct Envelope * mutt_env_new(void)
Create a new Envelope.
void mutt_env_to_local(struct Envelope *env)
Convert an Envelope's Address fields to local format.
char * msgid_generate(void)
Generate a Message-ID.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file's modification time by 1 second.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
bool OptGui
(pseudo) when the gui (and curses) are started
int dlg_compose(struct Email *e, struct Buffer *fcc, uint8_t flags, struct ConfigSubset *sub)
Allow the user to edit the message envelope -.
#define mutt_warning(...)
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
void mutt_select_fcc(struct Buffer *path, struct Email *e)
Select the FCC path for an email.
void exec_message_hook(struct Mailbox *m, struct Email *e, enum CommandId id)
Perform a message hook.
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG1
Log at debug level 1.
@ TYPE_MULTIPART
Type: 'multipart/*'.
@ TYPE_APPLICATION
Type: 'application/*'.
@ DISP_INLINE
Content is inline.
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
@ MUTT_REPLIED
Messages that have been replied to.
bool mutt_edit_attachment(struct Body *b)
Edit an attachment.
void mutt_sleep(short s)
Sleep for a while.
void pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
bool mutt_needs_mailcap(struct Body *b)
Does this type need a mailcap entry do display.
#define SEC_INLINE
Email has an inline signature.
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
#define SEC_NO_FLAGS
No flags are set.
#define SEC_ENCRYPT
Email is encrypted.
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
#define SEC_SIGN
Email is signed.
int nm_record_message(struct Mailbox *m, char *path, struct Email *e)
Add a message to the Notmuch database.
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
int mutt_num_postponed(struct Mailbox *m, bool force)
Return the number of postponed messages.
int mutt_get_postponed(struct Mailbox *m_cur, struct Email *hdr, struct Email **cur, struct Buffer *fcc)
Recall a postponed message.
@ MUTT_NO
User answered 'No', or assume 'No'.
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
void mutt_rfc3676_space_stuff(struct Email *e)
Perform RFC3676 space stuffing on an Email.
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.
static bool is_reply(struct Email *reply, struct Email *orig)
Is one email a reply to another?
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.
static int envelope_defaults(struct Envelope *env, struct EmailArray *ea, SendFlags flags, struct ConfigSubset *sub)
Fill in some defaults for a new email.
void mutt_fix_reply_recipients(struct Envelope *env, struct ConfigSubset *sub)
Remove duplicate recipients.
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.
static void mutt_make_greeting(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add greetings string.
static int invoke_mta(struct Mailbox *m, struct Email *e, struct ConfigSubset *sub)
Send an email.
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
static void process_user_recips(struct Envelope *env)
Process the user headers.
static void process_user_header(struct Envelope *env)
Process the user headers.
static int edit_envelope(struct Envelope *en, SendFlags flags, struct ConfigSubset *sub)
Edit Envelope fields.
static bool abort_for_missing_attachments(const struct Body *b, struct ConfigSubset *sub)
Should we abort sending because of missing attachments?
static void set_reverse_name(struct AddressList *al, struct Envelope *env, struct ConfigSubset *sub)
Try to set the 'from' field from the recipients.
static void fix_end_of_file(const char *data)
Ensure a file ends with a linefeed.
static bool is_text_plain(const struct Body *b)
Is a Body a text/plain MIME part?
static void decode_descriptions(struct Body *b)
RFC2047 decode them in case of an error.
static void append_signature(FILE *fp, struct ConfigSubset *sub)
Append a signature to an email.
#define SEND_POSTPONED_FCC
Used by mutt_get_postponed() to signal that the Mutt-Fcc header field was present.
#define SEND_BATCH
Send email in batch mode (without user interaction)
#define SEND_NO_FREE_HEADER
Used by the -E flag.
#define SEND_DRAFT_FILE
Used by the -H flag.
#define SEND_KEY
Mail a PGP public key.
#define SEND_POSTPONED
Recall a postponed email.
#define SEND_CONSUMED_STDIN
stdin has been read; don't read it twice
#define SEND_CLI_CRYPTO
Enable message security in modes that by default don't enable it.
#define SEND_REPLY
Reply to sender.
#define SEND_NEWS
Reply to a news article.
#define SEND_FORWARD
Forward email.
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
void mutt_unprepare_envelope(struct Envelope *env)
Undo the encodings of mutt_prepare_envelope()
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
struct Buffer * personal
Real name of address.
struct Body * parts
parts of a multipart or message/rfc822
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
struct Envelope * mime_headers
Memory hole protected headers.
struct ParameterList parameter
Parameters of the content-type.
bool use_disp
Content-Disposition uses filename= ?
unsigned int disposition
content-disposition, ContentDisposition
char * subtype
content-type subtype
unsigned int type
content-type primary type, ContentType
char * filename
When sending a message, this is the file to which this structure refers.
struct Envelope * env
Envelope information.
struct Body * body
List of MIME parts.
bool replied
Email has been replied to.
char * message_id
Message ID.
struct AddressList x_original_to
Email's 'X-Original-to'.
char * newsgroups
List of newsgroups.
struct AddressList bcc
Email's 'Bcc' list.
char * list_post
This stores a mailto URL, or nothing.
enum MailboxType type
Mailbox type.
void * mdata
Driver specific data.
NNTP-specific Mailbox data -.
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.
#define buf_mktemp_draft(buf)