NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
recvcmd.h File Reference

Send/reply with an attachment. More...

#include "send/lib.h"
+ Include dependency graph for recvcmd.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void attach_bounce_message (struct AttachPtrArray *aa, struct Mailbox *m)
 Bounce function, from the attachment menu.
 
void mutt_attach_resend (struct AttachPtrArray *aa, struct Mailbox *m)
 Resend-message, from the attachment menu.
 
void mutt_attach_forward (struct AttachPtrArray *aa, struct Email *e, struct AttachCtx *actx, SendFlags flags)
 Forward selected attachments.
 
void mutt_attach_reply (struct AttachPtrArray *aa, struct Mailbox *m, struct Email *e, struct AttachCtx *actx, SendFlags flags)
 Attach a reply.
 
void mutt_attach_mail_sender (struct AttachPtrArray *aa)
 Compose an email to the sender in the email attachment.
 

Detailed Description

Send/reply with an attachment.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file recvcmd.h.

Function Documentation

◆ attach_bounce_message()

void attach_bounce_message ( struct AttachPtrArray * aa,
struct Mailbox * m )

Bounce function, from the attachment menu.

Parameters
aaSelected attachments
mMailbox

Definition at line 158 of file recvcmd.c.

159{
160 if (!m || ARRAY_EMPTY(aa))
161 return;
162
163 if (!check_all_msg(aa, true))
164 return;
165
166 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
167 struct Buffer *prompt = buf_pool_get();
168 struct Buffer *buf = buf_pool_get();
169
170 /* RFC5322 mandates a From: header, so warn before bouncing
171 * messages without one */
172 struct AttachPtr **app = NULL;
173 ARRAY_FOREACH(app, aa)
174 {
175 if (TAILQ_EMPTY(&(*app)->body->email->env->from))
176 {
177 mutt_error(_("Warning: message contains no From: header"));
179 break;
180 }
181 }
182
183 /* one or more messages? */
184 const int num_msg = ARRAY_SIZE(aa);
185 if (num_msg == 1)
186 buf_strcpy(prompt, _("Bounce message to: "));
187 else
188 buf_strcpy(prompt, _("Bounce messages to: "));
189
191 &CompleteAliasOps, NULL) != 0) ||
192 buf_is_empty(buf))
193 {
194 goto done;
195 }
196
198 if (TAILQ_EMPTY(&al))
199 {
200 mutt_error(_("Error parsing address"));
201 goto done;
202 }
203
205
206 char *err = NULL;
207 if (mutt_addrlist_to_intl(&al, &err) < 0)
208 {
209 mutt_error(_("Bad IDN: '%s'"), err);
210 FREE(&err);
211 goto done;
212 }
213
214 buf_reset(buf);
215 buf_alloc(buf, 8192);
216 mutt_addrlist_write(&al, buf, true);
217
218 buf_printf(prompt, ngettext("Bounce message to %s?", "Bounce messages to %s?", num_msg),
219 buf_string(buf));
220
221 if (query_quadoption(buf_string(prompt), NeoMutt->sub, "bounce") != MUTT_YES)
222 {
223 msgwin_clear_text(NULL);
224 mutt_message(ngettext("Message not bounced", "Messages not bounced", num_msg));
225 goto done;
226 }
227
228 msgwin_clear_text(NULL);
229
230 int rc = 0;
231 ARRAY_FOREACH(app, aa)
232 {
233 if (mutt_bounce_message((*app)->fp, m, (*app)->body->email, &al, NeoMutt->sub))
234 {
235 rc = 1;
236 }
237 }
238
239 if (rc == 0)
240 mutt_message(ngettext("Message bounced", "Messages bounced", num_msg));
241 else
242 mutt_error(ngettext("Error bouncing message", "Error bouncing messages", num_msg));
243
244done:
246 buf_pool_release(&buf);
247 buf_pool_release(&prompt);
248}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1469
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition address.c:1215
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition address.c:480
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition address.c:1302
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:296
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
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
@ MUTT_COMP_NONE
No flags are set.
Definition wdata.h:46
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:502
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
@ HC_ALIAS
Aliases.
Definition lib.h:57
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition msgwin.c:554
#define _(a)
Definition message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
@ 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:384
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
#define TAILQ_EMPTY(head)
Definition queue.h:778
static bool check_all_msg(struct AttachPtrArray *aa, bool err)
Are all the selected Attachments RFC822 messages?
Definition recvcmd.c:85
int mutt_bounce_message(FILE *fp, struct Mailbox *m, struct Email *e, struct AddressList *to, struct ConfigSubset *sub)
Bounce an email message.
Definition sendlib.c:883
An email to which things will be attached.
Definition attach.h:36
String manipulation buffer.
Definition buffer.h:36
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_resend()

