[evolution-data-server] evo-I#1090 - Forward as iCalendar: Embed event's local attachments



commit 70784e21824991ebd9e8b3b202b49bdfa833e1b8
Author: Milan Crha <mcrha redhat com>
Date:   Mon Sep 14 15:48:05 2020 +0200

    evo-I#1090 - Forward as iCalendar: Embed event's local attachments
    
    Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/1090

 .../evolution-data-server-docs.sgml.in             |   4 +
 src/calendar/libecal/e-cal-util.c                  | 115 +++++++++++++++++++++
 src/calendar/libecal/e-cal-util.h                  |   4 +
 src/calendar/libedata-cal/e-cal-meta-backend.c     |  74 +------------
 4 files changed, 124 insertions(+), 73 deletions(-)
---
diff --git a/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in 
b/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
index a3fb65e82..1d6a6f9bb 100644
--- a/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
+++ b/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
@@ -360,6 +360,10 @@
     <title>Index of deprecated symbols</title>
     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
   </index>
+  <index id="api-index-3-40" role="3.40">
+    <title>Index of new symbols in 3.40</title>
+    <xi:include href="xml/api-index-3.40.xml"><xi:fallback /></xi:include>
+  </index>
   <index id="api-index-3-38" role="3.38">
     <title>Index of new symbols in 3.38</title>
     <xi:include href="xml/api-index-3.38.xml"><xi:fallback /></xi:include>
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index e91236bfb..e7b66dd9d 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -2832,3 +2832,118 @@ e_cal_util_conflict_resolution_to_operation_flags (EConflictResolution conflict_
 
        return E_CAL_OPERATION_FLAG_CONFLICT_KEEP_LOCAL;
 }
+
+static void
+ecu_remove_all_but_filename_parameter (ICalProperty *prop)
+{
+       ICalParameter *param;
+
+       g_return_if_fail (prop != NULL);
+
+       while (param = i_cal_property_get_first_parameter (prop, I_CAL_ANY_PARAMETER), param) {
+               if (i_cal_parameter_isa (param) == I_CAL_FILENAME_PARAMETER) {
+                       g_object_unref (param);
+                       param = i_cal_property_get_next_parameter (prop, I_CAL_ANY_PARAMETER);
+                       if (!param)
+                               break;
+               }
+
+               i_cal_property_remove_parameter_by_ref (prop, param);
+               g_object_unref (param);
+       }
+}
+
+/**
+ * e_cal_util_inline_local_attachments_sync:
+ * @component: an #ICalComponent to work with
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Changes all URL attachments which point to a local file in @component
+ * to inline attachments, aka adds the file content into the @component.
+ * It also populates FILENAME parameter on the attachment.
+ *
+ * Returns: Whether succeeded.
+ *
+ * Since: 3.40
+ **/
+gboolean
+e_cal_util_inline_local_attachments_sync (ICalComponent *component,
+                                         GCancellable *cancellable,
+                                         GError **error)
+{
+       ICalProperty *prop;
+       const gchar *uid;
+       gboolean success = TRUE;
+
+       g_return_val_if_fail (component != NULL, FALSE);
+
+       uid = i_cal_component_get_uid (component);
+
+       for (prop = i_cal_component_get_first_property (component, I_CAL_ATTACH_PROPERTY);
+            prop && success;
+            g_object_unref (prop), prop = i_cal_component_get_next_property (component, 
I_CAL_ATTACH_PROPERTY)) {
+               ICalAttach *attach;
+
+               attach = i_cal_property_get_attach (prop);
+               if (attach && i_cal_attach_get_is_url (attach)) {
+                       const gchar *url;
+
+                       url = i_cal_attach_get_url (attach);
+                       if (g_str_has_prefix (url, "file://")) {
+                               GFile *file;
+                               gchar *basename;
+                               gchar *content;
+                               gsize len;
+
+                               file = g_file_new_for_uri (url);
+                               basename = g_file_get_basename (file);
+                               if (g_file_load_contents (file, cancellable, &content, &len, NULL, error)) {
+                                       ICalAttach *new_attach;
+                                       ICalParameter *param;
+                                       gchar *base64;
+
+                                       base64 = g_base64_encode ((const guchar *) content, len);
+                                       new_attach = i_cal_attach_new_from_data (base64, (GFunc) g_free, 
NULL);
+                                       g_free (content);
+
+                                       ecu_remove_all_but_filename_parameter (prop);
+
+                                       i_cal_property_set_attach (prop, new_attach);
+                                       g_object_unref (new_attach);
+
+                                       param = i_cal_parameter_new_value (I_CAL_VALUE_BINARY);
+                                       i_cal_property_take_parameter (prop, param);
+
+                                       param = i_cal_parameter_new_encoding (I_CAL_ENCODING_BASE64);
+                                       i_cal_property_take_parameter (prop, param);
+
+                                       /* Preserve existing FILENAME parameter */
+                                       if (!e_cal_util_property_has_parameter (prop, 
I_CAL_FILENAME_PARAMETER)) {
+                                               const gchar *use_filename = basename;
+
+                                               /* generated filename by Evolution */
+                                               if (uid && g_str_has_prefix (use_filename, uid) &&
+                                                   use_filename[strlen (uid)] == '-') {
+                                                       use_filename += strlen (uid) + 1;
+                                               }
+
+                                               param = i_cal_parameter_new_filename (use_filename);
+                                               i_cal_property_take_parameter (prop, param);
+                                       }
+                               } else {
+                                       success = FALSE;
+                               }
+
+                               g_object_unref (file);
+                               g_free (basename);
+                       }
+               }
+
+               g_clear_object (&attach);
+       }
+
+       g_clear_object (&prop);
+
+       return success;
+}
diff --git a/src/calendar/libecal/e-cal-util.h b/src/calendar/libecal/e-cal-util.h
index a0d5ea2fb..ece7f9419 100644
--- a/src/calendar/libecal/e-cal-util.h
+++ b/src/calendar/libecal/e-cal-util.h
@@ -343,6 +343,10 @@ EConflictResolution
                                                (guint32 flags); /* bit-or of ECalOperationFlags */
 guint32                e_cal_util_conflict_resolution_to_operation_flags /* bit-or of ECalOperationFlags */
                                                (EConflictResolution conflict_resolution);
+gboolean       e_cal_util_inline_local_attachments_sync
+                                               (ICalComponent *component,
+                                                GCancellable *cancellable,
+                                                GError **error);
 
 G_END_DECLS
 
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index 61cfb3228..c4415d5bd 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -4053,81 +4053,9 @@ e_cal_meta_backend_inline_local_attachments_sync (ECalMetaBackend *meta_backend,
                                                  GCancellable *cancellable,
                                                  GError **error)
 {
-       ICalProperty *prop;
-       const gchar *uid;
-       gboolean success = TRUE;
-
        g_return_val_if_fail (E_IS_CAL_META_BACKEND (meta_backend), FALSE);
-       g_return_val_if_fail (component != NULL, FALSE);
-
-       uid = i_cal_component_get_uid (component);
 
-       for (prop = i_cal_component_get_first_property (component, I_CAL_ATTACH_PROPERTY);
-            prop && success;
-            g_object_unref (prop), prop = i_cal_component_get_next_property (component, 
I_CAL_ATTACH_PROPERTY)) {
-               ICalAttach *attach;
-
-               attach = i_cal_property_get_attach (prop);
-               if (attach && i_cal_attach_get_is_url (attach)) {
-                       const gchar *url;
-
-                       url = i_cal_attach_get_url (attach);
-                       if (g_str_has_prefix (url, LOCAL_PREFIX)) {
-                               GFile *file;
-                               gchar *basename;
-                               gchar *content;
-                               gsize len;
-
-                               file = g_file_new_for_uri (url);
-                               basename = g_file_get_basename (file);
-                               if (g_file_load_contents (file, cancellable, &content, &len, NULL, error)) {
-                                       ICalAttach *new_attach;
-                                       ICalParameter *param;
-                                       gchar *base64;
-
-                                       base64 = g_base64_encode ((const guchar *) content, len);
-                                       new_attach = i_cal_attach_new_from_data (base64, (GFunc) g_free, 
NULL);
-                                       g_free (content);
-
-                                       ecmb_remove_all_but_filename_parameter (prop);
-
-                                       i_cal_property_set_attach (prop, new_attach);
-                                       g_object_unref (new_attach);
-
-                                       param = i_cal_parameter_new_value (I_CAL_VALUE_BINARY);
-                                       i_cal_property_take_parameter (prop, param);
-
-                                       param = i_cal_parameter_new_encoding (I_CAL_ENCODING_BASE64);
-                                       i_cal_property_take_parameter (prop, param);
-
-                                       /* Preserve existing FILENAME parameter */
-                                       if (!e_cal_util_property_has_parameter (prop, 
I_CAL_FILENAME_PARAMETER)) {
-                                               const gchar *use_filename = basename;
-
-                                               /* generated filename by Evolution */
-                                               if (uid && g_str_has_prefix (use_filename, uid) &&
-                                                   use_filename[strlen (uid)] == '-') {
-                                                       use_filename += strlen (uid) + 1;
-                                               }
-
-                                               param = i_cal_parameter_new_filename (use_filename);
-                                               i_cal_property_take_parameter (prop, param);
-                                       }
-                               } else {
-                                       success = FALSE;
-                               }
-
-                               g_object_unref (file);
-                               g_free (basename);
-                       }
-               }
-
-               g_clear_object (&attach);
-       }
-
-       g_clear_object (&prop);
-
-       return success;
+       return e_cal_util_inline_local_attachments_sync (component, cancellable, error);
 }
 
 /**


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