From f05b6348e6927a3f6f127b98772d4b925e957f70 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Fri, 30 May 2008 12:16:48 +0200 Subject: make plugin for 1.1 work more or less It's not really tested, might leak memory, eat your mail, whatever... It no longer crashes though. --- antispam-storage-1.1.c | 72 ++++++++++++++++++++------------------------------ defconfig | 2 +- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/antispam-storage-1.1.c b/antispam-storage-1.1.c index 3654382..31042d7 100644 --- a/antispam-storage-1.1.c +++ b/antispam-storage-1.1.c @@ -63,10 +63,6 @@ struct antispam_mailbox { unsigned int save_hack:1; }; -struct antispam_mail { - union mail_module_context module_ctx; -}; - static uint32_t antispam_storage_module_id = 0; static bool antispam_storage_module_id_set = FALSE; @@ -77,14 +73,17 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, { struct antispam_mailbox *asbox = ANTISPAM_CONTEXT(t->box); struct antispam_internal_context *ast = ANTISPAM_CONTEXT(t); - struct mail *copy_dest_mail; int ret; bool src_trash, dst_trash; - if (dest_mail != NULL) - copy_dest_mail = dest_mail; - else - copy_dest_mail = mail_alloc(t, MAIL_FETCH_PHYSICAL_SIZE, NULL); + if (!dest_mail) { + /* always need mail */ + if (!ast->mail) + ast->mail = mail_alloc(t, MAIL_FETCH_STREAM_HEADER | + MAIL_FETCH_STREAM_BODY, + NULL); + dest_mail = ast->mail; + } i_assert(mail->box); @@ -118,7 +117,8 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, asbox->movetype = MMT_TO_SPAM; } - if (asbox->module_ctx.super.copy(t, mail, flags, keywords, copy_dest_mail) < 0) + if (asbox->module_ctx.super.copy(t, mail, flags, keywords, + dest_mail) < 0) return -1; /* @@ -127,7 +127,7 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, if (asbox->save_hack || asbox->movetype == MMT_UNINTERESTING) ret = 0; else - ret = backend_handle_mail(t, ast->backendctx, copy_dest_mail, + ret = backend_handle_mail(t, ast->backendctx, dest_mail, move_to_class(asbox->movetype)); /* @@ -141,9 +141,6 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, * save to the mailbox should not invoke the backend. */ asbox->movetype = MMT_APPEND; - - if (copy_dest_mail != dest_mail) - mail_free(©_dest_mail); return ret; } @@ -157,9 +154,11 @@ static int antispam_save_init(struct mailbox_transaction_context *t, struct antispam_internal_context *ast = ANTISPAM_CONTEXT(t); struct antispam_mailbox *asbox = ANTISPAM_CONTEXT(t->box); - if (!dest_mail && !ast->mail) { - ast->mail = mail_alloc(t, MAIL_FETCH_STREAM_HEADER | - MAIL_FETCH_STREAM_BODY, NULL); + if (!dest_mail) { + if (!ast->mail) + ast->mail = mail_alloc(t, MAIL_FETCH_STREAM_HEADER | + MAIL_FETCH_STREAM_BODY, + NULL); dest_mail = ast->mail; } return asbox->module_ctx.super.save_init(t, flags, keywords, received_date, @@ -285,7 +284,7 @@ antispam_mail_update_keywords(struct mail *mail, struct mail_keywords *keywords) { struct mail_private *pmail = (struct mail_private *)mail; - struct antispam_mail *amail = ANTISPAM_MAIL_CONTEXT(pmail); + union mail_module_context *amail = ANTISPAM_MAIL_CONTEXT(pmail); unsigned int i, numkwds; const ARRAY_TYPE(keywords) *idxkwd = mail_index_get_keywords(keywords->index); const char *const *keyword_names = array_get(idxkwd, &numkwds); @@ -341,7 +340,7 @@ antispam_mail_update_keywords(struct mail *mail, } } - amail->module_ctx.super.update_keywords(mail, modify_type, keywords); + amail->super.update_keywords(mail, modify_type, keywords); debug("previous-spam, now-spam: %d, %d\n", previous_spam_keyword, now_spam_keyword); @@ -356,16 +355,6 @@ antispam_mail_update_keywords(struct mail *mail, } } -static void -antispam_mail_free(struct mail *mail) -{ - struct mail_private *pmail = (struct mail_private *)mail; - struct antispam_mail *amail = ANTISPAM_MAIL_CONTEXT(pmail); - - amail->module_ctx.super.free(mail); - i_free(amail); -} - static struct mailbox_transaction_context * antispam_mailbox_transaction_begin(struct mailbox *box, enum mailbox_transaction_flags flags) @@ -429,23 +418,20 @@ antispam_mailbox_mail_alloc(struct mailbox_transaction_context *ctx, struct mailbox_header_lookup_ctx *wanted_headers) { struct antispam_mailbox *asbox = ANTISPAM_CONTEXT(ctx->box); - struct antispam_mail *amail = i_new(struct antispam_mail, 1); - struct mail_private *pmail; - - /* XXX: is this cast the right thing to do? */ - pmail = (struct mail_private *) asbox->module_ctx.super.mail_alloc( - ctx, - wanted_fields, - wanted_headers); - - amail->module_ctx.super = pmail->v; + union mail_module_context *amail; + struct mail *_mail; + struct mail_private *mail; - MODULE_CONTEXT_SET(pmail, antispam_mail_module, amail); + _mail = asbox->module_ctx.super. + mail_alloc(ctx, wanted_fields, wanted_headers); + mail = (struct mail_private *)_mail; - pmail->v.update_keywords = antispam_mail_update_keywords; - pmail->v.free = antispam_mail_free; + amail = p_new(mail->pool, union mail_module_context, 1); + amail->super = mail->v; - return (struct mail *)pmail; + mail->v.update_keywords = antispam_mail_update_keywords; + MODULE_CONTEXT_SET_SELF(mail, antispam_mail_module, amail); + return _mail; } static struct mailbox *antispam_mailbox_open(struct mail_storage *storage, diff --git a/defconfig b/defconfig index dbea209..38f174b 100644 --- a/defconfig +++ b/defconfig @@ -21,7 +21,7 @@ DOVECOT=../dovecot-1.0.5 # Dovecot version to build against DOVECOT_VERSION=1.0 -#DOVECOT_VERSION=1.1 # CURRENTLY BROKEN +#DOVECOT_VERSION=1.1 # CURRENTLY NOT REALLY TESTED # backend (select exactly one) # dspam-exec - direct dspam training by calling dspam executable -- cgit v1.2.3