summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c9
-rw-r--r--src/config.h5
-rw-r--r--src/dbase.c45
-rw-r--r--src/dbase.h2
-rw-r--r--src/dstring.c8
-rw-r--r--src/dstring.h4
-rw-r--r--src/global.h2
-rw-r--r--src/kbs.c2
-rw-r--r--src/msg.h2
-rw-r--r--src/pop3.c3
-rw-r--r--src/pop3.h2
-rw-r--r--src/rexp.c33
-rw-r--r--src/rexp.h9
-rw-r--r--src/util.c2
-rw-r--r--src/util.h2
15 files changed, 104 insertions, 26 deletions
diff --git a/src/config.c b/src/config.c
index 4e369f7..1c10591 100644
--- a/src/config.c
+++ b/src/config.c
@@ -38,6 +38,8 @@ static const char id[]="$Id$";
#include "rexp.h"
#include "util.h"
+static const char header_id[]=KBS_CONFIG_H;
+
/* ---------------------------------------- TYPES
*/
@@ -66,6 +68,7 @@ typedef enum {
TOK_VarTestmode,
TOK_VarBlockHTML,
TOK_VarVerbose,
+ TOK_VarShowmatch,
TOK_ConstOn,
TOK_ConstOff,
TOK_ConstBlock,
@@ -101,6 +104,7 @@ static int dejunk=FALSE;
static int testmode=FALSE;
static int blockhtml=FALSE;
static int verbose=TRUE;
+static int show_match=TRUE;
static int no_macro=0;
static Macro *macro=NULL;
@@ -138,6 +142,7 @@ static const Command cmd_table[]=
{"testmode", TOK_VarTestmode},
{"blockhtml", TOK_VarBlockHTML},
{"verbose", TOK_VarVerbose},
+ {"showmatch", TOK_VarShowmatch},
/* Constants
*/
@@ -225,6 +230,7 @@ static int DoSet(FILE *fp)
{TOK_VarTestmode, TYPE_ONOFF, (void *)&testmode},
{TOK_VarBlockHTML, TYPE_ONOFF, (void *)&blockhtml},
{TOK_VarVerbose, TYPE_ONOFF, (void *)&verbose},
+ {TOK_VarShowmatch, TYPE_ONOFF, (void *)&show_match},
{TOK_EOF,0,NULL}
};
@@ -863,6 +869,9 @@ int ConfigInt(ConfigIntVar var)
case CONFIG_VERBOSE:
return verbose;
+ case CONFIG_SHOWMATCH:
+ return show_match;
+
default:
return 0;
}
diff --git a/src/config.h b/src/config.h
index 3fec38f..7f48a70 100644
--- a/src/config.h
+++ b/src/config.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_CONFIG_H
-#define KBS_CONFIG_H
+#define KBS_CONFIG_H "$Id$"
/* ---------------------------------------- VARIABLE NAMES
@@ -54,7 +54,8 @@ typedef enum
CONFIG_DEJUNK,
CONFIG_TESTMODE,
CONFIG_BLOCKHTML,
- CONFIG_VERBOSE
+ CONFIG_VERBOSE,
+ CONFIG_SHOWMATCH
} ConfigIntVar;
/* ---------------------------------------- INTERFACES
diff --git a/src/dbase.c b/src/dbase.c
index 98a7629..c3e83b7 100644
--- a/src/dbase.c
+++ b/src/dbase.c
@@ -37,6 +37,8 @@ static const char id[]="$Id$";
#include "config.h"
#include "util.h"
+static const char header_id[]=KBS_DBASE_H;
+
/* ---------------------------------------- TYPES
*/
@@ -66,9 +68,9 @@ static int no_blacklist=0;
static char **trusted_user=NULL;
static char **trusted_domain=NULL;
-static RE_Expression **blacklist=NULL;
+static RE_Expression *blacklist=NULL;
-static const char *reason;
+static DString reason=NULL;
/* ---------------------------------------- PRVIVATE FUNCTIONS
@@ -236,8 +238,11 @@ int DBBlockMessage(const POP3Message *msg)
DString ds;
const Domain *dom;
int f;
+ int show;
+
+ show=ConfigInt(CONFIG_SHOWMATCH);
- reason="None";
+ reason=DSReset(reason);
if (IsTrustedDomain(msg->from_domain))
return FALSE;
@@ -249,7 +254,7 @@ int DBBlockMessage(const POP3Message *msg)
(strncmp(msg->content_type,html,strlen(html))==0 ||
strcmp(msg->content_type,"UNKNOWN")==0))
{
- reason="HTML message";
+ DSAddCP(reason,"HTML message");
return TRUE;
}
@@ -257,7 +262,14 @@ int DBBlockMessage(const POP3Message *msg)
{
if (RESearch(blacklist[f],msg->from_domain))
{
- reason="blacklisted";
+ if (show)
+ {
+ DSAddCP(reason,"blacklisted - ");
+ DSAddCP(reason,REGetExpression(blacklist[f]));
+ }
+ else
+ DSAddCP(reason,"blacklisted");
+
return TRUE;
}
}
@@ -293,7 +305,14 @@ int DBBlockMessage(const POP3Message *msg)
if (res==0)
{
DSFree(ds);
- reason="disallowed name";
+
+ if (show)
+ {
+ DSAddCP(reason,"disallowed name - ");
+ DSAddCP(reason,dom->user[f]);
+ }
+ else
+ DSAddCP(reason,"disallowed name");
return TRUE;
}
}
@@ -302,13 +321,19 @@ int DBBlockMessage(const POP3Message *msg)
{
if (RESearch(dom->block[f],ds->text))
{
- reason="disallowed subject";
+ if (show)
+ {
+ DSAddCP(reason,"disallowed subject - ");
+ DSAddCP(reason,REGetExpression(dom->block[f]));
+ }
+ else
+ DSAddCP(reason,"disallowed subject");
DSFree(ds);
return TRUE;
}
}
- reason="default";
+ DSAddCP(reason,"default block");
DSFree(ds);
return dom->def_block;
}
@@ -316,7 +341,7 @@ int DBBlockMessage(const POP3Message *msg)
const char *DBBlockReason(void)
{
- return reason;
+ return reason->text;
}
@@ -325,6 +350,8 @@ void DBClose(void)
Domain *d;
int f;
+ DSFree(reason);
+
for(f=0;f<no_trusted_domains;f++)
free(trusted_domain[f]);
diff --git a/src/dbase.h b/src/dbase.h
index 7ee7164..3c771af 100644
--- a/src/dbase.h
+++ b/src/dbase.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_DBASE_H
-#define KBS_DBASE_H
+#define KBS_DBASE_H "$Id$"
#include "msg.h"
#include "rexp.h"
diff --git a/src/dstring.c b/src/dstring.c
index 7e13067..ce434db 100644
--- a/src/dstring.c
+++ b/src/dstring.c
@@ -42,6 +42,7 @@ static const char id[]="$Id$";
#include "dstring.h"
#include "util.h"
+static const char header_id[]=KBS_DSTRING_H;
/* ---------------------------------------- CONSTANTS
*/
@@ -66,8 +67,11 @@ DString DSInit(void)
void DSFree(DString ds)
{
- free(ds->text);
- free(ds);
+ if (ds)
+ {
+ free(ds->text);
+ free(ds);
+ }
}
diff --git a/src/dstring.h b/src/dstring.h
index db6454f..36ea4fe 100644
--- a/src/dstring.h
+++ b/src/dstring.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_DSTRING_H
-#define KBS_DSTRING_H
+#define KBS_DSTRING_H "$Id$"
/* ---------------------------------------- TYPES
*/
@@ -48,7 +48,7 @@ typedef struct
DString DSInit();
-/* Frees a DString.
+/* Frees a DString. NULL can be safely passed.
*/
void DSFree(DString ds);
diff --git a/src/global.h b/src/global.h
index 6fcfe52..2d40f4a 100644
--- a/src/global.h
+++ b/src/global.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_GLOBAL_H
-#define KBS_GLOBAL_H
+#define KBS_GLOBAL_H "$Id$"
/* ---------------------------------------- MACROS
*/
diff --git a/src/kbs.c b/src/kbs.c
index 5c978b4..c951a63 100644
--- a/src/kbs.c
+++ b/src/kbs.c
@@ -38,6 +38,8 @@ static const char id[]="$Id$";
#include "dstring.h"
#include "util.h"
+static const char header_id[]=KBS_GLOBAL_H;
+
/* ---------------------------------------- PROTOS
*/
diff --git a/src/msg.h b/src/msg.h
index 314e9a7..fc64545 100644
--- a/src/msg.h
+++ b/src/msg.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_MSG_H
-#define KBS_MSG_H
+#define KBS_MSG_H "$Id$"
typedef struct
{
diff --git a/src/pop3.c b/src/pop3.c
index d9fab19..c6b6fe1 100644
--- a/src/pop3.c
+++ b/src/pop3.c
@@ -44,6 +44,9 @@ static const char id[]="$Id$";
#include "dstring.h"
#include "util.h"
+static const char header_id[]=KBS_POP3_H;
+static const char message_id[]=KBS_MSG_H;
+
/* ---------------------------------------- CONSTANTS
*/
diff --git a/src/pop3.h b/src/pop3.h
index c9ab4c8..7345d4e 100644
--- a/src/pop3.h
+++ b/src/pop3.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_POP3_H
-#define KBS_POP3_H
+#define KBS_POP3_H "$Id$"
#include "msg.h"
diff --git a/src/rexp.c b/src/rexp.c
index 3e51aa6..effa882 100644
--- a/src/rexp.c
+++ b/src/rexp.c
@@ -33,13 +33,23 @@ static const char id[]="$Id$";
#include "config.h"
#include "util.h"
+static const char header_id[]=KBS_REXP_H;
+
+
+/* ---------------------------------------- TYPES
+*/
+struct RE_Expression
+{
+ regex_t re;
+ char *expr;
+};
/* ---------------------------------------- INTERFACES
*/
RE_Expression RECompile(const char *regexpr)
{
- regex_t *re;
+ RE_Expression re;
int flags;
re=Malloc(sizeof *re);
@@ -49,11 +59,15 @@ RE_Expression RECompile(const char *regexpr)
if (!ConfigInt(CONFIG_CASESENSE))
flags|=REG_ICASE;
- if (regcomp(re,regexpr,flags))
+ if (regcomp(&re->re,regexpr,flags))
{
free(re);
re=NULL;
}
+ else
+ {
+ re->expr=CopyStr(regexpr);
+ }
return re;
}
@@ -61,7 +75,17 @@ RE_Expression RECompile(const char *regexpr)
int RESearch(const RE_Expression re, const char *string)
{
- return !regexec(re,string,0,NULL,0);
+ int ret;
+
+ ret=regexec(&re->re,string,0,NULL,0);
+
+ return !ret;
+}
+
+
+const char *REGetExpression(const RE_Expression re)
+{
+ return re->expr;
}
@@ -69,7 +93,8 @@ void REFree(RE_Expression re)
{
if (re)
{
- regfree(re);
+ regfree(&re->re);
+ free(re->expr);
free(re);
}
}
diff --git a/src/rexp.h b/src/rexp.h
index 98d685f..f7f4ed8 100644
--- a/src/rexp.h
+++ b/src/rexp.h
@@ -27,13 +27,13 @@
*/
#ifndef KBS_REXP_H
-#define KBS_REXP_H
+#define KBS_REXP_H "$Id$"
#include <stdlib.h>
/* ---------------------------------------- INTERFACES
*/
-typedef void *RE_Expression;
+typedef struct RE_Expression *RE_Expression;
/* Compile a regular expression for use. Returns NULL if the expression
@@ -47,6 +47,11 @@ RE_Expression RECompile(const char *regexpr);
int RESearch(const RE_Expression re, const char *string);
+/* Gets the original expression used to compile the regular expression.
+*/
+const char *REGetExpression(const RE_Expression re);
+
+
/* Free a regular expression
*/
void REFree(RE_Expression re);
diff --git a/src/util.c b/src/util.c
index b65ac01..62dd79c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -32,6 +32,8 @@ static const char id[]="$Id$";
#include "global.h"
#include "util.h"
+static const char header_id[]=KBS_UTIL_H;
+
/* ---------------------------------------- INTERFACES
*/
diff --git a/src/util.h b/src/util.h
index f37eb12..c754307 100644
--- a/src/util.h
+++ b/src/util.h
@@ -27,7 +27,7 @@
*/
#ifndef KBS_UTIL_H
-#define KBS_UTIL_H
+#define KBS_UTIL_H "$Id$"
#include <stdlib.h>