2007-06-17 [colin] 2.9.2cvs67
[claws.git] / src / procmsg.c
index 2dd93f192bad13abccb2fd4121873a67f9016be5..04b4b76f20e9e76c9a1846144157a43939a06b91 100644 (file)
@@ -50,7 +50,8 @@
 
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
                                            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;
 
@@ -725,8 +665,10 @@ void procmsg_empty_trash(FolderItem *trash)
                GSList *cur;
                for (cur = mlist ; cur != NULL ; cur = cur->next) {
                        MsgInfo * msginfo = (MsgInfo *) cur->data;
-                       if (MSG_IS_LOCKED(msginfo->flags))
+                       if (MSG_IS_LOCKED(msginfo->flags)) {
+                               procmsg_msginfo_free(msginfo);
                                continue;
+                       }
                        if (msginfo->total_size != 0 && 
                            msginfo->size != (off_t)msginfo->total_size)
                                partial_mark_for_delete(msginfo);
@@ -915,7 +857,7 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs, gchar **errstr)
        
        if (send_queue_lock) {
                /* Avoid having to translate two similar strings */
-               log_warning("%s\n", _("Already trying to send."));
+               log_warning(LOG_PROTOCOL, "%s\n", _("Already trying to send."));
                if (errstr) {
                        if (*errstr) g_free(*errstr);
                        *errstr = g_strdup_printf(_("Already trying to send."));
@@ -979,7 +921,9 @@ gint procmsg_send_queue(FolderItem *queue, gboolean save_msgs, gchar **errstr)
                while (node != NULL) {
                        int res = 0;
                        next = node->next;
+                       send_queue_lock = FALSE;
                        res = procmsg_send_queue(FOLDER_ITEM(node->data), save_msgs, errstr);
+                       send_queue_lock = TRUE;
                        if (res < 0) 
                                err = -res;
                        else
@@ -1073,7 +1017,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;
@@ -1453,19 +1397,6 @@ 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, gboolean *queued_removed)
 {
@@ -1814,8 +1745,13 @@ send_mail:
                        }
                        
                        if (msginfo != NULL) {
+                               MsgPermFlags to_unset = 0;
+
+                               if (prefs_common.mark_as_read_on_new_window)
+                                       to_unset = (MSG_NEW|MSG_UNREAD);
+
                                if (replymessageid != NULL) {
-                                       procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+                                       procmsg_msginfo_unset_flags(msginfo, to_unset|MSG_FORWARDED, 0);
                                        procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
                                }  else {
                                        procmsg_msginfo_unset_flags(msginfo, MSG_REPLIED, 0);
@@ -2113,7 +2049,7 @@ static 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;
@@ -2133,7 +2069,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;
@@ -2177,21 +2113,24 @@ 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;
                        
        mail_filtering_data.msginfo = msginfo;                  
        mail_filtering_data.msglist = NULL;                     
        mail_filtering_data.filtered = NULL;                    
-       mail_filtering_data.unfiltered = NULL;                  
-       if (hooks_invoke(MAIL_FILTERING_HOOKLIST, &mail_filtering_data)) {
+       mail_filtering_data.unfiltered = NULL;
+       mail_filtering_data.account = ac_prefs; 
+
+       if (!ac_prefs || ac_prefs->filterhook_on_recv)
+               if (hooks_invoke(MAIL_FILTERING_HOOKLIST, &mail_filtering_data))
                return TRUE;
-       }
 
        /* filter if enabled in prefs or move to inbox if not */
        if((filtering_rules != NULL) &&
-          filter_message_by_msginfo(filtering_rules, msginfo, ac_prefs)) {
+               filter_message_by_msginfo(filtering_rules, msginfo, ac_prefs,
+                               FILTERING_INCORPORATION, NULL)) {
                return TRUE;
        }
                
@@ -2229,7 +2168,9 @@ void procmsg_msglist_filter(GSList *list, PrefsAccount *ac,
        mail_filtering_data.msglist = list;                     
        mail_filtering_data.filtered = NULL;                    
        mail_filtering_data.unfiltered = NULL;  
+       mail_filtering_data.account = ac;       
                        
+       if (!ac || ac->filterhook_on_recv)
        hooks_invoke(MAIL_LISTFILTERING_HOOKLIST, &mail_filtering_data);
        
        if (mail_filtering_data.filtered == NULL &&
@@ -2357,19 +2298,31 @@ int procmsg_spam_learner_learn (MsgInfo *info, GSList *list, gboolean spam)
 }
 
 static gchar *spam_folder_item = NULL;
-void procmsg_spam_set_folder (const char *item_identifier)
+static FolderItem * (*procmsg_spam_get_folder_func)(MsgInfo *msginfo) = NULL;
+void procmsg_spam_set_folder (const char *item_identifier, FolderItem *(*spam_get_folder_func)(MsgInfo *info))
 {
        g_free(spam_folder_item);
        if (item_identifier)
                spam_folder_item = g_strdup(item_identifier);
        else
                spam_folder_item = NULL;
+       if (spam_get_folder_func != NULL)
+               procmsg_spam_get_folder_func = spam_get_folder_func;
+       else
+               procmsg_spam_get_folder_func = NULL;
 }
 
-FolderItem *procmsg_spam_get_folder (void)
+FolderItem *procmsg_spam_get_folder (MsgInfo *msginfo)
 {
-       FolderItem *item = spam_folder_item ? folder_find_item_from_identifier(spam_folder_item) : NULL;
-       return item ? item : folder_get_default_trash();
+       FolderItem *item = NULL;
+       
+       if (procmsg_spam_get_folder_func) 
+               item = procmsg_spam_get_folder_func(msginfo);
+       if (item == NULL && spam_folder_item)
+               item = folder_find_item_from_identifier(spam_folder_item);
+       if (item == NULL)
+               item = folder_get_default_trash();
+       return item;
 }
 
 static void item_has_queued_mails(FolderItem *item, gpointer data)
@@ -2387,3 +2340,19 @@ gboolean procmsg_have_queued_mails_fast (void)
        folder_func_to_all_folders(item_has_queued_mails, &result);
        return result;
 }
+
+static void item_has_trashed_mails(FolderItem *item, gpointer data)
+{
+       gboolean *result = (gboolean *)data;
+       if (*result == TRUE)
+               return;
+       if (folder_has_parent_of_type(item, F_TRASH) && item->total_msgs > 0)
+               *result = TRUE;
+}
+
+gboolean procmsg_have_trashed_mails_fast (void)
+{
+       gboolean result = FALSE;
+       folder_func_to_all_folders(item_has_trashed_mails, &result);
+       return result;
+}