[PATCH 4 of 4] Add support for sendbox (bounce path)
# HG changeset patch
# User Aron Griffis <agriffis@xxxxxxxxx>
# Date 1240931851 14400
# Branch HEAD
# Node ID 0069fde2f491feb879698ad00701d8f300f5e5a3
# Parent a1d30c5275203ead2b0addf53c2e47d892f6207f
Add support for sendbox (bounce path)
This patch adds support for "sendbox" to the bounce path.
Additionally a bug is fixed: previously there would be no warning or error
emitted if mutt failed to create the temporary file when bouncing a message.
Signed-off-by: Aron Griffis <agriffis@xxxxxxxxx>
diff -r a1d30c527520 -r 0069fde2f491 sendlib.c
--- a/sendlib.c Tue Apr 28 11:17:31 2009 -0400
+++ b/sendlib.c Tue Apr 28 11:17:31 2009 -0400
@@ -2483,6 +2483,13 @@
FILE *f;
char date[SHORT_STRING], tempfile[_POSIX_PATH_MAX];
MESSAGE *msg = NULL;
+ int ch_flags;
+ char *msgid_str;
+#ifdef USE_SENDBOX
+ struct mutt_message_handle *mh = NULL;
+ CONTEXT sctx;
+ MESSAGE *smsg = NULL;
+#endif
if (!h)
{
@@ -2499,28 +2506,65 @@
if (!fp) fp = msg->fp;
- mutt_mktemp (tempfile);
- if ((f = safe_fopen (tempfile, "w")) != NULL)
+ ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
+ if (!option (OPTBOUNCEDELIVERED))
+ ch_flags |= CH_WEED_DELIVERED;
+
+ /* create a message which is the original message with Resent
+ * header fields prepended. For sendmail and smtp, the message is
+ * a tempfile. For sendbox, it's a newly created message in the
+ * Sendbox folder.
+ */
+#ifdef USE_SENDBOX
+ if (Sendbox)
{
- int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
- char* msgid_str;
-
- if (!option (OPTBOUNCEDELIVERED))
- ch_flags |= CH_WEED_DELIVERED;
-
- fseeko (fp, h->offset, 0);
- fprintf (f, "Resent-From: %s", resent_from);
- fprintf (f, "\nResent-%s", mutt_make_date (date, sizeof(date)));
- msgid_str = mutt_gen_msgid();
- fprintf (f, "Resent-Message-ID: %s\n", msgid_str);
- fputs ("Resent-To: ", f);
- mutt_write_address_list (to, f, 11, 0);
- mutt_copy_header (fp, h, f, ch_flags, NULL);
- fputc ('\n', f);
- mutt_copy_bytes (fp, f, h->content->length);
+ mh = mutt_start_message (Sendbox, h, &sctx, &smsg, 1);
+ if (!mh)
+ {
+ ret = -1;
+ goto close_msg;
+ }
+ f = smsg->fp;
+
+ /* Resent-To: headers will be unioned by the MTA to
+ * determine the recipient, so weed any old ones
+ */
+ ch_flags |= CH_WEED_RESENT;
+ }
+ else
+#endif
+ {
+ mutt_mktemp (tempfile);
+ if ((f = safe_fopen (tempfile, "w")) == NULL)
+ {
+ mutt_perror (tempfile);
+ ret = -1;
+ goto close_msg;
+ }
+ }
+
+ /* prepend the Resent header fields */
+ fprintf (f, "Resent-From: %s", resent_from);
+ fprintf (f, "\nResent-%s", mutt_make_date (date, sizeof(date)));
+ msgid_str = mutt_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);
+
+ /* copy original message */
+ fseeko (fp, h->offset, 0);
+ mutt_copy_header (fp, h, f, ch_flags, NULL);
+ fputc ('\n', f);
+ mutt_copy_bytes (fp, f, h->content->length);
+
+#ifdef USE_SENDBOX
+ if (Sendbox)
+ ret = mutt_finish_message (mh, Sendbox, h, &sctx, &smsg, 1);
+ else
+#endif
+ {
safe_fclose (&f);
- FREE (&msgid_str);
-
#if USE_SMTP
if (SmtpUrl)
ret = mutt_smtp_send (env_from, to, NULL, NULL, tempfile,
@@ -2531,6 +2575,7 @@
h->content->encoding == ENC8BIT);
}
+close_msg:
if (msg)
mx_close_message (&msg);