* Review dimming rules to detect when modest is sedning mails.
[modest] / src / modest-tny-send-queue.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30
31 #include <modest-tny-send-queue.h>
32 #include <tny-simple-list.h>
33 #include <tny-iterator.h>
34 #include <tny-folder.h>
35 #include <tny-camel-msg.h>
36 #include <tny-folder-change.h>
37 #include <tny-folder-observer.h>
38 #include <modest-tny-account.h>
39 #include <modest-runtime.h>
40 #include <modest-platform.h>
41 #include <widgets/modest-window-mgr.h>
42 #include <modest-marshal.h>
43 #include <string.h> /* strcmp */
44
45 /* 'private'/'protected' functions */
46 static void modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass);
47 static void modest_tny_send_queue_finalize   (GObject *obj);
48 static void modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class);
49
50 /* Signal handlers */ 
51 static void _on_msg_start_sending (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, int done, int total, gpointer user_data);
52 static void _on_msg_has_been_sent (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, int done, int total, gpointer user_data);
53 static void _on_msg_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data);
54
55 static TnyFolder*modest_tny_send_queue_get_outbox (TnySendQueue *self);
56 static TnyFolder*modest_tny_send_queue_get_sentbox (TnySendQueue *self);
57
58 /* list my signals  */
59 enum {
60         STATUS_CHANGED,
61         /* MY_SIGNAL_1, */
62         /* MY_SIGNAL_2, */
63         LAST_SIGNAL
64 };
65
66 typedef struct _SendInfo SendInfo;
67 struct _SendInfo {
68         gchar* msg_id;
69         ModestTnySendQueueStatus status;
70 };
71
72 typedef struct _ModestTnySendQueuePrivate ModestTnySendQueuePrivate;
73 struct _ModestTnySendQueuePrivate {
74         /* Queued infos */
75         GQueue* queue;
76
77         /* The info that is currently being sent */
78         GList* current;
79 };
80
81 #define MODEST_TNY_SEND_QUEUE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
82                                                    MODEST_TYPE_TNY_SEND_QUEUE, \
83                                                    ModestTnySendQueuePrivate))
84
85 /* globals */
86 static TnyCamelSendQueueClass *parent_class = NULL;
87
88 /* uncomment the following if you have defined any signals */
89 static guint signals[LAST_SIGNAL] = {0};
90
91 /*
92  * this thread actually tries to send all the mails in the outbox and keeps
93  * track of their state.
94  */
95
96 static int
97 on_modest_tny_send_queue_compare_id(gconstpointer info, gconstpointer msg_id)
98 {
99         g_return_val_if_fail (info && ((SendInfo*)info)->msg_id && msg_id, -1);
100         
101         return strcmp( ((SendInfo*)info)->msg_id, msg_id);
102 }
103
104 static void
105 modest_tny_send_queue_info_free(SendInfo *info)
106 {
107         g_free(info->msg_id);
108         g_slice_free(SendInfo, info);
109 }
110
111 static GList*
112 modest_tny_send_queue_lookup_info (ModestTnySendQueue *self, const gchar *msg_id)
113 {
114         ModestTnySendQueuePrivate *priv;
115         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
116
117         return g_queue_find_custom (priv->queue, msg_id, on_modest_tny_send_queue_compare_id);
118 }
119
120 static void
121 modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err)
122 {
123         ModestTnySendQueuePrivate *priv;
124         SendInfo *info;
125         TnyIterator *iter = NULL;
126         TnyFolder *outbox = NULL;
127         TnyList *headers = tny_simple_list_new ();
128         TnyHeader *header = NULL;
129
130         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
131         if(priv->current != NULL)
132         {
133                 info = priv->current->data;
134                 priv->current = NULL;
135
136                 /* Keep in list until retry, so that we know that this was suspended
137                  * by the user and not by an error. */
138                 info->status = MODEST_TNY_SEND_QUEUE_SUSPENDED;
139
140                 g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
141         }
142
143         /* Set flags to supend sending operaiton (if removed, this is not necessary) */
144         if (!remove) {          
145                 outbox = modest_tny_send_queue_get_outbox (TNY_SEND_QUEUE(self));
146                 tny_folder_get_headers (outbox, headers, TRUE, err);
147                 if (err != NULL) goto frees;
148                 iter = tny_list_create_iterator (headers);
149                 while (!tny_iterator_is_done (iter)) {
150                         header = TNY_HEADER (tny_iterator_get_current (iter));
151                         if (header) {   
152                                 tny_header_unset_flags (header, TNY_HEADER_FLAG_PRIORITY);
153                                 tny_header_set_flags (header, TNY_HEADER_FLAG_SUSPENDED_PRIORITY);
154                                 tny_iterator_next (iter);
155                                 g_object_unref (header);
156                         }
157                 }
158                 
159                 g_queue_foreach (priv->queue, (GFunc)modest_tny_send_queue_info_free, NULL);
160                 g_queue_free (priv->queue);
161                 priv->queue = g_queue_new();
162         }
163                 
164         /* Dont call super class implementaiton, becasue camel removes messages from outbox */
165         TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->cancel_func (self, remove, err); /* FIXME */
166
167  frees:
168         if (headers != NULL)
169                 g_object_unref (G_OBJECT (headers));
170         if (outbox != NULL) 
171                 g_object_unref (G_OBJECT (outbox));
172         if (iter != NULL) 
173                 g_object_unref (iter);
174 }
175
176 static void
177 _on_added_to_outbox (TnySendQueue *self, gboolean cancelled, TnyMsg *msg, GError *err, gpointer user_data) 
178 {
179         ModestTnySendQueuePrivate *priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE(self);
180         TnyHeader *header = NULL;
181         SendInfo *info = NULL;
182         GList* existing = NULL;
183         const gchar* msg_id = NULL;
184
185         g_return_if_fail (TNY_IS_SEND_QUEUE(self));
186         g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
187
188         header = tny_msg_get_header (msg);
189         msg_id = modest_tny_send_queue_get_msg_id (header);
190 /*      msg_id = tny_header_get_message_id (header); */
191         g_return_if_fail(msg_id != NULL);
192
193         /* Put newly added message in WAITING state */
194         existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
195         if(existing != NULL)
196         {
197                 //g_assert(info->status == MODEST_TNY_SEND_QUEUE_SUSPENDED ||
198                 //        info->status == MODEST_TNY_SEND_QUEUE_FAILED);
199
200                 info = existing->data;
201                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
202         }
203         else
204         {
205                 
206                 info = g_slice_new (SendInfo);
207
208                 info->msg_id = strdup(msg_id);
209                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
210                 g_queue_push_tail (priv->queue, info);
211         }
212
213         g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
214
215         g_object_unref(G_OBJECT(header));
216 }
217
218 void
219 modest_tny_send_queue_add (ModestTnySendQueue *self, TnyMsg *msg, GError **err)
220 {
221         g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE(self));
222         g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
223
224         tny_send_queue_add_async (TNY_SEND_QUEUE(self), 
225                                   msg, 
226                                   _on_added_to_outbox, 
227                                   NULL, 
228                                   NULL);
229 }
230
231
232 static void
233 _add_message (ModestTnySendQueue *self, TnyHeader *header)
234 {
235         ModestWindowMgr *mgr = NULL;
236         ModestTnySendQueuePrivate *priv;
237         SendInfo *info = NULL;
238         GList* existing = NULL;
239         gchar* msg_uid = NULL;
240         ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_WAITING;
241         gboolean editing = FALSE;
242
243         g_return_if_fail (TNY_IS_SEND_QUEUE(self));
244         g_return_if_fail (TNY_IS_HEADER(header));
245         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
246         
247         /* Check whether the mail is already in the queue */
248         msg_uid = modest_tny_send_queue_get_msg_id (header);
249         status = modest_tny_send_queue_get_msg_status (self, msg_uid);
250         switch (status) {
251         case MODEST_TNY_SEND_QUEUE_UNKNONW:
252         case MODEST_TNY_SEND_QUEUE_SUSPENDED:
253         case MODEST_TNY_SEND_QUEUE_FAILED:
254                 if (status != MODEST_TNY_SEND_QUEUE_SUSPENDED)
255                         tny_header_unset_flags (header, TNY_HEADER_FLAG_PRIORITY);
256                 
257                 /* Check if it already exists on queue */
258                 existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_uid);
259                 if(existing != NULL)
260                         break;
261                 
262                 /* Check if its being edited */
263                 mgr = modest_runtime_get_window_mgr ();
264                 editing = modest_window_mgr_find_registered_header (mgr, header, NULL);
265                 if (editing)
266                         break;
267                 
268                 /* Add new meesage info */
269                 info = g_slice_new (SendInfo);
270                 info->msg_id = strdup(msg_uid);
271                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
272                 g_queue_push_tail (priv->queue, info);
273                 break;
274         default:
275                 break;
276         }
277
278         /* Free */
279         g_free(msg_uid);
280 }
281
282 static TnyFolder*
283 modest_tny_send_queue_get_sentbox (TnySendQueue *self)
284 {
285         TnyFolder *folder;
286         TnyCamelTransportAccount *account;
287
288         g_return_val_if_fail (self, NULL);
289
290         account = tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE(self));
291         if (!account) {
292                 g_printerr ("modest: no account for send queue\n");
293                 return NULL;
294         }
295         folder  = modest_tny_account_get_special_folder (TNY_ACCOUNT(account),
296                                                          TNY_FOLDER_TYPE_SENT);
297         g_object_unref (G_OBJECT(account));
298
299         return folder;
300 }
301
302
303 static TnyFolder*
304 modest_tny_send_queue_get_outbox (TnySendQueue *self)
305 {
306         TnyFolder *folder;
307         TnyCamelTransportAccount *account;
308
309         g_return_val_if_fail (self, NULL);
310
311         account = tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE(self));
312         if (!account) {
313                 g_printerr ("modest: no account for send queue\n");
314                 return NULL;
315         }
316         folder  = modest_tny_account_get_special_folder (TNY_ACCOUNT(account),
317                                                          TNY_FOLDER_TYPE_OUTBOX);
318
319         /* This vfunc's tinymail contract does not allow it to return NULL. */
320         if (!folder) {
321                 g_warning("%s: Returning NULL.\n", __FUNCTION__);
322         }
323
324         g_object_unref (G_OBJECT(account));
325
326         return folder;
327 }
328
329 GType
330 modest_tny_send_queue_get_type (void)
331 {
332         static GType my_type = 0;
333
334         if (my_type == 0) {
335                 static const GTypeInfo my_info = {
336                         sizeof(ModestTnySendQueueClass),
337                         NULL,           /* base init */
338                         NULL,           /* base finalize */
339                         (GClassInitFunc) modest_tny_send_queue_class_init,
340                         NULL,           /* class finalize */
341                         NULL,           /* class data */
342                         sizeof(ModestTnySendQueue),
343                         0,              /* n_preallocs */
344                         (GInstanceInitFunc) modest_tny_send_queue_instance_init,
345                         NULL
346                 };
347                 
348                 my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
349                                                   "ModestTnySendQueue",
350                                                   &my_info, 0);
351         }
352         return my_type;
353 }
354
355
356 static void
357 modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
358 {
359         GObjectClass *gobject_class;
360
361         gobject_class = (GObjectClass*) klass;
362         
363         parent_class            = g_type_class_peek_parent (klass);
364         gobject_class->finalize = modest_tny_send_queue_finalize;
365
366         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func  = modest_tny_send_queue_get_outbox;
367         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox;
368         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func      = modest_tny_send_queue_cancel;
369         klass->status_changed   = NULL;
370
371         signals[STATUS_CHANGED] =
372                 g_signal_new ("status_changed",
373                               G_TYPE_FROM_CLASS (gobject_class),
374                               G_SIGNAL_RUN_FIRST,
375                               G_STRUCT_OFFSET (ModestTnySendQueueClass, status_changed),
376                               NULL, NULL,
377                               modest_marshal_VOID__STRING_INT,
378                               G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
379
380         g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
381 }
382
383 static void
384 modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
385 {
386         ModestTnySendQueuePrivate *priv;
387
388         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (instance);
389         priv->queue = g_queue_new();
390         priv->current = NULL;
391 }
392
393 static void
394 modest_tny_send_queue_finalize (GObject *obj)
395 {
396         ModestTnySendQueuePrivate *priv;
397                 
398         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (obj);
399
400         g_queue_foreach (priv->queue, (GFunc)modest_tny_send_queue_info_free, NULL);
401         g_queue_free (priv->queue);
402
403         G_OBJECT_CLASS(parent_class)->finalize (obj);
404 }
405
406 ModestTnySendQueue*
407 modest_tny_send_queue_new (TnyCamelTransportAccount *account)
408 {
409         ModestTnySendQueue *self;
410         
411         g_return_val_if_fail (TNY_IS_CAMEL_TRANSPORT_ACCOUNT(account), NULL);
412         
413         self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL));
414         
415         tny_camel_send_queue_set_transport_account (TNY_CAMEL_SEND_QUEUE(self),
416                                                     account); 
417
418         /* Connect signals to control when a msg is being or has been sent */
419         g_signal_connect (G_OBJECT(self), "msg-sending",
420                           G_CALLBACK(_on_msg_start_sending),
421                           NULL);                          
422         g_signal_connect (G_OBJECT(self), "msg-sent",
423                           G_CALLBACK(_on_msg_has_been_sent), 
424                           NULL);
425         g_signal_connect (G_OBJECT(self), "error-happened",
426                           G_CALLBACK(_on_msg_error_happened),
427                           NULL);
428         return self;
429 }
430
431
432
433 void
434 modest_tny_send_queue_try_to_send (ModestTnySendQueue* self)
435 {
436         TnyIterator *iter = NULL;
437         TnyFolder *outbox = NULL;
438         TnyList *headers = tny_simple_list_new ();
439         TnyHeader *header = NULL;
440         GError *err = NULL;
441
442         outbox = modest_tny_send_queue_get_outbox (TNY_SEND_QUEUE(self));
443         if (!outbox)
444                 return;
445
446         tny_folder_get_headers (outbox, headers, TRUE, &err);
447         if (err != NULL) 
448                 goto frees;
449
450         iter = tny_list_create_iterator (headers);
451         while (!tny_iterator_is_done (iter)) {
452                 header = TNY_HEADER (tny_iterator_get_current (iter));
453                 if (header) {   
454                         _add_message (self, header); 
455                         g_object_unref (header);
456                 }
457
458                 tny_iterator_next (iter);
459         }
460         
461         /* Flush send queue */
462         tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE(self));
463
464  frees:
465         if (headers != NULL)
466                 g_object_unref (G_OBJECT (headers));
467         if (outbox != NULL) 
468                 g_object_unref (G_OBJECT (outbox));
469         if (iter != NULL) 
470                 g_object_unref (iter);
471 }
472
473 gboolean
474 modest_tny_send_queue_msg_is_being_sent (ModestTnySendQueue* self,
475                                          const gchar *msg_id)
476 {       
477         ModestTnySendQueueStatus status;
478         
479         g_return_val_if_fail (msg_id != NULL, FALSE); 
480         
481         status = modest_tny_send_queue_get_msg_status (self, msg_id);
482         return status == MODEST_TNY_SEND_QUEUE_SENDING;
483 }
484
485 gboolean
486 modest_tny_send_queue_sending_in_progress (ModestTnySendQueue* self)
487 {       
488         ModestTnySendQueuePrivate *priv;
489         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
490         
491         return priv->current != NULL;
492 }
493
494 ModestTnySendQueueStatus
495 modest_tny_send_queue_get_msg_status (ModestTnySendQueue *self, const gchar *msg_id)
496 {
497   GList *item;
498   item = modest_tny_send_queue_lookup_info (self, msg_id);
499   if(item == NULL) return MODEST_TNY_SEND_QUEUE_UNKNONW;
500   return ((SendInfo*)item->data)->status;
501 }
502
503 gchar *
504 modest_tny_send_queue_get_msg_id (TnyHeader *header)
505 {
506         const gchar *uid = NULL;
507         gchar* msg_uid = NULL;
508         gchar **tmp = NULL;
509                 
510         /* Get message uid */
511         uid = tny_header_get_uid (header);
512         if (uid)
513                 tmp = g_strsplit (uid, "__", 2);
514         
515         if (tmp) {
516                 if (tmp[1] != NULL) 
517                         msg_uid = g_strconcat (tmp[0], "_", NULL);
518                 else 
519                         msg_uid = g_strdup(tmp[0]);
520
521                 /* free */
522                 g_strfreev(tmp);
523         }
524
525         return msg_uid;
526 }
527
528
529 static void
530 _on_msg_start_sending (TnySendQueue *self,
531                        TnyHeader *header,
532                        TnyMsg *msg,
533                        int done, 
534                        int total,
535                        gpointer user_data)
536 {
537         ModestTnySendQueuePrivate *priv = NULL;
538         GList *item = NULL;
539         SendInfo *info = NULL;
540         gchar *msg_id = NULL;
541
542         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
543         
544         /* Get message uid */
545         msg_id = modest_tny_send_queue_get_msg_id (header);
546
547         /* Get status info */
548         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
549         if (!item) 
550                 g_warning  ("%s: item should not be NULL", __FUNCTION__);
551         else {
552                 info = item->data;
553                 info->status = MODEST_TNY_SEND_QUEUE_SENDING;
554                 
555                 /* Set current status item */
556                 g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
557                 priv->current = item;
558         }
559
560         /* free */
561         g_free (msg_id);
562 }
563
564 static void 
565 _on_msg_has_been_sent (TnySendQueue *self,
566                        TnyHeader *header,
567                        TnyMsg *msg, 
568                        int done, 
569                        int total,
570                        gpointer user_data)
571 {
572         ModestTnySendQueuePrivate *priv;
573         GList *item;
574         gchar *msg_id = NULL;
575
576         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
577
578         /* Get message uid */
579         msg_id = modest_tny_send_queue_get_msg_id (header);
580         
581         /* Get status info */
582         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
583         if (!item)
584                 g_warning ("%s: item should not be NULL", __FUNCTION__);
585         else {
586
587                 /* Remove status info */
588                 modest_tny_send_queue_info_free (item->data);
589                 g_queue_delete_link (priv->queue, item);
590                 priv->current = NULL;
591                 
592                 modest_platform_information_banner (NULL, NULL, _("mcen_ib_message_sent"));
593         }
594
595         /* free */
596         g_free(msg_id);
597 }
598
599 static void 
600 _on_msg_error_happened (TnySendQueue *self,
601                         TnyHeader *header,
602                         TnyMsg *msg,
603                         GError *err,
604                         gpointer user_data)
605 {
606         ModestTnySendQueuePrivate *priv = NULL;
607         SendInfo *info = NULL;
608         GList *item = NULL;
609         gchar* msg_uid = NULL;
610         
611         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
612         
613         /* Get sending info (create new if it doesn not exist) */
614         msg_uid = modest_tny_send_queue_get_msg_id (header);
615         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), 
616                                                   msg_uid);     
617         if (item == NULL) {
618                 info = g_slice_new (SendInfo);
619                 info->msg_id = strdup(msg_uid);
620                 g_queue_push_tail (priv->queue, info);
621         } else
622                 info = item->data;
623
624         /* Keep in queue so that we remember that the opertion has failed */
625         /* and was not just cancelled */
626         info->status = MODEST_TNY_SEND_QUEUE_FAILED;
627         
628         /* Notify status has changed */
629         g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
630
631         /* free */
632         g_free(msg_uid);
633 }