/**
* ci_bounce_message - Bounce an email
- * @param e Email to bounce
+ * @param m Mailbox
+ * @param el List of Emails to bounce
*/
-void ci_bounce_message(struct Email *e)
+void ci_bounce_message(struct Mailbox *m, struct EmailList *el)
{
+ if (!m || !el || STAILQ_EMPTY(el))
+ return;
+
char prompt[SHORT_STRING];
char scratch[SHORT_STRING];
char buf[HUGE_STRING] = { 0 };
struct Address *addr = NULL;
char *err = NULL;
int rc;
- int msgcount; // for L10N with ngettext
+ int msg_count = 0;
- /* RFC5322 mandates a From: header, so warn before bouncing
- * messages without one */
- if (e)
+ struct EmailNode *en = NULL;
+ STAILQ_FOREACH(en, el, entries)
{
- msgcount = 1;
- if (!e->env->from)
- {
+ /* RFC5322 mandates a From: header,
+ * so warn before bouncing messages without one */
+ if (!en->email->env->from)
mutt_error(_("Warning: message contains no From: header"));
- }
- }
- else if (Context)
- {
- msgcount = 0; // count the precise number of messages.
- for (rc = 0; rc < Context->mailbox->msg_count; rc++)
- {
- if (message_is_tagged(Context, rc) && !Context->mailbox->emails[rc]->env->from)
- {
- msgcount++;
- if (!Context->mailbox->emails[rc]->env->from)
- {
- mutt_error(_("Warning: message contains no From: header"));
- break;
- }
- }
- }
+
+ msg_count++;
}
- else
- msgcount = 0;
- if (e)
+ if (msg_count == 1)
mutt_str_strfcpy(prompt, _("Bounce message to: "), sizeof(prompt));
else
mutt_str_strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt));
#define EXTRA_SPACE (15 + 7 + 2)
snprintf(scratch, sizeof(scratch),
- ngettext("Bounce message to %s", "Bounce messages to %s", msgcount), buf);
+ ngettext("Bounce message to %s", "Bounce messages to %s", msg_count), buf);
if (mutt_strwidth(prompt) > MuttMessageWindow->cols - EXTRA_SPACE)
{
{
mutt_addr_free(&addr);
mutt_window_clearline(MuttMessageWindow, 0);
- mutt_message(ngettext("Message not bounced", "Messages not bounced", msgcount));
+ mutt_message(ngettext("Message not bounced", "Messages not bounced", msg_count));
return;
}
mutt_window_clearline(MuttMessageWindow, 0);
- rc = mutt_bounce_message(NULL, e, addr);
+ struct Message *msg = NULL;
+ STAILQ_FOREACH(en, el, entries)
+ {
+ msg = mx_msg_open(m, en->email->msgno);
+ if (!msg)
+ {
+ rc = -1;
+ break;
+ }
+
+ rc = mutt_bounce_message(msg->fp, en->email, addr);
+ mx_msg_close(m, &msg);
+
+ if (rc < 0)
+ break;
+ }
+
mutt_addr_free(&addr);
/* If no error, or background, display message. */
if ((rc == 0) || (rc == S_BKG))
- mutt_message(ngettext("Message bounced", "Messages bounced", msgcount));
+ mutt_message(ngettext("Message bounced", "Messages bounced", msg_count));
}
/**
/**
* pipe_msg - Pipe a message
- * @param e Email
+ * @param e Email to pipe
* @param fp File to write to
* @param decode If true, decode the message
* @param print If true, message is for printing
extern bool PrintSplit;
extern bool PromptAfter;
-void ci_bounce_message(struct Email *e);
+void ci_bounce_message(struct Mailbox *m, struct EmailList *el);
void mutt_check_stats(void);
bool mutt_check_traditional_pgp(struct Email *e, int *redraw);
void mutt_display_address(struct Envelope *env);
*/
case OP_BOUNCE_MESSAGE:
-
+ {
CHECK_ATTACH;
CHECK_MSGCOUNT;
CHECK_VISIBLE;
- ci_bounce_message(tag ? NULL : CUR_EMAIL);
+
+ struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+ el_add_tagged(&el, Context, CUR_EMAIL, tag);
+ ci_bounce_message(Context->mailbox, &el);
+ el_free(&el);
break;
+ }
case OP_CREATE_ALIAS:
*/
case OP_BOUNCE_MESSAGE:
+ {
+ struct Mailbox *m = Context ? Context->mailbox : NULL;
CHECK_MODE(IsEmail(extra) || IsMsgAttach(extra))
CHECK_ATTACH;
if (IsMsgAttach(extra))
- mutt_attach_bounce(extra->fp, extra->actx, extra->bdy);
+ mutt_attach_bounce(m, extra->fp, extra->actx, extra->bdy);
else
- ci_bounce_message(extra->email);
+ {
+ struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+ el_add_email(&el, extra->email);
+ ci_bounce_message(m, &el);
+ el_free(&el);
+ }
break;
+ }
case OP_RESEND:
CHECK_MODE(IsEmail(extra) || IsMsgAttach(extra))
case OP_BOUNCE_MESSAGE:
CHECK_ATTACH;
- mutt_attach_bounce(CURATTACH->fp, actx,
+ mutt_attach_bounce(m, CURATTACH->fp, actx,
menu->tagprefix ? NULL : CURATTACH->content);
menu->redraw = REDRAW_FULL;
break;
/**
* mutt_attach_bounce - Bounce function, from the attachment menu
+ * @param m Mailbox
* @param fp Handle of message
* @param actx Attachment context
* @param cur Body of email
*/
-void mutt_attach_bounce(FILE *fp, struct AttachCtx *actx, struct Body *cur)
+void mutt_attach_bounce(struct Mailbox *m, FILE *fp, struct AttachCtx *actx, struct Body *cur)
{
+ if (!m || !fp || !actx)
+ return;
+
char prompt[STRING];
char buf[HUGE_STRING];
char *err = NULL;
/* These Config Variables are only used in recvcmd.c */
extern unsigned char MimeForwardRest;
-void mutt_attach_bounce(FILE *fp, struct AttachCtx *actx, struct Body *cur);
+void mutt_attach_bounce(struct Mailbox *m, FILE *fp, struct AttachCtx *actx, struct Body *cur);
void mutt_attach_resend(FILE *fp, struct AttachCtx *actx, struct Body *cur);
void mutt_attach_forward(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *cur, int flags);
void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *cur, int flags);
static int bounce_message(FILE *fp, struct Email *e, struct Address *to,
const char *resent_from, struct Address *env_from)
{
- int rc = 0;
- FILE *f = NULL;
- char tempfile[PATH_MAX];
- struct Message *msg = NULL;
-
if (!e)
- {
- /* Try to bounce each message out, aborting if we get any failures. */
- for (int i = 0; i < Context->mailbox->msg_count; i++)
- if (message_is_tagged(Context, i))
- rc |= bounce_message(fp, Context->mailbox->emails[i], to, resent_from, env_from);
- return rc;
- }
-
- /* If we failed to open a message, return with error */
- if (!fp && !(msg = mx_msg_open(Context->mailbox, e->msgno)))
return -1;
- if (!fp)
- fp = msg->fp;
+ int rc = 0;
+ char tempfile[PATH_MAX];
mutt_mktemp(tempfile, sizeof(tempfile));
- f = mutt_file_fopen(tempfile, "w");
+ FILE *f = mutt_file_fopen(tempfile, "w");
if (f)
{
char date[SHORT_STRING];
int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
- char *msgid_str = NULL;
if (!BounceDelivered)
ch_flags |= CH_WEED_DELIVERED;
fseeko(fp, e->offset, SEEK_SET);
fprintf(f, "Resent-From: %s", resent_from);
fprintf(f, "\nResent-%s", mutt_date_make_date(date, sizeof(date)));
- msgid_str = gen_msgid();
+ char *msgid_str = gen_msgid();
fprintf(f, "Resent-Message-ID: %s\n", msgid_str);
+ FREE(&msgid_str);
fputs("Resent-To: ", f);
mutt_write_address_list(to, f, 11, 0);
mutt_copy_header(fp, e, f, ch_flags, NULL);
fputc('\n', f);
mutt_file_copy_bytes(fp, f, e->content->length);
- FREE(&msgid_str);
if (mutt_file_fclose(&f) != 0)
{
mutt_perror(tempfile);
if (SmtpUrl)
rc = mutt_smtp_send(env_from, to, NULL, NULL, tempfile, e->content->encoding == ENC_8BIT);
else
-#endif /* USE_SMTP */
+#endif
rc = mutt_invoke_sendmail(env_from, to, NULL, NULL, tempfile,
e->content->encoding == ENC_8BIT);
}
- if (msg)
- mx_msg_close(Context->mailbox, &msg);
-
return rc;
}
*/
int mutt_bounce_message(FILE *fp, struct Email *e, struct Address *to)
{
+ if (!fp || !e || !to)
+ return -1;
+
const char *fqdn = mutt_fqdn(true);
char resent_from[STRING];
char *err = NULL;