NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
recvcmd.h File Reference

Send/reply with an attachment. More...

#include <stdio.h>
#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 Mailbox *m, FILE *fp, struct AttachCtx *actx, struct Body *b)
 Bounce function, from the attachment menu.
 
void mutt_attach_resend (FILE *fp, struct Mailbox *m, struct AttachCtx *actx, struct Body *b)
 Resend-message, from the attachment menu.
 
void mutt_attach_forward (FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *b, SendFlags flags)
 Forward an Attachment.
 
void mutt_attach_reply (FILE *fp, struct Mailbox *m, struct Email *e, struct AttachCtx *actx, struct Body *b, SendFlags flags)
 Attach a reply.
 
void mutt_attach_mail_sender (struct AttachCtx *actx, struct Body *b)
 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 Mailbox m,
FILE *  fp,
struct AttachCtx actx,
struct Body b 
)

Bounce function, from the attachment menu.

Parameters
mMailbox
fpHandle of message
actxAttachment context
bBody of email

Definition at line 166 of file recvcmd.c.

168{
169 if (!m || !fp || !actx)
170 return;
171
172 if (!check_all_msg(actx, b, true))
173 return;
174
175 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
176 struct Buffer *prompt = buf_pool_get();
177 struct Buffer *buf = buf_pool_get();
178
179 /* RFC5322 mandates a From: header, so warn before bouncing
180 * messages without one */
181 if (b)
182 {
183 if (TAILQ_EMPTY(&b->email->env->from))
184 {
185 mutt_error(_("Warning: message contains no From: header"));
187 }
188 }
189 else
190 {
191 for (short i = 0; i < actx->idxlen; i++)
192 {
193 if (actx->idx[i]->body->tagged)
194 {
195 if (TAILQ_EMPTY(&actx->idx[i]->body->email->env->from))
196 {
197 mutt_error(_("Warning: message contains no From: header"));
199 break;
200 }
201 }
202 }
203 }
204
205 /* one or more messages? */
206 int num_msg = b ? 1 : count_tagged(actx);
207 if (num_msg == 1)
208 buf_strcpy(prompt, _("Bounce message to: "));
209 else
210 buf_strcpy(prompt, _("Bounce tagged messages to: "));
211
213 &CompleteAliasOps, NULL) != 0) ||
214 buf_is_empty(buf))
215 {
216 goto done;
217 }
218
220 if (TAILQ_EMPTY(&al))
221 {
222 mutt_error(_("Error parsing address"));
223 goto done;
224 }
225
227
228 char *err = NULL;
229 if (mutt_addrlist_to_intl(&al, &err) < 0)
230 {
231 mutt_error(_("Bad IDN: '%s'"), err);
232 FREE(&err);
233 goto done;
234 }
235
236 buf_reset(buf);
237 buf_alloc(buf, 8192);
238 mutt_addrlist_write(&al, buf, true);
239
240 buf_printf(prompt, ngettext("Bounce message to %s?", "Bounce messages to %s?", num_msg),
241 buf_string(buf));
242
243 if (query_quadoption(buf_string(prompt), NeoMutt->sub, "bounce") != MUTT_YES)
244 {
245 msgwin_clear_text(NULL);
246 mutt_message(ngettext("Message not bounced", "Messages not bounced", num_msg));
247 goto done;
248 }
249
250 msgwin_clear_text(NULL);
251
252 int rc = 0;
253 if (b)
254 {
255 rc = mutt_bounce_message(fp, m, b->email, &al, NeoMutt->sub);
256 }
257 else
258 {
259 for (short i = 0; i < actx->idxlen; i++)
260 {
261 if (actx->idx[i]->body->tagged)
262 {
263 if (mutt_bounce_message(actx->idx[i]->fp, m, actx->idx[i]->body->email,
264 &al, NeoMutt->sub))
265 {
266 rc = 1;
267 }
268 }
269 }
270 }
271
272 if (rc == 0)
273 mutt_message(ngettext("Message bounced", "Messages bounced", num_msg));
274 else
275 mutt_error(ngettext("Error bouncing message", "Error bouncing messages", num_msg));
276
277done:
279 buf_pool_release(&buf);
280 buf_pool_release(&prompt);
281}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
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_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: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
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
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
#define mutt_message(...)
Definition: logging2.h:91
@ HC_ALIAS
Aliases.
Definition: lib.h:52
#define FREE(x)
Definition: memory.h:45
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition: msgwin.c:519
#define _(a)
Definition: message.h:28
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
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
@ 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:379
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
#define TAILQ_EMPTY(head)
Definition: queue.h:721
static short count_tagged(struct AttachCtx *actx)
Count the number of tagged attachments.
Definition: recvcmd.c:131
static bool check_all_msg(struct AttachCtx *actx, struct Body *b, bool err)
Are all the Attachments RFC822 messages?
Definition: recvcmd.c:90
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:917
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:69
short idxlen
Number of attachmentes.
Definition: attach.h:70
struct Body * body
Attachment.
Definition: attach.h:38
FILE * fp
Used in the recvattach menu.
Definition: attach.h:39
struct Email * email
header information for message/rfc822
Definition: body.h:74
bool tagged
This attachment is tagged.
Definition: body.h:90
String manipulation buffer.
Definition: buffer.h:36
struct Envelope * env
Envelope information.
Definition: email.h:68
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_resend()

