2006-02-24 [colin] 2.0.0cvs83
[claws.git] / src / procmsg.c
index cb9be31a31ed8f0fd4de706b0c995e0cb4502989..c1c877fcd236d893a3f8b3b56f2d954620e476b3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include "defs.h"
@@ -42,6 +42,8 @@
 #include "hooks.h"
 #include "msgcache.h"
 #include "partial_download.h"
+#include "mainwindow.h"
+#include "summaryview.h"
 
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session);
 
@@ -980,8 +982,54 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out)
        fclose(outfp);
        fclose(fp);
        return 0;
+}
+#if 0
+gchar *procmsg_add_special_headers(const gchar *in, FolderItem *item)
+{
+       gchar *out = get_tmp_file();
+       FILE *fp = NULL;
+       PrefsAccount *account = NULL;
+       if (out == NULL)
+               return NULL;
+
+       fp = fopen(out, "wb");
+       if (fp == NULL) {
+               g_free(out);
+               return NULL;
+       }
 
+       if (item && item->prefs && item->prefs->enable_default_account)
+               account = account_find_from_id(item->prefs->default_account);
+
+       if (!account) account = cur_account;
+
+       if (!account) {
+               fclose(fp);
+               g_free(out);
+               return NULL;
+       }
+
+       fprintf(fp, "X-Sylpheed-Account-Id:%d\n", account->account_id);
+       fprintf(fp, "S:%s\n", account->address);
+       if (item && item->prefs && item->prefs->save_copy_to_folder) {
+               gchar *folderidentifier;
+
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
+               folderidentifier = folder_item_get_identifier(item);
+               fprintf(fp, "SCF:%s\n", folderidentifier);
+               g_free(folderidentifier);
+       } else if (account_get_special_folder(account, F_OUTBOX)) {
+               gchar *folderidentifier = folder_item_get_identifier(account_get_special_folder
+                                 (compose->account, F_OUTBOX));
+               fprintf(fp, "SCF:%s\n", folderidentifier);
+               g_free(folderidentifier);
+       }
+
+       fprintf(fp, "\n");
+       fclose(fp);
+       return out;
 }
+#endif
 gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                            gboolean is_queued)
 {
@@ -1152,6 +1200,7 @@ MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo)
        MEMBCOPY(folder);
        MEMBCOPY(to_folder);
 
+       MEMBDUP(face);
        MEMBDUP(xface);
        MEMBDUP(dispositionnotificationto);
        MEMBDUP(returnreceiptto);
@@ -1164,7 +1213,6 @@ MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo)
         newmsginfo->references = g_slist_reverse(newmsginfo->references);
 
        MEMBCOPY(score);
-       MEMBCOPY(threadscore);
        MEMBDUP(plaintext_file);
 
        return newmsginfo;
@@ -1195,6 +1243,8 @@ MsgInfo *procmsg_msginfo_get_full_info(MsgInfo *msginfo)
         * procheader.c::procheader_get_headernames() */
        if (!msginfo->xface)
                msginfo->xface = g_strdup(full_msginfo->xface);
+       if (!msginfo->face)
+               msginfo->face = g_strdup(full_msginfo->face);
        if (!msginfo->dispositionnotificationto)
                msginfo->dispositionnotificationto = 
                        g_strdup(full_msginfo->dispositionnotificationto);
@@ -1234,6 +1284,7 @@ void procmsg_msginfo_free(MsgInfo *msginfo)
        g_free(msginfo->returnreceiptto);
        g_free(msginfo->dispositionnotificationto);
        g_free(msginfo->xface);
+       g_free(msginfo->face);
 
        g_free(msginfo->fromname);
 
@@ -1285,6 +1336,8 @@ guint procmsg_msginfo_memusage(MsgInfo *msginfo)
                memusage += strlen(msginfo->inreplyto);
        if (msginfo->xface)
                memusage += strlen(msginfo->xface);
+       if (msginfo->face)
+               memusage += strlen(msginfo->face);
        if (msginfo->dispositionnotificationto)
                memusage += strlen(msginfo->dispositionnotificationto);
        if (msginfo->returnreceiptto)
