From: Richard Russon Date: Sat, 14 Jul 2018 01:46:30 +0000 (+0100) Subject: move url to libemail X-Git-Tag: 2019-10-25~756^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5c765eab8196e52d1d0c969c2e916e9a0286c7b;p=neomutt move url to libemail --- diff --git a/Makefile.autosetup b/Makefile.autosetup index ec4a0f20c..fd1400d8f 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -67,12 +67,12 @@ NEOMUTTOBJS= addrbook.o alias.o bcache.o browser.o buffy.o \ enriched.o enter.o filter.o flags.o group.o handler.o \ hdrline.o help.o hook.o init.o keymap.o \ main.o menu.o muttlib.o mutt_account.o mutt_attach.o mutt_body.o mutt_header.o \ - mutt_history.o mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.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 \ sendlib.o sidebar.o smtp.o sort.o state.o status.o system.o \ - terminal.o url.o version.o + terminal.o version.o @if !HAVE_WCSCASECMP NEOMUTTOBJS+= wcscasecmp.o @@ -90,7 +90,7 @@ 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/parameter.o email/tags.o email/thread.o + email/from.o email/header.o email/parameter.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 025ca77f9..ed7eb20d7 100644 --- a/bcache.c +++ b/bcache.c @@ -35,7 +35,7 @@ #include "mutt_account.h" #include "muttlib.h" #include "protos.h" -#include "url.h" +#include "email/email.h" /* These Config Variables are only used in bcache.c */ char *MessageCachedir; diff --git a/browser.c b/browser.c index 086cd1818..ddd8bee44 100644 --- a/browser.c +++ b/browser.c @@ -58,7 +58,6 @@ #include "protos.h" #include "sendlib.h" #include "sort.h" -#include "url.h" #ifdef USE_IMAP #include "imap/imap.h" #endif diff --git a/email/email.h b/email/email.h index b7d78d5f7..ff9dbd08c 100644 --- a/email/email.h +++ b/email/email.h @@ -36,6 +36,7 @@ * | email/parameter.c | @subpage email_parameter | * | email/tags.c | @subpage email_tags | * | email/thread.c | @subpage email_thread | + * | email/url.c | @subpage email_url | */ #ifndef _EMAIL_EMAIL_H @@ -51,5 +52,6 @@ #include "parameter.h" #include "tags.h" #include "thread.h" +#include "url.h" #endif /* _EMAIL_EMAIL_H */ diff --git a/url.c b/email/url.c similarity index 70% rename from url.c rename to email/url.c index 3bab2a9a3..00cc985c3 100644 --- a/url.c +++ b/email/url.c @@ -25,22 +25,13 @@ #include #include #include "mutt/mutt.h" -#include "email/email.h" -#include "mutt.h" #include "url.h" -#include "globals.h" -#include "parse.h" -#include "protos.h" -#include "rfc2047.h" static const struct Mapping UrlMap[] = { - { "file", U_FILE }, { "imap", U_IMAP }, { "imaps", U_IMAPS }, - { "pop", U_POP }, { "pops", U_POPS }, { "news", U_NNTP }, - { "snews", U_NNTPS }, { "mailto", U_MAILTO }, -#ifdef USE_NOTMUCH - { "notmuch", U_NOTMUCH }, -#endif - { "smtp", U_SMTP }, { "smtps", U_SMTPS }, { NULL, U_UNKNOWN }, + { "file", U_FILE }, { "imap", U_IMAP }, { "imaps", U_IMAPS }, + { "pop", U_POP }, { "pops", U_POPS }, { "news", U_NNTP }, + { "snews", U_NNTPS }, { "mailto", U_MAILTO }, { "notmuch", U_NOTMUCH }, + { "smtp", U_SMTP }, { "smtps", U_SMTPS }, { NULL, U_UNKNOWN }, }; int url_pct_decode(char *s) @@ -353,93 +344,3 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) return 0; } -int url_parse_mailto(struct Envelope *e, char **body, const char *src) -{ - char *p = NULL; - char *tag = NULL, *value = NULL; - - int rc = -1; - - char *t = strchr(src, ':'); - if (!t) - return -1; - - /* copy string for safe use of strtok() */ - char *tmp = mutt_str_strdup(t + 1); - if (!tmp) - return -1; - - char *headers = strchr(tmp, '?'); - if (headers) - *headers++ = '\0'; - - if (url_pct_decode(tmp) < 0) - goto out; - - e->to = mutt_addr_parse_list(e->to, tmp); - - tag = headers ? strtok_r(headers, "&", &p) : NULL; - - for (; tag; tag = strtok_r(NULL, "&", &p)) - { - value = strchr(tag, '='); - if (value) - *value++ = '\0'; - if (!value || !*value) - continue; - - if (url_pct_decode(tag) < 0) - goto out; - if (url_pct_decode(value) < 0) - goto out; - - /* Determine if this header field is on the allowed list. Since NeoMutt - * interprets some header fields specially (such as - * "Attach: ~/.gnupg/secring.gpg"), care must be taken to ensure that - * only safe fields are allowed. - * - * RFC2368, "4. Unsafe headers" - * The user agent interpreting a mailto URL SHOULD choose not to create - * a message if any of the headers are considered dangerous; it may also - * choose to create a message with only a subset of the headers given in - * the URL. - */ - if (mutt_list_match(tag, &MailToAllow)) - { - if (mutt_str_strcasecmp(tag, "body") == 0) - { - if (body) - mutt_str_replace(body, value); - } - else - { - char *scratch = NULL; - size_t taglen = mutt_str_strlen(tag); - - safe_asprintf(&scratch, "%s: %s", tag, value); - scratch[taglen] = 0; /* overwrite the colon as mutt_rfc822_parse_line expects */ - value = mutt_str_skip_email_wsp(&scratch[taglen + 1]); - mutt_rfc822_parse_line(e, NULL, scratch, value, 1, 0, 1); - FREE(&scratch); - } - } - } - - /* RFC2047 decode after the RFC822 parsing */ - rfc2047_decode_addrlist(e->from); - rfc2047_decode_addrlist(e->to); - rfc2047_decode_addrlist(e->cc); - rfc2047_decode_addrlist(e->bcc); - rfc2047_decode_addrlist(e->reply_to); - 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); - - rc = 0; - -out: - FREE(&tmp); - return rc; -} diff --git a/url.h b/email/url.h similarity index 77% rename from url.h rename to email/url.h index b3312270a..1c7ec4eea 100644 --- a/url.h +++ b/email/url.h @@ -3,6 +3,8 @@ * Parse and identify different URL schemes * * @authors + * Copyright (C) 2000-2002,2004 Thomas Roessler + * * @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 @@ -18,12 +20,11 @@ * this program. If not, see . */ -#ifndef _MUTT_URL_H -#define _MUTT_URL_H +#ifndef _EMAIL_URL_H +#define _EMAIL_URL_H #include #include "mutt/mutt.h" -#include "email/email.h" /** * enum UrlScheme - All recognised Url types @@ -41,9 +42,7 @@ enum UrlScheme U_SMTP, U_SMTPS, U_MAILTO, -#ifdef USE_NOTMUCH - U_NOTMUCH -#endif + U_NOTMUCH, }; #define U_DECODE_PASSWD (1 << 0) @@ -77,11 +76,10 @@ struct Url }; enum UrlScheme url_check_scheme(const char *s); -int url_parse(struct Url *u, char *src); -void url_free(struct Url *u); -int url_tostring(struct Url *u, char *dest, size_t len, int flags); -int url_parse_mailto(struct Envelope *e, char **body, const char *src); -int url_pct_decode(char *s); -void url_pct_encode(char *dst, size_t l, const char *src); +void url_free(struct Url *u); +int url_parse(struct Url *u, char *src); +int url_pct_decode(char *s); +void url_pct_encode(char *dst, size_t l, const char *src); +int url_tostring(struct Url *u, char *dest, size_t len, int flags); -#endif /* _MUTT_URL_H */ +#endif /* _EMAIL_URL_H */ diff --git a/imap/command.c b/imap/command.c index 98314d873..79612ce7b 100644 --- a/imap/command.c +++ b/imap/command.c @@ -55,7 +55,6 @@ #include "mx.h" #include "options.h" #include "protos.h" -#include "url.h" /* These Config Variables are only used in imap/command.c */ bool ImapServernoise; diff --git a/imap/imap.c b/imap/imap.c index d7d4bcfc9..d7e12a251 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -61,7 +61,6 @@ #include "progress.h" #include "protos.h" #include "sort.h" -#include "url.h" #ifdef USE_HCACHE #include "hcache/hcache.h" #endif diff --git a/imap/util.c b/imap/util.c index 08a72d723..2a3827bca 100644 --- a/imap/util.c +++ b/imap/util.c @@ -43,6 +43,7 @@ #include #include "imap_private.h" #include "mutt/mutt.h" +#include "email/email.h" #include "conn/conn.h" #include "bcache.h" #include "context.h" @@ -55,7 +56,6 @@ #include "mx.h" #include "options.h" #include "protos.h" -#include "url.h" #ifdef USE_HCACHE #include "hcache/hcache.h" #endif diff --git a/main.c b/main.c index 3dfc1722a..a22beafda 100644 --- a/main.c +++ b/main.c @@ -66,7 +66,6 @@ #include "send.h" #include "sendlib.h" #include "terminal.h" -#include "url.h" #include "version.h" #ifdef ENABLE_NLS #include diff --git a/mutt_account.c b/mutt_account.c index 242bc35cc..9aad748e8 100644 --- a/mutt_account.c +++ b/mutt_account.c @@ -30,13 +30,13 @@ #include #include #include "mutt/mutt.h" +#include "email/email.h" #include "conn/conn.h" #include "mutt_account.h" #include "curs_lib.h" #include "globals.h" #include "options.h" #include "protos.h" -#include "url.h" /* These Config Variables are only used in mutt_account.c */ char *ImapLogin; diff --git a/mutt_socket.c b/mutt_socket.c index 8bfb3e867..7d1b57149 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -30,12 +30,12 @@ #include #include #include "mutt/mutt.h" +#include "email/email.h" #include "conn/conn.h" #include "mutt_socket.h" #include "hook.h" #include "mutt_account.h" #include "protos.h" -#include "url.h" /** * mutt_conn_find - Find a connection from a list diff --git a/mutt_url.c b/mutt_url.c new file mode 100644 index 000000000..99e0190c0 --- /dev/null +++ b/mutt_url.c @@ -0,0 +1,123 @@ +/** + * @file + * Parse and identify different URL schemes + * + * @authors + * Copyright (C) 2000-2002,2004 Thomas Roessler + * + * @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 +#include +#include +#include "mutt/mutt.h" +#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) +{ + char *p = NULL; + char *tag = NULL, *value = NULL; + + int rc = -1; + + char *t = strchr(src, ':'); + if (!t) + return -1; + + /* copy string for safe use of strtok() */ + char *tmp = mutt_str_strdup(t + 1); + if (!tmp) + return -1; + + char *headers = strchr(tmp, '?'); + if (headers) + *headers++ = '\0'; + + if (url_pct_decode(tmp) < 0) + goto out; + + e->to = mutt_addr_parse_list(e->to, tmp); + + tag = headers ? strtok_r(headers, "&", &p) : NULL; + + for (; tag; tag = strtok_r(NULL, "&", &p)) + { + value = strchr(tag, '='); + if (value) + *value++ = '\0'; + if (!value || !*value) + continue; + + if (url_pct_decode(tag) < 0) + goto out; + if (url_pct_decode(value) < 0) + goto out; + + /* Determine if this header field is on the allowed list. Since NeoMutt + * interprets some header fields specially (such as + * "Attach: ~/.gnupg/secring.gpg"), care must be taken to ensure that + * only safe fields are allowed. + * + * RFC2368, "4. Unsafe headers" + * The user agent interpreting a mailto URL SHOULD choose not to create + * a message if any of the headers are considered dangerous; it may also + * choose to create a message with only a subset of the headers given in + * the URL. + */ + if (mutt_list_match(tag, &MailToAllow)) + { + if (mutt_str_strcasecmp(tag, "body") == 0) + { + if (body) + mutt_str_replace(body, value); + } + else + { + char *scratch = NULL; + size_t taglen = mutt_str_strlen(tag); + + safe_asprintf(&scratch, "%s: %s", tag, value); + scratch[taglen] = 0; /* overwrite the colon as mutt_rfc822_parse_line expects */ + value = mutt_str_skip_email_wsp(&scratch[taglen + 1]); + mutt_rfc822_parse_line(e, NULL, scratch, value, 1, 0, 1); + FREE(&scratch); + } + } + } + + /* RFC2047 decode after the RFC822 parsing */ + rfc2047_decode_addrlist(e->from); + rfc2047_decode_addrlist(e->to); + rfc2047_decode_addrlist(e->cc); + rfc2047_decode_addrlist(e->bcc); + rfc2047_decode_addrlist(e->reply_to); + 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); + + rc = 0; + +out: + FREE(&tmp); + return rc; +} diff --git a/muttlib.c b/muttlib.c index 07eb023ab..fbcd3bc64 100644 --- a/muttlib.c +++ b/muttlib.c @@ -53,7 +53,6 @@ #include "ncrypt/ncrypt.h" #include "options.h" #include "protos.h" -#include "url.h" #ifdef HAVE_SYS_SYSCALL_H #include #endif diff --git a/mx.c b/mx.c index 2d80629e3..1690663bd 100644 --- a/mx.c +++ b/mx.c @@ -61,7 +61,6 @@ #include "protos.h" #include "score.h" #include "sort.h" -#include "url.h" #ifdef USE_SIDEBAR #include "sidebar.h" #endif diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 3fa1ae9a6..314292a6b 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -40,6 +40,7 @@ #include #include "nntp_private.h" #include "mutt/mutt.h" +#include "email/email.h" #include "conn/conn.h" #include "mutt.h" #include "bcache.h" @@ -56,7 +57,6 @@ #include "options.h" #include "protos.h" #include "sort.h" -#include "url.h" #ifdef USE_HCACHE #include "hcache/hcache.h" #endif diff --git a/nntp/nntp.c b/nntp/nntp.c index b8f9e3e66..5b1db002a 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -58,7 +58,6 @@ #include "progress.h" #include "protos.h" #include "sort.h" -#include "url.h" #ifdef USE_HCACHE #include "hcache/hcache.h" #endif diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 7553581b6..3b8e9cf02 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -68,7 +68,6 @@ #include "mx.h" #include "progress.h" #include "protos.h" -#include "url.h" /* These Config Variables are only used in notmuch/mutt_notmuch.c */ int NmDbLimit; diff --git a/parse.c b/parse.c index 585d30d79..8dca557df 100644 --- a/parse.c +++ b/parse.c @@ -41,7 +41,6 @@ #include "recvattach.h" #include "rfc2047.h" #include "rfc2231.h" -#include "url.h" struct Context; diff --git a/pop/pop.c b/pop/pop.c index 4f0df9b01..b15e18d36 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -56,7 +56,6 @@ #include "parse.h" #include "progress.h" #include "protos.h" -#include "url.h" #ifdef USE_HCACHE #include "hcache/hcache.h" #endif diff --git a/pop/pop_lib.c b/pop/pop_lib.c index c3e23880f..0b722ace8 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -50,7 +50,6 @@ #include "pop.h" #include "progress.h" #include "protos.h" -#include "url.h" /* These Config Variables are only used in pop/pop_lib.c */ unsigned char PopReconnect; diff --git a/protos.h b/protos.h index 89560f5b1..fca4081e3 100644 --- a/protos.h +++ b/protos.h @@ -31,6 +31,7 @@ struct Context; struct EnterState; +struct Envelope; struct Header; /** @@ -65,6 +66,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app); int mutt_num_postponed(int force); int mutt_thread_set_flag(struct Header *hdr, int flag, int bf, int subthread); void mutt_update_num_postponed(void); +int url_parse_mailto(struct Envelope *e, char **body, const char *src); #ifndef HAVE_WCSCASECMP int wcscasecmp(const wchar_t *a, const wchar_t *b); diff --git a/send.c b/send.c index b9cdb0a7c..f219197c0 100644 --- a/send.c +++ b/send.c @@ -59,7 +59,6 @@ #include "sendlib.h" #include "smtp.h" #include "sort.h" -#include "url.h" #ifdef USE_NNTP #include "mx.h" #include "nntp/nntp.h" diff --git a/smtp.c b/smtp.c index f0f6086eb..494245a42 100644 --- a/smtp.c +++ b/smtp.c @@ -42,7 +42,6 @@ #include "progress.h" #include "protos.h" #include "sendlib.h" -#include "url.h" #ifdef USE_SASL #include #include