aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/em-utils.c239
-rw-r--r--mail/em-utils.h3
2 files changed, 0 insertions, 242 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 0e9742d8ab..0eab5f6fac 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -345,245 +345,6 @@ em_filename_make_safe (gchar *string)
/* Saving messages... */
-static const gchar *
-emu_save_get_filename_for_part (CamelMimePart *part)
-{
- const gchar *filename;
-
- filename = camel_mime_part_get_filename (part);
- if (filename == NULL) {
- if (CAMEL_IS_MIME_MESSAGE (part)) {
- filename = camel_mime_message_get_subject (
- CAMEL_MIME_MESSAGE (part));
- if (filename == NULL)
- filename = _("message");
- } else
- filename = _("attachment");
- }
-
- return filename;
-}
-
-/**
- * em_utils_save_part:
- * @parent: parent window
- * @prompt: prompt string
- * @part: part to save
- *
- * Saves a mime part to disk (prompting the user for filename).
- **/
-void
-em_utils_save_part (GtkWindow *parent, const gchar *prompt, CamelMimePart *part)
-{
- GtkWidget *file_chooser;
- const gchar *utf8_filename;
- gchar *uri = NULL, *filename;
-
- g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
-
- utf8_filename = emu_save_get_filename_for_part (part);
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- em_filename_make_safe (filename);
-
- file_chooser = e_file_get_save_filesel (
- parent, prompt, filename, GTK_FILE_CHOOSER_ACTION_SAVE);
-
- if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_OK)
- goto exit;
-
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
-
- /* XXX Would be nice to mention _why_ we can't save. */
- if (!e_file_can_save (GTK_WINDOW (file_chooser), uri)) {
- g_warning ("Unable to save %s", uri);
- goto exit;
- }
-
- e_file_update_save_path (
- gtk_file_chooser_get_current_folder_uri (
- GTK_FILE_CHOOSER (file_chooser)), TRUE);
-
- mail_save_part (part, uri, NULL, NULL, FALSE);
-
-exit:
- gtk_widget_destroy (file_chooser);
- g_free (uri);
- g_free (filename);
-}
-
-/* It "assigns" to each part its unique file name, based on the appearance.
- parts contains CamelMimePart, returned value contains gchar *, in same
- order as parts; resulting list should free data and GSList itself as well.
-*/
-static GSList *
-get_unique_file_names (GSList *parts)
-{
- GSList *iter;
- GSList *file_names = NULL;
-
- if (!parts)
- return NULL;
-
- for (iter = parts; iter != NULL; iter = iter->next) {
- CamelMimePart *part = iter->data;
- const gchar *utf8_filename;
- gchar *filename;
-
- utf8_filename = emu_save_get_filename_for_part (part);
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- em_filename_make_safe (filename);
-
- file_names = g_slist_prepend (file_names, filename);
- }
-
- if (file_names) {
- GSList *sorted_file_names;
- gint counter = 1;
- const gchar *last;
- GCompareFunc cmp_func = (GCompareFunc) strcmp;
-
- #ifdef G_OS_WIN32
- cmp_func = (GCompareFunc) g_ascii_strcasecmp;
- #endif
-
- /* we prepended, so reverse to make right order */
- file_names = g_slist_reverse (file_names);
-
- sorted_file_names = g_slist_sort (g_slist_copy (file_names), cmp_func);
- last = sorted_file_names->data;
- for (iter = sorted_file_names->next; iter; iter = iter->next) {
- gchar *name = iter->data;
-
- if (name && last && cmp_func (name, last) == 0) {
- gchar *new_name;
- gchar *p = strrchr (name, '.');
- GSList *i2;
-
- /* if we have an extension, then place number before it (at p is ".ext"),
- otherwise just append number in brackets */
- if (p)
- new_name = g_strdup_printf ("%.*s(%d)%s", (gint) (p - name), name, counter, p);
- else
- new_name = g_strdup_printf ("%s(%d)", name, counter);
-
- /* we need to find the proper item in unsorted list and replace with new name;
- we should always find that item, so no check for leaks */
- for (i2 = file_names; i2; i2 = i2->next) {
- if (i2->data == name) {
- g_free (name);
- i2->data = new_name;
- break;
- }
- }
-
- counter++;
- } else {
- last = name;
- counter = 1;
- }
- }
-
- g_slist_free (sorted_file_names);
- }
-
- return file_names;
-}
-
-void
-em_utils_save_parts (GtkWindow *parent, const gchar *prompt, GSList *parts)
-{
- GtkWidget *file_chooser;
- gchar *path_uri;
- GSList *iter, *file_names, *iter_file;
-
- g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
-
- file_chooser = e_file_get_save_filesel (
- parent, prompt, NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
-
- if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_OK)
- goto exit;
-
- path_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_chooser));
-
- e_file_update_save_path (path_uri, FALSE);
-
- file_names = get_unique_file_names (parts);
-
- for (iter = parts, iter_file = file_names; iter && iter_file; iter = iter->next, iter_file = iter_file->next) {
- CamelMimePart *part = iter->data;
- gchar *uri, *filename;
-
- filename = iter_file->data;
- uri = g_build_path ("/", path_uri, filename, NULL);
- g_free (filename);
- iter_file->data = NULL;
-
- /* XXX Would be nice to mention _why_ we can't save. */
- if (e_file_can_save (GTK_WINDOW (file_chooser), uri))
- mail_save_part (part, uri, NULL, NULL, FALSE);
- else
- g_warning ("Unable to save %s", uri);
-
- g_free (uri);
- }
-
- g_slist_free (file_names);
- g_free (path_uri);
-
-exit:
- gtk_widget_destroy (file_chooser);
-}
-
-/**
- * em_utils_save_part_to_file:
- * @parent: parent window
- * @filename: filename to save to
- * @part: part to save
- *
- * Save a part's content to a specific file
- * Creates all needed directories and overwrites without prompting
- *
- * Returns %TRUE if saving succeeded, %FALSE otherwise
- **/
-gboolean
-em_utils_save_part_to_file(GtkWindow *parent, const gchar *filename, CamelMimePart *part)
-{
- gint done;
- gchar *dirname;
- struct stat st;
-
- if (filename[0] == 0)
- return FALSE;
-
- dirname = g_path_get_dirname(filename);
- if (g_mkdir_with_parents(dirname, 0777) == -1) {
- GtkWidget *w = e_error_new(parent, "mail:no-create-path", filename, g_strerror(errno), NULL);
- g_free(dirname);
- em_utils_show_error_silent (w);
- return FALSE;
- }
- g_free(dirname);
-
- if (g_access(filename, F_OK) == 0) {
- if (g_access(filename, W_OK) != 0) {
- e_error_run(parent, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, filename, NULL);
- return FALSE;
- }
- }
-
- if (g_stat(filename, &st) != -1 && !S_ISREG(st.st_mode)) {
- GtkWidget *w = e_error_new(parent, "mail:no-write-path-notfile", filename, NULL);
- em_utils_show_error_silent (w);
- return FALSE;
- }
-
- /* FIXME: This doesn't handle default charsets */
- mail_msg_wait(mail_save_part(part, filename, emu_save_part_done, &done, FALSE));
-
- return done;
-}
-
struct _save_messages_data {
CamelFolder *folder;
GPtrArray *uids;
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 79caba050e..9bb35b1dc2 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -52,8 +52,6 @@ void em_utils_edit_filters (GtkWidget *parent);
void em_filename_make_safe (gchar *string);
void em_utils_edit_vfolders (GtkWidget *parent);
-void em_utils_save_part(GtkWindow *parent, const gchar *prompt, CamelMimePart *part);
-gboolean em_utils_save_part_to_file(GtkWindow *parent, const gchar *filename, CamelMimePart *part);
void em_utils_save_messages (GtkWindow *parent, CamelFolder *folder, GPtrArray *uids);
void em_utils_flag_for_followup (EMailReader *reader, CamelFolder *folder, GPtrArray *uids);
@@ -72,7 +70,6 @@ void em_utils_selection_set_urilist(GtkSelectionData *data, CamelFolder *folder,
void em_utils_selection_get_urilist(GtkSelectionData *data, CamelFolder *folder);
gchar *em_utils_temp_save_part(GtkWidget *parent, CamelMimePart *part, gboolean mode);
-void em_utils_save_parts (GtkWindow *parent, const gchar *prompt, GSList * parts);
gboolean em_utils_folder_is_drafts(CamelFolder *folder, const gchar *uri);
gboolean em_utils_folder_is_templates(CamelFolder *folder, const gchar *uri);