void mutt_attach_resend ( FILE *  fp,
struct Mailbox m,
struct AttachCtx actx,
struct Body b 
)

Resend-message, from the attachment menu.

Parameters
fpFile containing email
mCurrent mailbox
actxAttachment context
bAttachment

Definition at line 290 of file recvcmd.c.

291{
292 if (!check_all_msg(actx, b, true))
293 return;
294
295 if (b)
296 {
298 }
299 else
300 {
301 for (short i = 0; i < actx->idxlen; i++)
302 {
303 if (actx->idx[i]->body->tagged)
304 {
305 mutt_resend_message(actx->idx[i]->fp, m, actx->idx[i]->body->email,
306 NeoMutt->sub);
307 }
308 }
309 }
310}
int mutt_resend_message(FILE *fp, struct Mailbox *m, struct Email *e_cur, struct ConfigSubset *sub)
Resend an email.
Definition: send.c:1614
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_forward()

void mutt_attach_forward ( FILE *  fp,
struct Email e,
struct AttachCtx actx,
struct Body b,
SendFlags  flags 
)

Forward an Attachment.

Parameters
fpHandle to the attachment
eEmail
actxAttachment Context
bCurrent message
flagsSend mode, see SendFlags

Definition at line 793 of file recvcmd.c.

795{
796 if (check_all_msg(actx, b, false))
797 {
798 attach_forward_msgs(fp, actx, b, flags);
799 }
800 else
801 {
802 const short nattach = count_tagged(actx);
803 attach_forward_bodies(fp, e, actx, b, nattach);
804 }
805}
static void attach_forward_bodies(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *b, short nattach)
Forward one or several MIME bodies.
Definition: recvcmd.c:478
static void attach_forward_msgs(FILE *fp, struct AttachCtx *actx, struct Body *b, SendFlags flags)
Forward one or several message-type attachments.
Definition: recvcmd.c:662
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attach_reply()

void mutt_attach_reply ( FILE *  fp,
struct Mailbox m,
struct Email e,
struct AttachCtx actx,
struct Body b,
SendFlags  flags 
)

Attach a reply.

Parameters
fpFile handle to reply
mMailbox
eEmail
actxAttachment Context
bCurrent message
flagsSend mode, see SendFlags

Definition at line 949 of file recvcmd.c.