void mutt_attach_resend ( struct AttachPtrArray * aa,
struct Mailbox * m )

Resend-message, from the attachment menu.

Parameters
aaSelected attachments
mCurrent mailbox

Definition at line 255 of file recvcmd.c.

256{
257 if (!check_all_msg(aa, true))
258 return;
259
260 struct AttachPtr **app = NULL;
261 ARRAY_FOREACH(app, aa)
262 {
263 mutt_resend_message((*app)->fp, m, (*app)->body->email, NeoMutt->sub);
264 }
265}
int mutt_resend_message(FILE *fp, struct Mailbox *m, struct Email *e_cur, struct ConfigSubset *sub)
Resend an email.
Definition send.c:1560
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_forward()

void mutt_attach_forward ( struct AttachPtrArray * aa,
struct Email * e,
struct AttachCtx * actx,
SendFlags flags )

Forward selected attachments.

Parameters
aaSelected attachments
eEmail
actxAttachment Context
flagsSend mode, see SendFlags

Definition at line 737 of file recvcmd.c.

739{
740 if (check_all_msg(aa, false))
741 {
742 attach_forward_msgs(aa, flags);
743 }
744 else
745 {
746 attach_forward_bodies(e, actx, aa);
747 }
748}
static void attach_forward_bodies(struct Email *e, struct AttachCtx *actx, struct AttachPtrArray *aa)
Forward one or several MIME bodies.
Definition recvcmd.c:434
static void attach_forward_msgs(struct AttachPtrArray *aa, SendFlags flags)
Forward one or several message-type attachments.
Definition recvcmd.c:621
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_reply()

void mutt_attach_reply ( struct AttachPtrArray * aa,
struct Mailbox * m,
struct Email * e,
struct AttachCtx * actx,
SendFlags flags )

Attach a reply.

Parameters
aaSelected attachments
mMailbox
eEmail
actxAttachment Context
flagsSend mode, see SendFlags

Definition at line 885 of file recvcmd.c.

