From: Richard Russon Date: Mon, 7 Aug 2017 13:41:46 +0000 (+0100) Subject: split out envelope X-Git-Tag: neomutt-20170907~27^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ed0f838a4c60aecffbe539c6ad6d947b650b54f;p=neomutt split out envelope --- diff --git a/Makefile.am b/Makefile.am index 6071df9af..133e3cc42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 811cbba08..ad9bc1ed9 100644 --- a/buffy.c +++ b/buffy.c @@ -31,6 +31,7 @@ #include #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 index 000000000..196019555 --- /dev/null +++ b/envelope.c @@ -0,0 +1,143 @@ +/** + * @file + * Representation of an email header (envelope) + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @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 . + */ + +#include "config.h" +#include "envelope.h" +#include +#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); +} + diff --git a/envelope.h b/envelope.h index 8c774fc8a..c0aed881f 100644 --- a/envelope.h +++ b/envelope.h @@ -24,7 +24,6 @@ #define _MUTT_ENVELOPE_H #include -#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 */ diff --git a/muttlib.c b/muttlib.c index cb1e1c0c1..ba9037734 100644 --- 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) diff --git a/po/POTFILES.in b/po/POTFILES.in index 80e9516fb..853d14df3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -22,6 +22,7 @@ doc/makedoc.c edit.c editmsg.c enter.c +envelope.c filter.c flags.c from.c diff --git a/protos.h b/protos.h index 62066f079..de93692f4 100644 --- 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__)