[balsa] Save part under its own filename in a temporary directory
- From: Peter Bloomfield <PeterB src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [balsa] Save part under its own filename in a temporary directory
- Date: Mon, 21 Dec 2009 02:06:32 +0000 (UTC)
commit de66c3f602bae6617d15f224e5f2888477cfc4ce
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun Dec 20 21:06:26 2009 -0500
Save part under its own filename in a temporary directory
ChangeLog | 11 +++++++++++
libbalsa/body.c | 35 ++++++++++++++++++++++-------------
libbalsa/body.h | 1 +
3 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 58094ee..4f8ecbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2009-12-20 Peter Bloomfield
+ * libbalsa/body.h: new member LibBalsaMessageBody::own_dir, TRUE
+ if the temporary file for the body is in its own temporary
+ directory/
+ * libbalsa/body.c (libbalsa_message_body_new),
+ (libbalsa_message_body_free),
+ (libbalsa_message_body_save_temporary): if the body has a
+ filename, save the temporary file in its own temporary
+ directory.
+
+2009-12-20 Peter Bloomfield
+
* libbalsa/filter-funcs.c (lbcond_new): save negated as 0 or 1,
to simplify later comparison.
(libbalsa_condition_compare): return FALSE if negate differs;
diff --git a/libbalsa/body.c b/libbalsa/body.c
index 0cf60ed..3b62508 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -51,6 +51,7 @@ libbalsa_message_body_new(LibBalsaMessage * message)
body->filename = NULL;
body->file_uri = NULL;
body->temp_filename = NULL;
+ body->owns_dir = FALSE;
body->charset = NULL;
#ifdef HAVE_GPGME
@@ -80,8 +81,14 @@ libbalsa_message_body_free(LibBalsaMessageBody * body)
g_free(body->filename);
if (body->file_uri)
g_object_unref(body->file_uri);
- if (body->temp_filename)
+ if (body->temp_filename) {
unlink(body->temp_filename);
+ if (body->owns_dir) {
+ gchar *dirname = g_path_get_dirname(body->temp_filename);
+ rmdir(dirname);
+ g_free(dirname);
+ }
+ }
g_free(body->temp_filename);
g_free(body->charset);
@@ -301,7 +308,6 @@ libbalsa_message_body_save_temporary(LibBalsaMessageBody * body, GError **err)
do {
gint fd;
gchar *tmp_file_name;
- gchar *dotpos = NULL;
fd = g_file_open_tmp("balsa-body-XXXXXX", &tmp_file_name,
err);
@@ -309,24 +315,27 @@ libbalsa_message_body_save_temporary(LibBalsaMessageBody * body, GError **err)
return FALSE;
if (err && *err && /* We should have returned by now! */
(*err)->message) {
- printf("libbalsa_message_body_save_temporary:\n %s\n",
- (*err)->message);
+ printf("%s:\n %s\n", __func__, (*err)->message);
g_clear_error(err);
}
close(fd);
unlink(tmp_file_name);
if (body->filename) {
- gchar *seppos = strrchr(body->filename, G_DIR_SEPARATOR);
- dotpos = strchr(seppos ? seppos : body->filename, '.');
+ gchar *filename;
+
+ if (mkdir(tmp_file_name, S_IRWXU)) {
+ g_free(tmp_file_name);
+ continue;
+ }
+ filename =
+ g_build_filename(tmp_file_name, body->filename, NULL);
+ g_free(tmp_file_name);
+ tmp_file_name = filename;
+ body->owns_dir = TRUE;
}
- g_free(body->temp_filename);
- if (dotpos) {
- body->temp_filename =
- g_strdup_printf("%s%s", tmp_file_name, dotpos);
- g_free(tmp_file_name);
- } else
- body->temp_filename = tmp_file_name;
+ body->temp_filename = tmp_file_name;
+
fd = open(body->temp_filename, O_WRONLY | O_EXCL | O_CREAT,
LIBBALSA_MESSAGE_BODY_SAFE);
if (fd >= 0) {
diff --git a/libbalsa/body.h b/libbalsa/body.h
index 99d1cca..a5c4f0f 100644
--- a/libbalsa/body.h
+++ b/libbalsa/body.h
@@ -82,6 +82,7 @@ struct _LibBalsaMessageBody {
LibbalsaVfs * file_uri; /* file uri for attachments (used for sending) */
LibBalsaAttachMode attach_mode; /* attachment mode for sending */
gchar *temp_filename; /* Holds the filename of a the temporary file where this part is saved */
+ gboolean owns_dir; /* TRUE if the temporary file is in a temporary directory */
gchar *charset; /* the charset, used for sending, replying. */
GMimeObject *mime_part; /* mime body */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]