#include "tags.h"
#include "log.h"
-#define PREFSBUFSIZE 1024
-
GSList * pre_global_processing = NULL;
GSList * post_global_processing = NULL;
GSList * filtering_rules = NULL;
for (tmp = prop->action_list ; tmp != NULL ; tmp = tmp->next) {
filteringaction_free(tmp->data);
}
+ g_slist_free(prop->action_list);
g_free(prop->name);
g_free(prop);
}
-void filtering_move_and_copy_msg(MsgInfo *msginfo)
-{
- GSList *list = g_slist_append(NULL, msginfo);
- filtering_move_and_copy_msgs(list);
- g_slist_free(list);
-}
-
/* move and copy messages by batches to be faster on IMAP */
void filtering_move_and_copy_msgs(GSList *msgs)
{
GSList *messages = g_slist_copy(msgs);
FolderItem *last_item = NULL;
- gboolean is_copy = FALSE, is_move = FALSE;
+ FiltOp cur_op = IS_NOTHING;
+
debug_print("checking %d messages\n", g_slist_length(msgs));
while (messages) {
GSList *batch = NULL, *cur;
for (cur = messages; cur; cur = cur->next) {
MsgInfo *info = (MsgInfo *)cur->data;
if (last_item == NULL) {
- last_item = info->to_filter_folder;
+ if (info->filter_op == IS_COPY || info->filter_op == IS_MOVE)
+ last_item = info->to_filter_folder;
+ else if (info->filter_op == IS_DELE)
+ last_item = info->folder;
}
if (last_item == NULL)
continue;
- if (!is_copy && !is_move) {
- if (info->is_copy)
- is_copy = TRUE;
- else if (info->is_move)
- is_move = TRUE;
+ if (cur_op == IS_NOTHING) {
+ if (info->filter_op == IS_COPY)
+ cur_op = IS_COPY;
+ else if (info->filter_op == IS_MOVE)
+ cur_op = IS_MOVE;
+ else if (info->filter_op == IS_DELE)
+ cur_op = IS_DELE;
}
- found++;
- if (info->to_filter_folder == last_item
- && info->is_copy == is_copy
- && info->is_move == is_move) {
- batch = g_slist_prepend(batch, info);
+ if (info->filter_op == IS_COPY || info->filter_op == IS_MOVE) {
+ if (info->to_filter_folder == last_item
+ && cur_op == info->filter_op) {
+ found++;
+ batch = g_slist_prepend(batch, info);
+ }
+ } else if (info->filter_op == IS_DELE) {
+ if (info->folder == last_item
+ && cur_op == info->filter_op) {
+ found++;
+ batch = g_slist_prepend(batch, info);
+ }
}
}
if (found == 0) {
- debug_print("no more messages to move/copy\n");
+ debug_print("no more messages to move/copy/del\n");
break;
} else {
debug_print("%d messages to %s in %s\n", found,
- is_copy ? "copy":"move", last_item->name ? last_item->name:"(noname)");
+ cur_op==IS_COPY ? "copy":(cur_op==IS_DELE ?"delete":"move"),
+ last_item?(last_item->name ? last_item->name:"(noname)"):"nowhere");
}
for (cur = batch; cur; cur = cur->next) {
MsgInfo *info = (MsgInfo *)cur->data;
messages = g_slist_remove(messages, info);
+ info->to_filter_folder = NULL;
+ info->filter_op = IS_NOTHING;
}
batch = g_slist_reverse(batch);
if (g_slist_length(batch)) {
MsgInfo *info = (MsgInfo *)batch->data;
- if (is_copy && last_item != info->folder) {
+ if (cur_op == IS_COPY && last_item != info->folder) {
folder_item_copy_msgs(last_item, batch);
- } else if (is_move && last_item != info->folder) {
+ } else if (cur_op == IS_MOVE && last_item != info->folder) {
if (folder_item_move_msgs(last_item, batch) < 0)
folder_item_move_msgs(
folder_get_default_inbox(),
batch);
+ } else if (cur_op == IS_DELE && last_item == info->folder) {
+ folder_item_remove_msgs(last_item, batch);
}
/* we don't reference the msginfos, because caller will do */
if (prefs_common.real_time_sync)
GTK_EVENTS_FLUSH();
}
last_item = NULL;
- is_copy = FALSE;
- is_move = FALSE;
+ cur_op = IS_NOTHING;
}
/* we don't reference the msginfos, because caller will do */
g_slist_free(messages);
return value : return TRUE if the action could be applied
*/
+#define FLUSH_COPY_IF_NEEDED(info) { \
+ if (info->filter_op == IS_COPY && info->to_filter_folder) { \
+ debug_print("must debatch pending copy\n"); \
+ folder_item_copy_msg(info->to_filter_folder, info); \
+ info->filter_op = IS_NOTHING; \
+ } \
+}
+
static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
{
FolderItem * dest_folder;
return FALSE;
}
- /* check if mail is set to copy already,
- * in which case we have to do it */
- if (info->is_copy && info->to_filter_folder) {
- debug_print("should cp and mv !\n");
- folder_item_copy_msg(info->to_filter_folder, info);
- info->is_copy = FALSE;
- }
+ FLUSH_COPY_IF_NEEDED(info);
/* mark message to be moved */
- info->is_move = TRUE;
+ info->filter_op = IS_MOVE;
info->to_filter_folder = dest_folder;
return TRUE;
return FALSE;
}
- /* check if mail is set to copy already,
- * in which case we have to do it */
- if (info->is_copy && info->to_filter_folder) {
- debug_print("should cp and mv !\n");
- folder_item_copy_msg(info->to_filter_folder, info);
- info->is_copy = FALSE;
- }
+ FLUSH_COPY_IF_NEEDED(info);
/* mark message to be copied */
- info->is_copy = TRUE;
+ info->filter_op = IS_COPY;
info->to_filter_folder = dest_folder;
return TRUE;
action->destination ?action->destination :"(null)");
return FALSE;
}
-
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_update_tags(info, (action->type == MATCHACTION_SET_TAG), val);
return TRUE;
case MATCHACTION_CLEAR_TAGS:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_clear_tags(info);
return TRUE;
case MATCHACTION_DELETE:
- if (folder_item_remove_msg(info->folder, info->msgnum) == -1)
- return FALSE;
+ FLUSH_COPY_IF_NEEDED(info);
+ info->filter_op = IS_DELE;
return TRUE;
case MATCHACTION_MARK:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_set_flags(info, MSG_MARKED, 0);
return TRUE;
case MATCHACTION_UNMARK:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_unset_flags(info, MSG_MARKED, 0);
return TRUE;
case MATCHACTION_LOCK:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_set_flags(info, MSG_LOCKED, 0);
return TRUE;
case MATCHACTION_UNLOCK:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_unset_flags(info, MSG_LOCKED, 0);
return TRUE;
case MATCHACTION_MARK_AS_READ:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_unset_flags(info, MSG_UNREAD | MSG_NEW, 0);
return TRUE;
case MATCHACTION_MARK_AS_UNREAD:
- procmsg_msginfo_set_flags(info, MSG_UNREAD | MSG_NEW, 0);
+ FLUSH_COPY_IF_NEEDED(info);
+ procmsg_msginfo_set_flags(info, MSG_UNREAD, 0);
return TRUE;
case MATCHACTION_MARK_AS_SPAM:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_spam_learner_learn(info, NULL, TRUE);
procmsg_msginfo_change_flags(info, MSG_SPAM, 0, MSG_NEW|MSG_UNREAD, 0);
if (procmsg_spam_get_folder(info)) {
- info->is_move = TRUE;
+ info->filter_op = IS_MOVE;
info->to_filter_folder = procmsg_spam_get_folder(info);
}
return TRUE;
case MATCHACTION_MARK_AS_HAM:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_spam_learner_learn(info, NULL, FALSE);
procmsg_msginfo_unset_flags(info, MSG_SPAM, 0);
return TRUE;
case MATCHACTION_COLOR:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_unset_flags(info, MSG_CLABEL_FLAG_MASK, 0);
procmsg_msginfo_set_flags(info, MSG_COLORLABEL_TO_FLAGS(action->labelcolor), 0);
return TRUE;
return TRUE;
case MATCHACTION_SET_SCORE:
+ FLUSH_COPY_IF_NEEDED(info);
info->score = action->score;
return TRUE;
case MATCHACTION_CHANGE_SCORE:
+ FLUSH_COPY_IF_NEEDED(info);
info->score += action->score;
return TRUE;
return FALSE;
case MATCHACTION_HIDE:
+ FLUSH_COPY_IF_NEEDED(info);
info->hidden = TRUE;
return TRUE;
case MATCHACTION_IGNORE:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_set_flags(info, MSG_IGNORE_THREAD, 0);
return TRUE;
case MATCHACTION_WATCH:
+ FLUSH_COPY_IF_NEEDED(info);
procmsg_msginfo_set_flags(info, MSG_WATCH_THREAD, 0);
return TRUE;
gint errors = 0;
if (!addressbook_peek_folder_exists(action->destination, &book, &folder)) {
- g_warning("addressbook folder not found '%s'\n", action->destination);
+ g_warning("addressbook folder not found '%s'\n", action->destination?action->destination:"(null)");
return FALSE;
}
if (!book) {
gchar *path = NULL;
if (action->destination == NULL ||
- strcasecmp(action->destination, _("Any")) == 0 ||
+ strcasecmp(action->destination, "Any") == 0 ||
*(action->destination) == '\0')
path = NULL;
else
g_slist_free(address_list);
end_address_completion();
} else {
- g_warning("header '%s' not set or empty\n", action->header);
+ g_warning("header '%s' not set or empty\n", action->header?action->header:"(null)");
}
return (errors == 0);
}
log_status_ok(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"matching the account currently used to retrieve messages\n"),
- ac_prefs->account_id, ac_prefs->account_name);
+ ac_prefs->account_id, ac_prefs?ac_prefs->account_name:_("NON_EXISTENT"));
}
}
}
log_status_skip(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"not matching the account currently used to retrieve messages [id=%d, name='%s']\n"),
- filtering->account_id, account->account_name,
- ac_prefs->account_id, ac_prefs->account_name);
+ filtering->account_id, account?account->account_name:_("NON_EXISTENT"),
+ ac_prefs->account_id, ac_prefs?ac_prefs->account_name:_("NON_EXISTENT"));
}
}
}
log_status_ok(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"but all rules are applied on user request\n"),
- filtering->account_id, account->account_name);
+ filtering->account_id, account?account->account_name:_("NON_EXISTENT"));
}
}
}
log_status_skip(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"skipped on user request\n"),
- filtering->account_id, account->account_name);
+ filtering->account_id, account?account->account_name:_("NON_EXISTENT"));
} else {
log_status_skip(LOG_DEBUG_FILTERING,
_("rule is account-based, "
log_status_skip(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"not matching current account [id=%d, name='%s']\n"),
- filtering->account_id, account->account_name,
- cur_account->account_id, cur_account->account_name);
+ filtering->account_id, account?account->account_name:_("NON_EXISTENT"),
+ cur_account->account_id, cur_account?cur_account->account_name:_("NON_EXISTENT"));
} else {
log_status_skip(LOG_DEBUG_FILTERING,
_("rule is account-based, "
log_status_ok(LOG_DEBUG_FILTERING,
_("rule is account-based [id=%d, name='%s'], "
"current account [id=%d, name='%s']\n"),
- account->account_id, account->account_name,
- cur_account->account_id, cur_account->account_name);
+ account->account_id, account?account->account_name:_("NON_EXISTENT"),
+ cur_account->account_id, cur_account?cur_account->account_name:_("NON_EXISTENT"));
}
}
}
_("processing rule <unnamed> [ %s ]\n"),
buf);
}
+ g_free(buf);
}
if (filtering_match_condition(filtering, info, ac_prefs)) {
if (prefs_common.enable_filtering_debug) {
gchar *tmp = _("undetermined");
-
+#ifndef G_OS_WIN32
switch (context) {
case FILTERING_INCORPORATION:
tmp = _("incorporation");
debug_filtering_session = FALSE;
break;
}
+#else
+ debug_filtering_session = FALSE;
+#endif
if (debug_filtering_session) {
gchar *file = procmsg_get_message_file_path(info);
gchar *spc = g_strnfill(LOG_TIME_LEN + 1, ' ');
return filtering_str;
}
-void prefs_filtering_free(GSList * prefs_filtering)
+static void prefs_filtering_free(GSList * prefs_filtering)
{
while (prefs_filtering != NULL) {
FilteringProp * filtering = (FilteringProp *)