Fixed assertion failure in the keep/fileinto store actions and added testsuite item.
authorStephan Bosch <stephan@rename-it.nl>
Thu Jul 08 00:06:42 2010 +0200 (2010-07-08)
changeset 1320703f82bb2b09
parent 1319 e6c049bf72a9
child 1321 94ff6b42c1bd
Fixed assertion failure in the keep/fileinto store actions and added testsuite item.
src/lib-sieve/plugins/mailbox/tag-mailbox-create.c
src/lib-sieve/sieve-actions.c
tests/execute/errors.svtest
tests/execute/errors/fileinto.sieve
     1.1 --- a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c	Mon Jul 05 17:18:23 2010 +0200
     1.2 +++ b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c	Thu Jul 08 00:06:42 2010 +0200
     1.3 @@ -125,7 +125,7 @@
     1.4  	enum mail_error error;
     1.5  	
     1.6  	/* Check whether creation is necessary */
     1.7 -	if ( trans->box == NULL || trans->redundant || trans->disabled )
     1.8 +	if ( trans->box == NULL || trans->disabled )
     1.9  		return TRUE;
    1.10  
    1.11  	/* Check whether creation has a chance of working */
    1.12 @@ -133,6 +133,10 @@
    1.13  		trans->error_code != MAIL_ERROR_NOTFOUND )
    1.14  		return FALSE;
    1.15  
    1.16 +	trans->error = NULL;
    1.17 +	trans->error_code = MAIL_ERROR_NONE;
    1.18 +	
    1.19 +
    1.20  	*storage = mailbox_get_storage(trans->box);
    1.21  
    1.22  	/* Create mailbox */
    1.23 @@ -143,6 +147,7 @@
    1.24  			return FALSE;
    1.25  		}
    1.26  	}
    1.27 +
    1.28  	/* Subscribe to it if necessary */
    1.29  	if ( aenv->scriptenv->mailbox_autosubscribe ) {
    1.30  		(void)mailbox_list_set_subscribed
     2.1 --- a/src/lib-sieve/sieve-actions.c	Mon Jul 05 17:18:23 2010 +0200
     2.2 +++ b/src/lib-sieve/sieve-actions.c	Thu Jul 08 00:06:42 2010 +0200
     2.3 @@ -331,8 +331,8 @@
     2.4  /* Action implementation */
     2.5  
     2.6  static bool act_store_mailbox_open
     2.7 -(const struct sieve_action_exec_env *aenv, const char **mailbox,
     2.8 - struct mailbox **box_r, const char **error_r)
     2.9 +(const struct sieve_action_exec_env *aenv, const char *mailbox,
    2.10 +	struct mailbox **box_r, const char **error_r)
    2.11  {
    2.12  	struct mail_storage **storage = &(aenv->exec_status->last_storage);
    2.13  	struct mail_deliver_save_open_context save_ctx;
    2.14 @@ -340,10 +340,9 @@
    2.15  
    2.16  	*box_r = NULL;
    2.17  
    2.18 -	if ( !uni_utf8_str_is_valid(*mailbox) ) {
    2.19 +	if ( !uni_utf8_str_is_valid(mailbox) ) {
    2.20  		/* FIXME: check utf-8 validity at compiletime/runtime */
    2.21 -		*error_r = t_strdup_printf("mailbox name not utf-8: %s",
    2.22 -					   *mailbox);
    2.23 +		*error_r = t_strdup_printf("mailbox name not utf-8: %s", mailbox);
    2.24  		return FALSE;
    2.25  	}
    2.26  
    2.27 @@ -352,15 +351,11 @@
    2.28  	save_ctx.lda_mailbox_autocreate = aenv->scriptenv->mailbox_autocreate;
    2.29  	save_ctx.lda_mailbox_autosubscribe = aenv->scriptenv->mailbox_autosubscribe;
    2.30  
    2.31 -	if (mail_deliver_save_open(&save_ctx, *mailbox, box_r, &error) < 0) {
    2.32 -		*error_r = t_strdup_printf("failed to save mail to mailbox '%s': %s",
    2.33 -					   *mailbox, error);
    2.34 +	if (mail_deliver_save_open(&save_ctx, mailbox, box_r, &error) < 0) {
    2.35 +		*error_r = error;
    2.36  		return FALSE;
    2.37  	}
    2.38  
    2.39 -	/* FIXME: is box freed too early for this? is it even useful to update
    2.40 -	   this name now that box is set? */
    2.41 -	*mailbox = mailbox_get_vname(*box_r);
    2.42  	*storage = mailbox_get_storage(*box_r);
    2.43  	return TRUE;
    2.44  }
    2.45 @@ -371,12 +366,11 @@
    2.46  {  
    2.47  	struct act_store_context *ctx = (struct act_store_context *) action->context;
    2.48  	const struct sieve_script_env *senv = aenv->scriptenv;
    2.49 -	const struct sieve_message_data *msgdata = aenv->msgdata;
    2.50  	struct act_store_transaction *trans;
    2.51  	struct mailbox *box = NULL;
    2.52  	pool_t pool = sieve_result_pool(aenv->result);
    2.53  	const char *error = NULL;
    2.54 -	bool disabled = FALSE, redundant = FALSE, open_failed = FALSE;
    2.55 +	bool disabled = FALSE, open_failed = FALSE;
    2.56  
    2.57  	/* If context is NULL, the store action is the result of (implicit) keep */	
    2.58  	if ( ctx == NULL ) {
    2.59 @@ -390,16 +384,8 @@
    2.60  	 * to NULL. This implementation will then skip actually storing the message.
    2.61  	 */
    2.62  	if ( senv->user != NULL ) {
    2.63 -		if ( !act_store_mailbox_open(aenv, &ctx->mailbox, &box, &error) ) {
    2.64 +		if ( !act_store_mailbox_open(aenv, ctx->mailbox, &box, &error) ) {
    2.65  			open_failed = TRUE;
    2.66 -
    2.67 -		/* Check whether we are trying to store the message in the folder it
    2.68 -		 * originates from. In that case we skip actually storing it.
    2.69 -		 */
    2.70 -		} else if ( mailbox_backends_equal(box, msgdata->mail->box) ) {
    2.71 -			mailbox_free(&box);
    2.72 -			box = NULL;
    2.73 -			redundant = TRUE;
    2.74  		}
    2.75  	} else {
    2.76  		disabled = TRUE;
    2.77 @@ -413,11 +399,14 @@
    2.78  	trans->flags = 0;
    2.79  
    2.80  	trans->disabled = disabled;
    2.81 -	trans->redundant = redundant;
    2.82 -	trans->error_code = MAIL_ERROR_NONE;
    2.83  
    2.84 -	if ( open_failed && error != NULL )
    2.85 -		trans->error = p_strdup(sieve_result_pool(aenv->result), error);
    2.86 +	if ( open_failed  ) {
    2.87 +		trans->error = error;
    2.88 +		(void)mail_storage_get_last_error
    2.89 +			(mailbox_get_storage(trans->box), &trans->error_code);
    2.90 +	} else {
    2.91 +		trans->error_code = MAIL_ERROR_NONE;
    2.92 +	}
    2.93  
    2.94  	*tr_context = (void *)trans;
    2.95  
    2.96 @@ -464,10 +453,16 @@
    2.97  	/* Check whether we need to do anything */
    2.98  	if ( trans->disabled ) return TRUE;
    2.99  
   2.100 +	/* Exit early if mailbox is not available */
   2.101 +	if ( trans->box == NULL || trans->error_code != MAIL_ERROR_NONE ) 
   2.102 +		return FALSE;
   2.103 +
   2.104  	/* If the message originates from the target mailbox, only update the flags 
   2.105  	 * and keywords 
   2.106  	 */
   2.107 -	if ( trans->redundant ) {
   2.108 +	if ( mailbox_backends_equal(trans->box, msgdata->mail->box) ) {
   2.109 +		trans->redundant = TRUE;
   2.110 +
   2.111  		if ( trans->flags_altered ) {
   2.112  			keywords = act_store_keywords_create
   2.113  				(aenv, &trans->keywords, msgdata->mail->box);
   2.114 @@ -483,10 +478,6 @@
   2.115  		return TRUE;
   2.116  	}
   2.117  
   2.118 -	/* Exit early if mailbox is not available */
   2.119 -	if ( trans->box == NULL ) 
   2.120 -		return FALSE;
   2.121 -
   2.122  	/* Mark attempt to store in default mailbox */
   2.123  	if ( strcmp(trans->context->mailbox, 
   2.124  		SIEVE_SCRIPT_DEFAULT_MAILBOX(aenv->scriptenv)) == 0 ) 
   2.125 @@ -529,12 +520,15 @@
   2.126  }
   2.127  
   2.128  static void act_store_log_status
   2.129 -(struct act_store_transaction *trans, 
   2.130 -	const struct sieve_action_exec_env *aenv, bool rolled_back, bool status )
   2.131 +(struct act_store_transaction *trans, const struct sieve_action_exec_env *aenv,
   2.132 +	bool rolled_back, bool status )
   2.133  {
   2.134  	const char *mailbox_name;
   2.135 -	
   2.136 -	mailbox_name = str_sanitize(trans->context->mailbox, 128);
   2.137 +
   2.138 +	if ( trans->box != NULL )
   2.139 +		mailbox_name = str_sanitize(mailbox_get_vname(trans->box), 128);
   2.140 +	else
   2.141 +		mailbox_name = str_sanitize(trans->context->mailbox, 128);
   2.142  
   2.143  	/* Store disabled? */
   2.144  	if ( trans->disabled ) {
     3.1 --- a/tests/execute/errors.svtest	Mon Jul 05 17:18:23 2010 +0200
     3.2 +++ b/tests/execute/errors.svtest	Thu Jul 08 00:06:42 2010 +0200
     3.3 @@ -80,3 +80,27 @@
     3.4  		test_fail "unexpected error reported";
     3.5  	}
     3.6  }
     3.7 +
     3.8 +test "Fileinto missing folder" {
     3.9 +	if not test_script_compile "errors/fileinto.sieve" {
    3.10 +		test_fail "compile failed";
    3.11 +	}
    3.12 +
    3.13 +	test_mailbox :create "INBOX";
    3.14 +
    3.15 +	if not test_script_run {
    3.16 +		test_fail "execution failed";
    3.17 +	}
    3.18 +
    3.19 +    if test_result_execute {
    3.20 +        test_fail "execution of result should have failed";
    3.21 +    }	
    3.22 +
    3.23 +	if test_error :count "gt" :comparator "i;ascii-numeric" "1" {
    3.24 +		test_fail "too many runtime errors reported";
    3.25 +	}
    3.26 +	
    3.27 +/*	if not test_error :index 1 :contains "number of redirect actions exceeds policy limit"{
    3.28 +		test_fail "unexpected error reported";
    3.29 +	}*/
    3.30 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tests/execute/errors/fileinto.sieve	Thu Jul 08 00:06:42 2010 +0200
     4.3 @@ -0,0 +1,3 @@
     4.4 +require "fileinto";
     4.5 +
     4.6 +fileinto "FROP";