951{
952 bool mime_reply_any = false;
953
954 short nattach = 0;
955 struct AttachPtr *parent = NULL;
956 struct Email *e_parent = NULL;
957 FILE *fp_parent = NULL;
958 struct Email *e_tmp = NULL;
959 FILE *fp_tmp = NULL;
960 struct Buffer *tmpbody = NULL;
961 struct EmailArray ea = ARRAY_HEAD_INITIALIZER;
962
963 struct Buffer *prefix = buf_pool_get();
964
965 if (flags & SEND_NEWS)
966 OptNewsSend = true;
967 else
968 OptNewsSend = false;
969
970 if (!check_all_msg(actx, b, false))
971 {
972 nattach = count_tagged(actx);
973 parent = find_parent(actx, b, nattach);
974 if (parent)
975 {
976 e_parent = parent->body->email;
977 fp_parent = parent->fp;
978 }
979 else
980 {
981 e_parent = e;
982 fp_parent = actx->fp_root;
983 }
984 }
985
986 if ((nattach > 1) && !check_can_decode(actx, b))
987 {
988 const enum QuadOption ans = query_quadoption(_("Can't decode all tagged attachments. MIME-encapsulate the others?"),
989 NeoMutt->sub, "mime_forward_rest");
990 if (ans == MUTT_ABORT)
991 goto cleanup;
992 if (ans == MUTT_YES)
993 mime_reply_any = true;
994 }
995 else if (nattach == 1)
996 {
997 mime_reply_any = true;
998 }
999
1000 e_tmp = email_new();
1001 e_tmp->env = mutt_env_new();
1002
1003 if (attach_reply_envelope_defaults(e_tmp->env, actx,
1004 e_parent ? e_parent : (b ? b->email : NULL),
1005 flags) == -1)
1006 {
1007 goto cleanup;
1008 }
1009
1010 tmpbody = buf_pool_get();
1011 buf_mktemp(tmpbody);
1012 fp_tmp = mutt_file_fopen(buf_string(tmpbody), "w");
1013 if (!fp_tmp)
1014 {
1015 mutt_error(_("Can't create %s"), buf_string(tmpbody));
1016 goto cleanup;
1017 }
1018
1019 if (e_parent)
1020 {
1021 mutt_make_attribution_intro(e_parent, fp_tmp, NeoMutt->sub);
1022
1023 struct State state = { 0 };
1024 state.fp_out = fp_tmp;
1025
1026 const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
1027 if (c_text_flowed)
1028 {
1029 buf_strcpy(prefix, ">");
1030 }
1031 else
1032 {
1033 const char *const c_attribution_locale = cs_subset_string(NeoMutt->sub, "attribution_locale");
1034 const struct Expando *c_indent_string = cs_subset_expando(NeoMutt->sub, "indent_string");
1035 setlocale(LC_TIME, NONULL(c_attribution_locale));
1036 mutt_make_string(prefix, -1, c_indent_string, m, -1, e_parent,
1037 MUTT_FORMAT_NO_FLAGS, NULL);
1038 setlocale(LC_TIME, "");
1039 }
1040
1041 state.prefix = buf_string(prefix);
1042 state.flags = STATE_CHARCONV;
1043
1044 const bool c_weed = cs_subset_bool(NeoMutt->sub, "weed");
1045 if (c_weed)
1046 state.flags |= STATE_WEED;
1047
1048 const bool c_header = cs_subset_bool(NeoMutt->sub, "header");
1049 if (c_header)
1050 include_header(true, fp_parent, e_parent, fp_tmp, buf_string(prefix));
1051
1052 if (b)
1053 {
1054 if (mutt_can_decode(b))
1055 {
1056 state.fp_in = fp;
1057 mutt_body_handler(b, &state);
1058 state_putc(&state, '\n');
1059 }
1060 else
1061 {
1062 mutt_body_copy(fp, &e_tmp->body, b);
1063 }
1064 }
1065 else
1066 {
1067 for (short i = 0; i < actx->idxlen; i++)
1068 {
1069 if (actx->idx[i]->body->tagged && mutt_can_decode(actx->idx[i]->body))
1070 {
1071 state.fp_in = actx->idx[i]->fp;
1072 mutt_body_handler(actx->idx[i]->body, &state);
1073 state_putc(&state, '\n');
1074 }
1075 }
1076 }
1077
1078 mutt_make_attribution_trailer(e_parent, fp_tmp, NeoMutt->sub);
1079
1080 if (mime_reply_any && !b && !copy_problematic_attachments(&e_tmp->body, actx, false))
1081 {
1082 goto cleanup;
1083 }
1084 }
1085 else
1086 {
1087 if (b)
1088 {
1089 attach_include_reply(fp, fp_tmp, b->email);
1090 }
1091 else
1092 {
1093 for (short i = 0; i < actx->idxlen; i++)
1094 {
1095 if (actx->idx[i]->body->tagged)
1096 attach_include_reply(actx->idx[i]->fp, fp_tmp, actx->idx[i]->body->email);
1097 }
1098 }
1099 }
1100
1101 mutt_file_fclose(&fp_tmp);
1102
1103 ARRAY_ADD(&ea, e_parent ? e_parent : (b ? b->email : NULL));
1104 if (mutt_send_message(flags, e_tmp, buf_string(tmpbody), NULL, &ea, NeoMutt->sub) == 0)
1105 {
1106 mutt_set_flag(m, e, MUTT_REPLIED, true, true);
1107 }
1108 e_tmp = NULL; /* mutt_send_message frees this */
1109
1110cleanup:
1111 if (fp_tmp)
1112 {
1113 mutt_file_fclose(&fp_tmp);
1114 mutt_file_unlink(buf_string(tmpbody));
1115 }
1116 buf_pool_release(&tmpbody);
1117 buf_pool_release(&prefix);
1118 email_free(&e_tmp);
1119 ARRAY_FREE(&ea);
1120}
#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
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.
Definition: config_type.c:357
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:46
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:221
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
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 OptNewsSend
(pseudo) used to change behavior when posting
Definition: globals.c:68
bool mutt_can_decode(struct Body *b)
Will decoding the attachment produce any output.
Definition: handler.c:1865
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition: handler.c:1631
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:1719
#define STATE_WEED
Weed headers even when not in display mode.
Definition: state.h:36
#define state_putc(STATE, STR)
Definition: state.h:59
#define STATE_CHARCONV
Do character set conversions.
Definition: state.h:37
@ MUTT_REPLIED
Messages that have been replied to.
Definition: mutt.h:72
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: mutt_body.c:49
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:919
static struct Body ** copy_problematic_attachments(struct Body **last, struct AttachCtx *actx, bool force)
Attach the body parts which can't be decoded.
Definition: recvcmd.c:453
static bool check_can_decode(struct AttachCtx *actx, struct Body *b)
Can we decode all tagged attachments?
Definition: recvcmd.c:114
static struct AttachPtr * find_parent(struct AttachCtx *actx, struct Body *b, short nattach)
Find the parent of an Attachment.
Definition: recvcmd.c:374
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:407
static int attach_reply_envelope_defaults(struct Envelope *env, struct AttachCtx *actx, struct Email *parent, SendFlags flags)
Create the envelope defaults for a reply.
Definition: recvcmd.c:826
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
void mutt_make_attribution_intro(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add "on DATE, PERSON wrote" header.
Definition: send.c:660
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
void mutt_make_attribution_trailer(struct Email *e, FILE *fp_out, struct ConfigSubset *sub)
Add suffix to replied email text.
Definition: send.c:671
#define SEND_NEWS
Reply to a news article.
Definition: send.h:55
#define NONULL(x)
Definition: string2.h:37
FILE * fp_root
Used by recvattach for updating.
Definition: attach.h:67
An email to which things will be attached.
Definition: attach.h:37
The envelope/body of an email.
Definition: email.h:39
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:48
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:52
FILE * fp_out
File to write to.
Definition: state.h:50
FILE * fp_in
File to read from.
Definition: state.h:49
const char * prefix
String to add to the beginning of each output line.
Definition: state.h:51
#define buf_mktemp(buf)
Definition: tmp.h:33
+ 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 AttachCtx actx,
struct Body b 
)

