don't get a fright when encountering an unknown Content-Type
[claws.git] / src / procmime.c
index a5961b7add3e8312b8431e2f727f7d9b4eb4fa1e..0a40426877ac66f833eef8972914fec2ac1dcf05 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto & The Claws Mail Team
+ * Copyright (C) 1999-2020 the Claws Mail Team and Hiroyuki Yamamoto
  *
  * 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
@@ -262,7 +262,7 @@ const gchar *procmime_mimeinfo_get_parameter(MimeInfo *mimeinfo, const gchar *na
                gint llen = 0;                                                  \
                strretchomp(lastline);                                          \
                llen = strlen(lastline);                                        \
-               if (lastline[llen-1] == ' ' && !account_signatures_matchlist_str_found(lastline, "%s") &&       \
+               if (lastline[llen-1] == ' ' && !account_sigsep_matchlist_str_found(lastline, "%s") &&   \
                    !(llen == 2 && lastline[1] == ' ' && strchr(prefs_common.quote_chars, lastline[0]))) {                                      \
                        /* this is flowed */                                    \
                        if (delsp)                                              \
@@ -348,7 +348,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        tmp_file = TRUE;
        readend = mimeinfo->offset + mimeinfo->length;
 
-       account_signatures_matchlist_create(); /* FLUSH_LASTLINE will use it */
+       account_sigsep_matchlist_create(); /* FLUSH_LASTLINE will use it */
 
        *buf = '\0';
        if (encoding == ENC_QUOTED_PRINTABLE) {
@@ -470,7 +470,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        claws_fclose(outfp);
        claws_fclose(infp);
 
-       account_signatures_matchlist_delete();
+       account_sigsep_matchlist_delete();
 
        if (err == TRUE) {
                return FALSE;
@@ -2107,7 +2107,9 @@ static gboolean output_func(GNode *node, gpointer data)
        depth = g_node_depth(node);
        for (i = 0; i < depth; i++)
                g_print("    ");
-       g_print("%s/%s (offset:%d length:%d encoding: %d)\n", typenames[mimeinfo->type], mimeinfo->subtype, mimeinfo->offset, mimeinfo->length, mimeinfo->encoding_type);
+       g_print("%s/%s (offset:%d length:%d encoding: %d)\n", 
+               (mimeinfo->type < 8)? typenames[mimeinfo->type] : "unknown", 
+               mimeinfo->subtype, mimeinfo->offset, mimeinfo->length, mimeinfo->encoding_type);
 
        return FALSE;
 }
@@ -2719,15 +2721,15 @@ void *procmime_get_part_as_string(MimeInfo *mimeinfo,
 
 /* Returns an open GInputStream. The caller should just
  * read mimeinfo->length bytes from it and then release it. */
-GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo,
-               GError **error)
+GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo)
 {
        cm_return_val_if_fail(mimeinfo != NULL, NULL);
 
        if (mimeinfo->encoding_type != ENC_BINARY &&
-                       !procmime_decode_content(mimeinfo))
+                       !procmime_decode_content(mimeinfo)) {
+               g_warning("could not decode part");
                return NULL;
-
+       }
        if (mimeinfo->content == MIMECONTENT_MEM) {
                /* NULL for destroy func, since we're not copying
                 * the data for the stream. */
@@ -2740,3 +2742,28 @@ GInputStream *procmime_get_part_as_inputstream(MimeInfo *mimeinfo,
                                mimeinfo->length, g_free);
        }
 }
+
+GdkPixbuf *procmime_get_part_as_pixbuf(MimeInfo *mimeinfo, GError **error)
+{
+       GdkPixbuf *pixbuf;
+       GInputStream *stream;
+
+       if (error)
+               *error = NULL;
+
+       stream = procmime_get_part_as_inputstream(mimeinfo);
+       if (stream == NULL) {
+               if (error)
+                       *error = g_error_new_literal(G_FILE_ERROR, -1, _("Could not decode part"));
+               return NULL;
+       }
+
+       pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, error);
+       g_object_unref(stream);
+
+       if (error && *error != NULL)
+               return NULL;
+
+       return pixbuf;
+}
+