]> granicus.if.org Git - neomutt/commitdiff
move url to libemail
authorRichard Russon <rich@flatcap.org>
Sat, 14 Jul 2018 01:46:30 +0000 (02:46 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 16 Jul 2018 22:44:16 +0000 (23:44 +0100)
24 files changed:
Makefile.autosetup
bcache.c
browser.c
email/email.h
email/url.c [moved from url.c with 70% similarity]
email/url.h [moved from url.h with 77% similarity]
imap/command.c
imap/imap.c
imap/util.c
main.c
mutt_account.c
mutt_socket.c
mutt_url.c [new file with mode: 0644]
muttlib.c
mx.c
nntp/newsrc.c
nntp/nntp.c
notmuch/mutt_notmuch.c
parse.c
pop/pop.c
pop/pop_lib.c
protos.h
send.c
smtp.c

index ec4a0f20cd43ebae046408fa67ae3ebd3dddd9fb..fd1400d8fe2a020d6f99d30da516d0316769cacb 100644 (file)
@@ -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)
index 025ca77f9ec86156812716b4c96ad3c1994339fe..ed7eb20d75f5e4e5846c19046ce2c53c0037a8a6 100644 (file)
--- 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;
index 086cd1818c2d7053e59c77f43eb58aa89e0005ae..ddd8bee44758c3db443c7a06d36762ebbbda5540 100644 (file)
--- 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
index b7d78d5f7a4e6843daf09cd67d96505aa6e9fe4d..ff9dbd08c1ad5de5b69f26a56b04c538ef72e844 100644 (file)
@@ -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 */
similarity index 70%
rename from url.c
rename to email/url.c
index 3bab2a9a315fbb4e1669822c2f3a675caad92c84..00cc985c300b8558a97c052c6769786feea91f64 100644 (file)
--- a/url.c
 #include <stdio.h>
 #include <string.h>
 #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;
-}
similarity index 77%
rename from url.h
rename to email/url.h
index b3312270a727caafc72ee79b05e0a0b5ba2224d8..1c7ec4eea34e6d347107fe86774dc3f94725c1d7 100644 (file)
--- a/url.h
@@ -3,6 +3,8 @@
  * Parse and identify different URL schemes
  *
  * @authors
+ * Copyright (C) 2000-2002,2004 Thomas Roessler <roessler@does-not-exist.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
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _MUTT_URL_H
-#define _MUTT_URL_H
+#ifndef _EMAIL_URL_H
+#define _EMAIL_URL_H
 
 #include <stddef.h>
 #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 */
index 98314d87346eed164c306432e2f93391de992e62..79612ce7ba4a59225d500a207c96d80459c22877 100644 (file)
@@ -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;
index d7d4bcfc9e380b62b6f6ba02bf7fcaf47c9d9e6a..d7e12a251eb589d20a6821a0646821ee6ec27937 100644 (file)
@@ -61,7 +61,6 @@
 #include "progress.h"
 #include "protos.h"
 #include "sort.h"
-#include "url.h"
 #ifdef USE_HCACHE
 #include "hcache/hcache.h"
 #endif
index 08a72d7232a6c7f0324fedbbf84ab2b4d1cd7e06..2a3827bcafe1b332a9fc7042b97869f7c12a65aa 100644 (file)
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #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 3dfc1722ab2234143a45ac93a2cf400fe8d5bf1d..a22beafda78e016830f2677b7cb3f805a55a7917 100644 (file)
--- 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 <libintl.h>
index 242bc35cc9084aa6a29697a8cb09526f7340d24f..9aad748e84910ba90f66bda7df1d912d3ee962cd 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #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;
index 8bfb3e8671231876a4ded00b69432b59a90c3b72..7d1b571491daaf924389776e7c789fef96b1f34b 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #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 (file)
index 0000000..99e0190
--- /dev/null
@@ -0,0 +1,123 @@
+/**
+ * @file
+ * Parse and identify different URL schemes
+ *
+ * @authors
+ * Copyright (C) 2000-2002,2004 Thomas Roessler <roessler@does-not-exist.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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#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;
+}
index 07eb023abce56d358c44e409d79bf60b35a5070f..fbcd3bc64929f1f7529bdefd60412b8fa3d2f2c3 100644 (file)
--- 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 <sys/syscall.h>
 #endif
diff --git a/mx.c b/mx.c
index 2d80629e3606ba6b0cc4aabeef74a14a80fbf79f..1690663bdff5f3196f267eea6fbf6738f23a980c 100644 (file)
--- 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
index 3fa1ae9a60300c3317dd94cf0977b869ed52382e..314292a6bd977adf7168e71a6a5535c9948d20c1 100644 (file)
@@ -40,6 +40,7 @@
 #include <unistd.h>
 #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
index b8f9e3e664ef6598abf1ee9d0277e844208d7e7d..5b1db002a61ebfe78eaea67e719d437415a1ec81 100644 (file)
@@ -58,7 +58,6 @@
 #include "progress.h"
 #include "protos.h"
 #include "sort.h"
-#include "url.h"
 #ifdef USE_HCACHE
 #include "hcache/hcache.h"
 #endif
index 7553581b69e7dfc52ff21b40453233f0a6089ba9..3b8e9cf020182b14b5e066683b590f427c05a504 100644 (file)
@@ -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 585d30d79236fdab6bb6ad50bb82e66c38eeceb4..8dca557df271aa91ca6f7aa90dcf9f4d12b77813 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -41,7 +41,6 @@
 #include "recvattach.h"
 #include "rfc2047.h"
 #include "rfc2231.h"
-#include "url.h"
 
 struct Context;
 
index 4f0df9b01c72b7a496bc00301e6acb26df5bac8d..b15e18d36cb2aff37db2aff29dd4b5324aa919ce 100644 (file)
--- 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
index c3e23880f0d6170488d7b94816e1ee97938e93fc..0b722ace836f583ca9df5cd56a4266d3d4fe71f2 100644 (file)
@@ -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;
index 89560f5b128e7ba1d9dbf14b088b786af45fcf42..fca4081e36485bdb124b5d3273a16f9c288f6dec 100644 (file)
--- 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 b9cdb0a7ca112f4049b831aff78e51e8a9b2783b..f219197c00fc3258674f03175624aef8855c7668 100644 (file)
--- 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 f0f6086ebaca0c50716d64bbda62510128ee2142..494245a420b555842bdb54c48759997a2858cda5 100644 (file)
--- 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 <sasl/sasl.h>
 #include <sasl/saslutil.h>