+ /* Note that header could be NULL. Tinymail notifies about
+ generic send queue errors with this signal as well, and
+ those notifications are not bound to any particular header
+ or message */
+ if (header && TNY_IS_HEADER (header)) {
+ SendInfo *info = NULL;
+ GList *item = NULL;
+ gchar* msg_uid = NULL;
+
+ /* Get sending info (create new if it doesn not exist) */
+ msg_uid = modest_tny_send_queue_get_msg_id (header);
+ item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self),
+ msg_uid);
+
+ /* TODO: this should not happen (but it does), so the
+ problem should be located in the way we generate
+ the message uids */
+ if (!item) {
+ g_warning ("%s: could not find item with id '%s'", __FUNCTION__, msg_uid);
+ g_free(msg_uid);
+ return;
+ }
+
+ info = item->data;
+
+ /* Keep in queue so that we remember that the opertion has failed */
+ /* and was not just cancelled */
+ if (err->code == TNY_SYSTEM_ERROR_CANCEL) {
+ info->status = MODEST_TNY_SEND_QUEUE_SUSPENDED;
+ } else {
+ info->status = MODEST_TNY_SEND_QUEUE_FAILED;
+ }
+ priv->current = NULL;
+
+ /* Notify status has changed */
+ g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
+
+ /* free */
+ g_free(msg_uid);
+ }
+}
+
+static void
+_on_queue_start (TnySendQueue *self,
+ gpointer data)
+{
+ ModestTnySendQueuePrivate *priv;
+ ModestMailOperation *mail_op;
+
+ mail_op = modest_mail_operation_new (NULL);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ mail_op);
+ modest_mail_operation_run_queue (mail_op, MODEST_TNY_SEND_QUEUE (self));
+ g_object_unref (mail_op);
+
+ priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ priv->sending = TRUE;
+}
+
+static void
+_on_queue_stop (TnySendQueue *self,
+ gpointer data)
+{
+ ModestTnySendQueuePrivate *priv;
+
+ priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+ priv->sending = FALSE;