From bdf2f69bf96b877930e39dca59846ad70c48a733 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Mon, 1 Apr 2019 13:38:17 +0100 Subject: [PATCH] Fix dependencies of libemail Fixes #1618 --- Makefile.autosetup | 4 +- curs_lib.c | 2 +- email/email_globals.c | 8 +++ email/email_globals.h | 16 ++++-- email/parse.c | 93 +++++++++++++++++++++++++++++- email/parse.h | 1 + globals.h | 8 --- imap/message.c | 6 +- main.c | 2 +- mutt.h | 2 - mutt/string.c | 76 +++++++++++++++++++++++++ mutt/string2.h | 1 + mutt_url.c | 126 ----------------------------------------- notmuch/mutt_notmuch.c | 6 +- po/POTFILES.in | 2 - protos.h | 1 - safe_asprintf.c | 109 ----------------------------------- send.c | 2 +- test/pattern/dummy.c | 5 -- 19 files changed, 199 insertions(+), 271 deletions(-) delete mode 100644 mutt_url.c delete mode 100644 safe_asprintf.c diff --git a/Makefile.autosetup b/Makefile.autosetup index 6c5baace3..19abf26c2 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -68,9 +68,9 @@ NEOMUTTOBJS= account.o addrbook.o alias.o bcache.o browser.o color.o commands.o index.o init.o keymap.o mailbox.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_parse.o mutt_signal.o \ - mutt_socket.o mutt_thread.o mutt_url.o mutt_window.o mx.o myvar.o \ + mutt_socket.o mutt_thread.o mutt_window.o mx.o myvar.o \ pager.o pattern.o postpone.o progress.o query.o recvattach.o \ - recvcmd.o resize.o rfc1524.o rfc3676.o safe_asprintf.o \ + recvcmd.o resize.o rfc1524.o rfc3676.o \ score.o send.o sendlib.o sidebar.o smtp.o sort.o state.o \ status.o system.o terminal.o version.o icommands.o diff --git a/curs_lib.c b/curs_lib.c index fac1b8e47..aba0fba39 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -354,7 +354,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def) * around the screen in the even the question is wider than the screen, * ensure there is enough room for the answer and truncate the question * to fit. */ - safe_asprintf(&answer_string, " ([%s]/%s): ", (def == MUTT_YES) ? yes : no, + mutt_str_asprintf(&answer_string, " ([%s]/%s): ", (def == MUTT_YES) ? yes : no, (def == MUTT_YES) ? no : yes); answer_string_wid = mutt_strwidth(answer_string); msg_wid = mutt_strwidth(msg); diff --git a/email/email_globals.c b/email/email_globals.c index 80fb64067..939331b04 100644 --- a/email/email_globals.c +++ b/email/email_globals.c @@ -32,6 +32,7 @@ #include "mutt/mutt.h" /* Config items */ +bool C_AutoSubscribe; ///< Config: Automatically check if the user is subscribed to a mailing list bool C_MarkOld = false; ///< Config: Mark new emails as old when leaving the mailbox struct Regex *C_ReplyRegex = NULL; ///< Config: Regex to match message reply subjects like "re: " char *C_SendCharset = NULL; ///< Config: Character sets for outgoing mail ///< Config: List of character sets for outgoing messages @@ -43,3 +44,10 @@ struct RegexList NoSpamList = STAILQ_HEAD_INITIALIZER(NoSpamList); struct ReplaceList SpamList = STAILQ_HEAD_INITIALIZER(SpamList); struct ListHead Ignore = STAILQ_HEAD_INITIALIZER(Ignore); struct ListHead UnIgnore = STAILQ_HEAD_INITIALIZER(UnIgnore); +struct ListHead MailToAllow = STAILQ_HEAD_INITIALIZER(MailToAllow); +struct Hash *AutoSubscribeCache; +struct RegexList UnSubscribedLists = STAILQ_HEAD_INITIALIZER(UnSubscribedLists); +struct RegexList MailLists = STAILQ_HEAD_INITIALIZER(MailLists); +struct RegexList UnMailLists = STAILQ_HEAD_INITIALIZER(UnMailLists); +struct RegexList SubscribedLists = STAILQ_HEAD_INITIALIZER(SubscribedLists); +struct ReplaceList SubjectRegexList = STAILQ_HEAD_INITIALIZER(SubjectRegexList); diff --git a/email/email_globals.h b/email/email_globals.h index 15fe85995..8aa49df22 100644 --- a/email/email_globals.h +++ b/email/email_globals.h @@ -27,6 +27,7 @@ #include "mutt/mutt.h" /* Config items */ +extern bool C_AutoSubscribe; extern bool C_MarkOld; extern struct Regex * C_ReplyRegex; extern char * C_SendCharset; @@ -34,9 +35,16 @@ extern char * C_SpamSeparator; extern bool C_Weed; /* Global variables */ -extern struct ListHead Ignore; ///< List of header patterns to ignore -extern struct RegexList NoSpamList; ///< List of regexes to whitelist non-spam emails -extern struct ReplaceList SpamList; ///< List of regexes and patterns to match spam emails -extern struct ListHead UnIgnore; ///< List of header patterns to unignore (see) +extern struct ListHead Ignore; ///< List of header patterns to ignore +extern struct RegexList NoSpamList; ///< List of regexes to whitelist non-spam emails +extern struct ReplaceList SpamList; ///< List of regexes and patterns to match spam emails +extern struct ListHead UnIgnore; ///< List of header patterns to unignore (see) +extern struct ListHead MailToAllow; ///< List of permitted fields in a mailto: uri +extern struct Hash *AutoSubscribeCache; ///< Hash table of auto-subscribed mailing lists +extern struct RegexList UnSubscribedLists; ///< List of regexes to blacklist false matches in SubscribedLists +extern struct RegexList MailLists; ///< List of regexes to match mailing lists +extern struct RegexList UnMailLists; ///< List of regexes to blacklist false matches in MailLists +extern struct RegexList SubscribedLists; ///< List of regexes to match subscribed mailing lists +extern struct ReplaceList SubjectRegexList; ///< List of regexes to tidy the view of the email's subject #endif /* MUTT_EMAIL_EMAIL_GLOBALS_H */ diff --git a/email/parse.c b/email/parse.c index a9369056f..7d85dcc22 100644 --- a/email/parse.c +++ b/email/parse.c @@ -42,10 +42,8 @@ #include "email_globals.h" #include "envelope.h" #include "from.h" -#include "globals.h" #include "mime.h" #include "parameter.h" -#include "protos.h" #include "rfc2047.h" #include "rfc2231.h" #include "url.h" @@ -68,7 +66,7 @@ void mutt_auto_subscribe(const char *mailto) lpenv = mutt_env_new(); /* parsed envelope from the List-Post mailto: URL */ - if ((url_parse_mailto(lpenv, NULL, mailto) != -1) && lpenv->to && lpenv->to->mailbox && + if ((mutt_parse_mailto(lpenv, NULL, mailto) != -1) && lpenv->to && lpenv->to->mailbox && !mutt_regexlist_match(&UnSubscribedLists, lpenv->to->mailbox) && !mutt_regexlist_match(&UnMailLists, lpenv->to->mailbox) && !mutt_regexlist_match(&UnSubscribedLists, lpenv->to->mailbox)) @@ -1437,3 +1435,92 @@ struct Body *mutt_rfc822_parse_message(FILE *fp, struct Body *parent) mutt_parse_part(fp, msg); return msg; } + +/** + * mutt_parse_mailto - Parse a mailto:// url + * @param[in] e Envelope to fill + * @param[out] body Body to + * @param[in] src String to parse + * @retval 0 Success + * @retval -1 Error + */ +int mutt_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); + + mutt_str_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, true, false, true); + FREE(&scratch); + } + } + } + + /* RFC2047 decode after the RFC822 parsing */ + rfc2047_decode_envelope(e); + + rc = 0; + +out: + FREE(&tmp); + return rc; +} diff --git a/email/parse.h b/email/parse.h index 4ef1c42f8..2eec779b8 100644 --- a/email/parse.h +++ b/email/parse.h @@ -38,6 +38,7 @@ char * mutt_extract_message_id(const char *s, const char **saveptr); bool mutt_is_message_type(int type, const char *subtype); bool mutt_matches_ignore(const char *s); void mutt_parse_content_type(const char *s, struct Body *ct); +int mutt_parse_mailto(struct Envelope *e, char **body, const char *src); struct Body * mutt_parse_multipart(FILE *fp, const char *boundary, LOFF_T end_off, bool digest); void mutt_parse_part(FILE *fp, struct Body *b); struct Body * mutt_read_mime_header(FILE *fp, bool digest); diff --git a/globals.h b/globals.h index 763cb0540..f52479ca8 100644 --- a/globals.h +++ b/globals.h @@ -57,13 +57,11 @@ extern const char *GitVer; WHERE struct Hash *ReverseAliases; ///< Hash table of aliases (email address -> alias) WHERE struct Hash *TagFormats; ///< Hash table of tag-formats (tag -> format string) -WHERE struct Hash *AutoSubscribeCache; ///< Hash table of auto-subscribed mailing lists /* Lists of strings */ WHERE struct ListHead AlternativeOrderList INITVAL(STAILQ_HEAD_INITIALIZER(AlternativeOrderList)); ///< List of preferred mime types to display WHERE struct ListHead AutoViewList INITVAL(STAILQ_HEAD_INITIALIZER(AutoViewList)); ///< List of mime types to auto view WHERE struct ListHead HeaderOrderList INITVAL(STAILQ_HEAD_INITIALIZER(HeaderOrderList)); ///< List of header fields in the order they should be displayed -WHERE struct ListHead MailToAllow INITVAL(STAILQ_HEAD_INITIALIZER(MailToAllow)); ///< List of permitted fields in a mailto: uri WHERE struct ListHead MimeLookupList INITVAL(STAILQ_HEAD_INITIALIZER(MimeLookupList)); ///< List of mime types that that shouldn't use the mailcap entry WHERE struct ListHead Muttrc INITVAL(STAILQ_HEAD_INITIALIZER(Muttrc)); ///< List of config files to read #ifdef USE_SIDEBAR @@ -77,14 +75,8 @@ WHERE struct ListHead AttachAllow INITVAL(STAILQ_HEAD_INITIALIZER(AttachAllow)); WHERE struct ListHead AttachExclude INITVAL(STAILQ_HEAD_INITIALIZER(AttachExclude)); ///< List of attachment types to be ignored WHERE struct ListHead InlineAllow INITVAL(STAILQ_HEAD_INITIALIZER(InlineAllow)); ///< List of inline types to counted WHERE struct ListHead InlineExclude INITVAL(STAILQ_HEAD_INITIALIZER(InlineExclude)); ///< List of inline types to ignore - WHERE struct RegexList Alternates INITVAL(STAILQ_HEAD_INITIALIZER(Alternates)); ///< List of regexes to match the user's alternate email addresses WHERE struct RegexList UnAlternates INITVAL(STAILQ_HEAD_INITIALIZER(UnAlternates)); ///< List of regexes to blacklist false matches in Alternates -WHERE struct RegexList MailLists INITVAL(STAILQ_HEAD_INITIALIZER(MailLists)); ///< List of regexes to match mailing lists -WHERE struct RegexList UnMailLists INITVAL(STAILQ_HEAD_INITIALIZER(UnMailLists)); ///< List of regexes to blacklist false matches in MailLists -WHERE struct RegexList SubscribedLists INITVAL(STAILQ_HEAD_INITIALIZER(SubscribedLists)); ///< List of regexes to match subscribed mailing lists -WHERE struct RegexList UnSubscribedLists INITVAL(STAILQ_HEAD_INITIALIZER(UnSubscribedLists)); ///< List of regexes to blacklist false matches in SubscribedLists -WHERE struct ReplaceList SubjectRegexList INITVAL(STAILQ_HEAD_INITIALIZER(SubjectRegexList)); ///< List of regexes to tidy the view of the email's subject /* flags for received signals */ WHERE SIG_ATOMIC_VOLATILE_T SigAlrm; ///< true after SIGALRM is received diff --git a/imap/message.c b/imap/message.c index b868814f9..20decd33f 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1027,12 +1027,12 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, if (adata->capabilities & IMAP_CAP_IMAP4REV1) { - safe_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers, + mutt_str_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers, C_ImapHeaders ? " " : "", NONULL(C_ImapHeaders)); } else if (adata->capabilities & IMAP_CAP_IMAP4) { - safe_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s%s%s)", want_headers, + mutt_str_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s%s%s)", want_headers, C_ImapHeaders ? " " : "", NONULL(C_ImapHeaders)); } else @@ -1069,7 +1069,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, fetch_msn_end = msn_end; char *cmd = NULL; - safe_asprintf(&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)", b->data, hdrreq); + mutt_str_asprintf(&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)", b->data, hdrreq); imap_cmd_start(adata, cmd); FREE(&cmd); mutt_buffer_free(&b); diff --git a/main.c b/main.c index 4a0f585a9..6e9f87a4c 100644 --- a/main.c +++ b/main.c @@ -860,7 +860,7 @@ int main(int argc, char *argv[], char *envp[]) { if (url_check_scheme(argv[i]) == U_MAILTO) { - if (url_parse_mailto(msg->env, &bodytext, argv[i]) < 0) + if (mutt_parse_mailto(msg->env, &bodytext, argv[i]) < 0) { mutt_error(_("Failed to parse mailto: link")); goto main_curses; // TEST25: neomutt mailto: diff --git a/mutt.h b/mutt.h index 1daef8940..567a0ae3e 100644 --- a/mutt.h +++ b/mutt.h @@ -134,8 +134,6 @@ struct AttachMatch #define EXECSHELL "/bin/sh" -int safe_asprintf(char **, const char *, ...); - char *mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items); int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags); diff --git a/mutt/string.c b/mutt/string.c index 2567a3d7b..f015dcab0 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -30,13 +30,16 @@ #include #include #include +#include #include #include #include #include #include +#include "exit.h" #include "logging.h" #include "memory.h" +#include "message.h" #include "string2.h" #include "list.h" #ifdef HAVE_SYSEXITS_H @@ -1176,3 +1179,76 @@ struct ListHead mutt_str_split(const char *src, char sep) return head; } + +#ifdef HAVE_VASPRINTF +/** + * mutt_str_asprintf - Format a string, allocating space as necessary + * @param[out] strp New string saved here + * @param[in] fmt Format string + * @param[in] ... Format arguments + * @retval num Characters written + * @retval -1 Error + */ +int mutt_str_asprintf(char **strp, const char *fmt, ...) +{ + va_list ap; + int n; + + va_start(ap, fmt); + n = vasprintf(strp, fmt, ap); + va_end(ap); + + /* GNU libc man page for vasprintf(3) states that the value of *strp + * is undefined when the return code is -1. */ + if (n < 0) + { + mutt_error(_("Out of memory")); + mutt_exit(1); + } + + if (n == 0) + { + /* NeoMutt convention is to use NULL for 0-length strings */ + FREE(strp); + } + + return n; +} +#else +/* Allocate a C-string large enough to contain the formatted string. + * This is essentially malloc+sprintf in one. + */ +int mutt_str_asprintf(char **strp, const char *fmt, ...) +{ + int rlen = 256; + + *strp = mutt_mem_malloc(rlen); + while (true) + { + va_list ap; + va_start(ap, fmt); + const int n = vsnprintf(*strp, rlen, fmt, ap); + va_end(ap); + if (n < 0) + { + FREE(strp); + return n; + } + + if (n < rlen) + { + /* reduce space to just that which was used. note that 'n' does not + * include the terminal nul char. */ + if (n == 0) /* convention is to use NULL for zero-length strings. */ + FREE(strp); + else if (n != rlen - 1) + mutt_mem_realloc(strp, n + 1); + return n; + } + /* increase size and try again */ + rlen = n + 1; + mutt_mem_realloc(strp, rlen); + } + /* not reached */ +} +#endif /* HAVE_ASPRINTF */ diff --git a/mutt/string2.h b/mutt/string2.h index 896657a65..ff265fc64 100644 --- a/mutt/string2.h +++ b/mutt/string2.h @@ -69,6 +69,7 @@ enum CaseSensitivity void mutt_str_adjust(char **p); void mutt_str_append_item(char **str, const char *item, int sep); +int mutt_str_asprintf(char **strp, const char *fmt, ...); int mutt_str_atoi(const char *str, int *dst); int mutt_str_atol(const char *str, long *dst); int mutt_str_atos(const char *str, short *dst); diff --git a/mutt_url.c b/mutt_url.c deleted file mode 100644 index 0ae7eedc8..000000000 --- a/mutt_url.c +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @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 . - */ - -/** - * @page mutt_url Parse and identify different URL schemes - * - * Parse and identify different URL schemes - */ - -#include "config.h" -#include -#include -#include -#include -#include "mutt/mutt.h" -#include "email/lib.h" -#include "mutt.h" -#include "globals.h" - -/** - * url_parse_mailto - Parse a mailto:// url - * @param[in] e Envelope to fill - * @param[out] body Body to - * @param[in] src String to parse - * @retval 0 Success - * @retval -1 Error - */ -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, true, false, true); - FREE(&scratch); - } - } - } - - /* RFC2047 decode after the RFC822 parsing */ - rfc2047_decode_envelope(e); - - rc = 0; - -out: - FREE(&tmp); - return rc; -} diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index e62ce1642..6b2e754cd 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1842,7 +1842,7 @@ bool nm_message_is_still_queried(struct Mailbox *m, struct Email *e) char *new_str = NULL; bool rc = false; - if (safe_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0) + if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0) return false; mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str); @@ -1978,12 +1978,12 @@ static int nm_mbox_check_stats(struct Mailbox *m, int flags) char *qstr = NULL; // unread messages - safe_asprintf(&qstr, "( %s ) tag:%s", db_query, C_NmUnreadTag); + mutt_str_asprintf(&qstr, "( %s ) tag:%s", db_query, C_NmUnreadTag); m->msg_unread = count_query(db, qstr, limit); FREE(&qstr); // flagged messages - safe_asprintf(&qstr, "( %s ) tag:%s", db_query, C_NmFlaggedTag); + mutt_str_asprintf(&qstr, "( %s ) tag:%s", db_query, C_NmFlaggedTag); m->msg_flagged = count_query(db, qstr, limit); FREE(&qstr); diff --git a/po/POTFILES.in b/po/POTFILES.in index a280bcc10..a94027143 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -128,7 +128,6 @@ mutt_parse.c mutt_signal.c mutt_socket.c mutt_thread.c -mutt_url.c mutt_window.c mx.c myvar.c @@ -170,7 +169,6 @@ remailer.c resize.c rfc1524.c rfc3676.c -safe_asprintf.c score.c send.c sendlib.c diff --git a/protos.h b/protos.h index b98ea8f89..00ef25952 100644 --- a/protos.h +++ b/protos.h @@ -80,7 +80,6 @@ SecurityFlags mutt_parse_crypt_hdr(const char *p, int set_empty_signas, Security int mutt_num_postponed(struct Mailbox *m, bool force); int mutt_thread_set_flag(struct Email *e, int flag, bool bf, bool subthread); void mutt_update_num_postponed(void); -int url_parse_mailto(struct Envelope *e, char **body, const char *src); int mutt_is_quote_line(char *buf, regmatch_t *pmatch); #ifndef HAVE_WCSCASECMP diff --git a/safe_asprintf.c b/safe_asprintf.c deleted file mode 100644 index 5c029da40..000000000 --- a/safe_asprintf.c +++ /dev/null @@ -1,109 +0,0 @@ -/** - * @file - * Wrapper for vasprintf()/vsnprintf() - * - * @authors - * Copyright (C) 2010 Michael R. Elkins - * - * @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 . - */ - -/** - * @page safe_asprintf Wrapper for vasprintf() - * - * Wrapper for vasprintf() - * - * @note Currently there is no check in configure for vasprintf(3). The - * undefined behavior of the error condition makes it difficult to write a safe - * version using it. - */ - -#include "config.h" -#include -#include -#include "mutt/mutt.h" - -#ifdef HAVE_VASPRINTF -/** - * safe_asprintf - Format a string, allocating space as necessary - * @param[out] strp New string saved here - * @param[in] fmt Format string - * @param[in] ... Format arguments - * @retval num Characters written - * @retval -1 Error - */ -int safe_asprintf(char **strp, const char *fmt, ...) -{ - va_list ap; - int n; - - va_start(ap, fmt); - n = vasprintf(strp, fmt, ap); - va_end(ap); - - /* GNU libc man page for vasprintf(3) states that the value of *strp - * is undefined when the return code is -1. */ - if (n < 0) - { - mutt_error(_("Out of memory")); - mutt_exit(1); - } - - if (n == 0) - { - /* NeoMutt convention is to use NULL for 0-length strings */ - FREE(strp); - } - - return n; -} -#else -/* Allocate a C-string large enough to contain the formatted string. - * This is essentially malloc+sprintf in one. - */ -int safe_asprintf(char **strp, const char *fmt, ...) -{ - int rlen = 256; - - *strp = mutt_mem_malloc(rlen); - while (true) - { - va_list ap; - va_start(ap, fmt); - const int n = vsnprintf(*strp, rlen, fmt, ap); - va_end(ap); - if (n < 0) - { - FREE(strp); - return n; - } - - if (n < rlen) - { - /* reduce space to just that which was used. note that 'n' does not - * include the terminal nul char. */ - if (n == 0) /* convention is to use NULL for zero-length strings. */ - FREE(strp); - else if (n != rlen - 1) - mutt_mem_realloc(strp, n + 1); - return n; - } - /* increase size and try again */ - rlen = n + 1; - mutt_mem_realloc(strp, rlen); - } - /* not reached */ -} -#endif /* HAVE_ASPRINTF */ diff --git a/send.c b/send.c index adddebf0b..9b0effe68 100644 --- a/send.c +++ b/send.c @@ -1833,7 +1833,7 @@ int ci_send_message(SendFlags flags, struct Email *msg, const char *tempfile, if ((flags & SEND_LIST_REPLY) && cur && cur->env && cur->env->list_post) { /* Use any list-post header as a template */ - url_parse_mailto(msg->env, NULL, cur->env->list_post); + mutt_parse_mailto(msg->env, NULL, cur->env->list_post); /* We don't let them set the sender's address. */ mutt_addr_free(&msg->env->from); } diff --git a/test/pattern/dummy.c b/test/pattern/dummy.c index e57737048..51eb077fe 100644 --- a/test/pattern/dummy.c +++ b/test/pattern/dummy.c @@ -120,8 +120,3 @@ const char *myvar_get(const char *var) { return g_myvar; } - -int url_parse_mailto(struct Envelope *e, char **body, const char *src) -{ - return -1; -} -- 2.40.0