evolution-data-server r9113 - in branches/EXCHANGE_MAPI_BRANCH: calendar/backends/mapi calendar/libecal servers/mapi
- From: msuman svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r9113 - in branches/EXCHANGE_MAPI_BRANCH: calendar/backends/mapi calendar/libecal servers/mapi
- Date: Fri, 11 Jul 2008 04:02:25 +0000 (UTC)
Author: msuman
Date: Fri Jul 11 04:02:24 2008
New Revision: 9113
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9113&view=rev
Log:
Get the attachments stuff working again.
Modified:
branches/EXCHANGE_MAPI_BRANCH/calendar/backends/mapi/ChangeLog
branches/EXCHANGE_MAPI_BRANCH/calendar/backends/mapi/e-cal-backend-mapi.c
branches/EXCHANGE_MAPI_BRANCH/calendar/libecal/e-cal.c
branches/EXCHANGE_MAPI_BRANCH/servers/mapi/ChangeLog
branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.c
branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.h
branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.c
branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.h
Modified: branches/EXCHANGE_MAPI_BRANCH/calendar/backends/mapi/e-cal-backend-mapi.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/calendar/backends/mapi/e-cal-backend-mapi.c (original)
+++ branches/EXCHANGE_MAPI_BRANCH/calendar/backends/mapi/e-cal-backend-mapi.c Fri Jul 11 04:02:24 2008
@@ -507,7 +507,8 @@
g_static_mutex_lock (&updating);
serv_time = e_cal_backend_cache_get_server_utc_time (priv->cache);
- itt_cache = icaltime_from_string (serv_time);
+ if (serv_time)
+ itt_cache = icaltime_from_string (serv_time);
if (!icaltime_is_null_time (itt_cache)) {
struct SPropValue sprop;
struct timeval t;
@@ -985,6 +986,9 @@
priv = cbmapi->priv;
+ if (!priv->fid)
+ return GNOME_Evolution_Calendar_OtherError;
+
source = e_cal_backend_get_source (E_CAL_BACKEND (cbmapi));
if (!authenticated) {
@@ -1126,7 +1130,7 @@
exchange_mapi_util_mapi_id_from_string (fid, &priv->fid);
priv->olFolder = olFolder;
- /* Set the local attachment store*/
+ /* Set the local attachment store */
mangled_uri = g_strdup (e_cal_backend_get_uri (E_CAL_BACKEND (cbmapi)));
/* mangle the URI to not contain invalid characters */
for (i = 0; i < strlen (mangled_uri); i++) {
@@ -1340,7 +1344,9 @@
e_cal_backend_notify_object_created (E_CAL_BACKEND (cbmapi), *calobj);
break;
default:
- break;
+ exchange_mapi_util_free_recipient_list (&recipients);
+ exchange_mapi_util_free_attachment_list (&attachments);
+ return GNOME_Evolution_Calendar_CalListener_MODE_NOT_SUPPORTED;
}
g_object_unref (comp);
@@ -1413,6 +1419,8 @@
cache_comp = e_cal_backend_cache_get_component (priv->cache, uid, rid);
if (!cache_comp) {
g_message ("CRITICAL : Could not find the object in cache");
+ g_object_unref (comp);
+ exchange_mapi_util_free_recipient_list (&recipients);
exchange_mapi_util_free_attachment_list (&attachments);
return GNOME_Evolution_Calendar_ObjectNotFound;
}
@@ -1429,16 +1437,20 @@
status = exchange_mapi_modify_item (priv->olFolder, priv->fid, mid,
exchange_mapi_cal_util_build_name_id, GINT_TO_POINTER(kind),
exchange_mapi_cal_util_build_props, &cbdata,
- NULL, NULL, MAPI_OPTIONS_DONT_SUBMIT);
+ recipients, attachments, MAPI_OPTIONS_DONT_SUBMIT);
g_free (cbdata.props);
if (!status) {
g_object_unref (comp);
g_object_unref (cache_comp);
+ exchange_mapi_util_free_recipient_list (&recipients);
exchange_mapi_util_free_attachment_list (&attachments);
return GNOME_Evolution_Calendar_OtherError;
}
break;
default :
+ g_object_unref (comp);
+ g_object_unref (cache_comp);
+ exchange_mapi_util_free_recipient_list (&recipients);
exchange_mapi_util_free_attachment_list (&attachments);
return GNOME_Evolution_Calendar_CalListener_MODE_NOT_SUPPORTED;
}
@@ -1446,8 +1458,9 @@
*old_object = e_cal_component_get_as_string (cache_comp);
*new_object = e_cal_component_get_as_string (comp);
- g_object_unref (cache_comp);
g_object_unref (comp);
+ g_object_unref (cache_comp);
+ exchange_mapi_util_free_recipient_list (&recipients);
exchange_mapi_util_free_attachment_list (&attachments);
return GNOME_Evolution_Calendar_Success;
Modified: branches/EXCHANGE_MAPI_BRANCH/calendar/libecal/e-cal.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/calendar/libecal/e-cal.c (original)
+++ branches/EXCHANGE_MAPI_BRANCH/calendar/libecal/e-cal.c Fri Jul 11 04:02:24 2008
@@ -1386,7 +1386,16 @@
priv->local_attachment_store =
g_filename_to_uri (filename, NULL, NULL);
g_free (filename);
+ } else if (g_str_has_prefix (priv->uri, "mapi://")) {
+ gchar *filename = g_build_filename (g_get_home_dir (),
+ ".evolution/cache/calendar",
+ mangled_uri,
+ NULL);
+ priv->local_attachment_store =
+ g_filename_to_uri (filename, NULL, NULL);
+ g_free (filename);
}
+
g_free (mangled_uri);
}
Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.c (original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.c Fri Jul 11 04:02:24 2008
@@ -207,62 +207,47 @@
}
void
-exchange_mapi_cal_util_fetch_attachments (ECalComponent *comp, GSList **attach_list, const char *local_store)
+exchange_mapi_cal_util_fetch_attachments (ECalComponent *comp, GSList **attach_list, const char *local_store_uri)
{
GSList *comp_attach_list = NULL, *new_attach_list = NULL;
GSList *l;
- char *dest_file;
- int fd;
const char *uid;
e_cal_component_get_attachment_list (comp, &comp_attach_list);
e_cal_component_get_uid (comp, &uid);
for (l = comp_attach_list; l ; l = l->next) {
- gchar *sfname = (gchar *) l->data;
- gchar *filename, *new_filename;
+ gchar *sfname_uri = (gchar *) l->data;
+ gchar *sfname = g_filename_from_uri (sfname_uri, NULL, NULL);
+ gchar *filename;
GMappedFile *mapped_file;
GError *error = NULL;
- guint filelength = 0;
mapped_file = g_mapped_file_new (sfname, FALSE, &error);
- if (!mapped_file) {
- g_message ("DEBUG: could not map %s: %s\n", sfname, error->message);
- g_error_free (error);
- continue;
- }
-
filename = g_path_get_basename (sfname);
- new_filename = g_strconcat (uid, "-", filename, NULL);
- g_free (filename);
- dest_file = g_build_filename (local_store, new_filename, NULL);
- g_free (new_filename);
-
- filelength = g_mapped_file_get_length (mapped_file);
- fd = g_open (dest_file, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
- if (fd == -1) {
- /* skip gracefully */
- g_message ("DEBUG: could not open %s for writing\n", dest_file);
- } else if (write (fd, g_mapped_file_get_contents (mapped_file), filelength) == -1) {
- /* skip gracefully */
- g_message ("DEBUG: attachment write failed.\n");
- }
- if (fd != -1) {
+ if (mapped_file && g_str_has_prefix (filename, uid)) {
ExchangeMAPIAttachment *attach_item;
+ gchar *attach_crlf = exchange_lf_to_crlf (g_mapped_file_get_contents (mapped_file));
+ guint filelength = strlen (attach_crlf);
+ const gchar *split_name = (filename + strlen (uid) + strlen ("-"));
- close (fd);
- new_attach_list = g_slist_append (new_attach_list, g_filename_to_uri (dest_file, NULL, NULL));
+ new_attach_list = g_slist_append (new_attach_list, g_strdup (sfname_uri));
attach_item = g_new0 (ExchangeMAPIAttachment, 1);
- attach_item->filename = g_path_get_basename (sfname);
+ attach_item->filename = g_strdup(split_name);
attach_item->value = g_byte_array_sized_new (filelength);
- attach_item->value = g_byte_array_append (attach_item->value, g_mapped_file_get_contents (mapped_file), filelength);
+ attach_item->value = g_byte_array_append (attach_item->value, attach_crlf, filelength + 1);
*attach_list = g_slist_append (*attach_list, attach_item);
+
+ g_mapped_file_free (mapped_file);
+ g_free (attach_crlf);
+ } else {
+ g_message ("DEBUG: could not map %s: %s\n", sfname, error->message);
+ g_error_free (error);
}
- g_mapped_file_free (mapped_file);
- g_free (dest_file);
+ g_free (filename);
}
e_cal_component_set_attachment_list (comp, new_attach_list);
@@ -314,7 +299,7 @@
}
static void
-set_attachments_to_cal_component (ECalComponent *comp, GSList *attach_list, const char *local_store)
+set_attachments_to_cal_component (ECalComponent *comp, GSList *attach_list, const char *local_store_uri)
{
GSList *comp_attach_list = NULL, *l;
const char *uid;
@@ -323,28 +308,30 @@
for (l = attach_list; l ; l = l->next) {
ExchangeMAPIAttachment *attach_item = (ExchangeMAPIAttachment *) (l->data);
gchar *attach_file_url, *filename;
- struct stat st;
+ guint len;
+ int fd = -1;
+ gchar *attach_lf = exchange_crlf_to_lf((const char *)attach_item->value->data);
- attach_file_url = g_strconcat (local_store, "/", uid, "-", attach_item->filename, NULL);
+ len = (attach_lf != NULL) ? strlen (attach_lf) : 0;
+ attach_file_url = g_strconcat (local_store_uri, G_DIR_SEPARATOR_S, uid, "-", attach_item->filename, NULL);
filename = g_filename_from_uri (attach_file_url, NULL, NULL);
- if (g_stat (filename, &st) == -1) {
- int fd = g_open (filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
- if (fd == -1) {
- /* skip gracefully */
- g_message ("DEBUG: could not open %s for writing\n", filename);
- } else if (write (fd, attach_item->value->data, attach_item->value->len) == -1) {
- /* skip gracefully */
- g_message ("DEBUG: attachment write failed.\n");
- }
- if (fd != -1) {
- close (fd);
- comp_attach_list = g_slist_append (comp_attach_list, g_strdup (attach_file_url));
- }
+ fd = g_open (filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
+ if (fd == -1) {
+ /* skip gracefully */
+ g_message ("DEBUG: could not open %s for writing\n", filename);
+ } else if (len && write (fd, attach_lf, len) == -1) {
+ /* skip gracefully */
+ g_message ("DEBUG: attachment write failed.\n");
+ }
+ if (fd != -1) {
+ close (fd);
+ comp_attach_list = g_slist_append (comp_attach_list, g_strdup (attach_file_url));
}
g_free (filename);
g_free (attach_file_url);
+ g_free (attach_lf);
}
e_cal_component_set_attachment_list (comp, comp_attach_list);
@@ -546,7 +533,7 @@
ECalComponent *
exchange_mapi_cal_util_mapi_props_to_comp (icalcomponent_kind kind, const gchar *mid, struct mapi_SPropValue_array *properties,
GSList *streams, GSList *recipients, GSList *attachments,
- const char *local_store, const icaltimezone *default_zone)
+ const char *local_store_uri, const icaltimezone *default_zone)
{
ECalComponent *comp = NULL;
struct timeval t;
@@ -797,7 +784,7 @@
/* FIXME: categories */
- set_attachments_to_cal_component (comp, attachments, local_store);
+ set_attachments_to_cal_component (comp, attachments, local_store_uri);
e_cal_component_rescan (comp);
Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.h
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.h (original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-cal-utils.h Fri Jul 11 04:02:24 2008
@@ -67,12 +67,12 @@
void
exchange_mapi_cal_util_fetch_recipients (ECalComponent *comp, GSList **recip_list);
void
-exchange_mapi_cal_util_fetch_attachments (ECalComponent *comp, GSList **attach_list, const char *local_store);
+exchange_mapi_cal_util_fetch_attachments (ECalComponent *comp, GSList **attach_list, const char *local_store_uri);
ECalComponent *
exchange_mapi_cal_util_mapi_props_to_comp (icalcomponent_kind kind, const gchar *mid, struct mapi_SPropValue_array *properties,
GSList *streams, GSList *recipients, GSList *attachments,
- const char *local_store, const icaltimezone *default_zone);
+ const char *local_store_uri, const icaltimezone *default_zone);
gboolean
exchange_mapi_cal_util_build_name_id (struct mapi_nameid *nameid, gpointer data);
Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.c (original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.c Fri Jul 11 04:02:24 2008
@@ -526,3 +526,68 @@
return entryid;
}
+/**
+ * exchange_lf_to_crlf:
+ * @in: input text in UNIX ("\n") format
+ *
+ * Creates a copy of @in with all LFs converted to CRLFs.
+ *
+ * Return value: the converted text, which the caller must free.
+ **/
+char *
+exchange_lf_to_crlf (const char *in)
+{
+ int len;
+ const char *s;
+ char *out, *d;
+
+ g_return_val_if_fail (in != NULL, NULL);
+
+ len = strlen (in);
+ for (s = strchr (in, '\n'); s; s = strchr (s + 1, '\n'))
+ len++;
+
+ out = g_malloc (len + 1);
+ for (s = in, d = out; *s; s++) {
+ if (*s == '\n')
+ *d++ = '\r';
+ *d++ = *s;
+ }
+ *d = '\0';
+
+ return out;
+}
+
+/**
+ * exchange_crlf_to_lf:
+ * @in: input text in network ("\r\n") format
+ *
+ * Creates a copy of @in with all CRLFs converted to LFs. (Actually,
+ * it just strips CRs, so any raw CRs will be removed.)
+ *
+ * Return value: the converted text, which the caller must free.
+ **/
+char *
+exchange_crlf_to_lf (const char *in)
+{
+ int len;
+ const char *s;
+ char *out;
+ GString *str;
+
+ g_return_val_if_fail (in != NULL, NULL);
+
+ str = g_string_new ("");
+
+ len = strlen (in);
+ for (s = in; *s; s++) {
+ if (*s != '\r')
+ str = g_string_append_c (str, *s);
+ }
+
+ out = str->str;
+ g_string_free (str, FALSE);
+
+ return out;
+}
+
Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.h
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.h (original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-utils.h Fri Jul 11 04:02:24 2008
@@ -69,5 +69,10 @@
struct SBinary *
exchange_mapi_util_entryid_generate_local (TALLOC_CTX *mem_ctx, const char *exchange_dn);
+char *
+exchange_lf_to_crlf (const char *in);
+char *
+exchange_crlf_to_lf (const char *in);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]