aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-07-25 08:16:32 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-07-25 08:16:32 +0800
commitbd34e927c740ec7171565abf4dfc7f743179e944 (patch)
tree59f41c7dfa8517ae41f62b4f6045ed38d84f7db1
parent1cf393ef9a95f6f8b1f6f80042cf8e873a4fe454 (diff)
downloadgsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar.gz
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar.bz2
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar.lz
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar.xz
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.tar.zst
gsoc2013-evolution-bd34e927c740ec7171565abf4dfc7f743179e944.zip
Pass the O_TRUNC flag to open so that we don't leave trailing garbage at
2001-07-24 Jeffrey Stedfast <fejj@ximian.com> * mail-ops.c (save_part_save): Pass the O_TRUNC flag to open so that we don't leave trailing garbage at the end of the file if the new file content is shorter than the old file content. svn path=/trunk/; revision=11373
-rw-r--r--mail/ChangeLog4
-rw-r--r--mail/mail-display.c11
-rw-r--r--mail/mail-ops.c72
3 files changed, 48 insertions, 39 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 1f52782136..d16b628130 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,9 @@
2001-07-24 Jeffrey Stedfast <fejj@ximian.com>
+ * mail-ops.c (save_part_save): Pass the O_TRUNC flag to open so
+ that we don't leave trailing garbage at the end of the file if the
+ new file content is shorter than the old file content.
+
* component-factory.c (create_view): Fix for bug #5174.
2001-07-24 Jason Leach <jleach@ximian.com>
diff --git a/mail/mail-display.c b/mail/mail-display.c
index ea795fc6d2..a681fdd5cf 100644
--- a/mail/mail-display.c
+++ b/mail/mail-display.c
@@ -94,7 +94,7 @@ write_data_to_file (CamelMimePart *part, const char *name, gboolean unique)
if (fd == -1 && errno == EEXIST && !unique) {
GtkWidget *dlg;
GtkWidget *text;
-
+
dlg = gnome_dialog_new (_("Overwrite file?"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
@@ -103,15 +103,16 @@ write_data_to_file (CamelMimePart *part, const char *name, gboolean unique)
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox), text, TRUE, TRUE, 4);
gtk_window_set_policy(GTK_WINDOW(dlg), FALSE, TRUE, FALSE);
gtk_widget_show (text);
-
+
if (gnome_dialog_run_and_close (GNOME_DIALOG (dlg)) != 0)
return FALSE;
}
+
if (fd != -1)
- close(fd);
-
+ close (fd);
+
/* should this have progress of what its doing? */
- mail_msg_wait(mail_save_part(part, name, write_data_written, &ret));
+ mail_msg_wait (mail_save_part (part, name, write_data_written, &ret));
return ret;
}
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index c3b36f5008..3d1b994dae 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -1987,7 +1987,8 @@ 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)
+static void
+save_part_save (struct _mail_msg *mm)
{
struct _save_part_msg *m = (struct _save_part_msg *)mm;
CamelMimeFilterCharset *charsetfilter;
@@ -1996,57 +1997,60 @@ static void save_part_save(struct _mail_msg *mm)
CamelStream *stream_fs;
CamelDataWrapper *data;
const char *charset;
-
- stream_fs = camel_stream_fs_new_with_name(m->path, O_WRONLY|O_CREAT, 0600);
+
+ stream_fs = camel_stream_fs_new_with_name (m->path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (stream_fs == NULL) {
- camel_exception_setv(&mm->ex, 1, _("Cannot create output file: %s:\n %s"), m->path, strerror(errno));
+ camel_exception_setv (&mm->ex, 1, _("Cannot create output file: %s:\n %s"), m->path,
+ g_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));
+ data = camel_medium_get_content_object (CAMEL_MEDIUM (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"))
+ && g_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));
+ 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));
-
+ 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"), g_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)
+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);
+ m->done (m->part, m->path, !camel_exception_is_set (&mm->ex), m->data);
}
-static void save_part_free(struct _mail_msg *mm)
+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);
+ camel_object_unref (CAMEL_OBJECT (m->part));
+ g_free (m->path);
}
static struct _mail_msg_op save_part_op = {
@@ -2057,22 +2061,22 @@ static struct _mail_msg_op save_part_op = {
};
int
-mail_save_part(CamelMimePart *part, const char *path,
- void (*done)(CamelMimePart *part, char *path, int saved, void *data), void *data)
+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 = mail_msg_new (&save_part_op, NULL, sizeof (*m));
m->part = part;
- camel_object_ref((CamelObject *)part);
- m->path = g_strdup(path);
+ camel_object_ref (CAMEL_OBJECT (part));
+ m->path = g_strdup (path);
m->data = data;
m->done = done;
-
+
id = m->msg.seq;
- e_thread_put(mail_thread_queued, (EMsg *)m);
-
+ e_thread_put (mail_thread_queued, (EMsg *)m);
+
return id;
}