Send an email.
2101{
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
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
2121
2122 int rc = -1;
2123
2126 else
2128
2130
2132 {
2133
2134
2137 return rc;
2138
2141 }
2142
2144 {
2146 {
2149 }
2151 {
2152 const char *
const c_smime_sign_as =
cs_subset_string(sub,
"smime_sign_as");
2154 }
2155 }
2156
2157
2158
2159
2160
2161 if (!e_templ)
2162 {
2164
2166 {
2168 if (rc < 0)
2169 {
2171 goto cleanup;
2172 }
2173 flags = rc;
2174
2175
2177 {
2180 }
2181 else
2182 {
2183 flags &= ~SEND_NEWS;
2185 }
2186 }
2187
2189 {
2194 if (!fp_tmp)
2195 {
2197 goto cleanup;
2198 }
2199 }
2200
2203 }
2204
2205
2207 {
2208
2210
2212 }
2213
2215 {
2216
2217
2219 {
2222 e_templ->
body = pbody;
2223
2225 ctype = c_content_type;
2226 if (!ctype)
2227 ctype = "text/plain";
2232
2233 if (tempfile)
2234 {
2239 }
2240 else
2241 {
2247 }
2248 }
2249 else
2250 {
2255 }
2256
2257 if (!fp_tmp)
2258 {
2262 goto cleanup;
2263 }
2264 }
2265
2267
2269 {
2270
2271
2272
2273
2274
2275
2277 {
2281 }
2283 }
2284
2285 const bool c_reply_with_xorig =
cs_subset_bool(sub,
"reply_with_xorig");
2287 {
2288
2289
2290
2291
2292
2293
2294
2295
2297 {
2301 }
2302 }
2303
2306
2307 const bool c_resume_draft_files =
cs_subset_bool(sub,
"resume_draft_files");
2310 {
2313 {
2314 goto cleanup;
2315 }
2316
2318 if (c_hdrs)
2320
2321
2323
2326
2328 {
2330 }
2331
2335 if (!(flags &
SEND_BATCH) && !(c_auto_edit && c_edit_headers) &&
2337 {
2339 goto cleanup;
2340 }
2341
2342
2343
2344
2345
2346
2348 if (killfrom)
2349 {
2351 }
2352
2354 {
2355
2357
2358
2359
2360
2362 }
2363
2364
2365
2367
2368
2369
2370
2371
2373
2374
2375 if (killfrom)
2376 {
2378
2382 }
2383
2384 if (c_hdrs)
2386
2388 {
2390 {
2392 goto cleanup;
2393 }
2394 }
2395
2398
2402 {
2404 }
2405
2406
2409 {
2410 goto cleanup;
2411 }
2412
2414 {
2416 }
2417 }
2418
2419
2420
2421
2422
2424 {
2427 {
2429 }
2430 }
2431
2432
2433
2435
2436
2437
2438 {
2441 {
2443 if (c_real_name)
2445 }
2446 }
2447
2450
2452 {
2453 struct stat st = { 0 };
2454 time_t mtime;
2459 if (mtime == (time_t) -1)
2460 {
2462 goto cleanup;
2463 }
2464
2466
2469
2470
2471
2472
2473
2474
2475
2476
2477
2479 (((flags &
SEND_FORWARD) == 0) || (c_edit_headers && c_auto_edit) ||
2481 {
2482
2488 {
2490 goto cleanup;
2491 }
2492 else if (c_edit_headers)
2493 {
2497 }
2498 else
2499 {
2502 {
2503 if (mtime != st.st_mtime)
2505 }
2506 else
2507 {
2509 }
2510 }
2511
2513 }
2514
2516 {
2518 {
2519
2520 if ((mtime == st.st_mtime) && !e_templ->
body->
next &&
2522 {
2524 goto cleanup;
2525 }
2526 }
2527 else
2528 {
2530 }
2531 }
2532 }
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2546 {
2547 bool c_autocrypt = false;
2548 bool c_autocrypt_reply = false;
2549
2550#ifdef USE_AUTOCRYPT
2553#endif
2554
2556 {
2558 }
2559 else
2560 {
2561 const bool c_crypt_auto_sign =
cs_subset_bool(sub,
"crypt_auto_sign");
2562 const bool c_crypt_auto_encrypt =
cs_subset_bool(sub,
"crypt_auto_encrypt");
2563 const bool c_crypt_reply_encrypt =
cs_subset_bool(sub,
"crypt_reply_encrypt");
2564 const bool c_crypt_reply_sign =
cs_subset_bool(sub,
"crypt_reply_sign");
2565 const bool c_crypt_reply_sign_encrypted =
cs_subset_bool(sub,
"crypt_reply_sign_encrypted");
2566
2567 if (c_crypt_auto_sign)
2569 if (c_crypt_auto_encrypt)
2577
2578 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2579
2582 {
2583 const bool c_pgp_auto_inline =
cs_subset_bool(sub,
"pgp_auto_inline");
2584 const bool c_pgp_reply_inline =
cs_subset_bool(sub,
"pgp_reply_inline");
2585
2586 if (c_pgp_auto_inline)
2590 }
2591 }
2592
2593 const bool c_crypt_opportunistic_encrypt =
cs_subset_bool(sub,
"crypt_opportunistic_encrypt");
2594
2595 if (e_templ->
security || c_crypt_opportunistic_encrypt)
2596 {
2597 const bool c_crypt_auto_pgp =
cs_subset_bool(sub,
"crypt_auto_pgp");
2598 const bool c_crypt_auto_smime =
cs_subset_bool(sub,
"crypt_auto_smime");
2599
2600
2601
2602
2603
2604
2605
2606
2607 if (e_cur)
2608 {
2611 {
2613 }
2616 {
2618 }
2619 }
2620
2621 const bool c_smime_is_default =
cs_subset_bool(sub,
"smime_is_default");
2622
2623
2624
2626 {
2628 {
2630 }
2632 {
2634 }
2636 {
2638 }
2639 }
2640 }
2641
2642
2643 if (c_crypt_opportunistic_encrypt)
2644 {
2645
2646
2647
2649 {
2652 }
2653 }
2654
2655
2658 }
2659
2660
2661
2662
2664 {
2665 mutt_error(
_(
"No crypto backend configured. Disabling message security setting."));
2667 }
2668
2669
2670
2671
2673
2676 {
2677
2679 if (killfrom)
2680 {
2682 }
2684 if (killfrom)
2685 {
2687 }
2688 }
2689
2691
2693
2695 {
2696 main_loop:
2697
2701 if (i == -1)
2702 {
2703
2706 else
2708 goto cleanup;
2709 }
2710 else if (i == 1)
2711 {
2713 goto main_loop;
2715 rc = 1;
2716 goto cleanup;
2717 }
2718 }
2719
2721 {
2725 {
2727 {
2728 puts(
_(
"No recipients specified"));
2729 goto cleanup;
2730 }
2731
2733 goto main_loop;
2734 }
2735 }
2736
2738 {
2742 goto cleanup;
2743 goto main_loop;
2744 }
2745
2747
2750 {
2751
2754 goto main_loop;
2755 }
2756
2758 {
2760 goto main_loop;
2761 }
2762
2764 {
2766 goto main_loop;
2767 }
2768
2770 {
2771 goto main_loop;
2772 }
2773
2776
2777
2778
2779
2780
2782
2783
2784
2785
2786
2787
2788 clear_content = NULL;
2789 free_clear_content = false;
2790
2792 {
2794 {
2795
2796 clear_content = e_templ->
body;
2797
2800 {
2803
2805
2807
2809 {
2811 rc = -1;
2812 goto cleanup;
2813 }
2814
2815 goto main_loop;
2816 }
2818 }
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828 if (clear_content && (e_templ->
body != clear_content) &&
2829 (e_templ->
body->
parts != clear_content))
2830 free_clear_content = true;
2831 }
2832
2835
2837
2838 const bool c_fcc_before_send =
cs_subset_bool(sub,
"fcc_before_send");
2839 if (c_fcc_before_send)
2840 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2841
2843 if (i < 0)
2844 {
2846 {
2848 ;
2851 {
2852 if (e_templ->
body != clear_content)
2853 {
2855 e_templ->
body = clear_content;
2856 }
2857 }
2859 {
2863 {
2865 }
2866 }
2867
2876 goto main_loop;
2877 }
2878 else
2879 {
2880 puts(
_(
"Could not send the message"));
2881 goto cleanup;
2882 }
2883 }
2884
2885 if (!c_fcc_before_send)
2886 save_fcc(m, e_templ, fcc, clear_content, pgpkeylist, flags, &finalpath, sub);
2887
2889 {
2893#ifdef USE_NOTMUCH
2895 if (c_nm_record)
2897#endif
2899 }
2900
2903
2906
2907
2908
2910 {
2912 {
2913 struct Email **ep = NULL;
2915 {
2916 struct Email *e = *ep;
2918 }
2919 }
2920 }
2921
2922 rc = 0;
2923
2924cleanup:
2926
2928 {
2930 {
2933 }
2935 {
2937 FREE(&smime_sign_as);
2938 }
2939 }
2940
2944
2946 return rc;
2947}
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.
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
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
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.
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.
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.
time_t mutt_file_decrease_mtime(const char *fp, struct stat *st)
Decrease a file's modification time by 1 second.
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 OptNoCurses
(pseudo) when sending in batch mode
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_debug(LEVEL,...)
void mutt_select_fcc(struct Buffer *path, struct Email *e)
Select the FCC path for an email.
#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.
@ DISP_INLINE
Content is inline.
@ 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_NO_FLAGS
No flags are set.
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
int nm_record_message(struct Mailbox *m, char *path, struct Email *e)
Add a message to the Notmuch database.
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.
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.
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 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_NO_FREE_HEADER
Used by the -E flag.
#define SEND_DRAFT_FILE
Used by the -H flag.
#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.
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
char * mutt_gen_msgid(void)
Generate a random Message ID.
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
bool use_disp
Content-Disposition uses filename= ?
unsigned int disposition
content-disposition, ContentDisposition
bool replied
Email has been replied to.
struct AddressList x_original_to
Email's 'X-Original-to'.
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.