diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-05-31 10:41:45 +0200 |
---|---|---|
committer | Johannes Berg <johannes@sipsolutions.net> | 2008-05-31 10:41:45 +0200 |
commit | bccbcfb6b48906eec7a9436922cdb8f6be6c8ad8 (patch) | |
tree | f935d1f478d5f9d13c7a8452cc90d2e1389fceef | |
parent | 38db5199da4be4832bf852244951a07b0bc28edb (diff) | |
download | dovecot-antispam-bccbcfb6b48906eec7a9436922cdb8f6be6c8ad8.tar.gz dovecot-antispam-bccbcfb6b48906eec7a9436922cdb8f6be6c8ad8.tar.xz dovecot-antispam-bccbcfb6b48906eec7a9436922cdb8f6be6c8ad8.zip |
clean up dovecot compat code a bit
-rw-r--r-- | antispam-plugin.c | 5 | ||||
-rw-r--r-- | antispam-plugin.h | 32 | ||||
-rw-r--r-- | mailtrain.c | 13 |
3 files changed, 36 insertions, 14 deletions
diff --git a/antispam-plugin.c b/antispam-plugin.c index fdde26d..2e6449d 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -40,9 +40,8 @@ extern void (*hook_mail_storage_created)(struct mail_storage *storage); /* internal stuff we need */ #include "antispam-plugin.h" -#ifdef CONFIG_DOVECOT_11 -uint32_t PLUGIN_FUNCTION(id) = 0; -#endif +/* macro since only needed for dovecot 1.1 */ +PLUGIN_ID; static pool_t global_pool; static char **trash_folders = NULL; diff --git a/antispam-plugin.h b/antispam-plugin.h index d6e05ca..dfe4445 100644 --- a/antispam-plugin.h +++ b/antispam-plugin.h @@ -1,6 +1,7 @@ #ifndef _ANTISPAM_PLUGIN_H #define _ANTISPAM_PLUGIN_H +#include "config.h" #include "lib.h" #include "str.h" #include "client.h" @@ -74,14 +75,45 @@ bool keyword_is_spam(const char *keyword); extern bool need_keyword_hook; extern bool need_folder_hook; +/* + * Dovecot version compat code + */ + #if defined(CONFIG_DOVECOT_11) #define __attr_unused__ ATTR_UNUSED #define ME(err) MAIL_ERROR_ ##err, +#define PLUGIN_ID uint32_t PLUGIN_FUNCTION(id) = 0 #define mempool_unref(x) pool_unref(x) + +static inline struct istream *get_mail_stream(struct mail *mail) +{ + struct istream *result; + if (mail_get_stream(mail, NULL, NULL, &result) < 0) + return NULL; + return result; +} + +static inline struct ostream * +o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED) +{ + return o_stream_create_fd(fd, 0, TRUE); +} #elif defined(CONFIG_DOVECOT_10) #define ME(err) +#define PLUGIN_ID #define str_array_length(x) strarray_length(x) #define mempool_unref(x) pool_unref(*(x)) + +static inline struct istream *get_mail_stream(struct mail *mail) +{ + return mail_get_stream(mail, NULL, NULL); +} + +static inline struct ostream * +o_stream_create_from_fd(int fd, pool_t pool) +{ + return o_stream_create_file(fd, pool, 0, TRUE); +} #else #error "Building against this dovecot version is not supported" #endif diff --git a/mailtrain.c b/mailtrain.c index a0e4a40..7156805 100644 --- a/mailtrain.c +++ b/mailtrain.c @@ -233,12 +233,7 @@ int backend_handle_mail(struct mailbox_transaction_context *t, return -1; } -#ifdef CONFIG_DOVECOT_11 - if (mail_get_stream(mail, NULL, NULL, &mailstream) < 0) - mailstream = NULL; -#else - mailstream = mail_get_stream(mail, NULL, NULL); -#endif + mailstream = get_mail_stream(mail); if (!mailstream) { mail_storage_set_error(t->box->storage, ME(EXPUNGED) @@ -262,11 +257,7 @@ int backend_handle_mail(struct mailbox_transaction_context *t, ast->count++; -#ifdef CONFIG_DOVECOT_11 - outstream = o_stream_create_fd(fd, 0, TRUE); -#else - outstream = o_stream_create_file(fd, t->box->pool, 0, TRUE); -#endif + outstream = o_stream_create_from_fd(fd, t->box->pool); if (!outstream) { ret = -1; mail_storage_set_error(t->box->storage, |