]> granicus.if.org Git - neomutt/commitdiff
move idna functions to muttlib
authorRichard Russon <rich@flatcap.org>
Sat, 30 Dec 2017 16:15:09 +0000 (16:15 +0000)
committerRichard Russon <rich@flatcap.org>
Sun, 31 Dec 2017 00:40:50 +0000 (00:40 +0000)
27 files changed:
Makefile.autosetup
address.c
alias.c
commands.c
compose.c
conn/socket.c
conn/ssl.c
copy.c
edit.c
envelope.c
hdrline.c
header.c
init.c
main.c
mutt/idna.c [moved from mutt_idna.c with 67% similarity]
mutt/idna2.h [moved from mutt_idna.h with 69% similarity]
mutt/mutt.h
mutt_address.c
ncrypt/pgpinvoke.c
options.h
protos.h
query.c
recvcmd.c
rfc2047.c
send.c
sendlib.c
sort.c

index 6089f957b824f8fd82b28134bfccfd47b1e08fd7..5219b5780901df9b45af3273d818258911caa5c7 100644 (file)
@@ -61,7 +61,7 @@ NEOMUTTOBJS=  mutt_account.o addrbook.o alias.o attach.o bcache.o body.o \
                curs_main.o edit.o editmsg.o enter.o envelope.o filter.o \
                flags.o from.o group.o handler.o hdrline.o \
                header.o help.o history.o hook.o init.o keymap.o main.o \
-               mbox.o mbyte.o menu.o mh.o muttlib.o mutt_address.o mutt_idna.o \
+               mbox.o mbyte.o menu.o mh.o muttlib.o mutt_address.o \
                mutt_socket.o tags.o mx.o \
                newsrc.o nntp.o pager.o parameter.o parse.o pattern.o pop.o \
                pop_auth.o pop_lib.o postpone.o query.o recvattach.o recvcmd.o \
@@ -93,7 +93,7 @@ ALLOBJS+=     $(NEOMUTTOBJS)
 # libmutt
 LIBMUTT=       libmutt.a
 LIBMUTTOBJS=   mutt/base64.o mutt/buffer.o mutt/charset.o mutt/date.o mutt/debug.o mutt/exit.o \
-               mutt/file.o mutt/hash.o mutt/list.o mutt/mapping.o mutt/mbyte.o mutt/md5.o \
+               mutt/file.o mutt/hash.o mutt/idna.o mutt/list.o mutt/mapping.o mutt/mbyte.o mutt/md5.o \
                mutt/memory.o mutt/message.o mutt/regex.o mutt/sha1.o mutt/signal.o mutt/string.o
 CLEANFILES+=   $(LIBMUTT) $(LIBMUTTOBJS)
 MUTTLIBS+=     $(LIBMUTT)
index fbf25076261d37f031e35ee7777d5e13a17eeaa6..44c68e8052f6c79864422f90c28f53039843eb73 100644 (file)
--- a/address.c
+++ b/address.c
@@ -62,7 +62,6 @@
 #include <string.h>
 #include "mutt/mutt.h"
 #include "address.h"
-#include "mutt_idna.h"
 
 /**
  * AddressSpecials - Characters with special meaning for email addresses
diff --git a/alias.c b/alias.c
index 7f98a290b1c0fb39c40f09c4de179780ec036318..e3baccafc18c75e1de6a414663c4a730c46d2f18 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -36,7 +36,6 @@
 #include "envelope.h"
 #include "globals.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "options.h"
 #include "protos.h"
 #ifdef ENABLE_NLS
index 40f09a23868623048bb8f9e86c7230c41174f1a3..9a0e8de1c9e1a58aade6137fe9ee2165fc3cde49 100644 (file)
@@ -48,7 +48,6 @@
 #include "mailbox.h"
 #include "mime.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
index dd4dcd8055d6041ae3efdb8dfcb92d674818a40d..fee1b2f56cc0a7928a1e8e49596a0c05b02d6167 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -46,7 +46,6 @@
 #include "mailbox.h"
 #include "mime.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
index fb5a4b0c1123b72c9e40acdb3807ef86c118c1db..ca65bfeaac3cf85091528ca05050022422e7335e 100644 (file)
@@ -65,7 +65,6 @@
 #include "conn_globals.h"
 #include "connection.h"
 #include "globals.h"
-#include "mutt_idna.h"
 #include "options.h"
 #include "protos.h"
 #ifdef USE_SSL
index ec1877275814cd19886501e23503155eccd80ecd..0f0bdacf1974455c8eb4e4eb514bd45be4458e66 100644 (file)
@@ -65,7 +65,6 @@
 #include "globals.h"
 #include "keymap.h"
 #include "mutt_account.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "opcodes.h"
 #include "options.h"
diff --git a/copy.c b/copy.c
index d68728878cc87b3f475ce604df11aba5ac0bf644..1ea14168eb2af1c8f4e9c0c3af780ad5dc99b7de 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -37,7 +37,6 @@
 #include "mailbox.h"
 #include "mime.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
diff --git a/edit.c b/edit.c
index d30fb6c413d154eb4d745176d7ca8a56ebda4cff..3f2676c3cb131ef36b5b358962df10c8759e4fdd 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -40,7 +40,6 @@
 #include "globals.h"
 #include "header.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "options.h"
 #include "protos.h"
 #ifdef ENABLE_NLS
index e8b21d69f61fb26d4d96b7c0aa2f1ce55413ffb2..f8e7925d7967b2c4b6c28c181998716e5233713b 100644 (file)
@@ -43,7 +43,7 @@
 #include "mutt/string2.h"
 #include "envelope.h"
 #include "address.h"
-#include "mutt_idna.h"
+#include "protos.h"
 
 /**
  * mutt_env_new - Create a new Envelope
index ae310714df2efe5fb6942667fb6c5450b9a57628..e5c30b1705a6c1084821f3083d0fa4bcb40b9f80 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -41,7 +41,6 @@
 #include "header.h"
 #include "mbtable.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
 #include "protos.h"
index ec84f7092ca6f09dbb89b44ea6760ad0471386ed..601a7093422faeba18807a33bdabd7f12a730bf6 100644 (file)
--- a/header.c
+++ b/header.c
@@ -36,7 +36,6 @@
 #include "context.h"
 #include "envelope.h"
 #include "globals.h"
-#include "mutt_idna.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
 #include "protos.h"
diff --git a/init.c b/init.c
index 68562eddce1371a6074b46f7b74052f3c7709208..193d3275e0b5780fb673928fb30fbadd5e73bad4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -53,7 +53,6 @@
 #include "mbtable.h"
 #include "mbyte.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "mx.h"
 #include "myvar.h"
diff --git a/main.c b/main.c
index 7477be0ab3d3bca1b9d6718fafd1fa259c44e2c5..76b3048feea1d45f242fe990ed31db0492875a3e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -47,7 +47,6 @@
 #include "keymap.h"
 #include "mailbox.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "mutt_socket.h"
 #include "ncrypt/ncrypt.h"
similarity index 67%
rename from mutt_idna.c
rename to mutt/idna.c
index 7b48cc62c7752838ccc40475bc8a9fd43ce44b00..43bf21de647160158b2f747ca5fa852fb65a89d3 100644 (file)
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/**
+ * @page idna Handling of international domain names
+ *
+ * Handling of international domain names
+ *
+ * | Function                  | Description
+ * | :------------------------ | :---------------------------------------------------------
+ * | mutt_idna_intl_to_local() | Convert an email's domain from Punycode
+ * | mutt_idna_local_to_intl() | Convert an email's domain to Punycode
+ * | mutt_idna_to_ascii_lz()   | Convert a domain to Punycode
+ */
+
 #include "config.h"
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
-#include "mutt/mutt.h"
-#include "mutt_idna.h"
-#include "address.h"
-#include "envelope.h"
-#include "globals.h"
-#include "options.h"
+#include "charset.h"
+#include "debug.h"
+#include "idna2.h"
+#include "memory.h"
+#include "string2.h"
 #ifdef HAVE_IDNA_H
 #include <idna.h>
 #elif defined(HAVE_IDN_IDNA_H)
 #include <idn/idna.h>
 #endif
 
