do not use description as attachment name
[claws.git] / src / mimeview.c
index b10a4554c6b1c466235ef097811add6f7abe22fc..3a65ed13148f2f8ce12726d5c9e2cbcbc5ebc5dc 100644 (file)
@@ -102,14 +102,12 @@ static void mimeview_drag_data_get      (GtkWidget          *widget,
 static void mimeview_display_as_text   (MimeView       *mimeview);
 static void mimeview_show_image                (MimeView       *mimeview);
 static void mimeview_save_as           (MimeView       *mimeview);
+static void mimeview_save_all          (MimeView       *mimeview);
 static void mimeview_launch            (MimeView       *mimeview);
 static void mimeview_open_with         (MimeView       *mimeview);
 static void mimeview_view_file         (const gchar    *filename,
                                         MimeInfo       *partinfo,
                                         const gchar    *cmdline);
-#if USE_GPGME
-static void mimeview_check_signature   (MimeView       *mimeview);
-#endif
 
 static GtkItemFactoryEntry mimeview_popup_entries[] =
 {
@@ -117,7 +115,8 @@ static GtkItemFactoryEntry mimeview_popup_entries[] =
        {N_("/Open _with..."),    NULL, mimeview_open_with,       0, NULL},
        {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
        {N_("/_Display image"),   NULL, mimeview_show_image,      0, NULL},
-       {N_("/_Save as..."),      NULL, mimeview_save_as,         0, NULL}
+       {N_("/_Save as..."),      NULL, mimeview_save_as,         0, NULL},
+       {N_("/Save _all..."),     NULL, mimeview_save_all,        0, NULL}
 #if USE_GPGME
         ,
         {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
@@ -145,7 +144,7 @@ MimeView *mimeview_create(void)
        gint n_entries;
        gint i;
 
-       debug_print(_("Creating MIME view...\n"));
+       debug_print("Creating MIME view...\n");
        mimeview = g_new0(MimeView, 1);
 
        titles[COL_MIMETYPE] = _("MIME Type");
@@ -306,7 +305,8 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
 
        procmime_scan_multipart_message(mimeinfo, fp);
 #if USE_GPGME
-       if (prefs_common.auto_check_signatures)
+       if ((prefs_common.auto_check_signatures)
+           && (gpg_started))
                rfc2015_check_signature(mimeinfo, fp);
        else
                set_unchecked_signature(mimeinfo);
@@ -361,6 +361,12 @@ static void mimeview_set_multipart_tree(MimeView *mimeview,
 
        if (!mimeinfo->sub && mimeinfo->parent)
                current = mimeview_append_part(mimeview, mimeinfo, parent);
+       if (mimeinfo->sub && !mimeinfo->sub->children &&
+           mimeinfo->sub->mime_type != MIME_TEXT &&
+           mimeinfo->sub->mime_type != MIME_TEXT_HTML) {
+               mimeview_append_part(mimeview, mimeinfo->sub, parent);
+               return;
+       }
 
        if (mimeinfo->sub)
                mimeview_set_multipart_tree(mimeview, mimeinfo->sub, current);
@@ -383,6 +389,20 @@ static gchar *get_part_name(MimeInfo *partinfo)
                return partinfo->name;
        else if (partinfo->filename)
                return partinfo->filename;
+       else if (partinfo->description)
+               return partinfo->description;
+       else
+               return "";
+}
+
+static gchar *get_part_description(MimeInfo *partinfo)
+{
+       if (partinfo->description)
+               return partinfo->description;
+       else if (partinfo->name)
+               return partinfo->name;
+       else if (partinfo->filename)
+               return partinfo->filename;
        else
                return "";
 }
@@ -398,7 +418,10 @@ static GtkCTreeNode *mimeview_append_part(MimeView *mimeview,
        str[COL_MIMETYPE] =
                partinfo->content_type ? partinfo->content_type : "";
        str[COL_SIZE] = to_human_readable(partinfo->size);
-       str[COL_NAME] = get_part_name(partinfo);
+       if (prefs_common.attach_desc)
+               str[COL_NAME] = get_part_description(partinfo);
+       else
+               str[COL_NAME] = get_part_name(partinfo);
 
        node = gtk_ctree_insert_node(ctree, parent, NULL, str, 0,
                                     NULL, NULL, NULL, NULL,
@@ -460,7 +483,8 @@ static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
                /* Workaround for the GTK+ bug with handling scroll adjustments
                 * in GtkViewport */
                imageview_clear(mimeview->imageview);
-               imageview_show_image(mimeview->imageview, partinfo, filename);
+               imageview_show_image(mimeview->imageview, partinfo, filename,
+                                    prefs_common.resize_image);
                unlink(filename);
        }
 
@@ -535,7 +559,9 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
                if (gdk_pointer_is_grabbed())
                        gdk_pointer_ungrab(GDK_CURRENT_TIME);
        }
-
+       
+       mimeview->textview->default_text = FALSE;
+       
        switch (partinfo->mime_type) {
        case MIME_TEXT:
        case MIME_TEXT_HTML:
@@ -543,9 +569,11 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
        case MIME_MESSAGE_RFC822:
        case MIME_MULTIPART:
                mimeview_show_message_part(mimeview, partinfo);
+               
                break;
 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
        case MIME_IMAGE:
+               mimeview->textview->default_text = TRUE;        
                if (prefs_common.display_img)
                        mimeview_show_image_part(mimeview, partinfo);
                else {
@@ -555,6 +583,7 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
                break;
 #endif
        default:
+               mimeview->textview->default_text = TRUE;        
                mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
 #if USE_GPGME
                if (g_strcasecmp(partinfo->content_type,
@@ -779,6 +808,63 @@ static void mimeview_drag_data_get(GtkWidget           *widget,
        g_free(filename);
 }
 
+static void mimeview_save_all(MimeView *mimeview)
+{
+       gchar *dirname;
+       gchar *defname = NULL;
+       MimeInfo *partinfo;
+       MimeInfo *attachment;
+       gchar buf[1024];
+
+       if (!mimeview->opened) return;
+       if (!mimeview->file) return;
+
+       partinfo = gtk_ctree_node_get_row_data
+               (GTK_CTREE(mimeview->ctree), mimeview->opened);
+       g_return_if_fail(partinfo != NULL);
+
+       dirname = filesel_select_file(_("Save as"), defname);
+       if (!dirname) return;
+
+       /* return to first children */
+       if (!partinfo->parent->children) return;  /* multipart container? */
+       attachment = partinfo->parent->children->next;
+       /* for each attachment, extract it in the selected dir. */
+       while (attachment != NULL) {
+               static guint subst_cnt = 1;
+               gchar *attachdir;
+               gchar *attachname = g_strdup(get_part_name(attachment));
+               AlertValue aval = G_ALERTDEFAULT;
+               gchar *res;
+
+               if (!attachname || !strlen(attachname))
+                       attachname = g_strdup_printf("noname.%d",subst_cnt++);
+               subst_chars(attachname, ":?*&|<>\t\r\n", '_');
+               g_snprintf(buf, sizeof(buf), "%s%s",
+                          dirname,
+                          (attachname[0] == G_DIR_SEPARATOR)
+                          ? &attachname[1]
+                          : attachname);
+               subst_chars(buf, "/\\", G_DIR_SEPARATOR);
+               attachdir = g_dirname(buf);
+               make_dir_hier(attachdir);
+               g_free(attachdir);
+
+               if (is_file_exist(buf)) {
+                       res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                             attachname);
+                       aval = alertpanel(_("Overwrite"), res, _("OK"), 
+                                         _("Cancel"), NULL);
+                       g_free(res);                                      
+               }
+               g_free(attachname);
+
+               if ((G_ALERTDEFAULT != aval) || (procmime_get_part(buf, mimeview->file, attachment) < 0))
+                       alertpanel_error(_("Can't save the part of multipart message."));
+               attachment = attachment->next;
+       }
+}
+
 static void mimeview_display_as_text(MimeView *mimeview)
 {
        MimeInfo *partinfo;
@@ -806,6 +892,7 @@ static void mimeview_save_as(MimeView *mimeview)
        gchar *filename;
        gchar *defname = NULL;
        MimeInfo *partinfo;
+       gchar *res;
 
        if (!mimeview->opened) return;
        if (!mimeview->file) return;
@@ -825,10 +912,11 @@ static void mimeview_save_as(MimeView *mimeview)
        if (!filename) return;
        if (is_file_exist(filename)) {
                AlertValue aval;
-
-               aval = alertpanel(_("Overwrite"),
-                                 _("Overwrite existing file?"),
-                                 _("OK"), _("Cancel"), NULL);
+               res = g_strdup_printf(_("Overwrite existing file '%s'?"),
+                                     filename);
+               aval = alertpanel(_("Overwrite"), res, _("OK"), 
+                                 _("Cancel"), NULL);
+               g_free(res);                                      
                if (G_ALERTDEFAULT != aval) return;
        }
 
@@ -909,8 +997,7 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
 {
        static gchar *default_image_cmdline = "display '%s'";
        static gchar *default_audio_cmdline = "play '%s'";
-       static gchar *default_html_cmdline =
-               "netscape -remote 'openURL(%s,raise)'";
+       static gchar *default_html_cmdline = DEFAULT_BROWSER_CMD;
        static gchar *mime_cmdline = "metamail -d -b -x -c %s '%s'";
        gchar buf[1024];
        gchar m_buf[1024];
@@ -944,7 +1031,7 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                g_snprintf(buf, sizeof(buf), cmd, filename);
        else {
                if (cmd)
-                       g_warning(_("MIME viewer command line is invalid: `%s'"), cmd);
+                       g_warning("MIME viewer command line is invalid: `%s'", cmd);
                if (def_cmd)
                        g_snprintf(buf, sizeof(buf), def_cmd, filename);
                else
@@ -993,13 +1080,13 @@ static void mimeview_update_signature_info(MimeView *mimeview)
        }
 }
 
-static void mimeview_check_signature(MimeView *mimeview)
+void mimeview_check_signature(MimeView *mimeview)
 {
        MimeInfo *mimeinfo;
-       gchar buf[BUFFSIZE];
        FILE *fp;
 
        g_return_if_fail (mimeview_is_signed(mimeview));
+       g_return_if_fail (gpg_started);
 
        mimeinfo = gtk_ctree_node_get_row_data
                (GTK_CTREE(mimeview->ctree), mimeview->opened);
@@ -1014,19 +1101,13 @@ static void mimeview_check_signature(MimeView *mimeview)
                return;
        }
 
-       /* skip headers */
-       if (mimeinfo->mime_type == MIME_MULTIPART) {
-               if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
-               FILE_OP_ERROR(mimeview->file, "fseek");
-               while (fgets(buf, sizeof(buf), fp) != NULL)
-                       if (buf[0] == '\r' || buf[0] == '\n') break;
-       }
-
-       procmime_scan_multipart_message(mimeinfo, fp);
        rfc2015_check_signature(mimeinfo, fp);
        fclose(fp);
 
        mimeview_update_names(mimeview);
        mimeview_update_signature_info(mimeview);
+
+       textview_show_message(mimeview->messageview->textview, mimeinfo,
+                             mimeview->file);
 }
 #endif /* USE_GPGME */