@@ -1961,16 +2014,19 @@ gboolean procmsg_msginfo_filter(MsgInfo *msginfo)
        MailFilteringData mail_filtering_data;
                        
        mail_filtering_data.msginfo = msginfo;                  
-       if (hooks_invoke(MAIL_FILTERING_HOOKLIST, &mail_filtering_data))
+       if (hooks_invoke(MAIL_FILTERING_HOOKLIST, &mail_filtering_data)) {
+               hooks_invoke(MAIL_POSTFILTERING_HOOKLIST, msginfo);
                return TRUE;
+       }
 
        /* filter if enabled in prefs or move to inbox if not */
        if((filtering_rules != NULL) &&
-          filter_message_by_msginfo(filtering_rules, msginfo))
+          filter_message_by_msginfo(filtering_rules, msginfo)) {
+               hooks_invoke(MAIL_POSTFILTERING_HOOKLIST, msginfo);
                return TRUE;
+       }
                
        hooks_invoke(MAIL_POSTFILTERING_HOOKLIST, msginfo);
-
        return FALSE;
 }
 
@@ -2001,7 +2057,8 @@ MsgInfo *procmsg_msginfo_new_from_mimeinfo(MsgInfo *src_msginfo, MimeInfo *mimei
                fclose(fp);
 
        if (tmp_msginfo != NULL) {
-               tmp_msginfo->folder = src_msginfo->folder;
+               if (src_msginfo)
+                       tmp_msginfo->folder = src_msginfo->folder;
                tmp_msginfo->plaintext_file = g_strdup(tmpfile);
        } else {
                g_warning("procmsg_msginfo_new_from_mimeinfo(): Can't generate new msginfo");
@@ -2011,3 +2068,57 @@ MsgInfo *procmsg_msginfo_new_from_mimeinfo(MsgInfo *src_msginfo, MimeInfo *mimei
 
        return tmp_msginfo;
 }
+
+static GSList *spam_learners = NULL;
+
+void procmsg_register_spam_learner (void (*learn_func)(MsgInfo *info, GSList *list, gboolean spam))
+{
+       if (!g_slist_find(spam_learners, learn_func))
+               spam_learners = g_slist_append(spam_learners, learn_func);
+       if (mainwindow_get_mainwindow()) {
+               main_window_set_menu_sensitive(mainwindow_get_mainwindow());
+               summary_set_menu_sensitive(
+                       mainwindow_get_mainwindow()->summaryview);
+       }
+}
+
+void procmsg_unregister_spam_learner (void (*learn_func)(MsgInfo *info, GSList *list, gboolean spam))
+{
+       spam_learners = g_slist_remove(spam_learners, learn_func);
+       if (mainwindow_get_mainwindow()) {
+               main_window_set_menu_sensitive(mainwindow_get_mainwindow());
+               summary_set_menu_sensitive(
+                       mainwindow_get_mainwindow()->summaryview);
+       }
+}
+
+gboolean procmsg_spam_can_learn(void)
+{
+       return g_slist_length(spam_learners) > 0;
+}
+
+void procmsg_spam_learner_learn (MsgInfo *info, GSList *list, gboolean spam)
+{
+       GSList *cur = spam_learners;
+       for (; cur; cur = cur->next) {
+               void ((*func)(MsgInfo *info, GSList *list, gboolean spam)) = cur->data;
+               func(info, list, spam);
+       }
+}
+
+static gchar *spam_folder_item = NULL;
+void procmsg_spam_set_folder (const char *item_identifier)
+{
+       if (spam_folder_item)
+               g_free(spam_folder_item);
+       if (item_identifier)
+               spam_folder_item = g_strdup(item_identifier);
+       else
+               spam_folder_item = NULL;
+}
+
+FolderItem *procmsg_spam_get_folder (void)
+{
+       FolderItem *item = spam_folder_item ? folder_find_item_from_identifier(spam_folder_item) : NULL;
+       return item ? item : folder_get_default_trash();
+}