]> granicus.if.org Git - neomutt/commitdiff
split out envelope
authorRichard Russon <rich@flatcap.org>
Mon, 7 Aug 2017 13:41:46 +0000 (14:41 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 10 Aug 2017 12:53:36 +0000 (13:53 +0100)
Makefile.am
buffy.c
envelope.c [new file with mode: 0644]
envelope.h
muttlib.c
po/POTFILES.in
protos.h

index 6071df9af450c8619ede0c0322faf9bb3bbf6a53..133e3cc427a32b32ede6e5bfa42388ddc9f23631 100644 (file)
@@ -48,7 +48,7 @@ mutt_SOURCES = account.c addrbook.c address.h alias.c alias.h attach.c \
        bcache.c body.c body.h browser.c buffy.c charset.c color.c \
        commands.c complete.c compose.c compress.c content.h context.h copy.c \
        curs_lib.c curs_main.c edit.c editmsg.c enter.c enter_state.h \
-       envelope.h filter.c flags.c format_flags.h from.c getdomain.c group.c \
+       envelope.c envelope.h filter.c flags.c format_flags.h from.c getdomain.c group.c \
        handler.c hdrline.c header.h headers.c help.c history.c hook.c \
        init.c keymap.c list.h main.c mbox.c mbyte.c mbyte_table.h \
        menu.c mh.c muttlib.c mutt_idna.c mutt_sasl_plain.c mutt_socket.c \
diff --git a/buffy.c b/buffy.c
index 811cbba08c25233eb6b3fa4bdadad394c78e0098..ad9bc1ed9015be8917ddd11d308b2e86ce5350f0 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -31,6 +31,7 @@
 #include <utime.h>
 #include "buffy.h"
 #include "context.h"
+#include "envelope.h"
 #include "globals.h"
 #include "header.h"
 #include "lib/lib.h"
diff --git a/envelope.c b/envelope.c
new file mode 100644 (file)
index 0000000..1960195
--- /dev/null
@@ -0,0 +1,143 @@
+/**
+ * @file
+ * Representation of an email header (envelope)
+ *
+ * @authors
+ * Copyright (C) 2017 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "envelope.h"
+#include <stddef.h>
+#include "lib/buffer.h"
+#include "lib/memory.h"
+#include "queue.h"
+#include "rfc822.h"
+
+struct Envelope *mutt_new_envelope(void)
+{
+  struct Envelope *e = safe_calloc(1, sizeof(struct Envelope));
+  STAILQ_INIT(&e->references);
+  STAILQ_INIT(&e->in_reply_to);
+  STAILQ_INIT(&e->userhdrs);
+  return e;
+}
+
+void mutt_free_envelope(struct Envelope **p)
+{
+  if (!*p)
+    return;
+  rfc822_free_address(&(*p)->return_path);
+  rfc822_free_address(&(*p)->from);
+  rfc822_free_address(&(*p)->to);
+  rfc822_free_address(&(*p)->cc);
+  rfc822_free_address(&(*p)->bcc);
+  rfc822_free_address(&(*p)->sender);
+  rfc822_free_address(&(*p)->reply_to);
+  rfc822_free_address(&(*p)->mail_followup_to);
+
+  FREE(&(*p)->list_post);
+  FREE(&(*p)->subject);
+  /* real_subj is just an offset to subject and shouldn't be freed */
+  FREE(&(*p)->disp_subj);
+  FREE(&(*p)->message_id);
+  FREE(&(*p)->supersedes);
+  FREE(&(*p)->date);
+  FREE(&(*p)->x_label);
+  FREE(&(*p)->organization);
+#ifdef USE_NNTP
+  FREE(&(*p)->newsgroups);
+  FREE(&(*p)->xref);
+  FREE(&(*p)->followup_to);
+  FREE(&(*p)->x_comment_to);
+#endif
+
+  mutt_buffer_free(&(*p)->spam);
+
+  mutt_list_free(&(*p)->references);
+  mutt_list_free(&(*p)->in_reply_to);
+  mutt_list_free(&(*p)->userhdrs);
+  FREE(p);
+}
+
+/**
+ * mutt_merge_envelopes - Merge the headers of two emails
+ *
+ * Move all the headers from extra not present in base into base
+ */
+void mutt_merge_envelopes(struct Envelope *base, struct Envelope **extra)
+{
+/* copies each existing element if necessary, and sets the element
+  * to NULL in the source so that mutt_free_envelope doesn't leave us
+  * with dangling pointers. */
+#define MOVE_ELEM(h)                                                           \
+  if (!base->h)                                                                \
+  {                                                                            \
+    base->h = (*extra)->h;                                                     \
+    (*extra)->h = NULL;                                                        \
+  }
+
+#define MOVE_STAILQ(h)                                                         \
+  if (STAILQ_EMPTY(&base->h))                                                  \
+  {                                                                            \
+    STAILQ_SWAP(&base->h, &((*extra))->h, ListNode);                         \
+  }
+
+  MOVE_ELEM(return_path);
+  MOVE_ELEM(from);
+  MOVE_ELEM(to);
+  MOVE_ELEM(cc);
+  MOVE_ELEM(bcc);
+  MOVE_ELEM(sender);
+  MOVE_ELEM(reply_to);
+  MOVE_ELEM(mail_followup_to);
+  MOVE_ELEM(list_post);
+  MOVE_ELEM(message_id);
+  MOVE_ELEM(supersedes);
+  MOVE_ELEM(date);
+  MOVE_ELEM(x_label);
+  MOVE_ELEM(x_original_to);
+  if (!base->refs_changed)
+  {
+    MOVE_STAILQ(references);
+  }
+  if (!base->irt_changed)
+  {
+    MOVE_STAILQ(in_reply_to);
+  }
+
+  /* real_subj is subordinate to subject */
+  if (!base->subject)
+  {
+    base->subject = (*extra)->subject;
+    base->real_subj = (*extra)->real_subj;
+    base->disp_subj = (*extra)->disp_subj;
+    (*extra)->subject = NULL;
+    (*extra)->real_subj = NULL;
+    (*extra)->disp_subj = NULL;
+  }
+  /* spam and user headers should never be hashed, and the new envelope may
+    * have better values. Use new versions regardless. */
+  mutt_buffer_free(&base->spam);
+  mutt_list_free(&base->userhdrs);
+  MOVE_ELEM(spam);
+  MOVE_STAILQ(userhdrs);
+#undef MOVE_ELEM
+
+  mutt_free_envelope(extra);
+}
+
index 8c774fc8a77df9227d8eee14e9df80b4342956b1..c0aed881f63e180eb64c48cf1fde2817d00f8873 100644 (file)
@@ -24,7 +24,6 @@
 #define _MUTT_ENVELOPE_H
 
 #include <stdbool.h>
