0.8.6claws43
[claws.git] / src / procmime.c
index a0d1f8280acda6b4bd490be30c459368f99d9680..0e98c97fc04703cae2f131069a4d3f4deb136c4e 100644 (file)
@@ -32,8 +32,8 @@
 #include "intl.h"
 #include "procmime.h"
 #include "procheader.h"
-#include "base64.h"
-#include "uuencode.h"
+#include "common/base64.h"
+#include "common/uuencode.h"
 #include "unmime.h"
 #include "html.h"
 #include "enriched.h"
@@ -60,28 +60,6 @@ MimeInfo *procmime_mimeinfo_new(void)
        return mimeinfo;
 }
 
-void procmime_mimeinfo_free(MimeInfo *mimeinfo)
-{
-       if (!mimeinfo) return;
-
-       g_free(mimeinfo->encoding);
-       g_free(mimeinfo->content_type);
-       g_free(mimeinfo->charset);
-       g_free(mimeinfo->name);
-       g_free(mimeinfo->boundary);
-       g_free(mimeinfo->content_disposition);
-       g_free(mimeinfo->filename);
-#if USE_GPGME
-       g_free(mimeinfo->plaintextfile);
-       g_free(mimeinfo->sigstatus);
-       g_free(mimeinfo->sigstatus_full);
-#endif
-
-       procmime_mimeinfo_free(mimeinfo->sub);
-
-       g_free(mimeinfo);
-}
-
 void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
 {
        while (mimeinfo != NULL) {
@@ -271,7 +249,7 @@ void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
                        if (!sub) break;
 
                        sub->level = partinfo->level + 1;
-                       sub->parent = partinfo->parent;
+                       sub->parent = partinfo;
                        sub->main = partinfo;
 
                        if (sub->level < 8) {
@@ -403,7 +381,10 @@ void procmime_scan_content_type(MimeInfo *mimeinfo, const gchar *content_type)
                                Xalloca(tmp, len, return);
                                conv_unmime_header(tmp, len, value, NULL);
                                g_free(mimeinfo->name);
-                               mimeinfo->name = g_strdup(tmp);
+                               /*pgp signatures should NOT have a name */
+                               if (mimeinfo->content_type 
+                               &&  strcasecmp(mimeinfo->content_type, "application/pgp-signature"))
+                                       mimeinfo->name = g_strdup(tmp);
                        } else if (!strcasecmp(attr, "boundary"))
                                mimeinfo->boundary = g_strdup(value);
                }
@@ -467,7 +448,10 @@ void procmime_scan_content_disposition(MimeInfo *mimeinfo,
                                Xalloca(tmp, len, return);
                                conv_unmime_header(tmp, len, value, NULL);
                                g_free(mimeinfo->filename);
-                               mimeinfo->filename = g_strdup(tmp);
+                               /*pgp signatures should NOT have a name */
+                               if (mimeinfo->content_type 
+                               &&  strcasecmp(mimeinfo->content_type, "application/pgp-signature"))
+                                       mimeinfo->filename = g_strdup(tmp);
                                break;
                        }
                }
@@ -498,7 +482,11 @@ void procmime_scan_content_description(MimeInfo *mimeinfo,
        Xalloca(tmp, blen, return);
        conv_unmime_header(tmp, blen, buf, NULL);
        g_free(mimeinfo->name);
-       mimeinfo->name = g_strdup(tmp);
+       mimeinfo->name = NULL;
+       /*pgp signatures should NOT have a name */
+       if (mimeinfo->content_type 
+       &&  strcasecmp(mimeinfo->content_type, "application/pgp-signature"))
+               mimeinfo->name = g_strdup(tmp);
 }
 
 void procmime_scan_subject(MimeInfo *mimeinfo,
@@ -1282,15 +1270,29 @@ EncodingType procmime_get_encoding_for_file(const gchar *file)
        return ENC_7BIT;
 }
 
-const gchar *procmime_get_encoding_str(EncodingType encoding)
+struct EncodingTable 
 {
-       static const gchar *encoding_str[] = {
-               "7bit", "8bit", "quoted-printable", "base64", "x-uuencode",
-               NULL
-       };
+       gchar *str;
+       EncodingType enc_type;
+};
 
-       if (encoding >= ENC_7BIT && encoding <= ENC_UNKNOWN)
-               return encoding_str[encoding];
-       else
-               return NULL;
+struct EncodingTable encoding_table[] = {
+       {"7bit", ENC_7BIT},
+       {"8bit", ENC_8BIT},
+       {"binary", ENC_BINARY},
+       {"quoted-printable", ENC_QUOTED_PRINTABLE},
+       {"base64", ENC_BASE64},
+       {"x-uuencode", ENC_UNKNOWN},
+       {NULL, ENC_UNKNOWN},
+};
+
+const gchar *procmime_get_encoding_str(EncodingType encoding)
+{
+       struct EncodingTable *enc_table;
+       
+       for (enc_table = encoding_table; enc_table->str != NULL; enc_table++) {
+               if (enc_table->enc_type == encoding)
+                       return enc_table->str;
+       }
+       return NULL;
 }