Compose an email to the sender in the email attachment.

Parameters
actxAttachment Context
bCurrent attachment

Definition at line 1127 of file recvcmd.c.

1128{
1129 if (!check_all_msg(actx, b, 0))
1130 {
1131 /* L10N: You will see this error message if you invoke <compose-to-sender>
1132 when you are on a normal attachment. */
1133 mutt_error(_("You may only compose to sender with message/rfc822 parts"));
1134 return;
1135 }
1136
1137 struct Email *e_tmp = email_new();
1138 e_tmp->env = mutt_env_new();
1139
1140 if (b)
1141 {
1142 if (mutt_fetch_recips(e_tmp->env, b->email->env, SEND_TO_SENDER, NeoMutt->sub) == -1)
1143 {
1144 email_free(&e_tmp);
1145 return;
1146 }
1147 }
1148 else
1149 {
1150 for (int i = 0; i < actx->idxlen; i++)
1151 {
1152 if (actx->idx[i]->body->tagged &&
1153 (mutt_fetch_recips(e_tmp->env, actx->idx[i]->body->email->env,
1154 SEND_TO_SENDER, NeoMutt->sub) == -1))
1155 {
1156 email_free(&e_tmp);
1157 return;
1158 }
1159 }
1160 }
1161
1162 // This call will free e_tmp for us
1163 mutt_send_message(SEND_NO_FLAGS, e_tmp, NULL, NULL, NULL, NeoMutt->sub);
1164}
int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, SendFlags flags, struct ConfigSubset *sub)
Generate recpients for a reply email.
Definition: send.c:936
#define SEND_TO_SENDER
Compose new email to sender.
Definition: send.h:53
#define SEND_NO_FLAGS
No flags are set.
Definition: send.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function: