[PATCH] Three fixes against current CVS

Matthias Andree matthias.andree at stud.uni-dortmund.de
Mon Sep 16 16:49:40 CEST 2002


On Mon, 16 Sep 2002, David Relson wrote:

> >Letting go of the Subject: ordering may look as nit-picking, but:
> >
> >a- it serves no purpose
> >b- it is executed in a very tight loop, wasting time with expensive
> >   string comparisons, slowing down bogofilter -p mode
> >c- less lines of code => less bugs. Ahem, sort of at least ;-)
> 
> If speed is the issue, why not extract the first char and use it as a 
> precondition to calling str?cmp(), i.e.
>         ch = textend->block[0];
>         ...
>         else if (ch == 'X' && strncmp( ..., "X-Spam-Status", ...) { ... }
>         else if (ch == 'S' && strncmp( ..., "Subject", ...) { ... }
>         else if (ch == '\n' && textend->block[1]=='\0') { ... }
>         else

It is absolutely unnecessary to put the X-Spam-Status header on top of
the Subject header. procmail and maildrop won't care, and a mail user
agent won't care either at any rate.

> This maintains the order (which may or may not matter, I don't know) and 
> should be faster.

It does not matter, so let's get rid of the code.

I can optimize that even more, by turning loop invariant code and the
loop control inside out, and go dropping even more tests. There's no
reason to drop existing Spam-Status headers when printing the mail, they
should be eliminated at read time anyhow.

Adding these lines to lexer.l would do:

    if (strncmp(buf, "X-Spam-Status:", 14))
        return yyinput(buf, max_size);

The remaining code is about sufficient.

(Don't apply this, it's too early to do optimizations that are not
clean-ups, and for that reason, it's mutilated:)

@@ -171,35 +171,24 @@
 	{
 	    int	inheaders = 1;
 
+	    /* print headers */
 	    for (textend=&textblocks; textend->block; textend=textend->next)
 	    {
-		if (inheaders == 0) {
-			/* print message body lines without further checks */
-			(void) fputs(textend->block, stdout);
-		}
-		else if (strncmp(textend->block, "X-Spam-Status:", 14) == 0) {
-			/* Don't print existing X-Spam-Status: headers */
-			#ifdef HAVE_SYSLOG_H
-			syslog(LOG_INFO, "Ignored exising X-Spam-Status header");
-			#endif
-		}
-		else if (strncmp(textend->block, "Subject:", 8) == 0) {
-			/* Append the X-Spam-Status: header before subject */
-			printf("X-Spam-Status: %s, tests=bogofilter\n", 
-			(status==RC_SPAM) ? "Yes" : "No");
-			(void) fputs(textend->block, stdout);
-		}
-		else if (strcmp(textend->block, "\n") == 0) {
-			/* Mark the beginning of the message body */
-			inheaders = 0;
-			(void) fputs(textend->block, stdout);
-		}
-		else {
-			/* in case none of the above conditions were met */
-			(void) fputs(textend->block, stdout);
-		}
+		if (strcmp(textend->block, "\n") == 0) break;
+		(void) fputs(textend->block, stdout);
 	    }
 
+	    /* print spam-status at the end of the header
+	     * then mark the beginning of the message body */
+	    printf("X-Spam-Status: %s, tests=bogofilter\n", 
+		    (status==RC_SPAM) ? "Yes" : "No");
+	    (void)fputs ("\n", stdout);
+
+	    /* print body */
+	    for (; textend->block; textend=textend->next)
+	    {
+		(void) fputs(textend->block, stdout);
+	    }
 	}
 	exit(status);
     }
-- 
Matthias Andree

For summay digest subscription: bogofilter-digest-subscribe at aotto.com



More information about the Bogofilter mailing list