2007-05-25 Murray Cumming <murrayc@murrayc.com>
* src/modest-tny-account.c:
+ (modest_tny_account_new_from_server_account):
+ Call modest_runtime_get_send_queue() immediately after creating transport
+ accounts, so that they start trying to send email from the outbox as soon
+ as possible at startup. This is probably what we want.
+
+ * src/modest-mail-operation.c: (update_account_thread):
+ * src/modest-runtime.c: (modest_runtime_get_send_queue):
+ * src/modest-tny-send-queue.c: (modest_tny_send_queue_try_to_send):
+ * src/modest-tny-send-queue.h:
+ * src/modest-ui-actions.c: (modest_ui_actions_do_send_receive),
+ (modest_ui_actions_on_send):
+ Added comments about how sending works, though it needs some more work.
+
+2007-05-25 Murray Cumming <murrayc@murrayc.com>
+
+ * src/modest-tny-account.c:
(modest_tny_account_get_special_folder): Add TODO because this fails when
the network is busy.
(modest_tny_folder_store_get_local_size): Fix an incorrect type check.
TnyIterator *iter = NULL;
TnyFolderStoreQuery *query = NULL;
ModestMailOperationPrivate *priv;
- ModestTnySendQueue *send_queue;
- gint timeout, msg_num;
info = (UpdateAccountInfo *) thr_user_data;
priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
Gtk+. We use a timeout in order to provide more status
information, because the sync tinymail call does not
provide it for the moment */
- timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
+ gint timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
/* Refresh folders */
new_headers = tny_simple_list_new ();
/* Apply message count limit */
/* TODO if the number of messages exceeds the maximum, ask the
user to download them all */
- msg_num = 0;
+ gint msg_num = 0;
priv->total = MIN (tny_list_get_length (new_headers), info->retrieve_limit);
iter = tny_list_create_iterator (new_headers);
while ((msg_num < info->retrieve_limit) && !tny_iterator_is_done (iter)) {
g_object_unref (iter);
g_object_unref (new_headers);
+
/* Perform send */
priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
priv->done = 0;
priv->total = 0;
- send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(info->transport_account));
+ ModestTnySendQueue *send_queue = modest_runtime_get_send_queue
+ (info->transport_account);
timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
- modest_tny_send_queue_flush (send_queue);
+ /* TODO: Is this meant to block? */
+ modest_tny_send_queue_try_to_send (send_queue);
g_source_remove (timeout);
g_object_unref (G_OBJECT(send_queue));
ModestTnySendQueue*
modest_runtime_get_send_queue (TnyTransportAccount *account)
{
+ /* printf ("DEBUG: %s: transport account id=%s\n", __FUNCTION__, tny_account_get_id (TNY_ACCOUNT(account))); */
ModestCacheMgr *cache_mgr;
GHashTable *send_queue_cache;
gpointer orig_key, send_queue;
send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+ /* Each transport account has its own send queue.
+ * Note that each transport account will have its own outbox folder,
+ * returned by TnySendQueue::get_outbox_func().
+ */
if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
+ /* Note that this send queue will start sending messages from its outbox
+ * as soon as it is instantiated: */
send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
+
g_hash_table_insert (send_queue_cache, account, send_queue);
}
g_free (url);
/***********************/
+ /* For transport accounts, now is a good time to create the send queues,
+ * so that the send queues start trying as soon as possible to send any
+ * messages that are already in their outboxes: */
+ if ( (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SENDMAIL) ||
+ (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP) ) {
+ /* modest_runtime_get_send_queue() instantiates and stores the send queue: */
+ modest_runtime_get_send_queue( TNY_TRANSPORT_ACCOUNT (tny_account));
+ }
+
return tny_account;
}
void
-modest_tny_send_queue_flush (ModestTnySendQueue* self)
+modest_tny_send_queue_try_to_send (ModestTnySendQueue* self)
{
+ /* TODO: Rename this to tny_camel_send_queue_try_to_send() in tinymail
+ and check that it works, without creating a second worker. */
/* tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE(self)); */
}
/**
- * modest_tny_send_queue_flush:
+ * modest_tny_send_queue_try_to_send:
* @self: a valid #ModestTnySendQueue instance
*
- * (try to) send the messages in the outbox folder
- *
+ * Try to send the messages that are in the queue's outbox folder.
+ * This is not always necessary because the queue tries to send
+ * messages as soon as a message is added, and as soon as the queue
+ * is instantiated.
*/
-void modest_tny_send_queue_flush (ModestTnySendQueue* self);
+void modest_tny_send_queue_try_to_send (ModestTnySendQueue* self);
G_END_DECLS
/*
* This function performs the send & receive required actions. The
- * window it's used to create the mail operation. Tipically it should
- * be allways the main window, but we pass it as argument in order to
+ * window is used to create the mail operation. Typically it should
+ * always be the main window, but we pass it as argument in order to
* be more flexible.
*/
void
{
gchar *acc_name = NULL;
- /* If no account name was provided get the current account, if
- there is none either then pick the default one */
+ /* If no account name was provided then get the current account, and if
+ there is no current account then pick the default one: */
if (!account_name) {
acc_name = g_strdup (modest_window_get_active_account(win));
if (!acc_name)
*/
/* As per the UI spec,
- * for POP accounts, we should receive,
- * for IMAP we should synchronize everything, including receiving,
- * for SMTP we should send,
- * first receiving, then sending:
+ * Store:
+ * - for POP accounts, we should receive,
+ * - for IMAP we should synchronize everything, including receiving,
+ * Transport:
+ * - for SMTP we should send.
+ * First receiving (store), then sending (transport):
*/
- /* Create the mail operation */
/* TODO: The spec wants us to first do any pending deletions, before receiving. */
+
+ /* Receive, by creating the mail operation */
ModestMailOperation *mail_op;
mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
void
modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
{
- TnyTransportAccount *transport_account;
- ModestMailOperation *mail_operation;
- MsgData *data;
- gchar *account_name, *from;
- ModestAccountMgr *account_mgr;
-
g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
if (!modest_msg_edit_window_check_names (edit_window))
return;
- data = modest_msg_edit_window_get_msg_data (edit_window);
-
/* FIXME: Code added just for testing. The final version will
use the send queue provided by tinymail and some
classifier */
- account_mgr = modest_runtime_get_account_mgr();
- account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
+ ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
+ gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
if (!account_name)
account_name = modest_account_mgr_get_default_account (account_mgr);
+
if (!account_name) {
g_printerr ("modest: no account found\n");
- modest_msg_edit_window_free_msg_data (edit_window, data);
return;
}
- transport_account =
+
+ /* Get the currently-active transport account for this modest account: */
+ TnyTransportAccount *transport_account =
TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
(modest_runtime_get_account_store(),
account_name));
if (!transport_account) {
g_printerr ("modest: no transport account found for '%s'\n", account_name);
g_free (account_name);
- modest_msg_edit_window_free_msg_data (edit_window, data);
return;
}
- from = modest_account_mgr_get_from_string (account_mgr, account_name);
+
+ gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
- /* Create the mail operation */
- mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
+ /* Create the mail operation */
+ ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
+ MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
modest_mail_operation_send_new_mail (mail_operation,
transport_account,
from,
data->html_body,
data->attachments,
data->priority_flags);
- /* Frees */
+
+ /* Free data: */
g_free (from);
g_free (account_name);
g_object_unref (G_OBJECT (transport_account));
modest_msg_edit_window_free_msg_data (edit_window, data);
- /* Save settings and close the window */
+ /* Save settings and close the window: */
gtk_widget_destroy (GTK_WIDGET (edit_window));
}