887{
888 bool mime_reply_any = false;
889
890 const short nattach = ARRAY_SIZE(aa);
891 struct AttachPtr **first = ARRAY_GET(aa, 0);
892 if (!first)
893 return;
894
895 struct AttachPtr *current = *first;
896 FILE *fp = current->fp;
897 struct Body *b = current->body;
898 struct AttachPtr *parent = NULL;
899 struct Email *e_parent = NULL;
900 FILE *fp_parent = NULL;
901 struct Email *e_tmp = NULL;
902 FILE *fp_tmp = NULL;
903 struct Buffer *tempfile = NULL;
904 struct EmailArray ea = ARRAY_HEAD_INITIALIZER;
905
906 struct Buffer *prefix = buf_pool_get();
907
908 if (flags & SEND_NEWS)
909 OptNewsSend = true;
910 else
911 OptNewsSend = false;
912
913 /* Determine the parent message for the reply: either the selected
914 * attachment's parent or the top-level email if not nested */
915 if (!check_all_msg(aa, false))
916 {
917 parent = find_parent(actx, aa);
918 if (parent)
919 {
920 e_parent = parent->body->email;
921 fp_parent = parent->fp;
922 }
923 else
924 {
925 e_parent = e;
926 fp_parent = actx->fp_root;
927 }
928 }
929
930 /* Check if non-decodable attachments should be MIME-encapsulated */
931 if ((nattach > 1) && !check_can_decode(aa))
932 {
933 const enum QuadOption ans = query_quadoption(_("Can't decode all selected attachments. MIME-encapsulate the others?"),
934 NeoMutt->sub, "mime_forward_rest");
935 if (ans == MUTT_ABORT)
936 goto cleanup;
937 if (ans == MUTT_YES)
938 mime_reply_any = true;
939 }
940 else if (nattach == 1)
941 {
942 mime_reply_any = true;
943 }
944
945 e_tmp = email_new();
946 e_tmp->env = mutt_env_new();
947
948 if (attach_reply_envelope_defaults(e_tmp->env, aa,
949 e_parent ? e_parent : (b ? b->email : NULL),
950 flags) == -1)
951 {
952 goto cleanup;
953 }
954
955 /* Create a temporary file for the reply body and write the quoted
956 * content of the selected attachment(s) into it */
957 tempfile = buf_pool_get();
958 buf_mktemp_draft(tempfile);
959 fp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
960 if (!fp_tmp)
961 {
962 mutt_error(_("Can't create %s"), buf_string(tempfile));
963 goto cleanup;
964 }
965
966 if (e_parent)
967 {
968 mutt_make_attribution_intro(e_parent, fp_tmp, NeoMutt->sub);
969
970 struct State state = { 0 };
971 state.fp_out = fp_tmp;
972
973 const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
974 if (c_text_flowed)
975 {
976 buf_strcpy(prefix, ">");
977 }
978 else
979 {
980 const char *const c_attribution_locale = cs_subset_string(NeoMutt->sub, "attribution_locale");
981 const struct Expando *c_indent_string = cs_subset_expando(NeoMutt->sub, "indent_string");
982 setlocale(LC_TIME, NONULL(c_attribution_locale));
983 mutt_make_string(prefix, -1, c_indent_string, m, -1, e_parent, MUTT_FORMAT_NONE, NULL);
984 setlocale(LC_TIME, "");
985 }
986
987 state.prefix = buf_string(prefix);
988 state.flags = STATE_CHARCONV;
989
990 const bool c_weed = cs_subset_bool(NeoMutt->sub, "weed");
991 if (c_weed)
992 state.flags |= STATE_WEED;
993
994 const bool c_header = cs_subset_bool(NeoMutt->sub, "header");
995 if (c_header)
996 include_header(true, fp_parent, e_parent, fp_tmp, buf_string(prefix));
997
998 if (nattach == 1)
999 {
1000 if (mutt_can_decode(b))
1001 {
1002 state.fp_in = fp;
1003 mutt_body_handler(b, &state);
1004 state_putc(&state, '\n');
1005 }
1006 else
1007 {
1008 mutt_body_copy(fp, &e_tmp->body, b);
1009 }
1010 }
1011 else
1012 {
1013 struct AttachPtr **app = NULL;
1014 ARRAY_FOREACH(app, aa)
1015 {
1016 if (mutt_can_decode((*app)->body))
1017 {
1018 state.fp_in = (*app)->fp;
1019 mutt_body_handler((*app)->body, &state);
1020 state_putc(&state, '\n');
1021 }
1022 }
1023 }
1024
1025 mutt_make_attribution_trailer(e_parent, fp_tmp, NeoMutt->sub);
1026
1027 if (mime_reply_any && (nattach > 1) &&
1028 !copy_problematic_attachments(&e_tmp->body, aa, false))
1029 {
1030 goto cleanup;
1031 }
1032 }
1033 else
1034 {
1035 if (nattach == 1)
1036 {
1037 attach_include_reply(fp, fp_tmp, b->email);
1038 }
1039 else
1040 {
1041 struct AttachPtr **app = NULL;
1042 ARRAY_FOREACH(app, aa)
1043 {
1044 attach_include_reply((*app)->fp, fp_tmp, (*app)->body->email);
1045 }
1046 }
1047 }
1048
1049 mutt_file_fclose(&fp_tmp);
1050
1051 ARRAY_ADD(&ea, e_parent ? e_parent : b->email);
1052 if (mutt_send_message(flags, e_tmp, buf_string(tempfile), NULL, &ea, NeoMutt->sub) == 0)
1053 {
1054 mutt_set_flag(m, e, MUTT_REPLIED, true, true);
1055 }
1056 e_tmp = NULL; /* mutt_send_message frees this */
1057
1058cleanup:
1059 if (fp_tmp)
1060 {
1061 mutt_file_fclose(&fp_tmp);
1062 mutt_file_unlink(buf_string(tempfile));
1063 }
1064 buf_pool_release(&tempfile);
1065 buf_pool_release(&prefix);
1066 email_free(&e_tmp);
1067 ARRAY_FREE(&ea);
1068}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
int mutt_body_copy(FILE *fp, struct Body **b_dst, struct Body *b_src)
Create a send-mode duplicate from a receive-mode body.
Definition copy_body.c:50
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 dlg_index.c:824
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
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition file.c:156
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
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:54
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition globals.c:54
bool mutt_can_decode(struct Body *b)
Will decoding the attachment produce any output.
Definition handler.c:1898
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition handler.c:1664
#define state_putc(STATE, STR)
Definition state.h:65
@ STATE_CHARCONV
Do character set conversions.
Definition state.h:41
@ STATE_WEED
Weed headers even when not in display mode.
Definition state.h:40
@ MUTT_REPLIED
Messages that have been replied to.
Definition mutt.h:91
QuadOption
Possible values for a quad-option.
Definition quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
Definition quad.h:37
static void attach_include_reply(FILE *fp, FILE *fp_tmp, struct Email *e)
This is very similar to send.c's include_reply()
Definition recvcmd.c:856
static struct AttachPtr * find_parent(struct AttachCtx *actx, struct AttachPtrArray *aa)
Find the parent of a selected Attachment set.
Definition recvcmd.c:328
static bool check_can_decode(struct AttachPtrArray *aa)
Can we decode all selected attachments?
Definition recvcmd.c:101
static int attach_reply_envelope_defaults(struct Envelope *env, struct AttachPtrArray *aa, struct Email *parent, SendFlags flags)
Create the envelope defaults for a reply.
Definition recvcmd.c:769
static void include_header(bool quote, FILE *fp_in, struct Email *e, FILE *fp_out, const char *prefix)
Write an email header to a file, optionally quoting it.
Definition recvcmd.c:364
static struct Body ** copy_problematic_attachments(struct Body **last, struct AttachPtrArray *aa, bool force)
Attach the body parts which can't be decoded.
Definition recvcmd.c:410
@ MUTT_FORMAT_NONE
No flags are set.
Definition render.h:37
void mutt_make_attribution_intro(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add "on DATE, PERSON wrote" header.
Definition send.c:668
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:2030
void mutt_make_attribution_trailer(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add suffix to replied email text.
Definition send.c:679
@ SEND_NEWS
Reply to a news article.
Definition send.h:59
#define NONULL(x)
Definition string2.h:44
FILE * fp_root
Used by recvattach for updating.
Definition attach.h:67
struct Body * body
Attachment.
Definition attach.h:37
FILE * fp
Used in the recvattach menu.
Definition attach.h:38
The body of an email.
Definition body.h:36
struct Email * email
header information for message/rfc822
Definition body.h:74
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
struct Body * body
List of MIME parts.
Definition email.h:69
Parsed Expando trees.
Definition expando.h:41
Keep track when processing files.
Definition state.h:54
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition state.h:58
FILE * fp_out
File to write to.
Definition state.h:56
FILE * fp_in
File to read from.
Definition state.h:55
const char * prefix
String to add to the beginning of each output line.
Definition state.h:57
#define buf_mktemp_draft(buf)
Definition tmp.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_mail_sender()

void mutt_attach_mail_sender ( struct AttachPtrArray * aa)

Compose an email to the sender in the email attachment.

Parameters
aaSelected attachments

Definition at line 1074 of file recvcmd.c.

1075{
1076 if (!check_all_msg(aa, false))
1077 {
1078 /* L10N: You will see this error message if you invoke <compose-to-sender>
1079 when you are on a normal attachment. */
1080 mutt_error(_("You may only compose to sender with message/rfc822 parts"));
1081 return;
1082 }
1083
1084 struct Email *e_tmp = email_new();
1085 e_tmp->env = mutt_env_new();
1086
1087 struct AttachPtr **app = NULL;
1088 ARRAY_FOREACH(app, aa)
1089 {
1090 if (mutt_fetch_recips(e_tmp->env, (*app)->body->email->env, SEND_TO_SENDER,
1091 NeoMutt->sub) == -1)
1092 {
1093 email_free(&e_tmp);
1094 return;
1095 }
1096 }
1097
1098 // This call will free e_tmp for us
1099 mutt_send_message(SEND_NONE, e_tmp, NULL, NULL, NULL, NeoMutt->sub);
1100}
int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, SendFlags flags, struct ConfigSubset *sub)
Generate recpients for a reply email.
Definition send.c:878
@ SEND_NONE
No flags are set.
Definition send.h:45
@ SEND_TO_SENDER
Compose new email to sender.
Definition send.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function: