]> granicus.if.org Git - mutt/commitdiff
Change charset-hook's behaviour.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 13 Feb 2001 22:06:14 +0000 (22:06 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 13 Feb 2001 22:06:14 +0000 (22:06 +0000)
charset.c
charset.h
gettext.c
gnupgparse.c
handler.c
imap/utf7.c
rfc2047.c
rfc2231.c
sendlib.c

index 6d36e79e34a92646e793c5b3934afb0c3dc0b53b..e6529be736da1cac4114730967a879544048e0dc 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -278,18 +278,18 @@ int iconv_close (iconv_t cd)
  * Like iconv_open, but canonicalises the charsets
  */
 
-iconv_t mutt_iconv_open (const char *tocode, const char *fromcode)
+iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags)
 {
   char tocode1[SHORT_STRING];
   char fromcode1[SHORT_STRING];
   char *tmp;
 
   mutt_canonical_charset (tocode1, sizeof (tocode1), tocode);
-  if ((tmp = mutt_charset_hook (tocode1)))
+  if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook (tocode1)))
     mutt_canonical_charset (tocode1, sizeof (tocode1), tmp);
 
   mutt_canonical_charset (fromcode1, sizeof (fromcode1), fromcode);
-  if ((tmp = mutt_charset_hook (fromcode1)))
+  if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1)))
     mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp);
 
   return iconv_open (tocode1, fromcode1);
@@ -367,7 +367,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft,
  * Used in rfc2047.c and rfc2231.c
  */
 
-int mutt_convert_string (char **ps, const char *from, const char *to)
+int mutt_convert_string (char **ps, const char *from, const char *to, int flags)
 {
   iconv_t cd;
   const char *repls[] = { "\357\277\275", "?", 0 };
@@ -376,7 +376,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to)
   if (!s || !*s)
     return 0;
 
-  if (to && from && (cd = mutt_iconv_open (to, from)) != (iconv_t)-1) 
+  if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t)-1)
   {
     int len;
     const char *ib;
@@ -437,14 +437,14 @@ struct fgetconv_not
   iconv_t cd;
 };
 
-FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to)
+FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to, int flags)
 {
   struct fgetconv_s *fc;
   iconv_t cd = (iconv_t)-1;
   static const char *repls[] = { "\357\277\275", "?", 0 };
 
   if (from && to)
-    cd = mutt_iconv_open (to, from);
+    cd = mutt_iconv_open (to, from, flags);
 
   if (cd != (iconv_t)-1)
   {
index 2d281008f2dab55c8919be741fb831b91d8b8dee..ca2efbab2a64c442f0e703e7c054ba2957f600dc 100644 (file)
--- a/charset.h
+++ b/charset.h
 
 #include <iconv.h>
 
-int mutt_convert_string (char **, const char *, const char *);
+int mutt_convert_string (char **, const char *, const char *, int);
 
-iconv_t mutt_iconv_open (const char *, const char *);
+iconv_t mutt_iconv_open (const char *, const char *, int);
 size_t mutt_iconv (iconv_t, const char **, size_t *, char **, size_t *, const char **, const char *);
 
 typedef void * FGETCONV;
 
-FGETCONV *fgetconv_open (FILE *, const char *, const char *);
+FGETCONV *fgetconv_open (FILE *, const char *, const char *, int);
 int fgetconv (FGETCONV *);
 void fgetconv_close (FGETCONV **);
 
 void mutt_set_langinfo_charset (void);
 
+#define M_ICONV_HOOK_FROM 1
+#define M_ICONV_HOOK_TO   2
+
 #endif /* _CHARSET_H */
index bd178ef5c948dd631a742aa02461f833d9cc0340..7b5f3018b2a1cc7b56208e6d39c2a562706a756d 100644 (file)
--- a/gettext.c
+++ b/gettext.c
@@ -131,7 +131,8 @@ char *mutt_gettext (const char *message)
   mp = safe_malloc (sizeof (struct msg));
   mp->key = safe_strdup (orig);
   mp->data = safe_strdup (orig);
-  mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", MessageCharset);
+  mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", 
+                      MessageCharset, 0);
 
 # ifdef DEBUG
   if (debugfile)
index 88b1716ea872bc13b0d9481ca0cffda4b3443c47..407ace65e88b04565ac356de7131a6907df5f5aa 100644 (file)
@@ -87,7 +87,7 @@ static void fix_uid (char *uid)
   }
   *d = '\0';
 
