* fix some mem leaks (50Kb after clicking around a bit, according to valgrind)
[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 modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg, GError **err)
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         TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->add_func (self, msg, err); /* FIXME */
189
190         /* TODO: We cannot access the message ID of the message here because
191          * it might  just have been created. Wait for it being added to outbox. */
192
193         header = tny_msg_get_header (msg);
194         msg_id = tny_header_get_message_id (header);
195         g_return_if_fail(msg_id != NULL);
196
197         /* Put newly added message in WAITING state */
198         existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_id);
199         if(existing != NULL)
200         {
201                 //g_assert(info->status == MODEST_TNY_SEND_QUEUE_SUSPENDED ||
202                 //        info->status == MODEST_TNY_SEND_QUEUE_FAILED);
203
204                 info = existing->data;
205                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
206         }
207         else
208         {
209                 
210                 info = g_slice_new (SendInfo);
211
212                 info->msg_id = strdup(msg_id);
213                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
214                 g_queue_push_tail (priv->queue, info);
215         }
216
217         g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
218
219         g_object_unref(G_OBJECT(header));
220 }
221
222 static void
223 _add_message (ModestTnySendQueue *self, TnyHeader *header)
224 {
225         ModestWindowMgr *mgr = NULL;
226         ModestTnySendQueuePrivate *priv;
227         SendInfo *info = NULL;
228         GList* existing = NULL;
229         gchar* msg_uid = NULL;
230         ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_WAITING;
231         gboolean editing = FALSE;
232
233         g_return_if_fail (TNY_IS_SEND_QUEUE(self));
234         g_return_if_fail (TNY_IS_HEADER(header));
235         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
236         
237         /* Check whether the mail is already in the queue */
238         msg_uid = modest_tny_send_queue_get_msg_id (header);
239         status = modest_tny_send_queue_get_msg_status (self, msg_uid);
240         switch (status) {
241         case MODEST_TNY_SEND_QUEUE_UNKNONW:
242         case MODEST_TNY_SEND_QUEUE_SUSPENDED:
243         case MODEST_TNY_SEND_QUEUE_FAILED:
244                 if (status != MODEST_TNY_SEND_QUEUE_SUSPENDED)
245                         tny_header_unset_flags (header, TNY_HEADER_FLAG_PRIORITY);
246                 
247                 /* Check if it already exists on queue */
248                 existing = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE(self), msg_uid);
249                 if(existing != NULL)
250                         break;
251                 
252                 /* Check if its being edited */
253                 mgr = modest_runtime_get_window_mgr ();
254                 editing = modest_window_mgr_find_registered_header (mgr, header, NULL);
255                 if (editing)
256                         break;
257                 
258                 /* Add new meesage info */
259                 info = g_slice_new (SendInfo);
260                 info->msg_id = strdup(msg_uid);
261                 info->status = MODEST_TNY_SEND_QUEUE_WAITING;
262                 g_queue_push_tail (priv->queue, info);
263                 break;
264         default:
265                 break;
266         }
267
268         /* Free */
269         g_free(msg_uid);
270 }
271
272 static TnyFolder*
273 modest_tny_send_queue_get_sentbox (TnySendQueue *self)
274 {
275         TnyFolder *folder;
276         TnyCamelTransportAccount *account;
277
278         g_return_val_if_fail (self, NULL);
279
280         account = tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE(self));
281         if (!account) {
282                 g_printerr ("modest: no account for send queue\n");
283                 return NULL;
284         }
285         folder  = modest_tny_account_get_special_folder (TNY_ACCOUNT(account),
286                                                          TNY_FOLDER_TYPE_SENT);
287         g_object_unref (G_OBJECT(account));
288
289         return folder;
290 }
291
292
293 static TnyFolder*
294 modest_tny_send_queue_get_outbox (TnySendQueue *self)
295 {
296         TnyFolder *folder;
297         TnyCamelTransportAccount *account;
298
299         g_return_val_if_fail (self, NULL);
300
301         account = tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE(self));
302         if (!account) {
303                 g_printerr ("modest: no account for send queue\n");
304                 return NULL;
305         }
306         folder  = modest_tny_account_get_special_folder (TNY_ACCOUNT(account),
307                                                          TNY_FOLDER_TYPE_OUTBOX);
308
309         /* This vfunc's tinymail contract does not allow it to return NULL. */
310         if (!folder) {
311                 g_warning("%s: Returning NULL.\n", __FUNCTION__);
312         }
313
314         g_object_unref (G_OBJECT(account));
315
316         return folder;
317 }
318
319 GType
320 modest_tny_send_queue_get_type (void)
321 {
322         static GType my_type = 0;
323
324         if (my_type == 0) {
325                 static const GTypeInfo my_info = {
326                         sizeof(ModestTnySendQueueClass),
327                         NULL,           /* base init */
328                         NULL,           /* base finalize */
329                         (GClassInitFunc) modest_tny_send_queue_class_init,
330                         NULL,           /* class finalize */
331                         NULL,           /* class data */
332                         sizeof(ModestTnySendQueue),
333                         0,              /* n_preallocs */
334                         (GInstanceInitFunc) modest_tny_send_queue_instance_init,
335                         NULL
336                 };
337                 
338                 my_type = g_type_register_static (TNY_TYPE_CAMEL_SEND_QUEUE,
339                                                   "ModestTnySendQueue",
340                                                   &my_info, 0);
341         }
342         return my_type;
343 }
344
345
346 static void
347 modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
348 {
349         GObjectClass *gobject_class;
350
351         gobject_class = (GObjectClass*) klass;
352         
353         parent_class            = g_type_class_peek_parent (klass);
354         gobject_class->finalize = modest_tny_send_queue_finalize;
355
356         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->add_func         = modest_tny_send_queue_add;
357         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_outbox_func  = modest_tny_send_queue_get_outbox;
358         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->get_sentbox_func = modest_tny_send_queue_get_sentbox;
359         TNY_CAMEL_SEND_QUEUE_CLASS(klass)->cancel_func      = modest_tny_send_queue_cancel;
360         klass->status_changed   = NULL;
361
362         signals[STATUS_CHANGED] =
363                 g_signal_new ("status_changed",
364                               G_TYPE_FROM_CLASS (gobject_class),
365                               G_SIGNAL_RUN_FIRST,
366                               G_STRUCT_OFFSET (ModestTnySendQueueClass, status_changed),
367                               NULL, NULL,
368                               modest_marshal_VOID__STRING_INT,
369                               G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
370
371         g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
372 }
373
374 static void
375 modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
376 {
377         ModestTnySendQueuePrivate *priv;
378
379         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (instance);
380         priv->queue = g_queue_new();
381         priv->current = NULL;
382 }
383
384 static void
385 modest_tny_send_queue_finalize (GObject *obj)
386 {
387         ModestTnySendQueuePrivate *priv;
388                 
389         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (obj);
390
391         g_queue_foreach (priv->queue, (GFunc)modest_tny_send_queue_info_free, NULL);
392         g_queue_free (priv->queue);
393
394         G_OBJECT_CLASS(parent_class)->finalize (obj);
395 }
396
397 ModestTnySendQueue*
398 modest_tny_send_queue_new (TnyCamelTransportAccount *account)
399 {
400         ModestTnySendQueue *self;
401         
402         g_return_val_if_fail (TNY_IS_CAMEL_TRANSPORT_ACCOUNT(account), NULL);
403         
404         self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL));
405         
406         tny_camel_send_queue_set_transport_account (TNY_CAMEL_SEND_QUEUE(self),
407                                                     account); 
408
409         /* Connect signals to control when a msg is being or has been sent */
410         g_signal_connect (G_OBJECT(self), "msg-sending",
411                           G_CALLBACK(_on_msg_start_sending),
412                           NULL);                          
413         g_signal_connect (G_OBJECT(self), "msg-sent",
414                           G_CALLBACK(_on_msg_has_been_sent), 
415                           NULL);
416         g_signal_connect (G_OBJECT(self), "error-happened",
417                           G_CALLBACK(_on_msg_error_happened),
418                           NULL);
419         return self;
420 }
421
422
423
424 void
425 modest_tny_send_queue_try_to_send (ModestTnySendQueue* self)
426 {
427         TnyIterator *iter = NULL;
428         TnyFolder *outbox = NULL;
429         TnyList *headers = tny_simple_list_new ();
430         TnyHeader *header = NULL;
431         GError *err = NULL;
432
433         outbox = modest_tny_send_queue_get_outbox (TNY_SEND_QUEUE(self));
434         if (!outbox)
435                 return;
436
437         tny_folder_get_headers (outbox, headers, TRUE, &err);
438         if (err != NULL) 
439                 goto frees;
440
441         iter = tny_list_create_iterator (headers);
442         while (!tny_iterator_is_done (iter)) {
443                 header = TNY_HEADER (tny_iterator_get_current (iter));
444                 if (header) {   
445                         _add_message (self, header); 
446                         g_object_unref (header);
447                 }
448
449                 tny_iterator_next (iter);
450         }
451         
452         /* Flush send queue */
453         tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE(self));
454
455  frees:
456         if (headers != NULL)
457                 g_object_unref (G_OBJECT (headers));
458         if (outbox != NULL) 
459                 g_object_unref (G_OBJECT (outbox));
460         if (iter != NULL) 
461                 g_object_unref (iter);
462 }
463
464 gboolean
465 modest_tny_send_queue_msg_is_being_sent (ModestTnySendQueue* self,
466                                          const gchar *msg_id)
467 {       
468         ModestTnySendQueueStatus status;
469         
470         g_return_val_if_fail (msg_id != NULL, FALSE); 
471         
472         status = modest_tny_send_queue_get_msg_status (self, msg_id);
473         return status == MODEST_TNY_SEND_QUEUE_SENDING;
474 }
475
476 gboolean
477 modest_tny_send_queue_sending_in_progress (ModestTnySendQueue* self)
478 {       
479         ModestTnySendQueuePrivate *priv;
480         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
481         
482         return priv->current != NULL;
483 }
484
485 ModestTnySendQueueStatus
486 modest_tny_send_queue_get_msg_status (ModestTnySendQueue *self, const gchar *msg_id)
487 {
488   GList *item;
489   item = modest_tny_send_queue_lookup_info (self, msg_id);
490   if(item == NULL) return MODEST_TNY_SEND_QUEUE_UNKNONW;
491   return ((SendInfo*)item->data)->status;
492 }
493
494 gchar *
495 modest_tny_send_queue_get_msg_id (TnyHeader *header)
496 {
497         const gchar *uid = NULL;
498         gchar* msg_uid = NULL;
499         gchar **tmp = NULL;
500                 
501         /* Get message uid */
502         uid = tny_header_get_uid (header);
503         if (uid)
504                 tmp = g_strsplit (uid, "__", 2);
505         
506         if (tmp) {
507                 if (tmp[1] != NULL) 
508                         msg_uid = g_strconcat (tmp[0], "_", NULL);
509                 else 
510                         msg_uid = g_strdup(tmp[0]);
511
512                 /* free */
513                 g_strfreev(tmp);
514         }
515
516         return msg_uid;
517 }
518
519
520 static void
521 _on_msg_start_sending (TnySendQueue *self,
522                        TnyHeader *header,
523                        TnyMsg *msg,
524                        int done, 
525                        int total,
526                        gpointer user_data)
527 {
528         ModestTnySendQueuePrivate *priv = NULL;
529         GList *item = NULL;
530         SendInfo *info = NULL;
531         gchar *msg_id = NULL;
532
533         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
534         
535         /* Get message uid */
536         msg_id = modest_tny_send_queue_get_msg_id (header);
537
538         /* Get status info */
539         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
540         if (!item) 
541                 g_warning  ("%s: item should not be NULL", __FUNCTION__);
542         else {
543                 info = item->data;
544                 info->status = MODEST_TNY_SEND_QUEUE_SENDING;
545                 
546                 /* Set current status item */
547                 g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
548                 priv->current = item;
549         }
550
551         /* free */
552         g_free (msg_id);
553 }
554
555 static void 
556 _on_msg_has_been_sent (TnySendQueue *self,
557                        TnyHeader *header,
558                        TnyMsg *msg, 
559                        int done, 
560                        int total,
561                        gpointer user_data)
562 {
563         ModestTnySendQueuePrivate *priv;
564         GList *item;
565         gchar *msg_id = NULL;
566
567         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
568
569         /* Get message uid */
570         msg_id = modest_tny_send_queue_get_msg_id (header);
571         
572         /* Get status info */
573         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), msg_id);
574         if (!item)
575                 g_warning ("%s: item should not be NULL", __FUNCTION__);
576         else {
577
578                 /* Remove status info */
579                 modest_tny_send_queue_info_free (item->data);
580                 g_queue_delete_link (priv->queue, item);
581                 priv->current = NULL;
582                 
583                 modest_platform_information_banner (NULL, NULL, _("mcen_ib_message_sent"));
584         }
585
586         /* free */
587         g_free(msg_id);
588 }
589
590 static void 
591 _on_msg_error_happened (TnySendQueue *self,
592                         TnyHeader *header,
593                         TnyMsg *msg,
594                         GError *err,
595                         gpointer user_data)
596 {
597         ModestTnySendQueuePrivate *priv = NULL;
598         SendInfo *info = NULL;
599         GList *item = NULL;
600         gchar* msg_uid = NULL;
601         
602         priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
603         
604         /* Get sending info (create new if it doesn not exist) */
605         msg_uid = modest_tny_send_queue_get_msg_id (header);
606         item = modest_tny_send_queue_lookup_info (MODEST_TNY_SEND_QUEUE (self), 
607                                                   msg_uid);     
608         if (item == NULL) {
609                 info = g_slice_new (SendInfo);
610                 info->msg_id = strdup(msg_uid);
611                 g_queue_push_tail (priv->queue, info);
612         } else
613                 info = item->data;
614
615         /* Keep in queue so that we remember that the opertion has failed */
616         /* and was not just cancelled */
617         info->status = MODEST_TNY_SEND_QUEUE_FAILED;
618         
619         /* Notify status has changed */
620         g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
621
622         /* free */
623         g_free(msg_uid);
624 }