/*
* 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
*
* 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"
#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);
return root;
}
-void procmsg_move_messages(GSList *mlist)
+gint procmsg_move_messages(GSList *mlist)
{
GSList *cur, *movelist = NULL;
MsgInfo *msginfo;
FolderItem *dest = NULL;
-
- if (!mlist) return;
+ gint retval = 0;
+ gboolean finished = TRUE;
+ if (!mlist) return 0;
folder_item_update_freeze();
+next_folder:
for (cur = mlist; cur != NULL; cur = cur->next) {
msginfo = (MsgInfo *)cur->data;
+ if (!msginfo->to_folder) {
+ continue;
+ } else {
+ finished = FALSE;
+ }
if (!dest) {
dest = msginfo->to_folder;
movelist = g_slist_append(movelist, msginfo);
} else if (dest == msginfo->to_folder) {
movelist = g_slist_append(movelist, msginfo);
} else {
- folder_item_move_msgs(dest, movelist);
- g_slist_free(movelist);
- movelist = NULL;
- dest = msginfo->to_folder;
- movelist = g_slist_append(movelist, msginfo);
+ continue;
}
procmsg_msginfo_set_to_folder(msginfo, NULL);
}
-
if (movelist) {
- folder_item_move_msgs(dest, movelist);
+ retval |= folder_item_move_msgs(dest, movelist);
g_slist_free(movelist);
+ movelist = NULL;
+ }
+ if (finished == FALSE) {
+ finished = TRUE;
+ dest = NULL;
+ goto next_folder;
}
folder_item_update_thaw();
+ return retval;
}
void procmsg_copy_messages(GSList *mlist)
GSList *cur, *copylist = NULL;
MsgInfo *msginfo;
FolderItem *dest = NULL;
-
+ gboolean finished = TRUE;
if (!mlist) return;
folder_item_update_freeze();
+next_folder:
for (cur = mlist; cur != NULL; cur = cur->next) {
msginfo = (MsgInfo *)cur->data;
+ if (!msginfo->to_folder) {
+ continue;
+ } else {
+ finished = FALSE;
+ }
if (!dest) {
dest = msginfo->to_folder;
copylist = g_slist_append(copylist, msginfo);
} else if (dest == msginfo->to_folder) {
copylist = g_slist_append(copylist, msginfo);
} else {
- folder_item_copy_msgs(dest, copylist);
- g_slist_free(copylist);
- copylist = NULL;
- dest = msginfo->to_folder;
- copylist = g_slist_append(copylist, msginfo);
+ continue;
}
procmsg_msginfo_set_to_folder(msginfo, NULL);
}
-
if (copylist) {
folder_item_copy_msgs(dest, copylist);
g_slist_free(copylist);
+ copylist = NULL;
+ }
+ if (finished == FALSE) {
+ finished = TRUE;
+ dest = NULL;
+ goto next_folder;
}
folder_item_update_thaw();
{"X-Mailing-list:", NULL, TRUE},
{"List-Id:", NULL, TRUE},
{"X-Sequence:", NULL, TRUE},
+ {"Sender:", NULL, TRUE},
+ {"List-Post:", NULL, TRUE},
{NULL, NULL, FALSE}};
enum
{
H_X_LIST = 2,
H_X_MAILING_LIST = 3,
H_LIST_ID = 4,
- H_X_SEQUENCE = 5
+ H_X_SEQUENCE = 5,
+ H_SENDER = 6,
+ H_LIST_POST = 7
};
FILE *fp;
}
}
g_strstrip(*key);
+ } else if (hentry[H_SENDER].body != NULL) {
+ SET_FILTER_KEY("header \"Sender\"", H_SENDER);
+ } else if (hentry[H_LIST_POST].body != NULL) {
+ SET_FILTER_KEY("header \"Sender\"", H_LIST_POST);
+ } else if (msginfo->to) {
+ *header = g_strdup("to");
+ *key = g_strdup(msginfo->to);
} else if (msginfo->subject) {
*header = g_strdup("subject");
*key = g_strdup(msginfo->subject);
hentry[H_X_MAILING_LIST].body = NULL;
g_free(hentry[H_LIST_ID].body);
hentry[H_LIST_ID].body = NULL;
+ g_free(hentry[H_SENDER].body);
+ hentry[H_SENDER].body = NULL;
+ g_free(hentry[H_LIST_POST].body);
+ hentry[H_LIST_POST].body = NULL;
break;
case FILTER_BY_FROM:
void procmsg_empty_trash(FolderItem *trash)
{
+ GNode *node, *next;
+
+ if (!trash ||
+ (trash->stype != F_TRASH &&
+ !folder_has_parent_of_type(trash, F_TRASH)))
+ return;
+
if (trash && trash->total_msgs > 0) {
GSList *mlist = folder_item_get_msg_list(trash);
GSList *cur;
g_slist_free(mlist);
folder_item_remove_all_msg(trash);
}
+
+ if (!trash->node || !trash->node->children)
+ return;
+
+ node = trash->node->children;
+ while (node != NULL) {
+ next = node->next;
+ procmsg_empty_trash(FOLDER_ITEM(node->data));
+ node = next;
+ }
}
void procmsg_empty_all_trash(void)
cur = orig;
while (cur) {
gchar *file = NULL;
- PrefsAccount *ac = procmsg_get_account_from_file(file);
+ PrefsAccount *ac = NULL;
msg = (MsgInfo *)cur->data;
file = folder_item_fetch_msg(queue, msg->msgnum);
+ ac = procmsg_get_account_from_file(file);
g_free(file);
if (last_account == NULL || (ac != NULL && ac == last_account)) {
gint sent = 0, err = 0;
GSList *list, *elem;
GSList *sorted_list = NULL;
+ GNode *node, *next;
if (!queue)
queue = folder_get_default_queue();
}
g_slist_free(sorted_list);
+ folder_item_scan(queue);
+
+ if (queue->node && queue->node->children) {
+ node = queue->node->children;
+ while (node != NULL) {
+ int res = 0;
+ next = node->next;
+ res = procmsg_send_queue(FOLDER_ITEM(node->data), save_msgs);
+ if (res < 0)
+ err = -res;
+ else
+ sent += res;
+ node = next;
+ }
+ }
return (err != 0 ? -err : sent);
}
list = folder_item_get_msg_list(queue);
res = (list == NULL);
procmsg_msg_list_free(list);
+
+ if (res == TRUE) {
+ GNode *node, *next;
+ if (queue->node && queue->node->children) {
+ node = queue->node->children;
+ while (node != NULL) {
+ next = node->next;
+ if (!procmsg_queue_is_empty(FOLDER_ITEM(node->data)))
+ return FALSE;
+ node = next;
+ }
+ }
+ }
return res;
}
fclose(outfp);
fclose(fp);
return 0;
-
}
+
gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
gboolean is_queued)
{
MEMBCOPY(folder);
MEMBCOPY(to_folder);
+ MEMBDUP(face);
MEMBDUP(xface);
MEMBDUP(dispositionnotificationto);
MEMBDUP(returnreceiptto);
newmsginfo->references = g_slist_reverse(newmsginfo->references);
MEMBCOPY(score);
- MEMBCOPY(threadscore);
MEMBDUP(plaintext_file);
return newmsginfo;
* 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);
g_free(msginfo->returnreceiptto);
g_free(msginfo->dispositionnotificationto);
g_free(msginfo->xface);
+ g_free(msginfo->face);
g_free(msginfo->fromname);
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)
FolderItem *item;
if (replymessageid != NULL)
- tokens = g_strsplit(replymessageid, "\x7f", 0);
+ tokens = g_strsplit(replymessageid, "\t", 0);
else
- tokens = g_strsplit(fwdmessageid, "\x7f", 0);
+ tokens = g_strsplit(fwdmessageid, "\t", 0);
item = folder_find_item_from_identifier(tokens[0]);
/* check if queued message has valid folder and message id */
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)) {
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)) {
return TRUE;
+ }
- hooks_invoke(MAIL_POSTFILTERING_HOOKLIST, msginfo);
-
return FALSE;
}
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");
return tmp_msginfo;
}
+
+static GSList *spam_learners = NULL;
+
+void procmsg_register_spam_learner (int (*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);
+ toolbar_main_set_sensitive(mainwindow_get_mainwindow());
+ }
+}
+
+void procmsg_unregister_spam_learner (int (*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);
+ toolbar_main_set_sensitive(mainwindow_get_mainwindow());
+ }
+}
+
+gboolean procmsg_spam_can_learn(void)
+{
+ return g_slist_length(spam_learners) > 0;
+}
+
+int procmsg_spam_learner_learn (MsgInfo *info, GSList *list, gboolean spam)
+{
+ GSList *cur = spam_learners;
+ int ret = 0;
+ for (; cur; cur = cur->next) {
+ int ((*func)(MsgInfo *info, GSList *list, gboolean spam)) = cur->data;
+ ret |= func(info, list, spam);
+ }
+ return ret;
+}
+
+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();
+}