I've gone through the code lifecycle for headers and header->env and
checked whether it's possible for a header to exist without a
header->env.
The trickiest part of the code was in mh.c where allocation of the
header and envelope are separated between maildir_parse_dir() and
maildir_delayed_parsing().
The pop.c code is also separated, but not as convoluted.
One case in postpone.c has a "shell" header passed in to
mutt_prepare_template() for the sake of the file pointer to be used,
so I added a comment to the code for that case.
Otherwise I can't find any places in the code where a header exist
without the envelope.
---
copy.c | 9 ++++-----
imap/imap.c | 12 +++---------
mh.c | 14 ++++----------
postpone.c | 7 +++++--
4 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/copy.c b/copy.c
index f24f6465..eec9fb28 100644
--- a/copy.c
+++ b/copy.c
@@ -368,11 +368,10 @@ mutt_copy_header(FILE *in, HEADER *h, FILE *out, int
flags, const char *prefix)
char buffer[SHORT_STRING];
char *temp_hdr = NULL;
- if (h->env)
- flags |= ((h->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0)
- | ((h->env->changed & MUTT_ENV_CHANGED_REFS) ? CH_UPDATE_REFS : 0)
- | ((h->env->changed & MUTT_ENV_CHANGED_XLABEL) ? CH_UPDATE_LABEL : 0)
- | ((h->env->changed & MUTT_ENV_CHANGED_SUBJECT) ? CH_UPDATE_SUBJECT : 0);
+ flags |= ((h->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0)
+ | ((h->env->changed & MUTT_ENV_CHANGED_REFS) ? CH_UPDATE_REFS : 0)
+ | ((h->env->changed & MUTT_ENV_CHANGED_XLABEL) ? CH_UPDATE_LABEL : 0)
+ | ((h->env->changed & MUTT_ENV_CHANGED_SUBJECT) ? CH_UPDATE_SUBJECT : 0);
if (mutt_copy_hdr(in, out, h->offset, h->content->offset, flags, prefix) ==
-1)
return -1;
diff --git a/imap/imap.c b/imap/imap.c
index 0ce804e5..0778a5e6 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -648,10 +648,7 @@ int imap_reconnect(IMAP_DATA **p_idata)
mutt_set_flag(&new_ctx, new_hdr, MUTT_OLD, old_hdr->old);
mutt_set_flag(&new_ctx, new_hdr, MUTT_READ, old_hdr->read);
- /* TODO: the ->env check is unfortunately voodoo that I
- * haven't taken the time to track down yet. It's in other
- * parts of the code but I don't know why yet. */
- if (old_hdr->env && old_hdr->env->changed)
+ if (old_hdr->env->changed)
{
new_hdr->env->changed = old_hdr->env->changed;
new_hdr->changed = 1;
@@ -1546,8 +1543,7 @@ int imap_sync_mailbox(CONTEXT *ctx, int expunge, int
*index_hint)
/* if the message has been rethreaded or attachments have been deleted
* we delete the message and reupload it.
* This works better if we're expunging, of course. */
- /* TODO: why the h->env check? */
- if ((h->env && h->env->changed) || h->attach_del)
+ if (h->env->changed || h->attach_del)
{
/* NOTE and TODO:
*
@@ -1582,9 +1578,7 @@ int imap_sync_mailbox(CONTEXT *ctx, int expunge, int
*index_hint)
muttdbg(1, "imap_sync_mailbox: Error opening mailbox in append
mode");
else
_mutt_save_message(h, appendctx, 1, 0, 0);
- /* TODO: why the check for h->env? Is this possible? */
- if (h->env)
- h->env->changed = 0;
+ h->env->changed = 0;
#if USE_HCACHE
idata->hcache = imap_hcache_open(idata, NULL);
#endif
diff --git a/mh.c b/mh.c
index c7e71859..a74e94fb 100644
--- a/mh.c
+++ b/mh.c
@@ -1885,14 +1885,11 @@ static int mh_sync_message(CONTEXT * ctx, int msgno)
{
HEADER *h = ctx->hdrs[msgno];
- /* TODO: why the h->env check? */
- if (h->attach_del || (h->env && h->env->changed))
+ if (h->attach_del || h->env->changed)
{
if (mh_rewrite_message(ctx, msgno) != 0)
return -1;
- /* TODO: why the env check? */
- if (h->env)
- h->env->changed = 0;
+ h->env->changed = 0;
}
return 0;
@@ -1909,15 +1906,12 @@ static int maildir_sync_message(CONTEXT * ctx, int
msgno)
char *p;
int rc = 0;
- /* TODO: why the h->env check? */
- if (h->attach_del || (h->env && h->env->changed))
+ if (h->attach_del || h->env->changed)
{
/* when doing attachment deletion/rethreading, fall back to the MH case. */
if (mh_rewrite_message(ctx, msgno) != 0)
return (-1);
- /* TODO: why the env check? */
- if (h->env)
- h->env->changed = 0;
+ h->env->changed = 0;
}
else
{
diff --git a/postpone.c b/postpone.c
index 51cc62c1..86f4a99a 100644
--- a/postpone.c
+++ b/postpone.c
@@ -598,8 +598,11 @@ int mutt_prepare_template(FILE *fp, CONTEXT *ctx, HEADER
*newhdr, HEADER *hdr,
bfp = fp;
- /* parse the message header and MIME structure */
-
+ /* parse the message header and MIME structure
+ *
+ * Note that in some cases the hdr parameter does not contain an envelope,
+ * e.g. from main.c draftFile processing
+ */
fseeko(fp, hdr->offset, SEEK_SET);
newhdr->offset = hdr->offset;
/* enable header weeding for resent messages */
--
2.55.0