+#ifdef HAVE_LIBIDN
+bool IdnDecode;
+bool IdnEncode;
+#endif
+
 #ifdef HAVE_LIBIDN
 /* Work around incompatibilities in the libidn API */
 #if (!defined(HAVE_IDNA_TO_ASCII_8Z) && defined(HAVE_IDNA_TO_ASCII_FROM_UTF8))
 
 #ifdef HAVE_LIBIDN
 /**
- * mutt_idna_to_ascii_lz - XXX
- * @param input  XXX
- * @param output XXX
- * @param flags  XXX
+ * mutt_idna_to_ascii_lz - Convert a domain to Punycode
+ * @param input  Domain
+ * @param output Result
+ * @param flags  Flags, e.g. IDNA_ALLOW_UNASSIGNED
  * @retval 0 Success
  * @retval >0 Failure, error code
+ *
+ * Convert a domain from the current locale to Punycode.
+ *
+ * @note The caller must free output
  */
 int mutt_idna_to_ascii_lz(const char *input, char **output, int flags)
 {
   return idna_to_ascii_lz(input, output, flags);
 }
 
+/**
+ * check_idn - Is domain in Punycode?
+ * @param domain Domain to test
+ * @retval true At least one part of domain is in Punycode
+ */
 static bool check_idn(char *domain)
 {
   if (!domain)
@@ -84,7 +109,25 @@ static bool check_idn(char *domain)
 }
 #endif /* HAVE_LIBIDN */
 
-char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
+/**
+ * mutt_idna_intl_to_local - Convert an email's domain from Punycode
+ * @param user   Username
+ * @param domain Domain
+ * @param flags  Flags, e.g. #MI_MAY_BE_IRREVERSIBLE
+ * @retval ptr  Newly allocated local email address
+ * @retval NULL Error in conversion
+ *
+ * If #IdnDecode is set, then the domain will be converted from Punycode.
+ * For example, "xn--ls8h.la" becomes the emoji domain: ":poop:.la"
+ * Then the user and domain are changed from 'utf-8' to the encoding in
+ * #Charset.
+ *
+ * If the flag #MI_MAY_BE_IRREVERSIBLE is NOT given, then the results will be
+ * checked to make sure that the transformation is "undo-able".
+ *
+ * @note The caller must free the returned string.
+ */
+char *mutt_idna_intl_to_local(const char *user, const char *domain, int flags)
 {
   char *local_user = NULL, *local_domain = NULL, *mailbox = NULL;
   char *reversed_user = NULL, *reversed_domain = NULL;
@@ -93,8 +136,8 @@ char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
   bool is_idn_encoded = false;
 #endif /* HAVE_LIBIDN */
 
-  local_user = mutt_str_strdup(orig_user);
-  local_domain = mutt_str_strdup(orig_domain);
+  local_user = mutt_str_strdup(user);
+  local_domain = mutt_str_strdup(domain);
 
 #ifdef HAVE_LIBIDN
   is_idn_encoded = check_idn(local_domain);
@@ -114,10 +157,8 @@ char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
   if (mutt_cs_convert_string(&local_domain, "utf-8", Charset, 0) == -1)
     goto cleanup;
 
-  /*
-   * make sure that we can convert back and come out with the same
-   * user and domain name.
-   */
+  /* make sure that we can convert back and come out with the same
+   * user and domain name.  */
   if ((flags & MI_MAY_BE_IRREVERSIBLE) == 0)
   {
     reversed_user = mutt_str_strdup(local_user);
@@ -129,10 +170,9 @@ char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
       goto cleanup;
     }
 
-    if (mutt_str_strcasecmp(orig_user, reversed_user) != 0)
+    if (mutt_str_strcasecmp(user, reversed_user) != 0)
     {
-      mutt_debug(1, "#1 Not reversible. orig = '%s', reversed = '%s'.\n",
-                 orig_user, reversed_user);
+      mutt_debug(1, "#1 Not reversible. orig = '%s', reversed = '%s'.\n", user, reversed_user);
       goto cleanup;
     }
 
@@ -164,10 +204,9 @@ char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags)
     }
 #endif /* HAVE_LIBIDN */
 
