diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | doc/mailfromd.texi | 98 | ||||
-rw-r--r-- | src/main.c | 398 | ||||
-rw-r--r-- | tests/atlocal.in | 2 |
4 files changed, 439 insertions, 66 deletions
@@ -1,5 +1,12 @@ | |||
1 | 2007-11-22 Sergey Poznyakoff <gray@gnu.org.ua> | 1 | 2007-11-22 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 2 | ||
3 | * src/main.c: Implement MU configuration statements. | ||
4 | * tests/atlocal.in (MFOPTS): Ignore site-wide and per-user | ||
5 | configuration files. | ||
6 | * doc/mailfromd.texi: Document sieve interface. | ||
7 | |||
8 | 2007-11-22 Sergey Poznyakoff <gray@gnu.org.ua> | ||
9 | |||
3 | * doc/mailfromd.texi: Update | 10 | * doc/mailfromd.texi: Update |
4 | 11 | ||
5 | 2007-11-21 Sergey Poznyakoff <gray@gnu.org.ua> | 12 | 2007-11-21 Sergey Poznyakoff <gray@gnu.org.ua> |
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi index 731c4ae1..95c6741f 100644 --- a/doc/mailfromd.texi +++ b/doc/mailfromd.texi | |||
@@ -221,6 +221,7 @@ Built-in and Library Functions | |||
221 | * Database functions:: | 221 | * Database functions:: |
222 | * I/O functions:: | 222 | * I/O functions:: |
223 | * System functions:: | 223 | * System functions:: |
224 | * Sieve Interface:: | ||
224 | * Interfaces to Third-Party Programs:: | 225 | * Interfaces to Third-Party Programs:: |
225 | * Special test functions:: | 226 | * Special test functions:: |
226 | * Mail Sending Functions:: | 227 | * Mail Sending Functions:: |
@@ -985,7 +986,6 @@ the corresponding section below. | |||
985 | @node 410-420 | 986 | @node 410-420 |
986 | @section Upgrading from 4.1 to 4.2 | 987 | @section Upgrading from 4.1 to 4.2 |
987 | @cindex Upgrading from 4.1 to 4.2 | 988 | @cindex Upgrading from 4.1 to 4.2 |
988 | @UNREVISED{} | ||
989 | Upgrading to this version does not require any special efforts. You | 989 | Upgrading to this version does not require any special efforts. You |
990 | can use your configuration files and filter scripts without any | 990 | can use your configuration files and filter scripts without any |
991 | changes. The only difference worth noticing is that starting from this | 991 | changes. The only difference worth noticing is that starting from this |
@@ -5258,6 +5258,7 @@ in version @value{VERSION}. | |||
5258 | * Database functions:: | 5258 | * Database functions:: |
5259 | * I/O functions:: | 5259 | * I/O functions:: |
5260 | * System functions:: | 5260 | * System functions:: |
5261 | * Sieve Interface:: | ||
5261 | * Interfaces to Third-Party Programs:: | 5262 | * Interfaces to Third-Party Programs:: |
5262 | * Special test functions:: | 5263 | * Special test functions:: |
5263 | * Mail Sending Functions:: | 5264 | * Mail Sending Functions:: |
@@ -6477,8 +6478,101 @@ strftime('%Y-%m-%d %H:%M:%S %Z', 1164477564, 1) | |||
6477 | by calling @command{/bin/sh -c string}, and returns -1 on error or | 6478 | by calling @command{/bin/sh -c string}, and returns -1 on error or |
6478 | the return status of the command otherwise. | 6479 | the return status of the command otherwise. |
6479 | @end deftypefn | 6480 | @end deftypefn |
6480 | |||
6481 | 6481 | ||
6482 | @node Sieve Interface | ||
6483 | @subsubsection Sieve Interface | ||
6484 | @cindex Sieve | ||
6485 | @UNREVISED{} | ||
6486 | @samp{Sieve} is a powerful mail filtering language, defined in | ||
6487 | @acronym{RFC} 3028. @command{Mailfromd} supports an extended form | ||
6488 | of this language. For description of the language and available | ||
6489 | extensions, @xref{Sieve Language, Sieve Language, Sieve Language, | ||
6490 | mailutils, GNU Mailutils Manual}. | ||
6491 | |||
6492 | @deftypefn {Built-in Function} boolean sieve (string @var{script} @ | ||
6493 | [, number @var{flags}]) | ||
6494 | Compile the Sieve source file @var{script} and execute it over the | ||
6495 | collected message. This function can be used only in @code{eom} | ||
6496 | handler. | ||
6497 | |||
6498 | @findex sieve.mfh | ||
6499 | Optional @var{flags} define additional debugging and verbosity | ||
6500 | settings. It is a bit-mask field, consisting of a bitwise @code{or} | ||
6501 | of one or more of the following flags, defined in @file{sieve.mfh}: | ||
6502 | |||
6503 | @table @code | ||
6504 | @item MF_SIEVE_LOG | ||
6505 | Log every executed @samp{Sieve} action. | ||
6506 | |||
6507 | @item MF_SIEVE_DEBUG_TRACE | ||
6508 | Trace execution of @samp{Sieve} tests. | ||
6509 | |||
6510 | @item MF_SIEVE_DEBUG_INSTR | ||
6511 | Log every instruction, executed in the compiled @samp{Sieve} code. | ||
6512 | This produces huge amounts of output and is rarely useful, unless you | ||
6513 | suspect some bug in @samp{Sieve} implementation and wish to trace it. | ||
6514 | |||
6515 | @item MF_SIEVE_DEBUG_MAILUTILS | ||
6516 | Log debugging information about the underlying Mailutils calls. | ||
6517 | |||
6518 | @item MF_SIEVE_DEBUG_PROT | ||
6519 | Trace networking protocols. | ||
6520 | @end table | ||
6521 | |||
6522 | For example, @code{MF_SIEVE_LOG|MF_SIEVE_DEBUG_TRACE} enables logging | ||
6523 | @samp{Sieve} actions and tests. | ||
6524 | |||
6525 | The @code{sieve} function returns @code{true} if the message was | ||
6526 | accepted by the @var{script} program, and @code{false} otherwise. | ||
6527 | Here, the word @dfn{accepted} means that some form of @samp{KEEP} | ||
6528 | action (@pxref{Actions, keep, Actions, mailutils, GNU Mailutils | ||
6529 | Manual}) was executed over the message. | ||
6530 | @end deftypefn | ||
6531 | |||
6532 | The following example discards each message not accepted by the | ||
6533 | @samp{Sieve} program @file{/etc/mail/filter.siv}: | ||
6534 | |||
6535 | @smallexample | ||
6536 | #include_once <sieve.mfh> | ||
6537 | group eom | ||
6538 | do | ||
6539 | if not sieve("/etc/mail/filter.siv", MF_SIEVE_LOG) | ||
6540 | discard | ||
6541 | fi | ||
6542 | done | ||
6543 | @end smallexample | ||
6544 | |||
6545 | The example below illustrates how one can adjust logging flags | ||
6546 | depending on the current debugging level: | ||
6547 | |||
6548 | @smallexample | ||
6549 | #include_once <sieve.mfh> | ||
6550 | prog eom | ||
6551 | do | ||
6552 | number flags 0 | ||
6553 | number level debug_level("bi_sieve") | ||
6554 | if %level >= 1 | ||
6555 | set flags %flags | MF_SIEVE_LOG | ||
6556 | fi | ||
6557 | if %level >= 2 | ||
6558 | set flags %flags | MF_SIEVE_DEBUG_TRACE | ||
6559 | fi | ||
6560 | if %level > 9 | ||
6561 | set flags %flags | MF_SIEVE_DEBUG_INSTR | ||
6562 | fi | ||
6563 | if %level > 19 | ||
6564 | set flags %flags | MF_SIEVE_DEBUG_MAILUTILS | ||
6565 | fi | ||
6566 | if %level > 20 | ||
6567 | set flags %flags | MF_SIEVE_DEBUG_PROT | ||
6568 | fi | ||
6569 | |||
6570 | if not sieve("/etc/mail/filter.siv", %flags) | ||
6571 | discard | ||
6572 | fi | ||
6573 | done | ||
6574 | @end smallexample | ||
6575 | |||
6482 | @node Interfaces to Third-Party Programs | 6576 | @node Interfaces to Third-Party Programs |
6483 | @subsubsection Interfaces to Third-Party Programs | 6577 | @subsubsection Interfaces to Third-Party Programs |
6484 | 6578 | ||
@@ -37,6 +37,10 @@ | |||
37 | #include <mailutils/mailutils.h> | 37 | #include <mailutils/mailutils.h> |
38 | #if MAILUTILS_VERSION_NUMBER < 1290 | 38 | #if MAILUTILS_VERSION_NUMBER < 1290 |
39 | # include <mailutils/argp.h> | 39 | # include <mailutils/argp.h> |
40 | typedef struct { | ||
41 | char *file; | ||
42 | int line; | ||
43 | } mu_cfg_locus_t; | ||
40 | #else | 44 | #else |
41 | # include <mailutils/libargp.h> | 45 | # include <mailutils/libargp.h> |
42 | #endif | 46 | #endif |
@@ -237,6 +241,21 @@ log_status(sfsistat status, SMFICTX *ctx) | |||
237 | } | 241 | } |
238 | } | 242 | } |
239 | 243 | ||
244 | static void | ||
245 | mf_error_on_locus(mu_cfg_locus_t *locus, const char *fmt, ...) | ||
246 | { | ||
247 | va_list ap; | ||
248 | |||
249 | va_start(ap, fmt); | ||
250 | if (locus) { | ||
251 | char *newfmt = NULL; | ||
252 | asprintf(&newfmt, "%s:%d: %s", locus->file, locus->line, fmt); | ||
253 | mu_verror(newfmt, ap); | ||
254 | } else | ||
255 | mu_verror(fmt, ap); | ||
256 | va_end(ap); | ||
257 | } | ||
258 | |||
240 | 259 | ||
241 | /* Sendmail class file support */ | 260 | /* Sendmail class file support */ |
242 | 261 | ||
@@ -250,8 +269,8 @@ compare_string(const void *item, const void *value) | |||
250 | 269 | ||
251 | /* Read domains from sendmail-style domain file NAME and store them in | 270 | /* Read domains from sendmail-style domain file NAME and store them in |
252 | DOMAIN_LIST */ | 271 | DOMAIN_LIST */ |
253 | void | 272 | int |
254 | read_domain_file(char *name) | 273 | read_domain_file(mu_cfg_locus_t *locus, char *name) |
255 | { | 274 | { |
256 | FILE *fp; | 275 | FILE *fp; |
257 | char buf[256]; | 276 | char buf[256]; |
@@ -259,9 +278,9 @@ read_domain_file(char *name) | |||
259 | 278 | ||
260 | fp = fopen(name, "r"); | 279 | fp = fopen(name, "r"); |
261 | if (!fp) { | 280 | if (!fp) { |
262 | mu_error(_("Cannot open file `%s': %s"), | 281 | mf_error_on_locus(locus, _("Cannot open file `%s': %s"), |
263 | name, mu_strerror(errno)); | 282 | name, mu_strerror(errno)); |
264 | return; | 283 | return 1; |
265 | } | 284 | } |
266 | 285 | ||
267 | if (!domain_list) { | 286 | if (!domain_list) { |
@@ -287,6 +306,7 @@ read_domain_file(char *name) | |||
287 | } | 306 | } |
288 | 307 | ||
289 | fclose(fp); | 308 | fclose(fp); |
309 | return 0; | ||
290 | } | 310 | } |
291 | 311 | ||
292 | /* Return true if we relay domain NAME */ | 312 | /* Return true if we relay domain NAME */ |
@@ -327,6 +347,124 @@ host_in_relayed |