]> mj.ucw.cz Git - checkmail.git/blobdiff - charset.c
Use LDLIBS instead of LDFLAGS for libraries
[checkmail.git] / charset.c
index f9dcac9554104dfe7b5c9ebfce15d25c5a17dd03..c80ce9e0dfbbb2b5e9bbb4b958e227b1d40774e6 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -199,7 +199,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
       size_t dlen;
       if (convert_string (d0, strlen(d0), charset, system_charset, &dnew, &dlen) == (size_t) -1)
        {
-         debug("Charset conversion failure: <%s> from %s\n", d0, charset);
+         debug("Charset conversion failure: <%s> from %s (%m)\n", d0, charset);
          free (charset);
          free (d0);
          return (-1);
@@ -232,7 +232,8 @@ static const char *find_encoded_word (const char *s, const char **x)
       ;
     if (q[0] != '?' || !strchr ("BbQq", q[1]) || q[2] != '?')
       continue;
-    for (q = q + 3; 0x20 < *q && *q < 0x7f && *q != '?'; q++)
+    /* non-strict check since many MUAs will not encode spaces and question marks */
+    for (q = q + 3; 0x20 <= *q && *q < 0x7f && (*q != '?' || q[1] != '='); q++)
       ;
     if (q[0] != '?' || q[1] != '=')
     {
@@ -383,6 +384,13 @@ charset_init(void)
   system_charset = nl_langinfo(CODESET);
   if (!system_charset[0])
     system_charset = NULL;
+  if (system_charset)
+    {
+      /* FIXME: Use iconvctl() if available? */
+      char *t = xmalloc(strlen(system_charset) + 11);
+      sprintf(t, "%s//TRANSLIT", system_charset);
+      system_charset = t;
+    }
   debug("Charset is %s\n", system_charset);
 }
 
@@ -422,6 +430,16 @@ add_snippet(char **ppos, char *term, char *add)
   *pos = 0;
 }
 
+void
+add_snippet_raw(char **ppos, char *term, char *add)
+{
+  char *pos = *ppos;
+  while (pos < term && *add)
+    *pos++ = *add++;
+  *ppos = pos;
+  *pos = 0;
+}
+
 void
 add_subject_snippet(char **ppos, char *term, char *add)
 {
@@ -441,8 +459,8 @@ add_addr_snippet(char **ppos, char *term, char *add, int add_mbox, int add_perso
       add_subject_snippet(ppos, term, add);
       return;
     }
-  // debug("%s: pers=%s mbox=%s\n", add, addr->personal, addr->mailbox);
   rfc2047_decode(&addr->personal);
+  // debug("%s: pers=%s mbox=%s\n", add, addr->personal, addr->mailbox);
   if (!addr->mailbox || !addr->mailbox[0])
     add_mbox = 0;
   if (!addr->personal || !addr->personal[0])
@@ -461,13 +479,13 @@ add_addr_snippet(char **ppos, char *term, char *add, int add_mbox, int add_perso
       if (add_personal)
        add_snippet(ppos, term, addr->personal);
       if (add_mbox && add_personal)
-       add_snippet(ppos, term, " <");
+       add_snippet_raw(ppos, term, " <");
       if (add_mbox)
        add_snippet(ppos, term, addr->mailbox);
       if (add_mbox && add_personal)
-       add_snippet(ppos, term, ">");
+       add_snippet_raw(ppos, term, ">");
     }
   else
-    add_snippet(ppos, term, "???");
+    add_snippet_raw(ppos, term, "???");
   rfc822_free_address(&addr);
 }