2007-01-21 [colin] 2.7.1cvs47
[claws.git] / src / procmsg.c
index ea8b3b04cc4fcd7b2f8566ae4a4f18f7fc14e1e2..e1c7e1f0b0d6c6cd32e922f083fbaa76a4bcfa69 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,8 +49,9 @@
 #include "inc.h"
 
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
-                                           FolderItem *queue, gint msgnum);
-
+                                           FolderItem *queue, gint msgnum, gboolean *queued_removed);
+static void procmsg_update_unread_children     (MsgInfo        *info,
+                                        gboolean        newly_marked);
 enum
 {
        Q_SENDER           = 0,
@@ -72,67 +73,6 @@ enum
        Q_CLAWS_HDRS_OLD     = 16,
 };
 
-GHashTable *procmsg_msg_hash_table_create(GSList *mlist)
-{
-       GHashTable *msg_table;
-
-       if (mlist == NULL) return NULL;
-
-       msg_table = g_hash_table_new(NULL, g_direct_equal);
-       procmsg_msg_hash_table_append(msg_table, mlist);
-
-       return msg_table;
-}
-
-void procmsg_msg_hash_table_append(GHashTable *msg_table, GSList *mlist)
-{
-       GSList *cur;
-       MsgInfo *msginfo;
-
-       if (msg_table == NULL || mlist == NULL) return;
-
-       for (cur = mlist; cur != NULL; cur = cur->next) {
-               msginfo = (MsgInfo *)cur->data;
-
-               g_hash_table_insert(msg_table,
-                                   GUINT_TO_POINTER(msginfo->msgnum),
-                                   msginfo);
-       }
-}
-
-GHashTable *procmsg_to_folder_hash_table_create(GSList *mlist)
-{
-       GHashTable *msg_table;
-       GSList *cur;
-       MsgInfo *msginfo;
-
-       if (mlist == NULL) return NULL;
-
-       msg_table = g_hash_table_new(NULL, g_direct_equal);
-
-       for (cur = mlist; cur != NULL; cur = cur->next) {
-               msginfo = (MsgInfo *)cur->data;
-               g_hash_table_insert(msg_table, msginfo->to_folder, msginfo);
-       }
-
-       return msg_table;
-}
-
-gint procmsg_get_last_num_in_msg_list(GSList *mlist)
-{
-       GSList *cur;
-       MsgInfo *msginfo;
-       gint last = 0;
-
-       for (cur = mlist; cur != NULL; cur = cur->next) {
-               msginfo = (MsgInfo *)cur->data;
-               if (msginfo && msginfo->msgnum > last)
-                       last = msginfo->msgnum;
-       }
-
-       return last;
-}
-
 void procmsg_msg_list_free(GSList *mlist)
 {
        GSList *cur;
@@ -711,7 +651,7 @@ void procmsg_get_filter_keyword(MsgInfo *msginfo, gchar **header, gchar **key,
        }
 }
 
-void procmsg_empty_trash(FolderItem *trash)
+static void procmsg_empty_trash(FolderItem *trash)
 {
        GNode *node, *next;
 
@@ -950,15 +890,17 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs, gchar **errstr)
                if (!MSG_IS_LOCKED(msginfo->flags)) {
                        file = folder_item_fetch_msg(queue, msginfo->msgnum);
                        if (file) {
+                               gboolean queued_removed = FALSE;
                                if (procmsg_send_message_queue_full(file, 
                                                !procmsg_is_last_for_account(queue, msginfo, elem),
-                                               errstr, queue, msginfo->msgnum) < 0) {
+                                               errstr, queue, msginfo->msgnum, &queued_removed) < 0) {
                                        g_warning("Sending queued message %d failed.\n", 
                                                  msginfo->msgnum);
                                        err++;
                                } else {
                                        sent++; 
-                                       folder_item_remove_msg(queue, msginfo->msgnum);
+                                       if (!queued_removed)
+                                               folder_item_remove_msg(queue, msginfo->msgnum);
                                }
                                g_free(file);
                        }
@@ -1071,7 +1013,7 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
        return 0;
 }
 
-gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
+static gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                            gboolean is_queued)
 {
        gint num;
@@ -1451,21 +1393,8 @@ guint procmsg_msginfo_memusage(MsgInfo *msginfo)
        return memusage;
 }
 
