return FALSE;
}
+static void
+on_destroy (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
+{
+ gtk_main_quit();
+}
+
+
static void
connect_signals (ModestMainWindow *self)
G_CALLBACK(on_online_toggle_toggled), NULL);
/* window */
- //g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_main_window_destroy), NULL);
+ g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
}
#include <glib/gi18n.h>
-/* exit codes for the modest executable*/
-enum {
- MODEST_ERR_NONE = 0, /* no error */
- MODEST_ERR_OPTIONS, /* error in the options */
- MODEST_ERR_CONF, /* error getting confuration db */
- MODEST_ERR_UI, /* error in the UI */
- MODEST_ERR_HILDON, /* error with Hildon (maemo-only) */
- MODEST_ERR_RUN, /* errr running */
- MODEST_ERR_SEND, /* error sending mail */
- MODEST_ERR_PARAM, /* error in one or more of the parameters */
- MODEST_ERR_INIT /* error in initialization */
-};
-
-
/* some interesting dirs. NOTE, they should be prefixed
* with $HOME; also, except MODEST_DIR itself, they
* need to be prefixed with MODEST_DIR;
MODEST_MAIL_OPERATION_ERROR_BAD_ACCOUNT,
MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
- MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND
+ MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
+ MODEST_MAIL_OPERATION_ERROR_INTERNAL,
+
} ModestErrorCode;
G_END_DECLS
static void add_attachments (TnyMsg *msg,
GList *attachments_list);
-
-static TnyMimePart * add_body_part (TnyMsg *msg,
- const gchar *body,
- const gchar *content_type,
- gboolean has_attachments);
-
-
static void modest_mail_operation_xfer_folder (ModestMailOperation *self,
TnyFolder *folder,
TnyFolderStore *parent,
} RefreshFolderAsyncHelper;
-/* some utility functions */
-static char * get_content_type(const gchar *s);
-static gboolean is_ascii(const gchar *s);
-
/* globals */
static GObjectClass *parent_class = NULL;
void
modest_mail_operation_send_new_mail (ModestMailOperation *self,
TnyTransportAccount *transport_account,
- const gchar *from,
- const gchar *to,
- const gchar *cc,
- const gchar *bcc,
- const gchar *subject,
- const gchar *body,
+ const gchar *from, const gchar *to,
+ const gchar *cc, const gchar *bcc,
+ const gchar *subject, const gchar *body,
const GList *attachments_list)
{
- TnyPlatformFactory *fact;
TnyMsg *new_msg;
- TnyHeader *header;
- gchar *content_type;
ModestMailOperationPrivate *priv = NULL;
g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
if (to == NULL) {
g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
- _("Error trying to send a mail. You need to set almost one a recipient"));
+ _("Error trying to send a mail. You need to set at least one recipient"));
return;
}
- /* Create new msg */
- fact = modest_tny_platform_factory_get_instance ();
- new_msg = tny_platform_factory_new_msg (fact);
- header = tny_platform_factory_new_header (fact);
-
- /* WARNING: set the header before assign values to it */
- tny_msg_set_header (new_msg, header);
- tny_header_set_from (TNY_HEADER (header), from);
- tny_header_set_replyto (TNY_HEADER (header), from);
- tny_header_set_to (TNY_HEADER (header), to);
- tny_header_set_cc (TNY_HEADER (header), cc);
- tny_header_set_bcc (TNY_HEADER (header), bcc);
- tny_header_set_subject (TNY_HEADER (header), subject);
-
- content_type = get_content_type(body);
-
- /* Add the body of the new mail */
- add_body_part (new_msg, body, (const gchar *) content_type,
- (attachments_list == NULL) ? FALSE : TRUE);
-
- /* Add attachments */
- add_attachments (new_msg, (GList*) attachments_list);
-
- /* Send mail */
+ new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, body, NULL); /* FIXME: attachments */
+ if (!new_msg) {
+ g_printerr ("modest: failed to create a new msg\n");
+ return;
+ }
+
modest_mail_operation_send_mail (self, transport_account, new_msg);
- /* Clean */
- g_object_unref (header);
- g_object_unref (new_msg);
- g_free(content_type);
+ g_object_unref (G_OBJECT(new_msg));
}
static void
add_attachments (new_msg, attachments_list);
/* Clean */
- if (attachments_list) g_list_free (attachments_list);
+ if (attachments_list)
+ g_list_free (attachments_list);
g_object_unref (G_OBJECT (parts));
return new_msg;
/* ******************************************************************* */
/* ************************* UTILIY FUNCTIONS ************************ */
/* ******************************************************************* */
-static gboolean
-is_ascii(const gchar *s)
-{
- while (s[0]) {
- if (s[0] & 128 || s[0] < 32)
- return FALSE;
- s++;
- }
- return TRUE;
-}
-
-static char *
-get_content_type(const gchar *s)
-{
- GString *type;
-
- type = g_string_new("text/plain");
- if (!is_ascii(s)) {
- if (g_utf8_validate(s, -1, NULL)) {
- g_string_append(type, "; charset=\"utf-8\"");
- } else {
- /* it should be impossible to reach this, but better safe than sorry */
- g_warning("invalid utf8 in message");
- g_string_append(type, "; charset=\"latin1\"");
- }
- }
- return g_string_free(type, FALSE);
-}
static void
add_attachments (TnyMsg *msg, GList *attachments_list)
}
}
-
-static TnyMimePart *
-add_body_part (TnyMsg *msg,
- const gchar *body,
- const gchar *content_type,
- gboolean has_attachments)
-{
- TnyMimePart *text_body_part = NULL;
- TnyStream *text_body_stream;
- TnyPlatformFactory *fact;
-
- fact = modest_tny_platform_factory_get_instance ();
-
- /* Create the stream */
- text_body_stream = TNY_STREAM (tny_camel_stream_new
- (camel_stream_mem_new_with_buffer
- (body, strlen(body))));
-
- /* Create body part if needed */
- if (has_attachments)
- text_body_part = tny_platform_factory_new_mime_part (fact);
- else
- text_body_part = TNY_MIME_PART(msg);
-
- /* Construct MIME part */
- tny_stream_reset (text_body_stream);
- tny_mime_part_construct_from_stream (text_body_part,
- text_body_stream,
- content_type);
- tny_stream_reset (text_body_stream);
-
- /* Add part if needed */
- if (has_attachments) {
- tny_mime_part_add_part (TNY_MIME_PART (msg), text_body_part);
- g_object_unref (G_OBJECT(text_body_part));
- }
-
- /* Clean */
- g_object_unref (text_body_stream);
-
- return text_body_part;
-}
#include <modest-tny-platform-factory.h>
#include <modest-mail-operation.h>
#include <modest-tny-account.h>
+#include <modest-tny-msg.h>
#include <modest-account-mgr.h>
#include <modest-account-mgr-helpers.h>
#include <widgets/modest-main-window.h>
-
-
-static gchar* check_account (const gchar *account);
-static int start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
- const gchar* subject, const gchar *body);
-static int send_mail (const gchar* account,
- const gchar* mailto, const gchar *cc, const gchar *bcc,
- const gchar* subject, const gchar *body);
+#include <widgets/modest-msg-edit-window.h>
+
+typedef enum {
+ MODEST_ERR_NONE = 0, /* no error */
+ MODEST_ERR_OPTIONS, /* error in the options */
+ MODEST_ERR_CONF, /* error getting confuration db */
+ MODEST_ERR_UI, /* error in the UI */
+ MODEST_ERR_HILDON, /* error with Hildon (maemo-only) */
+ MODEST_ERR_RUN, /* errr running */
+ MODEST_ERR_SEND, /* error sending mail */
+ MODEST_ERR_PARAM, /* error in one or more of the parameters */
+ MODEST_ERR_INIT /* error in initialization */
+} ModestErrorCode;
+
+static gchar* check_account (const gchar *account);
+
+static ModestErrorCode start_ui (const gchar *account,
+ const gchar* mailto, const gchar *cc,
+ const gchar *bcc, const gchar* subject, const gchar *body);
+
+static ModestErrorCode send_mail (const gchar* account,
+ const gchar* mailto, const gchar *cc, const gchar *bcc,
+ const gchar* subject, const gchar *body);
int
main (int argc, char *argv[])
{
static gboolean batch = FALSE;
static gchar *mailto=NULL, *subject=NULL, *bcc=NULL,
*cc=NULL, *body=NULL, *account=NULL;
-
+ gchar *account_or_default;
static GOptionEntry options[] = {
{ "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
N_("New email to <addresses> (comma-separated)"), NULL},
goto cleanup;
}
g_option_context_free (context);
+
+ account_or_default = check_account (account);
+ g_free (account);
if (!batch) {
if (!modest_runtime_init_ui (argc, argv)) {
- g_printerr ("modest: cannot start UI\n");
+ g_printerr ("modest: cannot start ui\n");
retval = MODEST_ERR_UI;
goto cleanup;
} else
- retval = start_ui (mailto, cc, bcc, subject, body);
+ retval = start_ui (account_or_default,
+ mailto, cc, bcc, subject, body);
} else {
- gchar *account_or_default;
- account_or_default = check_account (account);
- g_free (account);
-
- if (!account_or_default) {
- g_printerr ("modest: account is not valid\n");
- retval = MODEST_ERR_PARAM;
- goto cleanup;
- }
- retval = send_mail (account, mailto, cc, bcc, subject, body);
+ retval = send_mail (account_or_default,
+ mailto, cc, bcc, subject, body);
}
cleanup:
}
-static int
-start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
+static ModestErrorCode
+start_ui (const gchar *account, const gchar* mailto, const gchar *cc, const gchar *bcc,
const gchar* subject, const gchar *body)
{
ModestWindow *win = NULL;
-
- gint retval = 0;
- //odest_ui = modest_ui_new ();
-
- if (mailto||cc||bcc||subject||body) {
- g_warning ("FIXME: implement this");
-/* ok = modest_ui_new_edit_window (modest_ui, */
-/* mailto, /\* to *\/ */
-/* cc, /\* cc *\/ */
-/* bcc, /\* bcc *\/ */
-/* subject, /\* subject *\/ */
-/* body, /\* body *\/ */
-/* NULL); /\* attachments *\/ */
+
+ if (mailto||cc||bcc||subject||body) {
+ gchar *from;
+ TnyMsg *msg;
+
+ if (!account) {
+ g_printerr ("modest: no valid account provided, nor is default one available\n");
+ return MODEST_ERR_PARAM;
+ }
+ from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account);
+ msg = modest_tny_msg_new (mailto,from,cc,bcc,subject,body,NULL);
+
+ win = modest_msg_edit_window_new (MODEST_EDIT_TYPE_NEW);
+ modest_msg_edit_window_set_msg (MODEST_MSG_EDIT_WINDOW(win), msg);
+
+ g_object_unref (G_OBJECT(msg));
+ g_free (from);
} else
win = modest_main_window_new ();
-
- if (win) {
- gtk_widget_show_all (GTK_WIDGET (win));
- gtk_main();
+
+ if (!win) {
+ g_printerr ("modest: failed to create window\n");
+ return MODEST_ERR_UI;
}
- return retval;
+ gtk_widget_show_all (GTK_WIDGET (win));
+ gtk_main();
+
+ return MODEST_ERR_NONE;
}
static gchar*
{
gchar *retval;
ModestAccountMgr *account_mgr;
-
+
account_mgr = modest_runtime_get_account_mgr();
if (!account)
retval = g_strdup (account);
/* sanity check */
- if (!modest_account_mgr_account_exists (account_mgr, account, FALSE, NULL)) {
+ if (!account || !modest_account_mgr_account_exists (account_mgr, account, FALSE, NULL)) {
g_free (retval);
retval = NULL;
}
return retval;
}
-static int
+static ModestErrorCode
send_mail (const gchar* account_name,
const gchar* mailto, const gchar *cc, const gchar *bcc,
const gchar* subject, const gchar *body)
retval = MODEST_ERR_SEND;
} else
retval = MODEST_ERR_NONE; /* hurray! */
-
+
g_object_unref (G_OBJECT(account));
g_object_unref (G_OBJECT(mail_operation));
g_free (from_string);
#include <tny-gtk-text-buffer-stream.h>
#include <tny-simple-list.h>
#include <tny-folder.h>
+#include <modest-tny-platform-factory.h>
+#include <tny-camel-stream.h>
+#include <camel/camel-stream-mem.h>
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#include <modest-tny-msg.h>
#include "modest-text-utils.h"
+static TnyMimePart * add_body_part (TnyMsg *msg, const gchar *body,
+ const gchar *content_type, gboolean has_attachments);
+static void add_attachments (TnyMsg *msg, GList *attachments_list);
+static char * get_content_type(const gchar *s);
+static gboolean is_ascii(const gchar *s);
+
+TnyMsg*
+modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc,
+ const gchar *bcc, const gchar* subject, const gchar *body,
+ GSList *attachments)
+{
+ TnyPlatformFactory *fact;
+ TnyMsg *new_msg;
+ TnyHeader *header;
+ gchar *content_type;
+
+ /* Create new msg */
+ fact = modest_tny_platform_factory_get_instance ();
+ new_msg = tny_platform_factory_new_msg (fact);
+ header = tny_platform_factory_new_header (fact);
+
+ /* WARNING: set the header before assign values to it */
+ tny_msg_set_header (new_msg, header);
+ tny_header_set_from (TNY_HEADER (header), from);
+ tny_header_set_replyto (TNY_HEADER (header), from);
+ tny_header_set_to (TNY_HEADER (header), mailto);
+ tny_header_set_cc (TNY_HEADER (header), cc);
+ tny_header_set_bcc (TNY_HEADER (header), bcc);
+ tny_header_set_subject (TNY_HEADER (header), subject);
+
+ content_type = get_content_type(body);
+
+
+ /* Add the body of the new mail */
+ add_body_part (new_msg, body, content_type, (attachments ? TRUE: FALSE));
+
+ /* Add attachments */
+ add_attachments (new_msg, (GList*) attachments);
+
+ return new_msg;
+}
+
+
+/* FIXME: this func copy from modest-mail-operation: refactor */
+static TnyMimePart *
+add_body_part (TnyMsg *msg,
+ const gchar *body,
+ const gchar *content_type,
+ gboolean has_attachments)
+{
+ TnyMimePart *text_body_part = NULL;
+ TnyStream *text_body_stream;
+ TnyPlatformFactory *fact;
+
+ fact = modest_tny_platform_factory_get_instance ();
+
+ /* Create the stream */
+ text_body_stream = TNY_STREAM (tny_camel_stream_new
+ (camel_stream_mem_new_with_buffer
+ (body, strlen(body))));
+
+ /* Create body part if needed */
+ if (has_attachments)
+ text_body_part = tny_platform_factory_new_mime_part (fact);
+ else
+ text_body_part = TNY_MIME_PART(msg);
+
+ /* Construct MIME part */
+ tny_stream_reset (text_body_stream);
+ tny_mime_part_construct_from_stream (text_body_part,
+ text_body_stream,
+ content_type);
+ tny_stream_reset (text_body_stream);
+
+ /* Add part if needed */
+ if (has_attachments) {
+ tny_mime_part_add_part (TNY_MIME_PART (msg), text_body_part);
+ g_object_unref (G_OBJECT(text_body_part));
+ }
+
+ /* Clean */
+ g_object_unref (text_body_stream);
+
+ return text_body_part;
+}
+
+static void
+add_attachments (TnyMsg *msg, GList *attachments_list)
+{
+ GList *pos;
+ TnyMimePart *attachment_part, *old_attachment;
+ const gchar *attachment_content_type;
+ const gchar *attachment_filename;
+ TnyStream *attachment_stream;
+ TnyPlatformFactory *fact;
+
+ fact = modest_tny_platform_factory_get_instance ();
+ for (pos = (GList *)attachments_list; pos; pos = pos->next) {
+
+ old_attachment = pos->data;
+ attachment_filename = tny_mime_part_get_filename (old_attachment);
+ attachment_stream = tny_mime_part_get_stream (old_attachment);
+ attachment_part = tny_platform_factory_new_mime_part (fact);
+
+ attachment_content_type = tny_mime_part_get_content_type (old_attachment);
+
+ tny_mime_part_construct_from_stream (attachment_part,
+ attachment_stream,
+ attachment_content_type);
+ tny_stream_reset (attachment_stream);
+
+ tny_mime_part_set_filename (attachment_part, attachment_filename);
+
+ tny_mime_part_add_part (TNY_MIME_PART (msg), attachment_part);
+/* g_object_unref (attachment_part); */
+ }
+}
+
gchar *
modest_tny_msg_get_body (TnyMsg *msg, gboolean want_html)
return modest_tny_msg_find_body_part_from_mime_part (TNY_MIME_PART(msg),
want_html);
}
+
+
+
+static gboolean
+is_ascii(const gchar *s)
+{
+ while (s[0]) {
+ if (s[0] & 128 || s[0] < 32)
+ return FALSE;
+ s++;
+ }
+ return TRUE;
+}
+
+static char *
+get_content_type(const gchar *s)
+{
+ GString *type;
+
+ type = g_string_new("text/plain");
+ if (!is_ascii(s)) {
+ if (g_utf8_validate(s, -1, NULL)) {
+ g_string_append(type, "; charset=\"utf-8\"");
+ } else {
+ /* it should be impossible to reach this, but better safe than sorry */
+ g_warning("invalid utf8 in message");
+ g_string_append(type, "; charset=\"latin1\"");
+ }
+ }
+ return g_string_free(type, FALSE);
+}
#define __MODEST_TNY_MSG_H__
/**
+ * modest_tny_msg_new:
+ * @mailto: recipient for the message
+ * @mailfrom: sender of this message
+ * @cc: Cc: address for the message
+ * @bcc: Bcc: address for the message
+ * @subject: subject for the messdage
+ * @body: body for the message
+ * @attachments: a list of attachments (local URIs)
+ *
+ * create a new TnyMsg with the given parameters
+ *
+ * Returns: a new TnyMsg (free with g_object_unref)
+ */
+TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gchar *cc,
+ const gchar *bcc, const gchar* subject, const gchar *body,
+ GSList *attachments);
+
+/**
* modest_tny_msg_find_body_part:
* @self: a message
* @want_html: prefer HTML-part when there are multiple body parts?