The reverse_name functionality is extended to also search the
Envelope-To: and X-Envelope-To: headers when looking for a suitable
From: address.
---
This second iteration drops $reverse_envelopeto, implements support for hcache, and actually contains all changes I wanted to submit

hcache.c       |  2 ++
imap/message.c |  2 +-
mutt.h         |  1 +
parse.c        | 15 ++++++++++++++-
send.c         | 10 +++++++++-
5 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/hcache.c b/hcache.c
index 492d5701..b96eb79c 100644
--- a/hcache.c
+++ b/hcache.c
@@ -523,6 +523,7 @@ dump_envelope(ENVELOPE * e, unsigned char *d, int *off, int 
convert)
  d = dump_address(e->sender, d, off, convert);
  d = dump_address(e->reply_to, d, off, convert);
  d = dump_address(e->mail_followup_to, d, off, convert);
+  d = dump_address(e->envelope_to, d, off, convert);

  d = dump_char(e->list_post, d, off, convert);
  d = dump_char(e->subject, d, off, convert);
@@ -559,6 +560,7 @@ restore_envelope(ENVELOPE * e, const unsigned char *d, int 
*off, int convert)
  restore_address(&e->sender, d, off, convert);
  restore_address(&e->reply_to, d, off, convert);
  restore_address(&e->mail_followup_to, d, off, convert);
+  restore_address(&e->envelope_to, d, off, convert);

  restore_char(&e->list_post, d, off, convert);
  if (option (OPTAUTOSUBSCRIBE))
diff --git a/imap/message.c b/imap/message.c
index 5c088cfc..a2d853d2 100644
--- a/imap/message.c
+++ b/imap/message.c
@@ -709,7 +709,7 @@ static int read_headers_fetch_new (IMAP_DATA *idata, 
unsigned int msn_begin,
  FILE *fp = NULL;
  IMAP_HEADER h;
  BUFFER *b = NULL;
-  static const char * const want_headers = "DATE FROM SENDER SUBJECT TO CC 
MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES 
LIST-POST X-LABEL";
+  static const char * const want_headers = "DATE FROM SENDER SUBJECT TO CC 
MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES 
LIST-POST X-LABEL ENVELOPE-TO X-ENVELOPE-TO";

  ctx = idata->ctx;
  idx = ctx->msgcount;
diff --git a/mutt.h b/mutt.h
index 71b66657..99a175f0 100644
--- a/mutt.h
+++ b/mutt.h
@@ -671,6 +671,7 @@ typedef struct envelope
  ADDRESS *sender;
  ADDRESS *reply_to;
  ADDRESS *mail_followup_to;
+  ADDRESS *envelope_to;
  char *list_post;              /* this stores a mailto URL, or nothing */
  char *subject;
  char *real_subj;              /* offset of the real subject */
diff --git a/parse.c b/parse.c
index 8f307aed..6d218f3a 100644
--- a/parse.c
+++ b/parse.c
@@ -1112,8 +1112,15 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, 
char *line, char *p, short

    case 'e':
      if (!ascii_strcasecmp ("xpires", line + 1) &&
-          hdr && mutt_parse_date (p, NULL) < time (NULL))
+          hdr && mutt_parse_date (p, NULL) < time (NULL)) {
        hdr->expired = 1;
+      }
+      else if (!ascii_strcasecmp (line+1, "nvelope-to"))
+      {
+        e->envelope_to = rfc822_parse_adrlist (e->envelope_to, p);
+        matched = 1;
+      }
+
      break;

    case 'f':
@@ -1318,6 +1325,12 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, 
char *line, char *p, short
        e->x_label = safe_strdup(p);
        matched = 1;
      }
+      else if (!ascii_strcasecmp (line+1, "-envelope-to"))
+      {
+        e->envelope_to = rfc822_parse_adrlist (e->envelope_to, p);
+        matched = 1;
+      }
+

    default:
      break;
diff --git a/send.c b/send.c
index 7c1460c3..616d1646 100644
--- a/send.c
+++ b/send.c
@@ -1037,12 +1037,20 @@ static ADDRESS *set_reverse_name (ENVELOPE *env)
{
  ADDRESS *tmp;

-  for (tmp = env->to; tmp; tmp = tmp->next)
+  for (tmp = env->envelope_to; tmp; tmp = tmp->next)
  {
    if (mutt_addr_is_user (tmp))
      break;
  }
  if (!tmp)
+  {
+    for (tmp = env->to; tmp; tmp = tmp->next)
+    {
+      if (mutt_addr_is_user (tmp))
+        break;
+    }
+  }
+  if (!tmp)
  {
    for (tmp = env->cc; tmp; tmp = tmp->next)
    {
--
2.20.1

Reply via email to