Ejemplo n.º 1
0
/* We search for any folders in our actions list that need updating, update them */
static GList *
filter_rename_uri(RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp)
{
	FilterRule *rule;
	GList *l, *el;
	FilterPart *action;
	FilterElement *element;
	int count = 0;
	GList *changed = NULL;

	d(printf("uri '%s' renamed to '%s'\n", olduri, newuri));

	/* For all rules, for all actions, for all elements, rename any folder elements */
	/* Yes we could do this inside each part itself, but not today */
	rule = NULL;
	while ((rule = rule_context_next_rule(rc, rule, NULL))) {
		int rulecount = 0;

		d(printf("checking rule '%s'\n", rule->name));

		l = EM_FILTER_RULE(rule)->actions;
		while (l) {
			action = l->data;

			d(printf("checking action '%s'\n", action->name));

			el = action->elements;
			while (el) {
				element = el->data;

				d(printf("checking element '%s'\n", element->name));
				if (EM_IS_FILTER_FOLDER_ELEMENT(element)) {
					d(printf(" is folder, existing uri = '%s'\n",
						 FILTER_FOLDER(element)->uri));
				}

				if (EM_IS_FILTER_FOLDER_ELEMENT(element)
				    && cmp(((EMFilterFolderElement *)element)->uri, olduri)) {
					d(printf(" Changed!\n"));
					em_filter_folder_element_set_value((EMFilterFolderElement *)element, newuri);
					rulecount++;
				}
				el = el->next;
			}
			l = l->next;
		}

		if (rulecount) {
			changed = g_list_append(changed, g_strdup(rule->name));
			filter_rule_emit_changed(rule);
		}

		count += rulecount;
	}

	/* might need to call parent class, if it did anything ... parent_class->rename_uri(f, olduri, newuri, cmp); */

	return changed;
}
Ejemplo n.º 2
0
EFilterRule *
filter_rule_from_message (EMFilterContext *context,
                          CamelMimeMessage *msg,
                          gint flags)
{
	EFilterRule *rule;
	EFilterPart *part;

	g_return_val_if_fail (EM_IS_FILTER_CONTEXT (context), NULL);
	g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (msg), NULL);

	rule = em_filter_rule_new ();
	rule_from_message (rule, E_RULE_CONTEXT (context), msg, flags);

	part = em_filter_context_next_action (context, NULL);

	em_filter_rule_add_action (
		EM_FILTER_RULE (rule), e_filter_part_clone (part));

	return rule;
}
Ejemplo n.º 3
0
static GList *
filter_delete_uri(RuleContext *rc, const char *uri, GCompareFunc cmp)
{
	/* We basically do similar to above, but when we find it,
	   Remove the action, and if thats the last action, this might create an empty rule?  remove the rule? */

	FilterRule *rule;
	GList *l, *el;
	FilterPart *action;
	FilterElement *element;
	int count = 0;
	GList *deleted = NULL;

	d(printf("uri '%s' deleted\n", uri));

	/* For all rules, for all actions, for all elements, check deleted folder elements */
	/* Yes we could do this inside each part itself, but not today */
	rule = NULL;
	while ((rule = rule_context_next_rule(rc, rule, NULL))) {
		int recorded = 0;

		d(printf("checking rule '%s'\n", rule->name));

		l = EM_FILTER_RULE(rule)->actions;
		while (l) {
			action = l->data;

			d(printf("checking action '%s'\n", action->name));

			el = action->elements;
			while (el) {
				element = el->data;

				d(printf("checking element '%s'\n", element->name));
				if (EM_IS_FILTER_FOLDER_ELEMENT(element)) {
					d(printf(" is folder, existing uri = '%s'\n",
						 FILTER_FOLDER(element)->uri));
				}

				if (EM_IS_FILTER_FOLDER_ELEMENT(element)
				    && cmp(((EMFilterFolderElement *)element)->uri, uri)) {
					d(printf(" Deleted!\n"));
					/* check if last action, if so, remove rule instead? */
					l = l->next;
					em_filter_rule_remove_action((EMFilterRule *)rule, action);
					g_object_unref(action);
					count++;
					if (!recorded)
						deleted = g_list_append(deleted, g_strdup(rule->name));
					goto next_action;
				}
				el = el->next;
			}
			l = l->next;
		next_action:
			;
		}
	}

	/* TODO: could call parent and merge lists */

	return deleted;
}