2007-06-19 Murray Cumming,,, <murrayc@murrayc-desktop>
authorMurray Cumming <murrayc@murrayc.com>
Tue, 19 Jun 2007 17:16:26 +0000 (17:16 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Tue, 19 Jun 2007 17:16:26 +0000 (17:16 +0000)
* libmodest-dbus-client/libmodest-dbus-client.c:
        (_dbus_iter_get_string_or_null): Initialize the string variable in
        case this helps with Dirk's crash.

2007-06-19  Murray Cumming  <murrayc@murrayc.com>

        * src/dbus_api/modest-dbus-api.h: Add the attachments enum for send_mail,
        though it is not implemented yet (this function is maybe not even used),
        to avoid breaking ABI in future.
        * libmodest-dbus-client/libmodest-dbus-client.c:
        (get_attachments_string): Moved some code into this generic function.
        (libmodest_dbus_client_send_mail): Corrected the documentation. This really
        sends email. It is maybe not used.
        * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_mail),
        (on_send_mail): Use attachments.

        * src/widgets/modest-msg-edit-window.h: Improve the documentation.
        * src/maemo/modest-msg-edit-window.c:
        (modest_msg_edit_window_attach_file_noninteractive): Convert the URI to
        a filename before using it, to fix projects.maemo.org bug NB#58233.

pmo-trunk-r2319

ChangeLog2
libmodest-dbus-client/libmodest-dbus-client.c
src/dbus_api/modest-dbus-api.h
src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-msg-edit-window.c
src/widgets/modest-msg-edit-window.h

index c105de8..4ceec2a 100644 (file)
@@ -1,3 +1,26 @@
+2007-06-19  Murray Cumming,,,  <murrayc@murrayc-desktop>
+
+       * libmodest-dbus-client/libmodest-dbus-client.c:
+       (_dbus_iter_get_string_or_null): Initialize the string variable in 
+       case this helps with Dirk's crash.
+
+2007-06-19  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/dbus_api/modest-dbus-api.h: Add the attachments enum for send_mail, 
+       though it is not implemented yet (this function is maybe not even used),
+       to avoid breaking ABI in future.
+       * libmodest-dbus-client/libmodest-dbus-client.c:
+       (get_attachments_string): Moved some code into this generic function.
+       (libmodest_dbus_client_send_mail): Corrected the documentation. This really 
+       sends email. It is maybe not used.
+       * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_mail),
+       (on_send_mail): Use attachments.
+       
+       * src/widgets/modest-msg-edit-window.h: Improve the documentation.
+       * src/maemo/modest-msg-edit-window.c:
+       (modest_msg_edit_window_attach_file_noninteractive): Convert the URI to 
+       a filename before using it, to fix projects.maemo.org bug NB#58233.
+
 2007-06-19  Murray Cumming  <murrayc@murrayc.com>
 
        * src/modest-ui-actions.c: (modest_ui_actions_on_copy):
index 6e25703..68fe837 100644 (file)
 #include <dbus/dbus-glib-lowlevel.h>
 #include <string.h>
 
+
+
+/** Get a comma-separated list of attachement URI strings, 
+ * from a list of strings.
+ */
+static gchar* get_attachments_string (GSList *attachments)
+{
+       if (!attachments)
+               return NULL;
+               
+       gchar *attachments_str = g_strdup("");
+       
+       GSList *iter = attachments;
+       while (iter)
+       {
+               if (iter->data) {
+                       gchar *tmp = g_strconcat(attachments_str, ",", (gchar *) (iter->data), NULL);
+                       g_free(attachments_str);
+                       attachments_str = tmp;
+               }
+               
+               iter = g_slist_next(iter);
+       }
+       
+       return attachments_str;
+}
+
+/* TODO: Is this actually used by anything?
+ * I guess that everything uses *_compose_mail() instead. murrayc.
+ */
 /**
  * libmodest_dbus_client_send_mail:
  * @osso_context: a valid #osso_context_t object.
  * @attachments: Additional list of attachments
  * 
  * This function will try to do a remote procedure call (rpc)
- * into modest (or start it if necessary) and open a composer
- * window with the supplied parameters prefilled.
+ * into modest (or start it if necessary) and send a new 
+ * email with the supplied parameters.
  *
  * Return value: Whether or not the rpc call to modest
  * was successfull
  **/
-
 gboolean
 libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, 
        const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
 {
+       gchar *attachments_str = get_attachments_string(attachments);
+       
        osso_rpc_t retval;
        const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, 
                   MODEST_DBUS_NAME, 
@@ -66,6 +98,7 @@ libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to,
                   DBUS_TYPE_STRING, bcc, 
                   DBUS_TYPE_STRING, subject, 
                   DBUS_TYPE_STRING, body, 
+                  DBUS_TYPE_STRING, attachments_str,
                   DBUS_TYPE_INVALID);
                
        if (ret != OSSO_OK) {
@@ -77,6 +110,8 @@ libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to,
        
        osso_rpc_free_val(&retval);
        
+       g_free (attachments_str);
+       
        return TRUE;
 }
        
@@ -102,26 +137,30 @@ libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto
        return TRUE;
 }
 
