+
+2007-06-06 Marcus Bauer <marcusb@openismus.com>
+
+ * libmodest-dbus-client/libmodest-dbus-client.h:
+ added libmodest_dbus_client_compose_mail()
+ * src/dbus_api/modest-dbus-callbacks.c: (on_idle_compose_mail),
+ (on_compose_mail):
+ added functions needed for SendAsMail() functionality
+ * src/maemo/modest-msg-edit-window.c:
+ (modest_msg_edit_window_attach_file_noninteractive):
+ non interactively attaching files to message edit window
+ * src/widgets/modest-msg-edit-window.h:
+ * tests/dbus_api/Makefile.am:
+ added test_compose_mail.c
+ * tests/dbus_api/test_compose_mail.c: (main):
+
2007-06-05 Johannes Schmid <johannes.schmid@openismus.com>
* src/modest-account-view.c:
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);
+
+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);
gboolean
libmodest_dbus_client_mail_to (osso_context_t *osso_context,
#include "modest-account-mgr-helpers.h"
#include "modest-tny-account.h"
#include "modest-ui-actions.h"
+
#include "modest-search.h"
#include "widgets/modest-msg-edit-window.h"
#include "modest-tny-msg.h"
#include <libgnomevfs/gnome-vfs-utils.h>
#include <stdio.h>
#include <string.h>
+#include <glib/gstdio.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
+#include <tny-fs-stream.h>
#include <tny-list.h>
#include <tny-iterator.h>
gchar *bcc;
gchar *subject;
gchar *body;
- GSList *attachments;
+ gchar *attachments;
} ComposeMailIdleData;
static gboolean
}
+
+
+
static gboolean
on_idle_compose_mail(gpointer user_data)
{
ComposeMailIdleData *idle_data = (ComposeMailIdleData*)user_data;
+ gchar **list = NULL;
+ gint i = 0;
/* Get the TnyTransportAccount so we can instantiate a mail operation: */
ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
}
if (!account) {
- g_printerr ("modest: failed to get tny account folder'\n", account_name);
+ g_printerr ("modest: failed to get tny account folder'%s'\n", account_name);
} else {
gchar * from = modest_account_mgr_get_from_string (account_mgr,
account_name);
if (!from) {
g_printerr ("modest: no from address for account '%s'\n", account_name);
} else {
-
+
/* Create the message: */
TnyMsg *msg = modest_tny_msg_new (idle_data->to, from,
idle_data->cc, idle_data->bcc, idle_data->subject, idle_data->body,
- idle_data->attachments);
+ NULL); /* NULL because m_t_m_n doesn't use it */
if (!msg) {
g_printerr ("modest: failed to create message\n");
tny_folder_add_msg (folder, msg, NULL); /* TODO: check err */
ModestWindow *win = modest_msg_edit_window_new (msg, account_name);
+
+ list = g_strsplit(idle_data->attachments, ",", 0);
+ for (i=0; list[i] != NULL; i++) {
+ modest_msg_edit_window_attach_file_noninteractive(
+ (ModestMsgEditWindow *)win, list[i]);
+ }
+ g_strfreev(list);
+
gtk_widget_show_all (GTK_WIDGET (win));
g_object_unref (G_OBJECT(folder));
static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retval)
{
- gchar **list = NULL;
- gint i = 0;
+
if (arguments->len != MODEST_DEBUS_COMPOSE_MAIL_ARGS_COUNT)
return OSSO_ERROR;
idle_data->body = g_strdup (val.value.s);
val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_COMPOSE_MAIL_ARG_ATTACHMENTS);
- gchar *attachments_str = g_strdup (val.value.s);
+ idle_data->attachments = g_strdup (val.value.s);
- list = g_strsplit(attachments_str, ",", 0);
- for (i=0; list[i] != NULL; i++) {
- idle_data->attachments = g_slist_append(idle_data->attachments, g_strdup(list[i]));
- }
- g_strfreev(list);
-
-
- /* printf(" debug: to=%s\n", idle_data->to); */
- g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
+ g_idle_add(on_idle_compose_mail, (gpointer)idle_data);
/* Note that we cannot report failures during sending,
* because that would be asynchronous. */
}
void
+modest_msg_edit_window_attach_file_noninteractive (
+ ModestMsgEditWindow *window,
+ gchar *filename)
+{
+
+ ModestMsgEditWindowPrivate *priv;
+
+ priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ if (filename) {
+ gint file_id;
+
+ file_id = g_open (filename, O_RDONLY, 0);
+ if (file_id != -1) {
+ TnyMimePart *mime_part;
+ TnyStream *stream;
+ const gchar *mime_type;
+ gchar *basename;
+ gchar *content_id;
+
+ mime_type = gnome_vfs_get_file_mime_type_fast (filename, NULL);
+ mime_part = tny_platform_factory_new_mime_part
+ (modest_runtime_get_platform_factory ());
+ stream = TNY_STREAM (tny_fs_stream_new (file_id));
+
+ tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
+
+ content_id = g_strdup_printf ("%d", priv->last_cid);
+ tny_mime_part_set_content_id (mime_part, content_id);
+ g_free (content_id);
+ priv->last_cid++;
+
+ basename = g_path_get_basename (filename);
+ tny_mime_part_set_filename (mime_part, basename);
+ g_free (basename);
+
+ priv->attachments = g_list_prepend (priv->attachments, mime_part);
+ modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+ mime_part);
+ gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
+ gtk_widget_show_all (priv->attachments_caption);
+ } else if (file_id == -1) {
+ close (file_id);
+ }
+ }
+}
+
+void
modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
GList *att_list)
{
void modest_msg_edit_window_attach_file (ModestMsgEditWindow *window);
/**
+ * modest_msg_edit_window_attach_file_noninteractive:
+ * @self: a #ModestMsgEditWindow
+ *
+ * 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);
+
+/**
* modest_msg_edit_window_remove_attachments:
* @self: a #ModestMsgEditWindow
* @att_list: a #GList of #TnyMimePart
G_END_DECLS
#endif /* __MODEST_MSG_EDIT_WINDOW_H__ */
-
test_mail_to \
test_open_message \
test_search \
- test_delete_message
+ test_delete_message \
+ test_compose_mail
test_send_mail_SOURCES = test_send_mail.c
test_send_mail_LDADD = $(objects)
test_open_message_SOURCES = test_open_message.c
test_open_message_LDADD = $(objects)
+
+test_compose_mail_SOURCES = test_compose_mail.c
+test_compose_mail_LDADD = $(objects)
+
test_search_SOURCES = test_search.c
test_search_LDADD = $(objects)
+
test_delete_message_SOURCES = test_delete_message.c
test_delete_message_LDADD = $(objects)
--- /dev/null
+#include <libmodest-dbus-client/libmodest-dbus-client.h>
+#include <stdio.h>
+
+
+int main(int argc, char *argv[])
+{
+ GSList *attachments = NULL;
+ /* Initialize maemo application */
+ osso_context_t * osso_context = osso_initialize(
+ "test_hello", "0.0.1", TRUE, NULL);
+
+ /* Check that initialization was ok */
+ if (osso_context == NULL)
+ {
+ printf("osso_initialize() failed.\n");
+ return OSSO_ERROR;
+ }
+
+ /* Call the function in libmodest-dbus-client: */
+ /* TODO: The Message URI system is not yet implemented. */
+
+ attachments = g_slist_append(attachments, "/home/m/MyDocs/bar1.txt,/home/m/MyDocs/foo.txt");
+
+ const gboolean ret = libmodest_dbus_client_compose_mail (
+ osso_context,
+ "marcusb@openismus.com", /* to */
+ "cc test", /* cc */
+ "bcc test", /* bcc */
+ "test subject", /* subject */
+ "test body\nline two", /* body */
+ attachments);
+
+
+ if (!ret) {
+ printf("libmodest_dbus_client_open_message() failed.\n");
+ return OSSO_ERROR;
+ } else {
+ printf("libmodest_dbus_client_open_message() succeeded!\n");
+ }
+
+ /* Exit */
+ return 0;
+}