#include <tny-iterator.h>
#include <tny-folder.h>
#include <tny-camel-msg.h>
+#include <tny-folder-change.h>
+#include <tny-folder-observer.h>
#include <modest-tny-account.h>
#include <modest-runtime.h>
+#include <modest-platform.h>
#include <widgets/modest-window-mgr.h>
#include <modest-marshal.h>
#include <string.h> /* strcmp */
static int
on_modest_tny_send_queue_compare_id(gconstpointer info, gconstpointer msg_id)
{
+ g_return_val_if_fail (info && ((SendInfo*)info)->msg_id && msg_id, -1);
+
return strcmp( ((SendInfo*)info)->msg_id, msg_id);
}
static void
modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err)
{
- ModestTnySendQueuePrivate *priv;
+ ModestTnySendQueuePrivate *priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE(self);
TnyHeader *header = NULL;
SendInfo *info = NULL;
GList* existing = NULL;
g_return_if_fail (TNY_IS_SEND_QUEUE(self));
g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
- priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
- header = tny_msg_get_header (msg);
-
- /* Note that this call actually sets the message id to something
- * sensible. */
TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg, err); /* FIXME */
- /* Check whether the mail is already in the queue */
-/* msg_id = tny_header_get_message_id (header); */
- msg_id = tny_header_get_uid (header);
- g_return_if_fail (msg_id != NULL);
+ /* TODO: We cannot access the message ID of the message here because
+ * it might just have been created. Wait for it being added to outbox. */
+
+ header = tny_msg_get_header (msg);
+ msg_id = tny_header_get_message_id (header);
+ g_return_if_fail(msg_id != NULL);
+
+ /* Put newly added message in WAITING state */
existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
if(existing != NULL)
{
g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
- /* free */
- g_object_unref (header);
+ g_object_unref(G_OBJECT(header));
}
static void
/* Check if it already exists on queue */
existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_uid);
- if(existing != NULL) return;
-
+ if(existing != NULL)
+ break;
+
/* Check if its being edited */
mgr = modest_runtime_get_window_mgr ();
editing = modest_window_mgr_find_registered_header (mgr, header, NULL);
- if (editing) return;
+ if (editing)
+ break;
/* Add new meesage info */
info = g_slice_new (SendInfo);
g_queue_push_tail (priv->queue, info);
break;
default:
- goto frees;
+ break;
}
/* Free */
- frees:
g_free(msg_uid);
}
(GInstanceInitFunc) modest_tny_send_queue_instance_init,
NULL
};
+
my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
"ModestTnySendQueue",
&my_info, 0);
GError *err = NULL;
outbox = modest_tny_send_queue_get_outbox (TNY_SEND_QUEUE(self));
+ if (!outbox)
+ return;
+
tny_folder_get_headers (outbox, headers, TRUE, &err);
- if (err != NULL) goto frees;
+ if (err != NULL)
+ goto frees;
+
iter = tny_list_create_iterator (headers);
while (!tny_iterator_is_done (iter)) {
header = TNY_HEADER (tny_iterator_get_current (iter));
/* Get message uid */
uid = tny_header_get_uid (header);
- tmp = g_strsplit (uid, "__", 2);
- if (tmp[1] != NULL)
- msg_uid = g_strconcat (tmp[0], "_", NULL);
- else
- msg_uid = g_strdup(tmp[0]);
-
- /* free */
- g_strfreev(tmp);
+ if (uid)
+ tmp = g_strsplit (uid, "__", 2);
+
+ if (tmp) {
+ if (tmp[1] != NULL)
+ msg_uid = g_strconcat (tmp[0], "_", NULL);
+ else
+ msg_uid = g_strdup(tmp[0]);
+
+ /* free */
+ g_strfreev(tmp);
+ }
return msg_uid;
}
/* Get status info */
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
- g_return_if_fail (item != NULL);
- info = item->data;
- info->status = MODEST_TNY_SEND_QUEUE_SENDING;
-
- /* Set current status item */
- g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
- priv->current = item;
+ if (!item)
+ g_warning ("%s: item should not be NULL", __FUNCTION__);
+ else {
+ info = item->data;
+ info->status = MODEST_TNY_SEND_QUEUE_SENDING;
+
+ /* Set current status item */
+ g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
+ priv->current = item;
+ }
/* free */
g_free (msg_id);
/* Get status info */
item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
- g_return_if_fail(item != NULL);
+ if (!item)
+ g_warning ("%s: item should not be NULL", __FUNCTION__);
+ else {
- /* Remove status info */
- modest_tny_send_queue_info_free (item->data);
- g_queue_delete_link (priv->queue, item);
- priv->current = NULL;
+ /* Remove status info */
+ modest_tny_send_queue_info_free (item->data);
+ g_queue_delete_link (priv->queue, item);
+ priv->current = NULL;
+
+ modest_platform_information_banner (NULL, NULL, _("mcen_ib_message_sent"));
+ }
/* free */
g_free(msg_id);
info = g_slice_new (SendInfo);
info->msg_id = strdup(msg_uid);
g_queue_push_tail (priv->queue, info);
- }
- else {
+ } else
info = item->data;
- }
/* Keep in queue so that we remember that the opertion has failed */
/* and was not just cancelled */