X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=libmodest-dbus-client%2Flibmodest-dbus-client.c;h=6e25703af7b43c39e5f74645d2eefd382d880bd9;hp=0e9668797da22f03ae4360ef4073692c92ab69ef;hb=69919988cc084f8dd70d17cdd11988386359922b;hpb=b91f5d417772ff0ae30acb9b955ad90ad89e1699 diff --git a/libmodest-dbus-client/libmodest-dbus-client.c b/libmodest-dbus-client/libmodest-dbus-client.c index 0e96687..6e25703 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.c +++ b/libmodest-dbus-client/libmodest-dbus-client.c @@ -35,6 +35,24 @@ #include #include +/** + * libmodest_dbus_client_send_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_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments) @@ -51,10 +69,10 @@ libmodest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, DBUS_TYPE_INVALID); if (ret != OSSO_OK) { - printf("debug: osso_rpc_run() failed.\n"); + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); return FALSE; } else { - printf("debug: osso_rpc_run() succeeded.\n"); + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); } osso_rpc_free_val(&retval); @@ -73,10 +91,10 @@ libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto DBUS_TYPE_INVALID); if (ret != OSSO_OK) { - printf("debug: osso_rpc_run() failed.\n"); + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); return FALSE; } else { - printf("debug: osso_rpc_run() succeeded.\n"); + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); } osso_rpc_free_val(&retval); @@ -117,10 +135,10 @@ libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *t DBUS_TYPE_INVALID); if (ret != OSSO_OK) { - printf("debug: osso_rpc_run() failed.\n"); + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); return FALSE; } else { - printf("debug: osso_rpc_run() succeeded.\n"); + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); } osso_rpc_free_val(&retval); @@ -128,6 +146,18 @@ libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *t return TRUE; } +/** + * libmodest_dbus_client_open_message: + * @osso_context: a valid #osso_context_t object. + * @msg_uri: A valid url to a mail + * + * This method will try to find the message supplied + * by @msg_uri and open it for display if found. + * It will use remote procedure calls (rpc) over + * dbus to do so. + * + * Return value: TRUE on successs, FALSE on error + **/ gboolean libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri) { @@ -139,10 +169,10 @@ libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *m DBUS_TYPE_INVALID); if (ret != OSSO_OK) { - printf("debug: osso_rpc_run() failed.\n"); + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); return FALSE; } else { - printf("debug: osso_rpc_run() succeeded.\n"); + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); } osso_rpc_free_val(&retval); @@ -160,10 +190,31 @@ libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) DBUS_TYPE_INVALID); if (ret != OSSO_OK) { - printf("debug: osso_rpc_run() failed.\n"); + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); + return FALSE; + } else { + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); + } + + osso_rpc_free_val(&retval); + + return TRUE; +} + +gboolean +libmodest_dbus_client_open_default_inbox (osso_context_t *osso_context) +{ + osso_rpc_t retval; + const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, + MODEST_DBUS_NAME, + MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX, &retval, + DBUS_TYPE_INVALID); + + if (ret != OSSO_OK) { + printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__); return FALSE; } else { - printf("debug: osso_rpc_run() succeeded.\n"); + printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__); } osso_rpc_free_val(&retval); @@ -171,14 +222,63 @@ libmodest_dbus_client_send_and_receive (osso_context_t *osso_context) return TRUE; } -static void +/** + * libmodest_dbus_client_delete_message: + * @osso_context: a valid #osso_context_t object. + * @msg_uri: A valid url to a mail + * + * This method will try to find the message supplied + * by @msg_uri and if found delete it. It will use + * remote procedure calls (rpc) over dbus to do so. + * + * Return value: TRUE on successs, FALSE on error + **/ +gboolean +libmodest_dbus_client_delete_message (osso_context_t *osso_ctx, + const char *msg_uri) +{ + osso_rpc_t retval; + osso_return_t ret; + + ret = osso_rpc_run_with_defaults (osso_ctx, + MODEST_DBUS_NAME, + MODEST_DBUS_METHOD_DELETE_MESSAGE, &retval, + DBUS_TYPE_STRING, msg_uri, + DBUS_TYPE_INVALID); + + if (ret != OSSO_OK) { + g_debug ("debug: osso_rpc_run() failed.\n"); + } else { + g_debug ("debug: osso_rpc_run() succeeded.\n"); + } + + osso_rpc_free_val (&retval); + + return ret == OSSO_OK; +} + +void modest_search_hit_free (ModestSearchHit *hit) { g_free (hit->msgid); - g_slice_free (ModestSearchHit, hit); } +void +modest_search_hit_list_free (GList *hits) +{ + GList *iter; + + if (hits == NULL) { + return; + } + + for (iter = hits; iter; iter = iter->next) { + modest_search_hit_free ((ModestSearchHit *) iter->data); + } + + g_list_free (hits); +} static char * _dbus_iter_get_string_or_null (DBusMessageIter *iter) @@ -399,7 +499,69 @@ out: return hit; } - +/** + * libmodest_dbus_client_search: + * @osso_ctx: A valid #osso_context_t object. + * @query: The term to search for. + * @folder: An url to specific folder or %NULL to search everywhere. + * @start_date: Search hits before this date will be ignored. + * @end_date: Search hits after this date will be ignored. + * @min_size: Messagers smaller then this size will be ingored. + * @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). + * + * 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) + * specified in @query. It is legal to specify 0 in @start_date, @end_date and + * @min_size to ignore these parameters during the search otherwise those message + * that do not meet the specifed dates or size will be ignored. + * Where to search, be it subject, sender or the whole body can be specified by + * the @flags parameter. + * + * Upon success TRUE is returned and @hits will include the search hits or the list + * migh be empty if none of the messages matched the search criteria. The returned + * list must be freed with modest_search_hit_list_free (). It is save to pass + * %NULL to this function so you can call this function on the result list no matter + * if a hit was found or not (means the list is empty - i.e. %NULL) + * FALSE will only be return if an error during the remote procedure call (rpc) + * occured or if the specified folder could not be found. + * + * NOTE: The body of a message can only be searched if it was previously downloaded by + * modest. This function does also not attempt do to remote searches (i.e. IMAP search). + * + * Example to search every account for message containing "no": + * + * ModestDBusSearchFlags flags; + * osso_context_t *osso_context; + * GList *hits; + * GList *iter; + * gboolean res; + * + * [...] Initialize osso context [...] + * + * res = libmodest_dbus_client_search (osso_context, + * "no", + * NULL, + * 0, + * 0, + * 0, + * flags, + * &hits); + * + * for (iter = hits; iter; iter = iter->next) { + * ModestSearchHit *hit = (ModestSearchHit *) iter->data; + * + * [...] Do something with the hit [...] + * + * } + * + * modest_search_hit_list_free (hits); + * + * + * Return value: TRUE if the search succeded or FALSE for an error during the search + **/ gboolean libmodest_dbus_client_search (osso_context_t *osso_ctx, const gchar *query, @@ -425,6 +587,9 @@ libmodest_dbus_client_search (osso_context_t *osso_ctx, dbus_int32_t flags_v; dbus_uint32_t size_v; + if (query == NULL) { + return FALSE; + } con = osso_get_dbus_connection (osso_ctx); @@ -445,6 +610,10 @@ libmodest_dbus_client_search (osso_context_t *osso_ctx, return OSSO_ERROR; } + if (folder == NULL) { + folder = ""; + } + sd_v = start_date; ed_v = end_date; flags_v = (dbus_int32_t) flags; @@ -508,6 +677,7 @@ libmodest_dbus_client_search (osso_context_t *osso_ctx, arg_type = dbus_message_iter_get_arg_type (&iter); dbus_message_iter_recurse (&iter, &child); + *hits = NULL; do { ModestSearchHit *hit;