+/**
+ * libmodest_dbus_client_compose_mail:
+ * @osso_context: a valid #osso_context_t object.
+ * @to: The Recipients (From: line)
+ * @cc: Recipients for carbon copies
+ * @bcc: Recipients for blind carbon copies
+ * @subject: Subject line
+ * @body: The actual body of the mail to send
+ * @attachments: Additional list of attachments
+ * 
+ * This function will try to do a remote procedure call (rpc)
+ * into modest (or start it if necessary) and open a composer
+ * window with the supplied parameters prefilled.
+ *
+ * Return value: Whether or not the rpc call to modest
+ * was successfull
+ **/
 gboolean
 libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, 
        const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
 {
        osso_rpc_t retval;
-       gchar *attachments_str = NULL;
-       gchar *tmp = NULL;
-       GSList *next = NULL;
        
-       attachments_str = g_strdup( (gchar *) attachments->data );
-       
-       for (next = g_slist_next(attachments); next != NULL; next = g_slist_next(next))
-       {
-               tmp = g_strconcat(attachments_str, ",", (gchar *) (next->data), NULL);
-               g_free(attachments_str);
-               attachments_str = tmp;
-               if (attachments_str == NULL) {
-                       return OSSO_ERROR;
-               }
-       }
+       gchar *attachments_str = get_attachments_string(attachments);
 
        const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, 
                   MODEST_DBUS_NAME, 
@@ -142,6 +181,8 @@ libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *t
        }
        
        osso_rpc_free_val(&retval);
+
+       g_free (attachments_str);
        
        return TRUE;
 }
@@ -283,12 +324,11 @@ modest_search_hit_list_free (GList *hits)
 static char *
 _dbus_iter_get_string_or_null (DBusMessageIter *iter)
 {
-       const char *string;
-       char       *ret;
+       const char *string = NULL;
+       char       *ret = NULL;
 
        dbus_message_iter_get_basic (iter, &string);
        
-       ret = NULL;
        if (string && strlen (string)) {
                ret = g_strdup (string);
        }
@@ -510,7 +550,8 @@ out:
  * @flags: A list of flags where to search so the documentation 
  * of %ModestDBusSearchFlags for details.
  * @hits: A pointer to a valid GList pointer that will contain the search
- * hits (must be freed by the caller).
+ * hits (ModestSearchHit). The list and the items must be freed by the caller 
+ * with modest_search_hit_list_free().
  *
  * This method will search the folder specified by a valid url in @folder or all
  * known accounts (local and remote) if %NULL for matches of the search term(s)
index 2a02242..c43cf50 100644 (file)
@@ -48,7 +48,7 @@ enum ModestDbusSendMailArguments
        MODEST_DEBUS_SEND_MAIL_ARG_BCC,
        MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT,
        MODEST_DEBUS_SEND_MAIL_ARG_BODY,
-       /* TODO: MODEST_DEBUS_SEND_MAIL_ARG_ATTACHMENTS, */
+       MODEST_DEBUS_SEND_MAIL_ARG_ATTACHMENTS,
        MODEST_DEBUS_SEND_MAIL_ARGS_COUNT
 };
 
index 7a772e4..d10cb96 100644 (file)
@@ -56,6 +56,7 @@ typedef struct
        gchar *bcc;
        gchar *subject;
        gchar *body;
+       gchar *attachments;
 } SendMailIdleData;
 
 typedef struct 
@@ -127,11 +128,15 @@ on_idle_send_mail(gpointer user_data)
        g_free (idle_data->bcc);
        g_free (idle_data->subject);
        g_free (idle_data->body);
+       g_free (idle_data->attachments);
        g_free (idle_data);
        
        return FALSE; /* Do not call this callback again. */
 }
 
+/* TODO: Is this actually used by anything?
+ * I guess that everything uses *_compose_mail() instead. murrayc.
+ */
 static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
 {
        if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT)
@@ -156,6 +161,9 @@ static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
        val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY);
        idle_data->body = g_strdup (val.value.s);
        
+       val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_ATTACHMENTS);
+       idle_data->attachments = g_strdup (val.value.s);
+       
        /* printf("  debug: to=%s\n", idle_data->to); */
        g_idle_add(on_idle_send_mail, (gpointer)idle_data);
        
index ad6b342..292ace4 100644 (file)
@@ -1541,16 +1541,24 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
 void
 modest_msg_edit_window_attach_file_noninteractive (
                ModestMsgEditWindow *window,
-               gchar *filename)
+               const gchar *file_uri)
 {
        
        ModestMsgEditWindowPrivate *priv;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
-       if (filename) {
-               gint file_id;
+       if (file_uri) {
+               gint file_id = 0;
                
+               /* TODO: We should probably try to use only the URI,
+                * instead of using a filename.
+                */
+               gchar* filename = g_filename_from_uri (file_uri, NULL, NULL);
+               if (!filename) {
+                       g_warning("%s: g_filename_from_uri(%s) failed.\n", __FUNCTION__, file_uri);
+               }
+
                file_id = g_open (filename, O_RDONLY, 0);
                if (file_id != -1) {
                        TnyMimePart *mime_part;
@@ -1584,6 +1592,8 @@ modest_msg_edit_window_attach_file_noninteractive (
                        close (file_id);
                        g_warning("file to be attached does not exist: %s", filename);
                }
+
+               g_free (filename);
        }
 }
 
index a0bb82e..bcbf164 100644 (file)
@@ -213,11 +213,12 @@ void                    modest_msg_edit_window_attach_file           (ModestMsgE
 /**
  * modest_msg_edit_window_attach_file_noninteractive:
  * @self: a #ModestMsgEditWindow
+ * @file_uri: The URI of a file to attach to the email message.
  *
  * attach a file to a MsgEditWindow non interactively, 
  * without file dialog. This is needed by dbus callbacks.
  */
-void                    modest_msg_edit_window_attach_file_noninteractive           (ModestMsgEditWindow *window, gchar *filename);
+void                    modest_msg_edit_window_attach_file_noninteractive           (ModestMsgEditWindow *window, const gchar *file_uri);
 
 /**
  * modest_msg_edit_window_remove_attachments: