aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2007-10-14 23:23:54 +0200
committerJohannes Berg <johannes@sipsolutions.net>2007-10-14 23:23:54 +0200
commit9d79926aebf81af7ca33648f992c22374def0922 (patch)
treee975057d8398951a054ff448576ab40f7bcdb6a9
parentc1b287878d7ae8d146e7054002479e53de47f6cb (diff)
downloaddovecot-antispam-9d79926aebf81af7ca33648f992c22374def0922.tar.gz
dovecot-antispam-9d79926aebf81af7ca33648f992c22374def0922.tar.xz
dovecot-antispam-9d79926aebf81af7ca33648f992c22374def0922.zip
make settings per-plugin
-rw-r--r--antispam-plugin.c36
-rw-r--r--antispam-plugin.h5
-rw-r--r--crm114-exec.c12
-rw-r--r--debug.c11
-rw-r--r--dspam-exec.c12
-rw-r--r--mailtrain.c18
-rw-r--r--signature-log.c10
-rw-r--r--signature.c6
-rw-r--r--signature.h2
9 files changed, 70 insertions, 42 deletions
diff --git a/antispam-plugin.c b/antispam-plugin.c
index d737758..ad849a6 100644
--- a/antispam-plugin.c
+++ b/antispam-plugin.c
@@ -78,6 +78,21 @@ bool mailbox_is_unsure(struct mailbox *box)
return mailbox_in_list(box, unsure_folders);
}
+const char *get_setting(const char *name)
+{
+ const char *env;
+
+ t_push();
+ env = t_strconcat(t_str_ucase(stringify(PLUGINNAME)),
+ "_",
+ name,
+ NULL);
+ env = getenv(env);
+ t_pop();
+
+ return env;
+}
+
#define __PLUGIN_FUNCTION(name, ioe) \
name ## _plugin_ ## ioe
#define _PLUGIN_FUNCTION(name, ioe) \
@@ -87,50 +102,51 @@ bool mailbox_is_unsure(struct mailbox *box)
void PLUGIN_FUNCTION(init)(void)
{
- char *tmp, **iter;
+ const char *tmp;
+ char * const *iter;
debug("antispam plugin initialising\n");
global_pool = pool_alloconly_create("antispam-pool", 1024);
- tmp = getenv("ANTISPAM_TRASH");
+ tmp = get_setting("TRASH");
if (tmp)
trash_folders = p_strsplit(global_pool, tmp, ";");
if (trash_folders) {
iter = trash_folders;
while (*iter) {
- debug("antispam: \"%s\" is trash folder\n", *iter);
+ debug("\"%s\" is trash folder\n", *iter);
iter++;
}
} else
- debug("antispam: no trash folders\n");
+ debug("no trash folders\n");
- tmp = getenv("ANTISPAM_SPAM");
+ tmp = get_setting("SPAM");
if (tmp)
spam_folders = p_strsplit(global_pool, tmp, ";");
if (spam_folders) {
iter = spam_folders;
while (*iter) {
- debug("antispam: \"%s\" is spam folder\n", *iter);
+ debug("\"%s\" is spam folder\n", *iter);
iter++;
}
} else
- debug("antispam: no spam folders\n");
+ debug("no spam folders\n");
- tmp = getenv("ANTISPAM_UNSURE");
+ tmp = get_setting("UNSURE");
if (tmp)
unsure_folders = p_strsplit(global_pool, tmp, ";");
if (unsure_folders) {
iter = unsure_folders;
while (*iter) {
- debug("antispam: \"%s\" is unsure folder\n", *iter);
+ debug("\"%s\" is unsure folder\n", *iter);
iter++;
}
} else
- debug("antispam: no unsure folders\n");
+ debug("no unsure folders\n");
backend_init(global_pool);
diff --git a/antispam-plugin.h b/antispam-plugin.h
index a660b9d..9b6bae5 100644
--- a/antispam-plugin.h
+++ b/antispam-plugin.h
@@ -7,6 +7,10 @@
#include "ostream.h"
#include "imap-search.h"
+#define __stringify_1(x) #x
+#define stringify(x) __stringify_1(x)
+
+
struct antispam_transaction_context;
enum classification {
@@ -45,5 +49,6 @@ void (*antispam_next_hook_mail_storage_created)(struct mail_storage *storage);
bool mailbox_is_spam(struct mailbox *box);
bool mailbox_is_trash(struct mailbox *box);
bool mailbox_is_unsure(struct mailbox *box);
+const char *get_setting(const char *name);
#endif /* _ANTISPAM_PLUGIN_H */
diff --git a/crm114-exec.c b/crm114-exec.c
index a10ba09..5c69a81 100644
--- a/crm114-exec.c
+++ b/crm114-exec.c
@@ -111,7 +111,7 @@ static int call_reaver(const char *signature, enum classification wanted)
argv[0] = (char *)reaver_binary;
argv[1] = (char *)class_arg;
- debug("antispam: %s %s ...", reaver_binary, class_arg);
+ debug("%s %s ...", reaver_binary, class_arg);
for (i = 0; i < extra_args_num; i++)
argv[i + FIXED_ARGS_NUM] = (char *)extra_args[i];
@@ -173,22 +173,22 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
void backend_init(pool_t pool)
{
- char *tmp;
+ const char *tmp;
int i;
- tmp = getenv("ANTISPAM_CRM_BINARY");
+ tmp = get_setting("CRM_BINARY");
if (tmp) {
reaver_binary = tmp;
- debug("antispam: reaver binary set to %s\n", tmp);
+ debug("reaver binary set to %s\n", tmp);
}
- tmp = getenv("ANTISPAM_CRM_ARGS");
+ tmp = get_setting("CRM_ARGS");
if (tmp) {
extra_args = p_strsplit(pool, tmp, ";");
extra_args_num = str_array_length(
(const char *const *)extra_args);
for (i = 0; i < extra_args_num; i++)
- debug("antispam: reaver extra arg %s\n",
+ debug("reaver extra arg %s\n",
extra_args[i]);
}
diff --git a/debug.c b/debug.c
index 271b9fe..7f46af7 100644
--- a/debug.c
+++ b/debug.c
@@ -6,14 +6,21 @@
static void _debug(const char *format, va_list ap)
{
+ char *fmt;
+
+ t_push();
+
+ fmt = t_strconcat(stringify(PLUGINNAME), ": ", format, NULL);
+
#if defined(DEBUG_SYSLOG)
- vsyslog(LOG_DEBUG, format, ap);
+ vsyslog(LOG_DEBUG, fmt, ap);
#elif defined(DEBUG_STDERR)
- vfprintf(stderr, format, ap);
+ vfprintf(stderr, fmt, ap);
fflush(stderr);
#else
#error no logging method
#endif
+ t_pop();
}
void debug(const char *fmt, ...)
diff --git a/dspam-exec.c b/dspam-exec.c
index 442132e..5c08fc2 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -136,7 +136,7 @@ static int call_dspam(const char *signature, enum classification wanted)
* not good with stderr debuggin since we then write to
* stderr which our parent takes as a bug
*/
- debug("antispam: %s --source=error --stdout %s %s ...",
+ debug("%s --source=error --stdout %s %s ...",
dspam_binary, class_arg, sign_arg);
#endif
@@ -200,21 +200,21 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
void backend_init(pool_t pool)
{
- char *tmp;
+ const char *tmp;
int i;
- tmp = getenv("ANTISPAM_DSPAM_BINARY");
+ tmp = get_setting("DSPAM_BINARY");
if (tmp)
dspam_binary = tmp;
- debug("antispam: dspam binary set to %s\n", dspam_binary);
+ debug("dspam binary set to %s\n", dspam_binary);
- tmp = getenv("ANTISPAM_DSPAM_ARGS");
+ tmp = get_setting("DSPAM_ARGS");
if (tmp) {
extra_args = p_strsplit(pool, tmp, ";");
extra_args_num = str_array_length(
(const char *const *)extra_args);
for (i = 0; i < extra_args_num; i++)
- debug("antispam: dspam extra arg %s\n",
+ debug("dspam extra arg %s\n",
extra_args[i]);
}
diff --git a/mailtrain.c b/mailtrain.c
index cdb522e..66f7087 100644
--- a/mailtrain.c
+++ b/mailtrain.c
@@ -272,30 +272,30 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
void backend_init(pool_t pool)
{
- char *tmp;
+ const char *tmp;
- tmp = getenv("ANTISPAM_MAIL_SPAM");
+ tmp = get_setting("MAIL_SPAM");
if (tmp) {
spamaddr = tmp;
- debug("antispam: mail backend spam address %s\n", tmp);
+ debug("mail backend spam address %s\n", tmp);
}
- tmp = getenv("ANTISPAM_MAIL_NOTSPAM");
+ tmp = get_setting("MAIL_NOTSPAM");
if (tmp) {
hamaddr = tmp;
- debug("antispam: mail backend not-spam address %s\n", tmp);
+ debug("mail backend not-spam address %s\n", tmp);
}
- tmp = getenv("ANTISPAM_MAIL_SENDMAIL");
+ tmp = get_setting("MAIL_SENDMAIL");
if (tmp) {
sendmail_binary = tmp;
- debug("antispam: mail backend sendmail %s\n", tmp);
+ debug("mail backend sendmail %s\n", tmp);
}
- tmp = getenv("ANTISPAM_MAIL_TMPDIR");
+ tmp = get_setting("MAIL_TMPDIR");
if (tmp)
tmpdir = tmp;
- debug("antispam: mail backend tmpdir %s\n", tmpdir);
+ debug("mail backend tmpdir %s\n", tmpdir);
}
void backend_exit(void)
diff --git a/signature-log.c b/signature-log.c
index 6d697d6..ab2e46d 100644
--- a/signature-log.c
+++ b/signature-log.c
@@ -131,18 +131,18 @@ int backend_handle_mail(struct mailbox_transaction_context *t,
void backend_init(pool_t pool)
{
- char *tmp;
+ const char *tmp;
- tmp = getenv("ANTISPAM_SIGLOG_DICT_URI");
+ tmp = get_setting("SIGLOG_DICT_URI");
if (tmp) {
dict_uri = tmp;
- debug("antispam: signature logger dict URI set to %s\n", tmp);
+ debug("signature logger dict URI set to %s\n", tmp);
}
- tmp = getenv("ANTISPAM_SIGLOG_DICT_USER");
+ tmp = get_setting("SIGLOG_DICT_USER");
if (tmp) {
dict_user = tmp;
- debug("antispam: signature logger dict user set to %s\n", tmp);
+ debug("signature logger dict user set to %s\n", tmp);
}
signature_init();
diff --git a/signature.c b/signature.c
index 9a632a3..8257586 100644
--- a/signature.c
+++ b/signature.c
@@ -4,14 +4,14 @@
#include "signature.h"
#include "mail-storage-private.h"
-char *signature_hdr = "X-DSPAM-Signature";
+const char *signature_hdr = "X-DSPAM-Signature";
void signature_init(void)
{
- char *tmp = getenv("ANTISPAM_SIGNATURE");
+ const char *tmp = get_setting("SIGNATURE");
if (tmp)
signature_hdr = tmp;
- debug("antispam: signature header line is \"%s\"\n", signature_hdr);
+ debug("signature header line is \"%s\"\n", signature_hdr);
}
int signature_extract_to_list(struct mailbox_transaction_context *t,
diff --git a/signature.h b/signature.h
index 85da0ff..e25d1b5 100644
--- a/signature.h
+++ b/signature.h
@@ -20,6 +20,6 @@ const char *signature_extract(struct mailbox_transaction_context *t,
struct mail *mail);
void signature_list_free(struct siglist **list);
-extern char *signature_hdr;
+extern const char *signature_hdr;
#endif /* _ANTISPAM_SIGNATURE_H */