+
+ /* 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);
+ existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
+ if(existing != NULL)
+ {
+ //g_assert(info->status == MODEST_TNY_SEND_QUEUE_SUSPENDED ||
+ // info->status == MODEST_TNY_SEND_QUEUE_FAILED);
+
+ info = existing->data;
+ info->status = MODEST_TNY_SEND_QUEUE_WAITING;
+ }
+ else
+ {
+
+ info = g_slice_new (SendInfo);
+
+ info->msg_id = strdup(msg_id);
+ info->status = MODEST_TNY_SEND_QUEUE_WAITING;
+ g_queue_push_tail (priv->queue, info);
+ }
+
+ g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
+}
+
+static void
+_add_message (ModestTnySendQueue *self, TnyHeader *header)
+{
+ ModestTnySendQueuePrivate *priv;
+ SendInfo *info = NULL;
+ GList* existing = NULL;
+ gchar* msg_uid = NULL;
+ ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_WAITING;
+
+ g_return_if_fail (TNY_IS_SEND_QUEUE(self));
+ g_return_if_fail (TNY_IS_HEADER(header));
+ priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
+
+ /* Check whether the mail is already in the queue */
+ msg_uid = modest_tny_send_queue_get_msg_id (header);
+ status = modest_tny_send_queue_get_msg_status (self, msg_uid);
+ switch (status) {
+ case MODEST_TNY_SEND_QUEUE_UNKNONW:
+ case MODEST_TNY_SEND_QUEUE_SUSPENDED:
+ case MODEST_TNY_SEND_QUEUE_FAILED:
+ if (status != MODEST_TNY_SEND_QUEUE_SUSPENDED)
+ tny_header_unset_flags (header, TNY_HEADER_FLAG_PRIORITY);
+ existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_uid);
+ if(existing != NULL) return;
+
+ /* Add new meesage info */
+ info = g_slice_new (SendInfo);
+ info->msg_id = strdup(msg_uid);
+ info->status = MODEST_TNY_SEND_QUEUE_WAITING;
+ g_queue_push_tail (priv->queue, info);
+ break;
+ default:
+ goto frees;
+ }
+
+ /* Free */
+ frees:
+ g_free(msg_uid);