-gint procmsg_cmp_msgnum_for_sort(gconstpointer a, gconstpointer b)
-{
-       const MsgInfo *msginfo1 = a;
-       const MsgInfo *msginfo2 = b;
-
-       if (!msginfo1)
-               return -1;
-       if (!msginfo2)
-               return -1;
-
-       return msginfo1->msgnum - msginfo2->msgnum;
-}
-
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
-                                           FolderItem *queue, gint msgnum)
+                                           FolderItem *queue, gint msgnum, gboolean *queued_removed)
 {
        static HeaderEntry qentry[] = {{"S:",    NULL, FALSE},
                                       {"SSV:",  NULL, FALSE},
@@ -1754,15 +1683,25 @@ send_mail:
                        
                if (save_clear_text || tmp_enc_file == NULL) {
                        gboolean saved = FALSE;
+                       *queued_removed = FALSE;
                        if (queue && msgnum > 0) {
                                MsgInfo *queued_mail = folder_item_get_msginfo(queue, msgnum);
-                               if (folder_item_copy_msg(outbox, queued_mail) >= 0)
+                               if (folder_item_move_msg(outbox, queued_mail) >= 0) {
+                                       debug_print("moved queued mail %d to sent folder\n", msgnum);
                                        saved = TRUE;
+                                       *queued_removed = TRUE;
+                               } else if (folder_item_copy_msg(outbox, queued_mail) >= 0) {
+                                       debug_print("copied queued mail %d to sent folder\n", msgnum);
+                                       saved = TRUE;
+                               }
                                procmsg_msginfo_free(queued_mail);
                        }
-                       if (!saved)
+                       if (!saved) {
+                               debug_print("resaving clear text queued mail to sent folder\n");
                                procmsg_save_to_outbox(outbox, file, TRUE);
+                       }
                } else {
+                       debug_print("saving encrpyted queued mail to sent folder\n");
                        procmsg_save_to_outbox(outbox, tmp_enc_file, FALSE);
                }
        }
@@ -1830,9 +1769,9 @@ send_mail:
        return (newsval != 0 ? newsval : mailval);
 }
 
-gint procmsg_send_message_queue(const gchar *file, gchar **errstr, FolderItem *queue, gint msgnum)
+gint procmsg_send_message_queue(const gchar *file, gchar **errstr, FolderItem *queue, gint msgnum, gboolean *queued_removed)
 {
-       gint result = procmsg_send_message_queue_full(file, FALSE, errstr, queue, msgnum);
+       gint result = procmsg_send_message_queue_full(file, FALSE, errstr, queue, msgnum, queued_removed);
        toolbar_main_set_sensitive(mainwindow_get_mainwindow());
        return result;
 }
@@ -2003,7 +1942,7 @@ void procmsg_msginfo_change_flags(MsgInfo *msginfo,
  *
  *\return      gboolean TRUE if perm_flags are found
  */
-gboolean procmsg_msg_has_flagged_parent_real(MsgInfo *info,
+static gboolean procmsg_msg_has_flagged_parent_real(MsgInfo *info,
                MsgPermFlags perm_flags, GHashTable *parentmsgs)
 {
        MsgInfo *tmp;
@@ -2040,7 +1979,7 @@ gboolean procmsg_msg_has_flagged_parent_real(MsgInfo *info,
 /*!
  *\brief       Callback for cleaning up hash of parentmsgs
  */
-gboolean parentmsgs_hash_remove(gpointer key,
+static gboolean parentmsgs_hash_remove(gpointer key,
                             gpointer value,
                             gpointer user_data)
 {
@@ -2075,7 +2014,7 @@ gboolean procmsg_msg_has_marked_parent(MsgInfo *info)
 }
 
 
-GSList *procmsg_find_children_func(MsgInfo *info, 
+static GSList *procmsg_find_children_func(MsgInfo *info, 
                                   GSList *children, GSList *all)
 {
        GSList *cur;
@@ -2101,7 +2040,7 @@ GSList *procmsg_find_children_func(MsgInfo *info,
        return children;
 }
 
-GSList *procmsg_find_children (MsgInfo *info)
+static GSList *procmsg_find_children (MsgInfo *info)
 {
        GSList *children;
        GSList *all, *cur;
@@ -2121,7 +2060,7 @@ GSList *procmsg_find_children (MsgInfo *info)
        return children;
 }
 
-void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
+static void procmsg_update_unread_children(MsgInfo *info, gboolean newly_marked)
 {
        GSList *children = procmsg_find_children(info);
        GSList *cur;
@@ -2165,7 +2104,7 @@ void procmsg_msginfo_set_to_folder(MsgInfo *msginfo, FolderItem *to_folder)
  * \return TRUE if the message was moved and MsgInfo is now invalid,
  *         FALSE otherwise
  */
-gboolean procmsg_msginfo_filter(MsgInfo *msginfo, PrefsAccount* ac_prefs)
+static gboolean procmsg_msginfo_filter(MsgInfo *msginfo, PrefsAccount* ac_prefs)
 {
        MailFilteringData mail_filtering_data;