From: Richard Russon Date: Sat, 14 Jul 2018 11:41:39 +0000 (+0100) Subject: move rfc2047,rfc2231 to libemail X-Git-Tag: 2019-10-25~756^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b8bc745c40feb20fd9ad4bfdc303ba376f2e66c;p=neomutt move rfc2047,rfc2231 to libemail --- diff --git a/Makefile.autosetup b/Makefile.autosetup index 526345e4d..00077a7e8 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -70,7 +70,7 @@ NEOMUTTOBJS= addrbook.o alias.o bcache.o browser.o buffy.o \ mutt_history.o mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_url.o mutt_window.o mx.o \ pager.o parse.o pattern.o \ postpone.o progress.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \ - rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \ + rfc3676.o safe_asprintf.o score.o send.o \ sendlib.o sidebar.o smtp.o sort.o state.o status.o system.o \ terminal.o version.o @@ -90,7 +90,9 @@ ALLOBJS+= $(NEOMUTTOBJS) # libemail LIBEMAIL= libemail.a LIBEMAILOBJS= email/address.o email/attach.o email/body.o email/envelope.o \ - email/from.o email/header.o email/idna.o email/mime.o email/parameter.o email/rfc2047.o email/tags.o email/thread.o email/url.o + email/from.o email/email_globals.o email/header.o email/idna.o \ + email/mime.o email/parameter.o email/rfc2047.o email/rfc2231.o email/tags.o \ + email/thread.o email/url.o CLEANFILES+= $(LIBEMAIL) $(LIBEMAILOBJS) MUTTLIBS+= $(LIBEMAIL) ALLOBJS+= $(LIBEMAILOBJS) diff --git a/bcache.c b/bcache.c index ed7eb20d7..6540d9499 100644 --- a/bcache.c +++ b/bcache.c @@ -30,12 +30,12 @@ #include #include #include "mutt/mutt.h" +#include "email/email.h" #include "bcache.h" #include "globals.h" #include "mutt_account.h" #include "muttlib.h" #include "protos.h" -#include "email/email.h" /* These Config Variables are only used in bcache.c */ char *MessageCachedir; diff --git a/copy.c b/copy.c index d0c28a0ad..7b68db8ed 100644 --- a/copy.c +++ b/copy.c @@ -46,7 +46,6 @@ #include "ncrypt/ncrypt.h" #include "options.h" #include "protos.h" -#include "rfc2047.h" #include "sendlib.h" #include "state.h" #ifdef USE_NOTMUCH @@ -192,7 +191,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, if (flags & CH_DECODE) { if (address_header_decode(&this_one) == 0) - mutt_rfc2047_decode(&this_one); + rfc2047_decode(&this_one); this_one_len = mutt_str_strlen(this_one); /* Convert CRLF line endings to LF */ @@ -309,7 +308,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, if (flags & CH_DECODE) { if (address_header_decode(&this_one) == 0) - mutt_rfc2047_decode(&this_one); + rfc2047_decode(&this_one); this_one_len = mutt_str_strlen(this_one); } diff --git a/email/email.h b/email/email.h index 6b3068122..8c3fbd7df 100644 --- a/email/email.h +++ b/email/email.h @@ -37,6 +37,7 @@ * | email/parameter.c | @subpage email_parameter | * | email/mime.c | @subpage email_mime | * | email/rfc2047.c | @subpage email_rfc2047 | + * | email/rfc2231.c | @subpage email_rfc2231 | * | email/tags.c | @subpage email_tags | * | email/thread.c | @subpage email_thread | * | email/url.c | @subpage email_url | @@ -49,6 +50,7 @@ #include "attach.h" #include "body.h" #include "content.h" +#include "email_globals.h" #include "envelope.h" #include "from.h" #include "header.h" @@ -56,6 +58,7 @@ #include "mime.h" #include "parameter.h" #include "rfc2047.h" +#include "rfc2231.h" #include "tags.h" #include "thread.h" #include "url.h" diff --git a/rfc2047.h b/email/email_globals.c similarity index 68% rename from rfc2047.h rename to email/email_globals.c index c396f8284..cfb828297 100644 --- a/rfc2047.h +++ b/email/email_globals.c @@ -1,9 +1,9 @@ /** * @file - * RFC2047 MIME extensions routines + * Email Global Variables * * @authors - * Copyright (C) 1996-2000 Michael R. Elkins + * Copyright (C) 2018 Richard Russon * * @copyright * This program is free software: you can redistribute it and/or modify it under @@ -20,13 +20,12 @@ * this program. If not, see . */ -#ifndef _MUTT_RFC2047_2_H -#define _MUTT_RFC2047_2_H - -struct Address; - -void rfc2047_encode_addrlist(struct Address *addr, const char *tag); -void rfc2047_decode_addrlist(struct Address *a); +/** + * @page email_globals Email Global Variables + * + * These global variables are private to the email library. + */ -#endif /* _MUTT_RFC2047_2_H */ +#include "config.h" +char *SendCharset; diff --git a/email/email_globals.h b/email/email_globals.h new file mode 100644 index 000000000..1ad38a1c6 --- /dev/null +++ b/email/email_globals.h @@ -0,0 +1,28 @@ +/** + * @file + * Email Global Variables + * + * @authors + * Copyright (C) 2018 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 . + */ + +#ifndef _EMAIL_GLOBALS_H +#define _EMAIL_GLOBALS_H + +extern char *SendCharset; + +#endif /* _EMAIL_GLOBALS_H */ diff --git a/email/rfc2047.c b/email/rfc2047.c index 98467a631..8e91d9a5d 100644 --- a/email/rfc2047.c +++ b/email/rfc2047.c @@ -35,8 +35,10 @@ #include #include #include -#include "rfc2047.h" #include "mutt/mutt.h" +#include "rfc2047.h" +#include "address.h" +#include "email_globals.h" #include "mime.h" #define ENCWORD_LEN_MAX 75 @@ -412,7 +414,7 @@ static char *rfc2047_decode_word(const char *s, size_t len, enum ContentEncoding } /** - * rfc2047_encode - RFC2047-encode a string + * rfc2047_encode2 - RFC2047-encode a string * @param d String to convert * @param dlen Length of string * @param col Starting column to convert @@ -423,8 +425,9 @@ static char *rfc2047_decode_word(const char *s, size_t len, enum ContentEncoding * @param specials Special characters to be encoded * @retval 0 Success */ -static int rfc2047_encode(const char *d, size_t dlen, int col, const char *fromcode, - const char *charsets, char **e, size_t *elen, const char *specials) +static int rfc2047_encode2(const char *d, size_t dlen, int col, + const char *fromcode, const char *charsets, char **e, + size_t *elen, const char *specials) { int rc = 0; char *buf = NULL; @@ -613,13 +616,13 @@ static int rfc2047_encode(const char *d, size_t dlen, int col, const char *fromc } /** - * mutt_rfc2047_encode - RFC-2047-encode a string + * rfc2047_encode - RFC-2047-encode a string * @param[in,out] pd String to be encoded, and resulting encoded string * @param[in] specials Special characters to be encoded * @param[in] col Starting index in string * @param[in] charsets List of charsets to choose from */ -void mutt_rfc2047_encode(char **pd, const char *specials, int col, const char *charsets) +void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets) { char *e = NULL; size_t elen; @@ -630,21 +633,21 @@ void mutt_rfc2047_encode(char **pd, const char *specials, int col, const char *c if (!charsets || !*charsets) charsets = "utf-8"; - rfc2047_encode(*pd, strlen(*pd), col, Charset, charsets, &e, &elen, specials); + rfc2047_encode2(*pd, strlen(*pd), col, Charset, charsets, &e, &elen, specials); FREE(pd); *pd = e; } /** - * mutt_rfc2047_decode - Decode any RFC2047-encoded header fields + * rfc2047_decode - Decode any RFC2047-encoded header fields * @param[in,out] pd String to be decoded, and resulting decoded string * * Try to decode anything that looks like a valid RFC2047 encoded header field, * ignoring RFC822 parsing rules. If decoding fails, for example due to an * invalid base64 string, the original input is left untouched. */ -void mutt_rfc2047_decode(char **pd) +void rfc2047_decode(char **pd) { if (!pd || !*pd) return; @@ -737,3 +740,42 @@ void mutt_rfc2047_decode(char **pd) mutt_buffer_addch(&buf, '\0'); *pd = buf.data; } + +/** + * rfc2047_encode_addrlist - Encode any RFC2047 headers, where required, in an Address list + * @param addr Address list + * @param tag Header tag (used for wrapping calculation) + */ +void rfc2047_encode_addrlist(struct Address *addr, const char *tag) +{ + struct Address *ptr = addr; + int col = tag ? strlen(tag) + 2 : 32; + + while (ptr) + { + if (ptr->personal) + rfc2047_encode(&ptr->personal, AddressSpecials, col, SendCharset); + else if (ptr->group && ptr->mailbox) + rfc2047_encode(&ptr->mailbox, AddressSpecials, col, SendCharset); + ptr = ptr->next; + } +} + +/** + * rfc2047_decode_addrlist - Decode any RFC2047 headers in an Address list + * @param a Address list + */ +void rfc2047_decode_addrlist(struct Address *a) +{ + while (a) + { + if (a->personal && + ((strstr(a->personal, "=?") != NULL) || (AssumedCharset && *AssumedCharset))) + { + rfc2047_decode(&a->personal); + } + else if (a->group && a->mailbox && (strstr(a->mailbox, "=?") != NULL)) + rfc2047_decode(&a->mailbox); + a = a->next; + } +} diff --git a/email/rfc2047.h b/email/rfc2047.h index 38c2ce6e3..31fedbf77 100644 --- a/email/rfc2047.h +++ b/email/rfc2047.h @@ -25,7 +25,12 @@ #ifndef _EMAIL_RFC2047_H #define _EMAIL_RFC2047_H -void mutt_rfc2047_decode(char **pd); -void mutt_rfc2047_encode(char **pd, const char *specials, int col, const char *charsets); +struct Address; + +void rfc2047_decode(char **pd); +void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets); + +void rfc2047_decode_addrlist(struct Address *a); +void rfc2047_encode_addrlist(struct Address *addr, const char *tag); #endif /* _EMAIL_RFC2047_H */ diff --git a/rfc2231.c b/email/rfc2231.c similarity index 99% rename from rfc2231.c rename to email/rfc2231.c index b945c7377..c5325b841 100644 --- a/rfc2231.c +++ b/email/rfc2231.c @@ -226,7 +226,7 @@ void rfc2231_decode_parameters(struct ParameterList *p) */ if (Rfc2047Parameters && np->value && strstr(np->value, "=?")) - mutt_rfc2047_decode(&np->value); + rfc2047_decode(&np->value); else if (AssumedCharset && *AssumedCharset) mutt_ch_convert_nonmime_string(&np->value); } diff --git a/rfc2231.h b/email/rfc2231.h similarity index 92% rename from rfc2231.h rename to email/rfc2231.h index 0a492722a..a71a0ab7a 100644 --- a/rfc2231.h +++ b/email/rfc2231.h @@ -20,8 +20,8 @@ * this program. If not, see . */ -#ifndef _MUTT_RFC2231_H -#define _MUTT_RFC2231_H +#ifndef _EMAIL_RFC2231_H +#define _EMAIL_RFC2231_H struct ParameterList; @@ -31,4 +31,4 @@ extern bool Rfc2047Parameters; void rfc2231_decode_parameters(struct ParameterList *p); int rfc2231_encode_string(char **pd); -#endif /* _MUTT_RFC2231_H */ +#endif /* _EMAIL_RFC2231_H */ diff --git a/email/url.c b/email/url.c index 7b1917156..200d12298 100644 --- a/email/url.c +++ b/email/url.c @@ -350,4 +350,3 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) return 0; } - diff --git a/globals.h b/globals.h index ab12ff142..79d43778e 100644 --- a/globals.h +++ b/globals.h @@ -142,7 +142,6 @@ WHERE char *IndentString; WHERE char *PrintCommand; WHERE char *NewMailCommand; WHERE char *Realname; -WHERE char *SendCharset; WHERE char *Shell; WHERE char *SimpleSearch; #ifdef USE_SMTP diff --git a/init.h b/init.h index 18ba0e2fc..5f97fe9b6 100644 --- a/init.h +++ b/init.h @@ -74,7 +74,6 @@ #include "recvcmd.h" #include "remailer.h" #include "rfc1524.h" -#include "rfc2231.h" #include "rfc3676.h" #include "score.h" #include "send.h" diff --git a/mutt_url.c b/mutt_url.c index 99e0190c0..505088971 100644 --- a/mutt_url.c +++ b/mutt_url.c @@ -28,7 +28,6 @@ #include "email/email.h" #include "mutt.h" #include "globals.h" -#include "rfc2047.h" #include "parse.h" int url_parse_mailto(struct Envelope *e, char **body, const char *src) @@ -112,8 +111,8 @@ int url_parse_mailto(struct Envelope *e, char **body, const char *src) rfc2047_decode_addrlist(e->mail_followup_to); rfc2047_decode_addrlist(e->return_path); rfc2047_decode_addrlist(e->sender); - mutt_rfc2047_decode(&e->x_label); - mutt_rfc2047_decode(&e->subject); + rfc2047_decode(&e->x_label); + rfc2047_decode(&e->subject); rc = 0; diff --git a/parse.c b/parse.c index 8dca557df..5107ddad9 100644 --- a/parse.c +++ b/parse.c @@ -39,8 +39,6 @@ #include "options.h" #include "protos.h" #include "recvattach.h" -#include "rfc2047.h" -#include "rfc2231.h" struct Context; @@ -484,7 +482,7 @@ struct Body *mutt_read_mime_header(FILE *fp, bool digest) else if (mutt_str_strcasecmp("description", line + 8) == 0) { mutt_str_replace(&p->description, c); - mutt_rfc2047_decode(&p->description); + rfc2047_decode(&p->description); } } #ifdef SUN_ATTACHMENT @@ -499,7 +497,7 @@ struct Body *mutt_read_mime_header(FILE *fp, bool digest) else if (mutt_str_strcasecmp("data-description", line + 6) == 0) { mutt_str_replace(&p->description, c); - mutt_rfc2047_decode(&p->description); + rfc2047_decode(&p->description); } } #endif @@ -851,7 +849,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (hdr) { mutt_str_replace(&hdr->content->description, p); - mutt_rfc2047_decode(&hdr->content->description); + rfc2047_decode(&hdr->content->description); } matched = 1; } @@ -1159,7 +1157,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { struct ListNode *np = mutt_list_insert_tail(&e->userhdrs, mutt_str_strdup(line)); if (do_2047) - mutt_rfc2047_decode(&np->data); + rfc2047_decode(&np->data); } } @@ -1304,7 +1302,7 @@ struct Envelope *mutt_rfc822_read_header(FILE *f, struct Header *hdr, { regmatch_t pmatch[1]; - mutt_rfc2047_decode(&e->subject); + rfc2047_decode(&e->subject); if (ReplyRegex && ReplyRegex->regex && (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0) == 0)) diff --git a/rfc2047.c b/rfc2047.c deleted file mode 100644 index b20538da2..000000000 --- a/rfc2047.c +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file - * RFC2047 MIME extensions routines - * - * @authors - * Copyright (C) 1996-2000,2010 Michael R. Elkins - * Copyright (C) 2000-2002 Edmund Grimley Evans - * - * @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 "mutt/mutt.h" -#include "email/email.h" -#include "globals.h" - -#include - -/** - * rfc2047_encode_addrlist - Encode any RFC2047 headers, where required, in an Address list - * @param addr Address list - * @param tag Header tag (used for wrapping calculation) - */ -void rfc2047_encode_addrlist(struct Address *addr, const char *tag) -{ - struct Address *ptr = addr; - int col = tag ? strlen(tag) + 2 : 32; - - while (ptr) - { - if (ptr->personal) - mutt_rfc2047_encode(&ptr->personal, AddressSpecials, col, SendCharset); - else if (ptr->group && ptr->mailbox) - mutt_rfc2047_encode(&ptr->mailbox, AddressSpecials, col, SendCharset); - ptr = ptr->next; - } -} - -/** - * rfc2047_decode_addrlist - Decode any RFC2047 headers in an Address list - * @param a Address list - */ -void rfc2047_decode_addrlist(struct Address *a) -{ - while (a) - { - if (a->personal && - ((strstr(a->personal, "=?") != NULL) || (AssumedCharset && *AssumedCharset))) - { - mutt_rfc2047_decode(&a->personal); - } - else if (a->group && a->mailbox && (strstr(a->mailbox, "=?") != NULL)) - mutt_rfc2047_decode(&a->mailbox); - a = a->next; - } -} diff --git a/send.c b/send.c index f219197c0..ae0350546 100644 --- a/send.c +++ b/send.c @@ -1231,7 +1231,7 @@ void mutt_encode_descriptions(struct Body *b, short recurse) { if (t->description) { - mutt_rfc2047_encode(&t->description, NULL, sizeof("Content-Description:"), SendCharset); + rfc2047_encode(&t->description, NULL, sizeof("Content-Description:"), SendCharset); } if (recurse && t->parts) mutt_encode_descriptions(t->parts, recurse); @@ -1247,7 +1247,7 @@ static void decode_descriptions(struct Body *b) { if (t->description) { - mutt_rfc2047_decode(&t->description); + rfc2047_decode(&t->description); } if (t->parts) decode_descriptions(t->parts); diff --git a/sendlib.c b/sendlib.c index 2912fce6a..7dd397ea1 100644 --- a/sendlib.c +++ b/sendlib.c @@ -58,8 +58,6 @@ #include "parse.h" #include "protos.h" #include "recvattach.h" -#include "rfc2047.h" -#include "rfc2231.h" #include "send.h" #include "smtp.h" #include "state.h" @@ -2322,7 +2320,7 @@ static void encode_headers(struct ListHead *h) if (!tmp) continue; - mutt_rfc2047_encode(&tmp, NULL, i + 2, SendCharset); + rfc2047_encode(&tmp, NULL, i + 2, SendCharset); mutt_mem_realloc(&np->data, i + 2 + mutt_str_strlen(tmp) + 1); sprintf(np->data + i + 2, "%s", tmp); @@ -2837,7 +2835,7 @@ void mutt_prepare_envelope(struct Envelope *env, bool final) if (!OptNewsSend || MimeSubject) #endif { - mutt_rfc2047_encode(&env->subject, NULL, sizeof("Subject:"), SendCharset); + rfc2047_encode(&env->subject, NULL, sizeof("Subject:"), SendCharset); } encode_headers(&env->userhdrs); } @@ -2854,7 +2852,7 @@ void mutt_unprepare_envelope(struct Envelope *env) struct ListNode *item = NULL; STAILQ_FOREACH(item, &env->userhdrs, entries) { - mutt_rfc2047_decode(&item->data); + rfc2047_decode(&item->data); } mutt_addr_free(&env->mail_followup_to); @@ -2865,7 +2863,7 @@ void mutt_unprepare_envelope(struct Envelope *env) rfc2047_decode_addrlist(env->bcc); rfc2047_decode_addrlist(env->from); rfc2047_decode_addrlist(env->reply_to); - mutt_rfc2047_decode(&env->subject); + rfc2047_decode(&env->subject); } static int bounce_message(FILE *fp, struct Header *h, struct Address *to, diff --git a/test/rfc2047.c b/test/rfc2047.c index b1d5e2c95..c6c2e0919 100644 --- a/test/rfc2047.c +++ b/test/rfc2047.c @@ -74,7 +74,7 @@ void test_rfc2047(void) { /* decode the original string */ char *s = mutt_str_strdup(test_data[i].original); - mutt_rfc2047_decode(&s); + rfc2047_decode(&s); if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0)) { TEST_MSG("Iteration: %zu", i); @@ -85,7 +85,7 @@ void test_rfc2047(void) /* encode the expected result */ s = mutt_str_strdup(test_data[i].decoded); - mutt_rfc2047_encode(&s, NULL, 0, "utf-8"); + rfc2047_encode(&s, NULL, 0, "utf-8"); if (!TEST_CHECK(strcmp(s, test_data[i].encoded) == 0)) { TEST_MSG("Iteration: %zu", i); @@ -96,7 +96,7 @@ void test_rfc2047(void) /* decode the encoded result */ s = mutt_str_strdup(test_data[i].encoded); - mutt_rfc2047_decode(&s); + rfc2047_decode(&s); if (!TEST_CHECK(strcmp(s, test_data[i].decoded) == 0)) { TEST_MSG("Iteration: %zu", i);