-  if (_chs && (cd = mutt_iconv_open (_chs, "utf-8")) != (iconv_t)-1) 
+  if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != (iconv_t)-1)
   {
     int n = s - uid + 1; /* chars available in original buffer */
     char *buf;
index 39172aebab09fcdcba14c27cab82dfaea374b97b..cc390d5e6fd87e6e792c9d6e61c0b8d78cccb061 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1366,7 +1366,7 @@ void mutt_decode_attachment (BODY *b, STATE *s)
   {
     char *charset = mutt_get_parameter ("charset", b->parameter);
     if (charset && Charset)
-      cd = mutt_iconv_open (Charset, charset);
+      cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
   }
 
   fseek (s->fpin, b->offset, 0);
index 93031503c5e74dfe746a44f2fcb2c254077f7a67..fc68203b057efc640e0eba44500797ccfb814d9d 100644 (file)
@@ -248,7 +248,7 @@ void imap_utf7_encode (char **s)
   if (Charset)
   {
     char *t = safe_strdup (*s);
-    if (!mutt_convert_string (&t, Charset, "UTF-8"))
+    if (!mutt_convert_string (&t, Charset, "UTF-8", 0))
       utf8_to_utf7 (t, strlen (t), s, 0);
     safe_free ((void **) &t);
   }
@@ -259,7 +259,7 @@ void imap_utf7_decode (char **s)
   if (Charset)
   {
     char *t = utf7_to_utf8 (*s, strlen (*s), 0, 0);
-    if (t && !mutt_convert_string (&t, "UTF-8", Charset))
+    if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0))
     {
       safe_free ((void **) s);
       *s = t;
index a28c8db4a0f9653dc4d2ad70148f48d2608344e8..69159bf5fcf2deeea5c45c0be751ad4c34b27159 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -59,7 +59,7 @@ static size_t convert_string (const char *f, size_t flen,
   size_t obl, n;
   int e;
 
-  cd = mutt_iconv_open (to, from);
+  cd = mutt_iconv_open (to, from, 0);
   if (cd == (iconv_t)(-1))
     return (size_t)(-1);
   obl = 4 * flen + 1;
@@ -236,7 +236,7 @@ static size_t try_block (const char *d, size_t dlen,
 
   if (fromcode)
   {
-    cd = mutt_iconv_open (tocode, fromcode);
+    cd = mutt_iconv_open (tocode, fromcode, 0);
     assert (cd != (iconv_t)(-1));
     ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode);
     if (iconv (cd, &ib, &ibl, &ob, &obl) == (size_t)(-1) ||
@@ -307,7 +307,7 @@ static size_t encode_block (char *s, char *d, size_t dlen,
 
   if (fromcode)
   {
-    cd = mutt_iconv_open (tocode, fromcode);
+    cd = mutt_iconv_open (tocode, fromcode, 0);
     assert (cd != (iconv_t)(-1));
     ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode);
     n1 = iconv (cd, &ib, &ibl, &ob, &obl);
@@ -671,7 +671,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
   }
   
   if (charset)
-    mutt_convert_string (&d0, charset, Charset);
+    mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM);
   strfcpy (d, d0, len);
   safe_free ((void **) &charset);
   safe_free ((void **) &d0);
index fe22c218b111ce4e393af5fc3541f74376939591..3c39658f00e6f0f5b12ea5efb2079886071a3b5f 100644 (file)
--- a/rfc2231.c
+++ b/rfc2231.c
@@ -124,7 +124,7 @@ void rfc2231_decode_parameters (PARAMETER **headp)
       
       s = rfc2231_get_charset (p->value, charset, sizeof (charset));
       rfc2231_decode_one (p->value, s);
-      mutt_convert_string (&p->value, charset, Charset);
+      mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM);
 
       *last = p;
       last = &p->next;
@@ -293,7 +293,7 @@ static void rfc2231_join_continuations (PARAMETER **head,
     if (value)
     {
       if (encoded)
-       mutt_convert_string (&value, charset, Charset);
+       mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM);
       *head = mutt_new_parameter ();
       (*head)->attribute = safe_strdup (attribute);
       (*head)->value = value;
index 013eab0f1f61aec0982aa4af0bb788cf4c7b318f..257640172adeace00cbf1a40f47196263b0f4954 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -493,9 +493,11 @@ int mutt_write_mime_body (BODY *a, FILE *f)
   }
 
   if (a->type == TYPETEXT && (!a->noconv))
-    fc = fgetconv_open (fpin, Charset, mutt_get_body_charset (send_charset, sizeof (send_charset), a));
+    fc = fgetconv_open (fpin, Charset, 
+                       mutt_get_body_charset (send_charset, sizeof (send_charset), a), 
+                       M_ICONV_HOOK_TO);
   else
-    fc = fgetconv_open (fpin, 0, 0);
+    fc = fgetconv_open (fpin, 0, 0, 0);
 
   if (a->encoding == ENCQUOTEDPRINTABLE)
     encode_quoted (fc, f, mutt_is_text_type (a->type, a->subtype));
@@ -674,7 +676,7 @@ static size_t convert_file_to (FILE *file, const char *fromcode,
   CONTENT_STATE *states;
   size_t *score;
 
-  cd1 = mutt_iconv_open ("UTF-8", fromcode);
+  cd1 = mutt_iconv_open ("UTF-8", fromcode, M_ICONV_HOOK_FROM);
   if (cd1 == (iconv_t)(-1))
     return -1;
 
@@ -688,7 +690,7 @@ static size_t convert_file_to (FILE *file, const char *fromcode,
   memset (infos, 0, ncodes * sizeof (CONTENT));
   for (i = 0; i < ncodes; i++)
     if (strcasecmp (tocodes[i], "UTF-8"))
-      cd[i] = mutt_iconv_open (tocodes[i], "UTF-8");
+      cd[i] = mutt_iconv_open (tocodes[i], "UTF-8", 0);
     else
       /* Special case for conversion to UTF-8 */
       cd[i] = (iconv_t)(-1), score[i] = (size_t)(-1);