* Fixes NB#81719, modest is no longer crashing when the send queue notifies errors...
[modest] / src / modest-tny-send-queue.c
index 9db9a6f..480d4ea 100644 (file)
@@ -442,8 +442,7 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account)
        modest_tny_send_queue_wakeup (self);
 
        /* Frees */
-       g_object_unref (G_OBJECT (headers));
-       g_object_unref (G_OBJECT (priv->outbox));
+       g_object_unref (headers);
        g_object_unref (iter);
 
        /* Do this at the end, because it'll call tny_send_queue_flush
@@ -514,12 +513,8 @@ modest_tny_send_queue_get_msg_id (TnyHeader *header)
 
 
 static void
-_on_msg_start_sending (TnySendQueue *self,
-                      TnyHeader *header,
-                      TnyMsg *msg,
-                      int done, 
-                      int total,
-                      gpointer user_data)
+_on_msg_start_sending (TnySendQueue *self, TnyHeader *header,
+                      TnyMsg *msg, int done, int total, gpointer user_data)
 {
        ModestTnySendQueuePrivate *priv = NULL;
        GList *item = NULL;
@@ -530,16 +525,20 @@ _on_msg_start_sending (TnySendQueue *self,
        
        /* Get message uid */
        msg_id = modest_tny_send_queue_get_msg_id (header);
-
-       /* Get status info */
-       item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
-
-       /* Set current status item */
-       info = item->data;
-       info->status = MODEST_TNY_SEND_QUEUE_SENDING;
-       g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
-       priv->current = item;
-
+       if (msg_id) 
+               item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
+       else
+               g_warning ("%s: could not get msg-id for header", __FUNCTION__);
+       
+       if (item) {
+               /* Set current status item */
+               info = item->data;
+               info->status = MODEST_TNY_SEND_QUEUE_SENDING;
+               g_signal_emit (self, signals[STATUS_CHANGED_SIGNAL], 0, info->msg_id, info->status);
+               priv->current = item;
+       } else
+               g_warning ("%s: could not find item with id '%s'", __FUNCTION__, msg_id);
+       
        /* free */
        g_free (msg_id);
 }
@@ -592,18 +591,8 @@ _on_msg_error_happened (TnySendQueue *self,
                        gpointer user_data)
 {
        ModestTnySendQueuePrivate *priv = NULL;
-       SendInfo *info = NULL;
-       GList *item = NULL;
-       gchar* msg_uid = NULL;
        
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
-       
-       /* 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);     
-
-       info = item->data;
 
        /* Keep in queue so that we remember that the opertion has failed */
        /* and was not just cancelled */
@@ -612,12 +601,29 @@ _on_msg_error_happened (TnySendQueue *self,
        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);
+       /* 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) {
+               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);     
+               
+               info = item->data;
+               
+               /* 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 
@@ -749,7 +755,7 @@ modest_tny_send_queue_wakeup (ModestTnySendQueue *self)
        }
 
        /* Make changes persistent on disk */
-       tny_folder_sync (priv->outbox, FALSE, NULL);
+       tny_folder_sync_async (priv->outbox, FALSE, NULL, NULL, NULL);
 
        /* Frees */
        g_object_unref (iter);