aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2014-12-12 05:49:09 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2014-12-12 05:49:09 +0000
commit1fcff6946e9a2579514539c73a747519b2c19680 (patch)
treee2b77158ec6452414431f2abe4df6c89e899c262
parent0085a6a12bca001914e6fe846a553fa1c482e377 (diff)
made file names generated on opening attachments more user-friendly.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3458 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--libsylph/libsylph-0.def1
-rw-r--r--libsylph/procmime.c43
-rw-r--r--libsylph/procmime.h2
-rw-r--r--src/mimeview.c6
5 files changed, 53 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d4a82a94..c575fbf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2014-12-12
+ * libsylph/procmime.[ch]
+ libsylph/libsylph-0.def
+ src/mimeview.c: made file names generated on opening attachments
+ more user-friendly.
+
+2014-12-12
+
* src/mainwindow.c: main_window_window_state_cb(): added more debug
print.
diff --git a/libsylph/libsylph-0.def b/libsylph/libsylph-0.def
index 939cf1fc..3a2f740d 100644
--- a/libsylph/libsylph-0.def
+++ b/libsylph/libsylph-0.def
@@ -709,3 +709,4 @@ EXPORTS
export_msgs_to_mbox @ 708
copy_file_stream @ 709
procmsg_save_message_as_text @ 710
+ procmime_get_tmp_file_name_for_user @ 711
diff --git a/libsylph/procmime.c b/libsylph/procmime.c
index 298c3cf9..f8f88e4e 100644
--- a/libsylph/procmime.c
+++ b/libsylph/procmime.c
@@ -1471,12 +1471,38 @@ gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo)
{
static guint32 id = 0;
gchar *base;
- gchar *filename;
+ gchar *filename = NULL;
gchar f_prefix[10];
g_return_val_if_fail(mimeinfo != NULL, NULL);
- g_snprintf(f_prefix, sizeof(f_prefix), "%08x.", id++);
+ if (MIME_TEXT_HTML == mimeinfo->mime_type)
+ base = g_strdup("mimetmp.html");
+ else
+ base = procmime_get_part_file_name(mimeinfo);
+
+ do {
+ g_snprintf(f_prefix, sizeof(f_prefix), "%08x.", id++);
+ if (filename)
+ g_free(filename);
+ filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+ f_prefix, base, NULL);
+ } while (is_file_entry_exist(filename));
+
+ g_free(base);
+
+ debug_print("procmime_get_tmp_file_name: %s\n", filename);
+
+ return filename;
+}
+
+gchar *procmime_get_tmp_file_name_for_user(MimeInfo *mimeinfo)
+{
+ gchar *base;
+ gchar *filename;
+ gint count = 1;
+
+ g_return_val_if_fail(mimeinfo != NULL, NULL);
if (MIME_TEXT_HTML == mimeinfo->mime_type)
base = g_strdup("mimetmp.html");
@@ -1484,10 +1510,21 @@ gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo)
base = procmime_get_part_file_name(mimeinfo);
filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
- f_prefix, base, NULL);
+ base, NULL);
+ while (is_file_entry_exist(filename)) {
+ gchar *base_alt;
+
+ base_alt = get_alt_filename(base, count++);
+ g_free(filename);
+ filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+ base_alt, NULL);
+ g_free(base_alt);
+ }
g_free(base);
+ debug_print("procmime_get_tmp_file_name_for_user: %s\n", filename);
+
return filename;
}
diff --git a/libsylph/procmime.h b/libsylph/procmime.h
index 1247601d..0242d34f 100644
--- a/libsylph/procmime.h
+++ b/libsylph/procmime.h
@@ -196,6 +196,8 @@ gboolean procmime_find_string (MsgInfo *msginfo,
gchar *procmime_get_part_file_name (MimeInfo *mimeinfo);
gchar *procmime_get_tmp_file_name (MimeInfo *mimeinfo);
+gchar *procmime_get_tmp_file_name_for_user
+ (MimeInfo *mimeinfo);
ContentType procmime_scan_mime_type (const gchar *mime_type);
gchar *procmime_get_mime_type (const gchar *filename);
diff --git a/src/mimeview.c b/src/mimeview.c
index d58788a4..e06b5308 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -1006,7 +1006,7 @@ static void mimeview_drag_begin(GtkWidget *widget, GdkDragContext *drag_context,
subst_for_filename(bname);
}
if (!bname || *bname == '\0')
- filename = procmime_get_tmp_file_name(partinfo);
+ filename = procmime_get_tmp_file_name_for_user(partinfo);
else
filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
bname, NULL);
@@ -1134,7 +1134,7 @@ void mimeview_launch_part(MimeView *mimeview, MimeInfo *partinfo)
if (!mimeview->messageview->file) return;
- filename = procmime_get_tmp_file_name(partinfo);
+ filename = procmime_get_tmp_file_name_for_user(partinfo);
if (procmime_get_part(filename, mimeview->messageview->file, partinfo) < 0)
alertpanel_error
@@ -1154,7 +1154,7 @@ void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo)
if (!mimeview->messageview->file) return;
- filename = procmime_get_tmp_file_name(partinfo);
+ filename = procmime_get_tmp_file_name_for_user(partinfo);
if (procmime_get_part(filename, mimeview->messageview->file, partinfo) < 0) {
alertpanel_error