[PATCH] Add smtp status log when using 'SmtpUrl'
- To: mutt-dev@xxxxxxxx
- Subject: [PATCH] Add smtp status log when using 'SmtpUrl'
- From: Wheelz <kernel.zeng@xxxxxxxxx>
- Date: Tue, 10 Nov 2009 12:08:27 +0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=4Vj1mWFiSdtVzcOQ3WYIwweejF4lEx46qqii+Mqd504=; b=Z76pzAXQNMKE8dDKWESdaMgWrxnz8uL8QpFlvCHuVd+dsna8aeq2zbIASEv8xnrxmd u7kpW5X44XM0pEqfVElpeQt1O8V22ar3cD1ckTuEM5gHThMquw+yVB2R4tLrcmEY6FnA lnm4IhjTTt7NPho5wOBClhXClm/auCZx1c5Gg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=FumPklEHdtPrlRF8KchXPc3TdIDXONabrD6B/p3ydcPiUGt9ICHomONMuYb1JlNwda JAifot8Goe+e54VeA5f1PJp2C1RTySoirseMhE/E4TC9uQDjokBUMuTE2id/zSR+jJ0b hSlz54qPwit4CCCe5J7GRASywEDn/8eXCqJ5I=
- List-post: <mailto:mutt-dev@mutt.org>
- List-unsubscribe: send mail to majordomo@mutt.org, body only "unsubscribe mutt-dev"
- Sender: owner-mutt-dev@xxxxxxxx
- User-agent: Mutt/1.5.19 (2009-01-05)
Hi, all,
SmtpUrl is a great feature, thank you all.
But it is inconvenience sometimes.
I can't determine whether mail is sent or not, if I don't notice the 'Mail
Sent' message.
Because this message will not be shown for a long time, especially when the
smtp server
is a slow server, and I may press more keys when sending in process.
The following is a patch to write the sending status to a log file
'~/.mutt_smtp_log',
including some envelope headers.
Cheers.
diff -paNur mutt-1.5.19/protos.h mutt-1.5.19.new/protos.h
--- mutt-1.5.19/protos.h 2009-01-06 03:20:53.000000000 +0800
+++ mutt-1.5.19.new/protos.h 2009-11-10 01:36:53.000000000 +0800
@@ -356,6 +356,7 @@ int _mutt_save_message (HEADER *, CONTEX
int mutt_save_message (HEADER *, int, int, int, int *);
int mutt_search_command (int, int);
#ifdef USE_SMTP
+void mutt_smtp_log(ENVELOPE *, int);
int mutt_smtp_send (const ADDRESS *, const ADDRESS *, const ADDRESS *,
const ADDRESS *, const char *, int);
#endif
diff -paNur mutt-1.5.19/send.c mutt-1.5.19.new/send.c
--- mutt-1.5.19/send.c 2009-01-06 03:20:53.000000000 +0800
+++ mutt-1.5.19.new/send.c 2009-11-10 01:33:08.000000000 +0800
@@ -1016,9 +1016,13 @@ static int send_message (HEADER *msg)
#if USE_SMTP
if (SmtpUrl)
- return mutt_smtp_send (msg->env->from, msg->env->to, msg->env->cc,
+ {
+ i = mutt_smtp_send (msg->env->from, msg->env->to, msg->env->cc,
msg->env->bcc, tempfile,
(msg->content->encoding == ENC8BIT));
+ mutt_smtp_log(msg->env, i);
+ return (i);
+ }
#endif /* USE_SMTP */
i = mutt_invoke_sendmail (msg->env->from, msg->env->to, msg->env->cc,
diff -paNur mutt-1.5.19/smtp.c mutt-1.5.19.new/smtp.c
--- mutt-1.5.19/smtp.c 2009-01-06 03:20:53.000000000 +0800
+++ mutt-1.5.19.new/smtp.c 2009-11-10 01:44:56.000000000 +0800
@@ -207,6 +207,115 @@ smtp_data (CONNECTION * conn, const char
return 0;
}
+void
+mutt_smtp_log(ENVELOPE *env, int error)
+{
+ FILE *fp;
+ char buffer[LONG_STRING];
+ time_t now;
+ struct tm *pt, t;
+ char *from;
+ char *to;
+
+ if (!env || !(env->from) || !(env->to))
+ return;
+
+ if (EnvFrom)
+ from = EnvFrom->mailbox;
+ else
+ from = env->from->mailbox;
+
+ to = env->to->mailbox;
+
+ snprintf(buffer, sizeof(buffer), "%s/.mutt_smtp_log", NONULL(Homedir));
+ if ((fp = safe_fopen(buffer, "a")) == NULL)
+ return;
+
+ now = time(NULL);
+ pt = localtime_r(&now, &t);
+ if (pt == NULL)
+ goto out_fclose;
+
+ fprintf(fp, "%04d-%02d-%02d, %02d:%02d:%02d, from=<%s>, to=<%s>, stat=%s\n",
+ pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday, pt->tm_hour, pt->tm_min,
pt->tm_sec,
+ NONULL(from), NONULL(to), (error==0)?"Sent":"Failed");
+ fprintf(fp,
"------------------------------------------------------------\n");
+
+ if (env->from)
+ {
+ buffer[0] = 0;
+ rfc822_write_address (buffer, sizeof (buffer), env->from, 0);
+ fprintf (fp, "From: %s\n", buffer);
+ }
+
+ if (env->sender)
+ {
+ buffer[0] = 0;
+ rfc822_write_address (buffer, sizeof (buffer), env->sender, 0);
+ fprintf (fp, "Sender: %s\n", buffer);
+ }
+
+ if (env->to)
+ {
+ fputs ("To: ", fp);
+ mutt_write_address_list (env->to, fp, 4, 0);
+ }
+ else
+ fputs ("To: \n", fp);
+
+ if (env->cc)
+ {
+ fputs ("Cc: ", fp);
+ mutt_write_address_list (env->cc, fp, 4, 0);
+ }
+ else
+ fputs ("Cc: \n", fp);
+
+ if (env->bcc)
+ {
+ fputs ("Bcc: ", fp);
+ mutt_write_address_list (env->bcc, fp, 5, 0);
+ }
+ else
+ fputs ("Bcc: \n", fp);
+
+ if (env->subject)
+ mutt_write_one_header (fp, "Subject", env->subject, NULL, 0);
+ else
+ fputs ("Subject: \n", fp);
+
+ /* save message id if the user has set it */
+ if (env->message_id)
+ fprintf (fp, "Message-ID: %s\n", env->message_id);
+
+ if (env->reply_to)
+ {
+ fputs ("Reply-To: ", fp);
+ mutt_write_address_list (env->reply_to, fp, 10, 0);
+ }
+ else
+ fputs ("Reply-To: \n", fp);
+
+ if (env->references)
+ {
+ fputs ("References:", fp);
+ mutt_write_references (env->references, fp, 10);
+ fputc('\n', fp);
+ }
+
+ if (env->in_reply_to)
+ {
+ fputs ("In-Reply-To:", fp);
+ mutt_write_references (env->in_reply_to, fp, 1);
+ fputc ('\n', fp);
+ }
+
+ fprintf(fp,
"------------------------------------------------------------\n\n");
+
+out_fclose:
+ fclose(fp);
+}
+
int
mutt_smtp_send (const ADDRESS* from, const ADDRESS* to, const ADDRESS* cc,
const ADDRESS* bcc, const char *msgfile, int eightbit)