-    if (mutt_str_strcasecmp(orig_domain, reversed_domain) != 0)
+    if (mutt_str_strcasecmp(domain, reversed_domain) != 0)
     {
-      mutt_debug(1, "#2 Not reversible. orig = '%s', reversed = '%s'.\n",
-                 orig_domain, reversed_domain);
+      mutt_debug(1, "#2 Not reversible. orig = '%s', reversed = '%s'.\n", domain, reversed_domain);
       goto cleanup;
     }
   }
@@ -185,7 +224,21 @@ cleanup:
   return mailbox;
 }
 
-char *mutt_idna_local_to_intl(char *user, char *domain)
+/**
+ * mutt_idna_local_to_intl - Convert an email's domain to Punycode
+ * @param user   Username
+ * @param domain Domain
+ * @retval ptr  Newly allocated Punycode email address
+ * @retval NULL Error in conversion
+ *
+ * The user and domain are assumed to be encoded according to #Charset.
+ * They are converted to 'utf-8'.  If #IdnEncode is set, then the domain
+ * will be converted to Punycode.  For example, the emoji domain:
+ * ":poop:.la" becomes "xn--ls8h.la"
+ *
+ * @note The caller must free the returned string.
+ */
+char *mutt_idna_local_to_intl(const char *user, const char *domain)
 {
   char *intl_user = NULL, *intl_domain = NULL;
   char *mailbox = NULL;
similarity index 69%
rename from mutt_idna.h
rename to mutt/idna2.h
index b7d520a233773fa24a996fe4843b1a15cf3c1b0a..bd20a1753667c166943281a25c7a9b01d936c09e 100644 (file)
 #ifndef _MUTT_IDNA_H
 #define _MUTT_IDNA_H
 
-struct Envelope;
-struct Address;
+#include <stdbool.h>
 
-#define MI_MAY_BE_IRREVERSIBLE (1 << 0)
-
-int mutt_idna_to_ascii_lz(const char *input, char **output, int flags);
+extern bool IdnDecode;
+extern bool IdnEncode;
 
-char *mutt_idna_intl_to_local(char *orig_user, char *orig_domain, int flags);
-char *mutt_idna_local_to_intl(char *user, char *domain);
-
-int mutt_addrlist_to_intl(struct Address *a, char **err);
-int mutt_addrlist_to_local(struct Address *a);
+#define MI_MAY_BE_IRREVERSIBLE (1 << 0)
 
-const char *mutt_addr_for_display(struct Address *a);
+int   mutt_idna_to_ascii_lz(const char *input, char **output, int flags);
+char *mutt_idna_intl_to_local(const char *user, const char *domain, int flags);
+char *mutt_idna_local_to_intl(const char *user, const char *domain);
 
 #endif /* _MUTT_IDNA_H */
index ee2723376c21df57d254a98b490d41a9a3982e14..b03cba2aee48e9a3213af100a37a121db0223250 100644 (file)
@@ -36,6 +36,7 @@
  * -# @subpage exit
  * -# @subpage file
  * -# @subpage hash
+ * -# @subpage idna
  * -# @subpage list
  * -# @subpage mapping
  * -# @subpage mbyte
@@ -59,6 +60,7 @@
 #include "exit.h"
 #include "file.h"
 #include "hash.h"
+#include "idna2.h"
 #include "list.h"
 #include "mapping.h"
 #include "mbyte.h"
index 948800b8679489ca66e01ee1d44a199b27a611c1..f90f0dcf90d90a593457cbf7c791ffe8d5e03712 100644 (file)
@@ -26,7 +26,6 @@
 #include <string.h>
 #include "mutt/mutt.h"
 #include "address.h"
-#include "mutt_idna.h"
 
 /**
  * mutt_addrlist_to_intl - Convert an Address list to Punycode
index fd71aaf1988a4771a67a3f228aee4a091f241576..a42b31175182743f685275e54c6ba6129f6a50e4 100644 (file)
@@ -36,7 +36,6 @@
 #include "format_flags.h"
 #include "globals.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "ncrypt.h"
 #include "pgp.h"
 #include "pgpkey.h"
index 2f8116527b0fbeca2b9b06abab35e5d848e33937..7a312bd083ca85644a3626607555c2211d817732 100644 (file)
--- a/options.h
+++ b/options.h
@@ -219,10 +219,6 @@ WHERE bool Use8bitmime;
 WHERE bool UseDomain;
 WHERE bool UseFrom;
 WHERE bool PgpUseGpgAgent;
-#ifdef HAVE_LIBIDN
-WHERE bool IdnDecode;
-WHERE bool IdnEncode;
-#endif
 #ifdef HAVE_GETADDRINFO
 WHERE bool UseIpv6;
 #endif
index 5a4ab1b39fe3995aa32f665da29384d5a278c603..4841d52f107c16abcbb40890d858354b74383e30 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -360,6 +360,10 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b);
 bool message_is_tagged(struct Context *ctx, int index);
 bool message_is_visible(struct Context *ctx, int index);
 
+int mutt_addrlist_to_local(struct Address *a);
+int mutt_addrlist_to_intl(struct Address *a, char **err);
+int mutt_env_to_intl(struct Envelope *env, char **tag, char **err);
+void mutt_env_to_local(struct Envelope *e);
 size_t rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display);
 void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display);
 
diff --git a/query.c b/query.c
index dd03a2084f533f09013e7bdf441b52c05b3b5f9a..56de2b0cf9308c7ba26300f7bc1c34dc42dfcd7c 100644 (file)
--- a/query.c
+++ b/query.c
@@ -38,7 +38,6 @@
 #include "header.h"
 #include "keymap.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mutt_menu.h"
 #include "opcodes.h"
 #include "protos.h"
index 0bfa12f30d6dd317dcf4ca13b148e7b1ca593914..8c23d77975ff9807604ccad43bd2df93bec89e61 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -36,7 +36,6 @@
 #include "globals.h"
 #include "header.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "options.h"
 #include "protos.h"
 #include "state.h"
index 7a6756b99d22bb6b89765b9ddfe596d78b08a525..5c6f15d164d8f924516f93c72697e10b5c018118 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -116,8 +116,8 @@ int convert_nonmime_string(char **ps)
       return 0;
     }
   }
-  mutt_cs_convert_string(ps, (const char *) mutt_cs_get_default_charset(), Charset,
-                      MUTT_ICONV_HOOK_FROM);
+  mutt_cs_convert_string(ps, (const char *) mutt_cs_get_default_charset(),
+                         Charset, MUTT_ICONV_HOOK_FROM);
   return -1;
 }
 
diff --git a/send.c b/send.c
index 9fba54f06b5b444145be2b5418e6a57f61646577..4c93cb1c62cd660315c3c204e3a1354b89e5c918 100644 (file)
--- a/send.c
+++ b/send.c
@@ -46,7 +46,6 @@
 #include "mailbox.h"
 #include "mime.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
 #include "parameter.h"
index bcca72fa6ef04b4bfb58fbf0cca182a585d6d95b..52ad7b037fc5c898ef7205e5b996e516e55f31fc 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -54,7 +54,6 @@
 #include "mailbox.h"
 #include "mime.h"
 #include "mutt_curses.h"
-#include "mutt_idna.h"
 #include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "options.h"
@@ -474,8 +473,8 @@ int mutt_write_mime_body(struct Body *a, FILE *f)
   }
 
   if (a->type == TYPETEXT && (!a->noconv))
-    fc = mutt_cs_fgetconv_open(fpin, a->charset,
-                       mutt_get_body_charset(send_charset, sizeof(send_charset), a), 0);
+    fc = mutt_cs_fgetconv_open(
+        fpin, a->charset, mutt_get_body_charset(send_charset, sizeof(send_charset), a), 0);
   else
     fc = mutt_cs_fgetconv_open(fpin, 0, 0, 0);
 
diff --git a/sort.c b/sort.c
index 8ae27a920bffd91acfc71248597bc846148d0819..9beecb26fb1ce8c21ebf10e98dfa62ca9592c8b8 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -32,7 +32,6 @@
 #include "envelope.h"
 #include "globals.h"
 #include "header.h"
-#include "mutt_idna.h"
 #include "options.h"
 #include "protos.h"
 #include "thread.h"