svarshavchik / courier-libs

Courier Mail Server - shared libraries
10 stars 8 forks source link

maildrop doesn't filter messages without a body #1

Closed pommi closed 9 years ago

pommi commented 9 years ago

Since a couple of days I'm receiving a lot of spam without a body. Unfortunately it isn't filtered by the maildroprc rules below. A X-Spam-Flag: YES header is present but maildrop doesn't seem to be able to process messages without a body. "Message 1" below is NOT filtered correctly. "Message 2" and "Message 3" are filtered correctly.

I'm using maildrop 2.7.1 (Debian Jessie). The issue exists since commit e0a0a6eba9f31aea09624b3ea21fb75107c96780. Reverting this commit solved the issue. But that's obviously not what I want to do.

I've been debugging for a while, but the lack of knowledge holds me from finding the issue and a proper solution (or a patch that already fixed the issue). What I've found out is that rfc2045_decodemsgtoutf8() is called from search.C (https://github.com/svarshavchik/courier-libs/blob/master/maildrop/search.C#L216). After that rfc2045header_get() is called (https://github.com/svarshavchik/courier-libs/blob/master/rfc2045/rfc2045decodemsgtoutf8.c#L125). And then rfc2045header_get() returns (0) because c == -1 in case of "Message 1" (https://github.com/svarshavchik/courier-libs/blob/master/rfc2045/rfc2045header.c#L180). That if statement is false in case of "Message 2" and "Message 3".

How to solve this? :confused:

RFC2822 says a body is optional:

A message consists of header fields (collectively called "the header of the message") followed, optionally, by a body.

maildroprc

if (/^X-Spam-Flag:.*YES/:h)
{
        to $DEFAULT/.Spam
}
to $DEFAULT

Message 1 (isn't filtered to $DEFAULT/.Spam)

Return-Path: <user@example.com>
X-Spam-Flag: YES
Message-ID: <0[10
Subject: [SPAM] 
Date: Wed,  8 Jul 2015 00:00:10 +0200 (CEST)
From: user@example.com

Message 2 (note the extra line at the end)

Return-Path: <user@example.com>
X-Spam-Flag: YES
Message-ID: <0[10
Subject: [SPAM] 
Date: Wed,  8 Jul 2015 00:00:10 +0200 (CEST)
From: user@example.com

Message 3

Return-Path: <user@example.com>
X-Spam-Flag: YES
Message-ID: <0[10
Subject: [SPAM] 
Date: Wed,  8 Jul 2015 00:00:10 +0200 (CEST)
From: user@example.com

body
svarshavchik commented 9 years ago

Fixed in build 20150809