-#include "lib/lib.h"
 #include "list.h"
 
 /**
@@ -66,13 +65,8 @@ struct Envelope
   bool refs_changed : 1; /**< References changed to break thread */
 };
 
-static inline struct Envelope *mutt_new_envelope(void)
-{
-  struct Envelope *e = safe_calloc(1, sizeof(struct Envelope));
-  STAILQ_INIT(&e->references);
-  STAILQ_INIT(&e->in_reply_to);
-  STAILQ_INIT(&e->userhdrs);
-  return e;
-}
+struct Envelope *mutt_new_envelope(void);
+void mutt_free_envelope(struct Envelope **p);
+void mutt_merge_envelopes(struct Envelope *base, struct Envelope **extra);
 
 #endif /* _MUTT_ENVELOPE_H */
index cb1e1c0c165cb30282d142fc8430472395c5dcdc..ba9037734a47f39cfa2a4d54d3af71e5a07a6a73 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -460,110 +460,6 @@ bool mutt_is_text_part(struct Body *b)
   return false;
 }
 
-void mutt_free_envelope(struct Envelope **p)
-{
-  if (!*p)
-    return;
-  rfc822_free_address(&(*p)->return_path);
-  rfc822_free_address(&(*p)->from);
-  rfc822_free_address(&(*p)->to);
-  rfc822_free_address(&(*p)->cc);
-  rfc822_free_address(&(*p)->bcc);
-  rfc822_free_address(&(*p)->sender);
-  rfc822_free_address(&(*p)->reply_to);
-  rfc822_free_address(&(*p)->mail_followup_to);
-
-  FREE(&(*p)->list_post);
-  FREE(&(*p)->subject);
-  /* real_subj is just an offset to subject and shouldn't be freed */
-  FREE(&(*p)->disp_subj);
-  FREE(&(*p)->message_id);
-  FREE(&(*p)->supersedes);
-  FREE(&(*p)->date);
-  FREE(&(*p)->x_label);
-  FREE(&(*p)->organization);
-#ifdef USE_NNTP
-  FREE(&(*p)->newsgroups);
-  FREE(&(*p)->xref);
-  FREE(&(*p)->followup_to);
-  FREE(&(*p)->x_comment_to);
-#endif
-
-  mutt_buffer_free(&(*p)->spam);
-
-  mutt_list_free(&(*p)->references);
-  mutt_list_free(&(*p)->in_reply_to);
-  mutt_list_free(&(*p)->userhdrs);
-  FREE(p);
-}
-
-/**
- * mutt_merge_envelopes - Merge the headers of two emails
- *
- * Move all the headers from extra not present in base into base
- */
-void mutt_merge_envelopes(struct Envelope *base, struct Envelope **extra)
-{
-/* copies each existing element if necessary, and sets the element
-  * to NULL in the source so that mutt_free_envelope doesn't leave us
-  * with dangling pointers. */
-#define MOVE_ELEM(h)                                                           \
-  if (!base->h)                                                                \
-  {                                                                            \
-    base->h = (*extra)->h;                                                     \
-    (*extra)->h = NULL;                                                        \
-  }
-
-#define MOVE_STAILQ(h)                                                         \
-  if (STAILQ_EMPTY(&base->h))                                                  \
-  {                                                                            \
-    STAILQ_SWAP(&base->h, &((*extra))->h, ListNode);                         \
-  }
-
-  MOVE_ELEM(return_path);
-  MOVE_ELEM(from);
-  MOVE_ELEM(to);
-  MOVE_ELEM(cc);
-  MOVE_ELEM(bcc);
-  MOVE_ELEM(sender);
-  MOVE_ELEM(reply_to);
-  MOVE_ELEM(mail_followup_to);
-  MOVE_ELEM(list_post);
-  MOVE_ELEM(message_id);
-  MOVE_ELEM(supersedes);
-  MOVE_ELEM(date);
-  MOVE_ELEM(x_label);
-  MOVE_ELEM(x_original_to);
-  if (!base->refs_changed)
-  {
-    MOVE_STAILQ(references);
-  }
-  if (!base->irt_changed)
-  {
-    MOVE_STAILQ(in_reply_to);
-  }
-
-  /* real_subj is subordinate to subject */
-  if (!base->subject)
-  {
-    base->subject = (*extra)->subject;
-    base->real_subj = (*extra)->real_subj;
-    base->disp_subj = (*extra)->disp_subj;
-    (*extra)->subject = NULL;
-    (*extra)->real_subj = NULL;
-    (*extra)->disp_subj = NULL;
-  }
-  /* spam and user headers should never be hashed, and the new envelope may
-    * have better values. Use new versions regardless. */
-  mutt_buffer_free(&base->spam);
-  mutt_list_free(&base->userhdrs);
-  MOVE_ELEM(spam);
-  MOVE_STAILQ(userhdrs);
-#undef MOVE_ELEM
-
-  mutt_free_envelope(extra);
-}
-
 static FILE *frandom;
 
 static void mutt_randbuf(void *out, size_t len)
