summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/INSTRUCTION34
-rw-r--r--src/config.c51
-rw-r--r--src/dbase.c26
-rw-r--r--src/dbase.h5
-rw-r--r--src/kbsrc39
5 files changed, 133 insertions, 22 deletions
diff --git a/doc/INSTRUCTION b/doc/INSTRUCTION
index e55fdef..9edde2a 100644
--- a/doc/INSTRUCTION
+++ b/doc/INSTRUCTION
@@ -23,6 +23,8 @@ order:
[trusted settings]
+[blacklist settings]
+
[subject macros]
[domain settings]
@@ -107,7 +109,8 @@ Trusted settings
================
These define users and domains for which mail is let thorugh, regardless of
-other tests.
+other tests. These are not regular expressions - they are simply compared
+with a case-insignificant test.
trusted_users
{
@@ -122,6 +125,22 @@ other tests.
}
+Blacklist settings
+==================
+
+These define domains for which mail will be deleted with extreme prejedice.
+
+ blacklist
+ {
+ <domain regular expression>
+ [<domain regular expression>]
+ }
+
+Note that unlike the trusted commands these are regular expressions. It's
+probably fairly useless as I'd imagine most messages will have butchered
+'From:' fields, but heck, it's there if you need it.
+
+
Subject Macros
==============
@@ -193,13 +212,14 @@ done in this order:
1. If a trusted domain, allow message.
2. If a trusted user, allow message.
3. If an HTML message and these are blocked, delete message.
-4. If the domain is not matched in a domain command, allow message.
-5. If the subject is allowed for the domain, allow message.
-6. If the username is blocked for the domain, delete message.
-7. If the subject is disallowed for the domain, delete message.
-8. Delete the message if the default is to block.
+4. If the domain is blacklisted, delete message.
+5. If the domain is not matched in a domain command, allow message.
+6. If the subject is allowed for the domain, allow message.
+7. If the username is blocked for the domain, delete message.
+8. If the subject is disallowed for the domain, delete message.
+9. Delete the message if the default is to block, otherwise allow.
-------------------------------------------------------------------------------
-$Id: INSTRUCTION,v 1.4 2003-12-08 02:20:14 ianc Exp $
+$Id: INSTRUCTION,v 1.5 2003-12-09 01:25:08 ianc Exp $
diff --git a/src/config.c b/src/config.c
index 268198d..4e369f7 100644
--- a/src/config.c
+++ b/src/config.c
@@ -54,6 +54,7 @@ typedef enum {
TOK_AllowSubject,
TOK_BlockSubject,
TOK_SubjectMacro,
+ TOK_Blacklist,
TOK_VarHostname,
TOK_VarPort,
TOK_VarUsername,
@@ -122,6 +123,7 @@ static const Command cmd_table[]=
{"allow_subject", TOK_AllowSubject},
{"block_subject", TOK_BlockSubject},
{"subject_macro", TOK_SubjectMacro},
+ {"blacklist", TOK_Blacklist},
/* Variables
*/
@@ -524,6 +526,50 @@ static int DoSubjectMacro(FILE *fp)
}
+static int DoBlacklist(FILE *fp)
+{
+ DString ds;
+ Token tok;
+
+ ds=DSInit();
+
+ tok=GetToken(fp,&ds);
+
+ if (tok!=TOK_OpenBracket)
+ {
+ DSAddCP(error,"Missing opening bracket in blacklist");
+ DSFree(ds);
+ return FALSE;
+ }
+
+ while((tok=GetToken(fp,&ds))!=TOK_CloseBracket)
+ {
+ RE_Expression re;
+
+ if (tok==TOK_EOF)
+ {
+ DSAddCP(error,"Missing close bracket in blacklist");
+ DSFree(ds);
+ return FALSE;
+ }
+
+ if (!(re=RECompile(ds->text)))
+ {
+ DSAddCP(error,"Bad regular expression: ");
+ DSAddDS(error,ds);
+ DSFree(ds);
+ return FALSE;
+ }
+
+ DBBlacklist(re);
+ }
+
+ DSFree(ds);
+
+ return TRUE;
+}
+
+
/* ---------------------------------------- PRVIVATE FUNCTIONS
*/
static int Getc(FILE *fp)
@@ -695,6 +741,11 @@ static int Parse(FILE *fp)
ok=FALSE;
break;
+ case TOK_Blacklist:
+ if (!DoBlacklist(fp))
+ ok=FALSE;
+ break;
+
case TOK_Expression:
DSAddCP(error,"Unknown command in config file: ");
DSAddDS(error,txt);
diff --git a/src/dbase.c b/src/dbase.c
index 43fe0b5..98a7629 100644
--- a/src/dbase.c
+++ b/src/dbase.c
@@ -62,9 +62,11 @@ static Domain *tail;
static int no_trusted_users=0;
static int no_trusted_domains=0;
+static int no_blacklist=0;
static char **trusted_user=NULL;
static char **trusted_domain=NULL;
+static RE_Expression **blacklist=NULL;
static const char *reason;
@@ -220,6 +222,14 @@ void DBTrustedDomain(const char *domain)
}
+void DBBlacklist(RE_Expression re)
+{
+ no_blacklist++;
+ blacklist=Realloc(blacklist,sizeof(RE_Expression)*no_blacklist);
+ blacklist[no_blacklist-1]=re;
+}
+
+
int DBBlockMessage(const POP3Message *msg)
{
static const char *html="text/html";
@@ -243,6 +253,15 @@ int DBBlockMessage(const POP3Message *msg)
return TRUE;
}
+ for(f=0;f<no_blacklist;f++)
+ {
+ if (RESearch(blacklist[f],msg->from_domain))
+ {
+ reason="blacklisted";
+ return TRUE;
+ }
+ }
+
if (!(dom=GetDomain(msg->from_domain)))
return FALSE;
@@ -316,6 +335,11 @@ void DBClose(void)
free(trusted_user);
+ for(f=0;f<no_blacklist;f++)
+ REFree(blacklist[f]);
+
+ free(blacklist);
+
d=head;
while(d)
@@ -337,7 +361,7 @@ void DBClose(void)
free(t->block);
for(f=0;f<t->no_allow;f++)
- free(t->allow[f]);
+ REFree(t->allow[f]);
free(t->allow);
diff --git a/src/dbase.h b/src/dbase.h
index c7a98ee..7ee7164 100644
--- a/src/dbase.h
+++ b/src/dbase.h
@@ -80,6 +80,11 @@ void DBTrustedUser(const char *username);
void DBTrustedDomain(const char *domain);
+/* Adds a blacklisted domain
+*/
+void DBBlacklist(RE_Expression re);
+
+
/* Returns TRUE if message is to be blocked
*/
int DBBlockMessage(const POP3Message *msg);
diff --git a/src/kbsrc b/src/kbsrc
index e59e512..5361dd3 100644
--- a/src/kbsrc
+++ b/src/kbsrc
@@ -24,31 +24,41 @@ trusted_domains
{
my-place-of-work.com
freebsd.org
+ kernel.org
}
+# Blacklist specific domains
+#
+blacklist
+{
+ ^wretched-hive-of-scum-and-villainy\.com$
+ ^jumbo-whatsits\.com$
+ ^microsoft\.com$
+}
+
+
+# Set up a few subject macros
+#
+subject_macro "i" "[il1!]"
+subject_macro "e" "[e3]"
+subject_macro "s" "[s5z]"
+
+
# Domain based rules
#
# Remember that the domain is defined in the form of a regular expression!
#
# Anyone who doesn't know me, has to include the string ansi-c to
-# get through from a .net address.
+# get through from a .com address.
#
-domain "\.net$"
+domain "\.com$"
{
default block
allow_subject ".*ansi-c.*"
}
-# 'Blacklist' a specific domain
-#
-domain "^wretched-hive-of-scum-and-villainy\.com$"
-{
- default block
-}
-
-
# Or alternatively apply general rules to all untrusted messages
#
domain "."
@@ -66,7 +76,7 @@ domain "."
# to check the delete logs once in a while.
#
# And to avoid insulting anyone, there are some obvious words missing
- # from this example list... If you're old enough, add them yourself.
+ # from this example list... If you're old enough, add them yourself...
#
# And finally remember a few variants - spelling isn't what it once was
# amongst spammers...
@@ -78,14 +88,15 @@ domain "."
block_subject ".* ?mortgage ?.*"
block_subject ".* ?credit card ?.*"
block_subject ".* ?miracle pill ?.*"
- block_subject ".* ?teenage girl ?.*"
+ block_subject ".* ?schoolgirl ?.*"
block_subject ".* ?video tape ?.*"
block_subject ".* ?sexy? ?.*"
block_subject ".* ?naked ?.*"
block_subject ".* ?nigeria ?.*"
# Why would anyone sane want to use my username in a subject?
- # I know who I am!
+ # I know who I am! Note it's capitilised so nothing bizarre gets
+ # done by the subject macros.
#
- block_subject "emailname@my-isp.co.uk"
+ block_subject "EMAILNAME@MY-ISP.CO.UK"
}