Example #1
0
int sieve_execute_bytecode(sieve_execute_t *exe, sieve_interp_t *interp,
			   void *script_context, void *message_context) 
{
    action_list_t *actions = NULL;
    notify_list_t *notify_list = NULL;
    /*   notify_action_t *notify_action;*/
    action_t lastaction = -1;
    int ret;
    char actions_string[ACTIONS_STRING_LEN] = "";
    const char *errmsg = NULL;
    strarray_t imapflags = STRARRAY_INITIALIZER;
    
    if (!interp) return SIEVE_FAIL;

    if (interp->notify) {
	notify_list = new_notify_list();
	if (notify_list == NULL) {
	    return do_sieve_error(SIEVE_NOMEM, interp,
				  script_context, message_context, &imapflags,
				  actions, notify_list, lastaction, 0,
				  actions_string, errmsg);
	}
    }

    actions = new_action_list();
    if (actions == NULL) {
	ret = do_sieve_error(SIEVE_NOMEM, interp,
			     script_context, message_context, &imapflags,
			     actions, notify_list, lastaction, 0,
			     actions_string, errmsg);
    }
    else {
	ret = sieve_eval_bc(exe, 0, interp,
			    script_context, message_context,
			    &imapflags, actions, notify_list, &errmsg);

	if (ret < 0) {
	    ret = do_sieve_error(SIEVE_RUN_ERROR, interp,
				 script_context, message_context, &imapflags,
				 actions, notify_list, lastaction, 0,
				 actions_string, errmsg);
	}
	else {
	    ret = do_action_list(interp,
				 script_context, message_context, 
				 &imapflags, actions, notify_list,
				 actions_string, errmsg);
	}
    }

    strarray_fini(&imapflags);

    return ret;
}
Example #2
0
/* fileinto message m into mailbox
 *
 * incompatible with: reject
 */
int do_fileinto(action_list_t *a, const char *mbox, int cancel_keep,
                strarray_t *imapflags)
{
    action_list_t *b = NULL;

    /* see if this conflicts with any previous actions taken on this message */
    while (a != NULL) {
        if (a->a == ACTION_REJECT)
            return SIEVE_RUN_ERROR;
        if (a->a == ACTION_FILEINTO && !strcmp(a->u.fil.mailbox, mbox)) {
            /* don't bother doing it twice */
            /* check that we have a valid action */
            if (b == NULL) {
                return SIEVE_INTERNAL_ERROR;
            }
            /* cut this action out of the list */
            b->next = a->next;
            a->next = NULL;
            /* find the end of the list */
            while (b->next != NULL) {
                b = b-> next;
            }
            /* add the action to the end of the list */
            b->next = a;
            break;
        }
        b = a;
        a = a->next;
    }

    if (a == NULL) {
        /* add to the action list */
        a = new_action_list();
        if (a == NULL)
            return SIEVE_NOMEM;
        b->next = a;
    }
    a->a = ACTION_FILEINTO;
    a->cancel_keep |= cancel_keep;
    a->u.fil.mailbox = mbox;
    a->u.fil.imapflags = imapflags;
    return 0;
}