[evolution-groupwise] Bug #656378 attachment name corruption



commit cc40a4bb33b42966a0447a1008117b757231f415
Author: Punit Jain <jpunit novell com>
Date:   Fri Sep 30 12:01:32 2011 +0530

    Bug #656378 attachment name corruption

 src/plugins/process-meeting.c |   58 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/process-meeting.c b/src/plugins/process-meeting.c
index a4b0ce2..2af8033 100644
--- a/src/plugins/process-meeting.c
+++ b/src/plugins/process-meeting.c
@@ -27,6 +27,8 @@
 
 #include <string.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <fcntl.h>
 #include <gtk/gtk.h>
 #include <libecal/e-cal-client.h>
 
@@ -39,6 +41,10 @@
 
 #include "gw-ui.h"
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 typedef struct {
 	ECalClient *client;
 	icalcomponent *icalcomp;
@@ -425,18 +431,70 @@ gw_resend_meeting_cb (GtkAction *action,
 		if (resend)
 		{
 			guint flags = 0;
+			gint fd;
 			gchar *new_uid = NULL;
+			const gchar *old_uid;
 			CompEditor *ce;
 			icalcomponent *icalcomp;
+			gchar *dest_url, *dest_file;
+			GSList *l, *attach_list = NULL, *new_attach_list = NULL;
 
 			flags |= COMP_EDITOR_NEW_ITEM;
 			flags |= COMP_EDITOR_MEETING;
 			flags |= COMP_EDITOR_USER_ORG;
 
 			new_comp = e_cal_component_clone (comp);
+			e_cal_component_get_uid (comp, &old_uid);
 			new_uid = e_cal_component_gen_uid ();
 			e_cal_component_set_recurid (new_comp, NULL);
 			e_cal_component_set_uid (new_comp, new_uid);
+			e_cal_component_get_attachment_list (new_comp, &attach_list);
+
+			for (l = attach_list; l; l = l->next) {
+				gchar *sfname = g_filename_from_uri ((gchar *)l->data, NULL, NULL);
+				gchar *filename, *new_filename;
+				gchar *cache_dir, *temp_filename;
+				GMappedFile *mapped_file;
+				GError *error = NULL;
+
+				mapped_file = g_mapped_file_new (sfname, FALSE, &error);
+				if (!mapped_file) {
+					g_error_free (error);
+					continue;
+				}
+				filename = g_path_get_basename (sfname);
+				cache_dir = g_path_get_dirname (sfname);
+				temp_filename = g_strdup (filename + strlen(old_uid)+1);
+				new_filename = g_strconcat (new_uid, "-", temp_filename, NULL);
+				g_free (temp_filename);
+				g_free (filename);
+				dest_file = g_build_filename (cache_dir, new_filename, NULL);
+				g_free (new_filename);
+				g_free (cache_dir);
+				fd = g_open (dest_file, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
+				if (fd == -1) {
+					/* TODO handle error conditions */
+				} else if (write (fd, g_mapped_file_get_contents (mapped_file),
+					  g_mapped_file_get_length (mapped_file)) == -1) {
+					/* TODO handle error condition */
+				}
+
+			#if GLIB_CHECK_VERSION(2,21,3)
+				g_mapped_file_unref (mapped_file);
+			#else
+				g_mapped_file_free (mapped_file);
+			#endif
+				if (fd != -1)
+					close (fd);
+				dest_url = g_filename_to_uri (dest_file, NULL, NULL);
+				g_free (dest_file);
+				new_attach_list = g_slist_append (new_attach_list, dest_url);
+			}
+			e_cal_component_set_attachment_list (new_comp, new_attach_list);
+			for (l = new_attach_list; l != NULL; l = l->next)
+				g_free (l->data);
+			g_slist_free (new_attach_list);
+
 			icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (new_comp));
 			ce = e_calendar_view_open_event_with_flags (cal_view, data->client, icalcomp, flags);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]