diff options
author | Not Zed <NotZed@Ximian.com> | 2001-01-28 11:53:08 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-01-28 11:53:08 +0800 |
commit | d8c95a55bc0d7dc465ce11070cd237c8b53c53fa (patch) | |
tree | f0dff3d323d2a5562fb79b65acdd8149870c8710 /mail/mail-ops.c | |
parent | 0deb194bc58eb4a4bf263486398a442d5ade6cc6 (diff) | |
download | gsoc2013-evolution-d8c95a55bc0d7dc465ce11070cd237c8b53c53fa.tar.gz gsoc2013-evolution-d8c95a55bc0d7dc465ce11070cd237c8b53c53fa.tar.zst gsoc2013-evolution-d8c95a55bc0d7dc465ce11070cd237c8b53c53fa.zip |
Changed to use mail_save_part to save the data in another thread.
2001-01-28 Not Zed <NotZed@Ximian.com>
* mail-display.c (write_data_to_file): Changed to use
mail_save_part to save the data in another thread.
(save_data_cb): Hide the fileselector once we have a button press,
and are saving stuff.
* mail-ops.c (mail_save_part): New function to save a part content
asynchronously.
svn path=/trunk/; revision=7867
Diffstat (limited to 'mail/mail-ops.c')
-rw-r--r-- | mail/mail-ops.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 8be18a34e2..d24c47dd85 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -1927,3 +1927,108 @@ mail_save_messages(CamelFolder *folder, GPtrArray *uids, const char *path, return id; } + +/* ** SAVE PART ******************************************************* */ + +struct _save_part_msg { + struct _mail_msg msg; + + CamelMimePart *part; + char *path; + void (*done)(CamelMimePart *part, char *path, int saved, void *data); + void *data; +}; + +static char *save_part_desc(struct _mail_msg *mm, int done) +{ + return g_strdup(_("Saving attachment")); +} + +static void save_part_save(struct _mail_msg *mm) +{ + struct _save_part_msg *m = (struct _save_part_msg *)mm; + CamelMimeFilterCharset *charsetfilter; + CamelContentType *content_type; + CamelStreamFilter *filtered_stream; + CamelStream *stream_fs; + CamelDataWrapper *data; + const char *charset; + + stream_fs = camel_stream_fs_new_with_name(m->path, O_WRONLY|O_CREAT, 0600); + if (stream_fs == NULL) { + camel_exception_setv(&mm->ex, 1, _("Cannot create output file: %s:\n %s"), m->path, strerror(errno)); + return; + } + + /* we only convert text/ parts, and we only convert if we have to + null charset param == us-ascii == utf8 always, and utf8 == utf8 obviously */ + /* this will also let "us-ascii that isn't really" parts pass out in + proper format, without us trying to treat it as what it isn't, which is + the same algorithm camel uses */ + + data = camel_medium_get_content_object((CamelMedium *)m->part); + content_type = camel_mime_part_get_content_type(m->part); + if (header_content_type_is(content_type, "text", "*") + && (charset = header_content_type_param(content_type, "charset")) + && strcasecmp(charset, "utf-8") != 0) { + charsetfilter = camel_mime_filter_charset_new_convert("utf-8", charset); + filtered_stream = camel_stream_filter_new_with_stream(stream_fs); + camel_stream_filter_add(filtered_stream, CAMEL_MIME_FILTER(charsetfilter)); + camel_object_unref(CAMEL_OBJECT(charsetfilter)); + } else { + /* no we can't use a CAMEL_BLAH() cast here, since its not true, HOWEVER + we only treat it as a normal stream from here on, so it is OK */ + filtered_stream = (CamelStreamFilter *)stream_fs; + camel_object_ref(CAMEL_OBJECT(stream_fs)); + } + + if (camel_data_wrapper_write_to_stream(data, CAMEL_STREAM(filtered_stream)) == -1 + || camel_stream_flush (CAMEL_STREAM(filtered_stream)) == -1) + camel_exception_setv(&mm->ex, 1, _("Could not write data: %s"), strerror(errno)); + + camel_object_unref (CAMEL_OBJECT (filtered_stream)); + camel_object_unref (CAMEL_OBJECT (stream_fs)); +} + +static void save_part_saved(struct _mail_msg *mm) +{ + struct _save_part_msg *m = (struct _save_part_msg *)mm; + + if (m->done) + m->done(m->part, m->path, !camel_exception_is_set(&mm->ex), m->data); +} + +static void save_part_free(struct _mail_msg *mm) +{ + struct _save_part_msg *m = (struct _save_part_msg *)mm; + + camel_object_unref((CamelObject *)m->part); + g_free(m->path); +} + +static struct _mail_msg_op save_part_op = { + save_part_desc, + save_part_save, + save_part_saved, + save_part_free, +}; + +int +mail_save_part(CamelMimePart *part, const char *path, + void (*done)(CamelMimePart *part, char *path, int saved, void *data), void *data) +{ + struct _save_part_msg *m; + int id; + + m = mail_msg_new(&save_part_op, NULL, sizeof(*m)); + m->part = part; + camel_object_ref((CamelObject *)part); + m->path = g_strdup(path); + m->data = data; + m->done = done; + + id = m->msg.seq; + e_thread_put(mail_thread_queued, (EMsg *)m); + + return id; +} |