Provide an up to date version of g_base64_decode() for older GLib.
[claws.git] / src / unmime.c
index 5c1e06d773e2a46ccfe86dc387f746b2d45817ef..424bde99a856a271b16cae5e260589f12eb04ba5 100644 (file)
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include <glib.h>
 #include <string.h>
 #include <ctype.h>
 
+#include "utils.h"
 #include "codeconv.h"
-#include "base64.h"
 #include "quoted-printable.h"
 
 #define ENCODED_WORD_BEGIN     "=?"
@@ -111,11 +112,10 @@ gchar *unmime_header(const gchar *encoded_str, gboolean addr_field)
                encoding = g_ascii_toupper(*(encoding_begin_p + 1));
 
                if (encoding == 'B') {
-                       decoded_text = g_malloc
-                               (eword_end_p - (text_begin_p + 1) + 1);
-                       len = base64_decode(decoded_text, text_begin_p + 1,
-                                           eword_end_p - (text_begin_p + 1));
-                       decoded_text[len] = '\0';
+                       gchar *tmp;
+                       tmp = g_strndup(text_begin_p + 1, eword_end_p - (text_begin_p + 1) + 1);
+                       decoded_text = g_base64_decode(tmp, &out_len);
+                       g_free(tmp);
                } else if (encoding == 'Q') {
                        decoded_text = g_malloc
                                (eword_end_p - (text_begin_p + 1) + 1);
@@ -133,7 +133,8 @@ gchar *unmime_header(const gchar *encoded_str, gboolean addr_field)
                 * We check there are no quotes just to be sure. If there
                 * are, well, the comma won't pose a problem, probably.
                 */
-               if (addr_field && strchr(decoded_text, ',') && !in_quote) {
+               if (addr_field && strchr(decoded_text, ',') && !in_quote &&
+                   !strchr(decoded_text, '"')) {
                        gchar *tmp = g_strdup_printf("\"%s\"", decoded_text);
                        g_free(decoded_text);
                        decoded_text = tmp;