Some code in mx.c used to open a new message still rely on context's
magic, so move that into their respective mx callbacks.
---
mailbox.h | 1 +
mbox.c | 31 ++++++++++++++++++++++++++++++-
mx.c | 33 ++++++---------------------------
3 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/mailbox.h b/mailbox.h
index 9ba4176..8c78089 100644
--- a/mailbox.h
+++ b/mailbox.h
@@ -54,6 +54,7 @@ typedef struct _message
unsigned flagged : 1;
unsigned replied : 1;
unsigned draft : 1;
+ unsigned add_from : 1;
} flags;
time_t received; /* the time at which this message was received */
} MESSAGE;
diff --git a/mbox.c b/mbox.c
index 1b03ee0..6a3988f 100644
--- a/mbox.c
+++ b/mbox.c
@@ -514,9 +514,38 @@ static int mmdf_commit_message (CONTEXT *ctx, MESSAGE *msg)
return 0;
}
+static void mbox_mmdf_new_msg_set_from (MESSAGE *msg, HEADER *hdr)
+{
+ ADDRESS *p = NULL;
+
+ if (!msg->flags.add_from || !hdr)
+ return;
+
+ if (hdr->env->return_path)
+ p = hdr->env->return_path;
+ else if (hdr->env->sender)
+ p = hdr->env->sender;
+ else
+ p = hdr->env->from;
+
+ fprintf (msg->fp, "From %s %s",
+ p ? p->mailbox : NONULL(Username), ctime (&msg->received));
+}
+
static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
{
msg->fp = dest->fp;
+ mbox_mmdf_new_msg_set_from (msg, hdr);
+
+ return 0;
+}
+
+static int mmdf_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
+{
+ msg->fp = dest->fp;
+ fputs (MMDF_SEP, msg->fp);
+ mbox_mmdf_new_msg_set_from (msg, hdr);
+
return 0;
}
@@ -1357,6 +1386,6 @@ struct mx_ops mx_mmdf_ops = {
.open_msg = mbox_open_message,
.close_msg = mbox_close_message,
.commit_msg = mmdf_commit_message,
- .open_new_msg = mbox_open_new_message,
+ .open_new_msg = mmdf_open_new_message,
.check = mbox_check_mailbox,
};
diff --git a/mx.c b/mx.c
index 1977ec7..1ca9420 100644
--- a/mx.c
+++ b/mx.c
@@ -1228,7 +1228,6 @@ int mx_sync_mailbox (CONTEXT *ctx, int *index_hint)
*/
MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags)
{
- ADDRESS *p = NULL;
MESSAGE *msg;
if (!dest->mx_ops->open_new_msg)
@@ -1243,38 +1242,18 @@ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER
*hdr, int flags)
if (hdr)
{
- msg->flags.flagged = hdr->flagged;
- msg->flags.replied = hdr->replied;
- msg->flags.read = hdr->read;
- msg->flags.draft = (flags & MUTT_SET_DRAFT) ? 1 : 0;
+ msg->flags.flagged = hdr->flagged;
+ msg->flags.replied = hdr->replied;
+ msg->flags.read = hdr->read;
+ msg->flags.draft = (flags & MUTT_SET_DRAFT) ? 1 : 0;
+ msg->flags.add_from = (flags & MUTT_ADD_FROM) ? 1 : 0;
msg->received = hdr->received;
}
if(msg->received == 0)
time(&msg->received);
- if (dest->mx_ops->open_new_msg (msg, dest, hdr) == 0)
- {
- if (dest->magic == MUTT_MMDF)
- fputs (MMDF_SEP, msg->fp);
-
- if ((dest->magic == MUTT_MBOX || dest->magic == MUTT_MMDF) &&
- flags & MUTT_ADD_FROM)
- {
- if (hdr)
- {
- if (hdr->env->return_path)
- p = hdr->env->return_path;
- else if (hdr->env->sender)
- p = hdr->env->sender;
- else
- p = hdr->env->from;
- }
-
- fprintf (msg->fp, "From %s %s", p ? p->mailbox : NONULL(Username), ctime
(&msg->received));
- }
- }
- else
+ if (dest->mx_ops->open_new_msg (msg, dest, hdr) != 0)
FREE (&msg);
return msg;
--
2.9.3