index 80e9516fbf40f16e63e54c9cddda9be0eff42a00..853d14df3f308c1696a374bc41273ad640d2e5b7 100644 (file)
@@ -22,6 +22,7 @@ doc/makedoc.c
 edit.c
 editmsg.c
 enter.c
+envelope.c
 filter.c
 flags.c
 from.c
index 62066f079cca61f5ae42fad47e127bb75fb5960d..de93692f4359088e7078a2ef5e78d22c557b2b60 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -194,7 +194,6 @@ void mutt_forward_trailer(struct Context *ctx, struct Header *cur, FILE *fp);
 void mutt_free_alias(struct Alias **p);
 void mutt_free_color(int fg, int bg);
 void mutt_free_enter_state(struct EnterState **esp);
-void mutt_free_envelope(struct Envelope **p);
 void mutt_free_header(struct Header **h);
 void mutt_free_regexp(struct Regex **pp);
 void mutt_help(int menu);
@@ -204,7 +203,6 @@ void mutt_make_forward_subject(struct Envelope *env, struct Context *ctx, struct
 void mutt_make_help(char *d, size_t dlen, const char *txt, int menu, int op);
 void mutt_make_misc_reply_headers(struct Envelope *env, struct Context *ctx, struct Header *cur, struct Envelope *curenv);
 void mutt_make_post_indent(struct Context *ctx, struct Header *cur, FILE *out);
-void mutt_merge_envelopes(struct Envelope *base, struct Envelope **extra);
 void mutt_message_to_7bit(struct Body *a, FILE *fp);
 #define mutt_mktemp(a, b) mutt_mktemp_pfx_sfx(a, b, "mutt", NULL)
 #define mutt_mktemp_pfx_sfx(a, b, c, d) _mutt_mktemp(a, b, c, d, __FILE__, __LINE__)