Send an email.
2037{
2039 FILE *fp_tmp = NULL;
2040 struct Body *pbody = NULL;
2041 int i;
2042 bool free_clear_content = false;
2043
2044 struct Body *clear_content = NULL;
2045 char *pgpkeylist = NULL;
2046
2047 char *pgp_sign_as = NULL;
2048 char *smime_sign_as = NULL;
2049 const char *tag = NULL;
2050 char *err = NULL;
2051 const char *ctype = NULL;
2052 char *finalpath = NULL;
2053 struct Email *e_cur = NULL;
2054
2057
2058 int rc = -1;
2059
2062 else
2064
2066
2068 {
2069
2070
2073 return rc;
2074
2077 }
2078
2080 {
2082 {
2085 }
2087 {
2088 const char *
const c_smime_sign_as =
cs_subset_string(sub,
"smime_sign_as");
2090 }
2091 }
2092
2093
2094
2095
2096
2097 if (!e_templ)
2098 {
2100
2102 {
2104 if (rc < 0)
2105 {
2107 goto cleanup;
2108 }
2109 flags = rc;
2110
2111
2113 {
2116 }
2117 else
2118 {
2121 }
2122 }
2123
2125 {
2130 if (!fp_tmp)
2131 {
2133 goto cleanup;
2134 }
2135 }
2136
2139 }
2140
2141
2143 {
2144
2146
2148 }
2149
2151 {
2152
2153
2155 {
2158 e_templ->
body = pbody;
2159
2161 ctype = c_content_type;
2162 if (!ctype)
2163 ctype = "text/plain";
2168
2169 if (tempfile)
2170 {
2175 }
2176 else
2177 {
2183 }
2184 }
2185 else
2186 {
2191 }
2192
2193 if (!fp_tmp)
2194 {
2198 goto cleanup;
2199 }
2200 }
2201
2203
2205 {
2206
2207
2208
2209
2210
2211
2213 {
2217 }
2219 }
2220
2221 const bool c_reply_with_xorig =
cs_subset_bool(sub,
"reply_with_xorig");
2223 {
2224
2225
2226
2227
2228
2229
2230
2231
2233 {
2237 }
2238 }
2239
2242
2243 const bool c_resume_draft_files =
cs_subset_bool(sub,
"resume_draft_files");
2246 {
2249 {
2250 goto cleanup;
2251 }
2252
2254 if (c_hdrs)
2256
2257
2259
2262
2264 {
2266 }
2267
2271 if (!(flags &
SEND_BATCH) && !(c_auto_edit && c_edit_headers) &&
2273 {
2275 goto cleanup;
2276 }
2277
2278
2279
2280
2281
2282
2284 if (killfrom)
2285 {
2287 }
2288
2290 {
2291
2293
2294
2295
2296
2298 }
2299
2300
2301
2303
2304
2305
2306
2307
2309
2310
2311 if (killfrom)
2312 {
2314
2318 }
2319
2320 if (c_hdrs)
2322
2324 {
2326 {
2328 goto cleanup;
2329 }
2330 }
2331
2334
2338 {
2340 }
2341
2342
2345 {
2346 goto cleanup;
2347 }
2348
2350 {
2352 }
2353 }
2354
2355
2356
2357
2358
2360 {
2363 {
2365 }
2366 }
2367
2368
2369
2371
2372
2373
2374 {
2377 {
2379 if (c_real_name)
2381 }
2382 }
2383
2386
2388 {
2389 struct stat st = { 0 };
2390 time_t mtime;
2395 if (mtime == (time_t) -1)
2396 {
2398 goto cleanup;
2399 }
2400
2402
2405
2406
2407
2408
2409
2410
2411
2412
2413
2415 (((flags &
SEND_FORWARD) == 0) || (c_edit_headers && c_auto_edit) ||
2417 {
2418
2424 {
2426 goto cleanup;
2427 }
2428 else if (c_edit_headers)
2429 {
2433 }
2434 else
2435 {
2438 {
2439 if (mtime != st.st_mtime)
2441 }
2442 else
2443 {
2445 }
2446 }
2447
2449 }
2450
2452 {
2454 {
2455
2456 if ((mtime == st.st_mtime) && !e_templ->
body->
next &&
2458 {
2460 goto cleanup;
2461 }
2462 }
2463 else
2464 {
2466 }
2467 }
2468 }
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2482 {
2483 bool c_autocrypt = false;
2484 bool c_autocrypt_reply = false;
2485
2486#ifdef USE_AUTOCRYPT
2489#endif
2490
2492 {
2494 }
2495 else
2496 {
2497 const bool c_crypt_auto_sign =
cs_subset_bool(sub,
"crypt_auto_sign");
2498 const bool c_crypt_auto_encrypt =
cs_subset_bool(sub,
"crypt_auto_encrypt");
2499 const bool c_crypt_reply_encrypt =
cs_subset_bool(sub,
"crypt_reply_encrypt");
2500 const bool c_crypt_reply_sign =
cs_subset_bool(sub,
"crypt_reply_sign");
2501 const bool c_crypt_reply_sign_encrypted =
cs_subset_bool(sub,
"crypt_reply_sign_encrypted");
2502
2503 if (c_crypt_auto_sign)
2505 if (c_crypt_auto_encrypt)
2513
2514 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2515
2518 {
2519 const bool c_pgp_auto_inline =
cs_subset_bool(sub,
"pgp_auto_inline");
2520 const bool c_pgp_reply_inline =
cs_subset_bool(sub,
"pgp_reply_inline");
2521
2522 if (c_pgp_auto_inline)
2526 }
2527 }
2528
2529 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2530
2531 if (e_templ->
security || c_crypt_opportunistic_encrypt)
2532 {
2533 const bool c_crypt_auto_pgp =
cs_subset_bool(sub,
"crypt_auto_pgp");
2534 const bool c_crypt_auto_smime =
cs_subset_bool(sub,
"crypt_auto_smime");
2535
2536
2537
2538
2539
2540
2541
2542
2543 if (e_cur)
2544 {
2547 {
2549 }
2552 {
2554 }
2555 }
2556
2557 const bool c_smime_is_default =
cs_subset_bool(sub,
"smime_is_default");
2558
2559
2560
2562 {
2564 {
2566 }
2568 {
2570 }
2572 {
2574 }
2575 }
2576 }
2577
2578
2579 if (c_crypt_opportunistic_encrypt)
2580 {
2581
2582
2583
2585 {
2588 }
2589 }
2590
2591
2594 }
2595
2596
2597
2598
2600 {
2601 mutt_error(
_(
"No crypto backend configured. Disabling message security setting."));
2603 }
2604
2605
2606
2607
2609
2612 {
2613
2615 if (killfrom)
2616 {
2618 }
2620 if (killfrom)
2621 {
2623 }
2624 }
2625
2627
2629
2631 {
2632 main_loop:
2633
2637 if (i == -1)
2638 {
2639
2642 else
2644 goto cleanup;
2645 }
2646 else if (i == 1)
2647 {
2649 goto main_loop;
2651 rc = 1;
2652 goto cleanup;
2653 }
2654 }
2655
2657 {
2661 {
2663 {
2664 puts(
_(
"No recipients specified"));
2665 goto cleanup;
2666 }
2667
2669 goto main_loop;
2670 }
2671 }
2672
2674 {
2678 goto cleanup;
2679 goto main_loop;
2680 }
2681
2683
2686 {
2687
2690 goto main_loop;
2691 }
2692
2694 {
2696 goto main_loop;
2697 }
2698
2700 {
2702 goto main_loop;
2703 }
2704
2706 {
2707 goto main_loop;
2708 }
2709
2710 const bool c_confirm_empty_to =
cs_subset_bool(sub,
"confirm_empty_to");
2713 {
2714 goto main_loop;
2715 }
2716
2719
2720
2721
2722
2723
2725
2726
2727
2728
2729
2730
2731 clear_content = NULL;
2732 free_clear_content = false;
2733
2735 {
2737 {
2738
2739 clear_content = e_templ->
body;
2740
2743 {
2746
2748
2750
2752 {
2754 rc = -1;
2755 goto cleanup;
2756 }
2757
2758 goto main_loop;
2759 }
2761 }
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771 if (clear_content && (e_templ->
body != clear_content) &&
2772 (e_templ->
body->
parts != clear_content))
2773 free_clear_content = true;
2774 }
2775
2778
2780
2781 const bool c_fcc_before_send =
cs_subset_bool(sub,
"fcc_before_send");
2782 if (c_fcc_before_send)
2783 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2784
2786 if (i < 0)
2787 {
2789 {
2791 ;
2794 {
2795 if (e_templ->
body != clear_content)
2796 {
2798 e_templ->
body = clear_content;
2799 }
2800 }
2802 {
2806 {
2808 }
2809 }
2810
2819 goto main_loop;
2820 }
2821 else
2822 {
2823 puts(
_(
"Could not send the message"));
2824 goto cleanup;
2825 }
2826 }
2827
2828 if (!c_fcc_before_send)
2829 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2830
2832 {
2836#ifdef USE_NOTMUCH
2838 if (c_nm_record)
2840#endif
2842 }
2843
2846
2849
2850
2851
2853 {
2855 {
2856 struct Email **ep = NULL;
2858 {
2859 struct Email *e = *ep;
2861 }
2862 }
2863 }
2864
2865 rc = 0;
2866
2867cleanup:
2869
2871 {
2873 {
2876 }
2878 {
2880 FREE(&smime_sign_as);
2881 }
2882 }
2883
2887
2889 return rc;
2890}
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.
#define MUTT_COMPOSE_NOFREEHEADER
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 mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
#define MUTT_SEND_HOOK
send-hook: when composing a new email
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
@ 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 buf_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.