dovecot-2.1-pigeonhole: lib-sieve: added support for substitutin...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Dec 27 22:12:02 EET 2011
details: http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/4cc6444438f6
changeset: 1586:4cc6444438f6
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Dec 27 21:11:49 2011 +0100
description:
lib-sieve: added support for substituting the entire message.
This is needed for the new extprograms plugin.
diffstat:
src/lib-sieve/cmd-discard.c | 2 +-
src/lib-sieve/cmd-keep.c | 2 -
src/lib-sieve/cmd-redirect.c | 4 +-
src/lib-sieve/ext-reject.c | 2 +-
src/lib-sieve/plugins/body/ext-body-common.c | 11 +-
src/lib-sieve/plugins/enotify/cmd-notify.c | 2 +-
src/lib-sieve/plugins/notify/cmd-notify.c | 2 +-
src/lib-sieve/plugins/vacation/cmd-vacation.c | 2 +-
src/lib-sieve/sieve-actions.c | 4 +-
src/lib-sieve/sieve-message.c | 223 ++++++++++++++++++++++++++-----
src/lib-sieve/sieve-message.h | 7 +-
src/lib-sieve/sieve-result.c | 24 ++-
src/lib-sieve/sieve-result.h | 4 +-
src/testsuite/testsuite-message.c | 14 +-
14 files changed, 226 insertions(+), 77 deletions(-)
diffs (truncated from 646 to 300 lines):
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/cmd-discard.c
--- a/src/lib-sieve/cmd-discard.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/cmd-discard.c Tue Dec 27 21:11:49 2011 +0100
@@ -109,7 +109,7 @@
"discard action; cancel implicit keep");
if ( sieve_result_add_action
- (renv, NULL, &act_discard, NULL, NULL, 0) < 0 )
+ (renv, NULL, &act_discard, NULL, NULL, 0, FALSE) < 0 )
return SIEVE_EXEC_FAILURE;
return SIEVE_EXEC_OK;
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/cmd-keep.c
--- a/src/lib-sieve/cmd-keep.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/cmd-keep.c Tue Dec 27 21:11:49 2011 +0100
@@ -107,8 +107,6 @@
if ( sieve_result_add_keep(renv, slist) < 0 )
return SIEVE_EXEC_FAILURE;
- sieve_message_snapshot(renv->msgctx);
-
return SIEVE_EXEC_OK;
}
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/cmd-redirect.c
--- a/src/lib-sieve/cmd-redirect.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/cmd-redirect.c Tue Dec 27 21:11:49 2011 +0100
@@ -248,11 +248,9 @@
if ( sieve_result_add_action
(renv, NULL, &act_redirect, slist, (void *) act,
- svinst->max_redirects) < 0 )
+ svinst->max_redirects, TRUE) < 0 )
return SIEVE_EXEC_FAILURE;
- sieve_message_snapshot(renv->msgctx);
-
return SIEVE_EXEC_OK;
}
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/ext-reject.c
--- a/src/lib-sieve/ext-reject.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/ext-reject.c Tue Dec 27 21:11:49 2011 +0100
@@ -306,7 +306,7 @@
act->ereject = ( sieve_operation_is(oprtn, ereject_operation) );
if ( sieve_result_add_action
- (renv, this_ext, &act_reject, slist, (void *) act, 0) < 0 )
+ (renv, this_ext, &act_reject, slist, (void *) act, 0, FALSE) < 0 )
return SIEVE_EXEC_FAILURE;
return SIEVE_EXEC_OK;
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/plugins/body/ext-body-common.c
--- a/src/lib-sieve/plugins/body/ext-body-common.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/plugins/body/ext-body-common.c Tue Dec 27 21:11:49 2011 +0100
@@ -192,9 +192,10 @@
* Add requested message body parts to the cache that are missing.
*/
static bool ext_body_parts_add_missing
-(const struct sieve_message_data *msgdata, struct ext_body_message_context *ctx,
+(struct sieve_message_context *msgctx, struct ext_body_message_context *ctx,
const char * const *content_types, bool decode_to_plain)
{
+ struct mail *mail = sieve_message_get_mail(msgctx);
struct ext_body_part_cached *body_part = NULL, *header_part = NULL;
struct message_parser_ctx *parser;
struct message_decoder_context *decoder;
@@ -212,9 +213,9 @@
}
/* Get the message stream */
- if ( mail_get_stream(msgdata->mail, NULL, NULL, &input) < 0 )
+ if ( mail_get_stream(mail, NULL, NULL, &input) < 0 )
return FALSE;
- //if (mail_get_parts(msgdata->mail, &parts) < 0)
+ //if (mail_get_parts(mail, &parts) < 0)
// return FALSE;
buffer_set_used_size(ctx->tmp_buffer, 0);
@@ -395,7 +396,7 @@
T_BEGIN {
/* Fill the return_body_parts array */
if ( !ext_body_parts_add_missing
- (renv->msgdata, ctx, content_types, decode_to_plain != 0) )
+ (renv->msgctx, ctx, content_types, decode_to_plain != 0) )
result = FALSE;
} T_END;
@@ -419,7 +420,7 @@
buffer_t *buf;
if ( ctx->raw_body == NULL ) {
- struct mail *mail = renv->msgdata->mail;
+ struct mail *mail = sieve_message_get_mail(renv->msgctx);
struct istream *input;
struct message_size hdr_size, body_size;
const unsigned char *data;
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/plugins/enotify/cmd-notify.c
--- a/src/lib-sieve/plugins/enotify/cmd-notify.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/plugins/enotify/cmd-notify.c Tue Dec 27 21:11:49 2011 +0100
@@ -487,7 +487,7 @@
act->from = p_strdup(pool, str_c(from));
if ( sieve_result_add_action
- (renv, this_ext, &act_notify, slist, (void *) act, 0) < 0 )
+ (renv, this_ext, &act_notify, slist, (void *) act, 0, FALSE) < 0 )
return SIEVE_EXEC_FAILURE;
return SIEVE_EXEC_OK;
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/plugins/notify/cmd-notify.c
--- a/src/lib-sieve/plugins/notify/cmd-notify.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/plugins/notify/cmd-notify.c Tue Dec 27 21:11:49 2011 +0100
@@ -554,7 +554,7 @@
}
if ( sieve_result_add_action
- (renv, this_ext, &act_notify_old, NULL, (void *) act, 0) < 0 )
+ (renv, this_ext, &act_notify_old, NULL, (void *) act, 0, FALSE) < 0 )
return SIEVE_EXEC_FAILURE;
}
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Dec 27 21:11:49 2011 +0100
@@ -728,7 +728,7 @@
}
if ( sieve_result_add_action
- (renv, this_ext, &act_vacation, slist, (void *) act, 0) < 0 )
+ (renv, this_ext, &act_vacation, slist, (void *) act, 0, FALSE) < 0 )
return SIEVE_EXEC_FAILURE;
return SIEVE_EXEC_OK;
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/sieve-actions.c
--- a/src/lib-sieve/sieve-actions.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/sieve-actions.c Tue Dec 27 21:11:49 2011 +0100
@@ -231,8 +231,8 @@
act = p_new(pool, struct act_store_context, 1);
act->mailbox = p_strdup(pool, mailbox);
- return sieve_result_add_action(renv, NULL, &act_store, seffects,
- (void *) act, 0);
+ return sieve_result_add_action
+ (renv, NULL, &act_store, seffects, (void *)act, 0, TRUE);
}
void sieve_act_store_add_flags
diff -r fc9923837fa0 -r 4cc6444438f6 src/lib-sieve/sieve-message.c
--- a/src/lib-sieve/sieve-message.c Tue Dec 27 11:56:25 2011 +0100
+++ b/src/lib-sieve/sieve-message.c Tue Dec 27 21:11:49 2011 +0100
@@ -7,7 +7,12 @@
#include "array.h"
#include "str.h"
#include "str-sanitize.h"
+#include "istream.h"
#include "mail-storage.h"
+#include "mail-user.h"
+#include "master-service.h"
+#include "master-service-settings.h"
+#include "raw-storage.h"
#include "edit-mail.h"
@@ -39,12 +44,21 @@
* Message context
*/
+struct sieve_message_version {
+ struct mail *mail;
+ struct mailbox *box;
+ struct mailbox_transaction_context *trans;
+ struct edit_mail *edit_mail;
+};
+
struct sieve_message_context {
pool_t pool;
+ pool_t context_pool;
int refcount;
struct sieve_instance *svinst;
+ struct mail_user *mail_user;
const struct sieve_message_data *msgdata;
/* Normalized envelope addresses */
@@ -55,9 +69,10 @@
const struct sieve_address *envelope_orig_recipient;
const struct sieve_address *envelope_final_recipient;
- /* Edited mail struct */
+ /* Message versioning */
- struct edit_mail *edit_mail;
+ struct mail_user *raw_mail_user;
+ ARRAY_DEFINE(versions, struct sieve_message_version);
/* Context data for extensions */
ARRAY_DEFINE(ext_contexts, void *);
@@ -65,18 +80,63 @@
unsigned int edit_snapshot:1;
};
+/*
+ * Message versions
+ */
+
+static inline struct sieve_message_version *sieve_message_version_new
+(struct sieve_message_context *msgctx)
+{
+ return array_append_space(&msgctx->versions);
+}
+
+static inline struct sieve_message_version *sieve_message_version_get
+(struct sieve_message_context *msgctx)
+{
+ struct sieve_message_version *versions;
+ unsigned int count;
+
+ versions = array_get_modifiable(&msgctx->versions, &count);
+ if ( count == 0 )
+ return array_append_space(&msgctx->versions);
+
+ return &versions[count-1];
+}
+
+static inline void sieve_message_version_free
+(struct sieve_message_version *version)
+{
+ if ( version->edit_mail != NULL ) {
+ edit_mail_unwrap(&version->edit_mail);
+ version->edit_mail = NULL;
+ }
+
+ if ( version->mail != NULL ) {
+ mail_free(&version->mail);
+ mailbox_transaction_rollback(&version->trans);
+ mailbox_free(&version->box);
+ version->mail = NULL;
+ }
+}
+
+/*
+ * Message context object
+ */
+
struct sieve_message_context *sieve_message_context_create
-(struct sieve_instance *svinst, const struct sieve_message_data *msgdata)
+(struct sieve_instance *svinst, struct mail_user *mail_user,
+ const struct sieve_message_data *msgdata)
{
struct sieve_message_context *msgctx;
-
+
msgctx = i_new(struct sieve_message_context, 1);
msgctx->refcount = 1;
msgctx->svinst = svinst;
+ msgctx->mail_user = mail_user;
msgctx->msgdata = msgdata;
- sieve_message_context_flush(msgctx);
+ sieve_message_context_reset(msgctx);
return msgctx;
}
@@ -86,50 +146,69 @@
msgctx->refcount++;
}
-void sieve_message_context_unref(struct sieve_message_context **msgctx)
+static void sieve_message_context_clear(struct sieve_message_context *msgctx)
{
- i_assert((*msgctx)->refcount > 0);
-
- if (--(*msgctx)->refcount != 0)
- return;
-
- pool_unref(&((*msgctx)->pool));
-
- if ( (*msgctx)->edit_mail != NULL )
- edit_mail_unwrap(&(*msgctx)->edit_mail);
-
- i_free(*msgctx);
- *msgctx = NULL;
-}
-
-void sieve_message_context_flush(struct sieve_message_context *msgctx)
-{
- pool_t pool;
+ struct sieve_message_version *versions;
+ unsigned int count, i;
if ( msgctx->pool != NULL ) {
- pool_unref(&msgctx->pool);
+ versions = array_get_modifiable(&msgctx->versions, &count);
+
+ for ( i = 0; i < count; i++ ) {
+ sieve_message_version_free(&versions[i]);
+ }
+
More information about the dovecot-cvs
mailing list