how to use procmail filter spam into imap folder

how to use procmail filter spam into imap folder

am 13.01.2007 14:54:13 von Pet

Hi,

I am currently using Postfix, cyurs imap, spamassassin and procmail
filter incoming email, and send all spam mail into a single file.
If I filter it into individual user's imap folder, how can I do that?

Your suggestion is much appreciated.

Thanks
S

Re: how to use procmail filter spam into imap folder

am 14.01.2007 00:48:12 von Garen Erdoisa

Pet wrote:
> Hi,
>
> I am currently using Postfix, cyurs imap, spamassassin and procmail
> filter incoming email, and send all spam mail into a single file.
> If I filter it into individual user's imap folder, how can I do that?
>
> Your suggestion is much appreciated.
>
> Thanks
> S

You would use procmail in this case to handle the delivery of the email
to an end user's folders. Procmail is an MDA (Mail Delivery Agent).

Basically you would have to write what is called a procmail run control
file with procmail recipes in that file where the recipes you write make
the decisions about where to deliver the email. ie: ${HOME}/.procmailrc
would contain recipes for a specific user, while /etc/.procmailrc would
contain recipes run by the system that affect every user on the system.

For general "how to" questions about procmail, I would suggest first
studying the existing documentation on procmail and see if you can
answer your own question. If you then have a problem not answered
already in that documentation try asking here with your specific question.

Here is a list of the standard documentation man pages:

man procmail (man page that explains procmail command line switches)
man procmailrc (man page that explains how to write a procmail run
control file)
man procmailsc (man page that explains how to use procmail scoring)
man procmailex (man page with examples of common procmail recipes.)

There are many other resources available on the web with working
examples also if you do a bit of searching.

--
Best Regards
Garen

Re: how to use procmail filter spam into imap folder

am 14.01.2007 01:33:31 von Pet

Garen Erdoisa wrote:
> Pet wrote:
>> Hi,
>>
>> I am currently using Postfix, cyurs imap, spamassassin and procmail
>> filter incoming email, and send all spam mail into a single file.
>> If I filter it into individual user's imap folder, how can I do that?
>>
>> Your suggestion is much appreciated.
>>
>> Thanks
>> S
>
> You would use procmail in this case to handle the delivery of the email
> to an end user's folders. Procmail is an MDA (Mail Delivery Agent).
>
> Basically you would have to write what is called a procmail run control
> file with procmail recipes in that file where the recipes you write make
> the decisions about where to deliver the email. ie: ${HOME}/.procmailrc
> would contain recipes for a specific user, while /etc/.procmailrc would
> contain recipes run by the system that affect every user on the system.
>
> For general "how to" questions about procmail, I would suggest first
> studying the existing documentation on procmail and see if you can
> answer your own question. If you then have a problem not answered
> already in that documentation try asking here with your specific question.
>
> Here is a list of the standard documentation man pages:
>
> man procmail (man page that explains procmail command line switches)
> man procmailrc (man page that explains how to write a procmail run
> control file)
> man procmailsc (man page that explains how to use procmail scoring)
> man procmailex (man page with examples of common procmail recipes.)
>
> There are many other resources available on the web with working
> examples also if you do a bit of searching.
>

Here is what I want to do written in the procmailrc:

SHELL=/bin/sh
DROPPRIVS=YES
LINEBUF=32768
SENDMAILFLAGS="-oi"
SPAMC="/usr/local/bin/spamc"

FROM="<$1>"
SHIFT=1

:0f
|$SPAMC -f -U /var/run/spamd.sock

:0
* ^X-Spam-Level: \*\*\*\*\*
{
SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
.Trash/
}

:0
! -f $FROM "$@"

# Dump all tagged spam into separate folder
:0
* ^X-Spam-Status: Yes
..Trash/

But when I sent a test spam mail to the mail server, the .Trash/ imap
folder contains nothing, while maillog indiciated the mail is already
been filtered.

I hope the statement here is more specific.

Thanks
Sam,

Re: [postfix,cyrus,spamassassin] how to use procmail filter spam into imap folder

am 14.01.2007 01:43:12 von Andrzej Adam Filip

Pet writes:
> I am currently using Postfix, cyurs imap, spamassassin and procmail
> filter incoming email, and send all spam mail into a single file.
> If I filter it into individual user's imap folder, how can I do that?
>
> Your suggestion is much appreciated.

My recomendation:
1) integrate spamassassin with postfix using milter
[ Milter support was added to Postfix 2.3.0 released 2006-07-12 ]
2) use (per user) sieve script to deliver incoming "tagged as spam"
messages to separate folder e.g. spambox
[sieve supported by cyrus IMAP]

--
[pl2en: Andrew] Andrzej Adam Filip : anfi@priv.onet.pl : anfi@xl.wp.pl
Home site: http://anfi.homeunix.net/

Re: how to use procmail filter spam into imap folder

am 14.01.2007 02:26:41 von Garen Erdoisa

Pet wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Hi,
[SNIP]
>>
>
> Here is what I want to do written in the procmailrc:
>
> SHELL=/bin/sh
> DROPPRIVS=YES
> LINEBUF=32768
> SENDMAILFLAGS="-oi"
> SPAMC="/usr/local/bin/spamc"
>
> FROM="<$1>"
> SHIFT=1
>
> :0f
> |$SPAMC -f -U /var/run/spamd.sock
>


> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
> .Trash/
> }

The above recipe opens a procmail nesting block the first line of which
turns over control of the procmail process to a different run control
file. If you wish the control of that procmail rc file to be returned to
the master file should it complete without delivering the email, then
you should use INCLUDERC instead of SWITCHRC here. Basically the
difference between calling a "subroutine", vs a "jump to location"

The 2nd line ".Trash/" is a syntax error. It looks as if you wish to run
your spamkill.rc file, then deliver the recipe to a .Trash/ directory.

So in that case I would write the recipe thus:

:0
* ^X-Spam-Level: \*\*\*\*\*
{
INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"

:0
.Trash/
}

In the above case, procmail will create a completely new filename for
each separate email in the .Trash/ directory since it's being told to
deliver the mail to a directory instead of to a file.

If you wish procmail to deliver to a specific file in that directory
instead of making up it's own file name on the fly, then you need to use
a specific file name. ie:

:0
* ^X-Spam-Level: \*\*\*\*\*
{
INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"

:0:
.Trash/spam
}

>
> :0
> ! -f $FROM "$@"

The above will instruct procmail to forward all email reaching this
point using sendmail. The command in this case would expand to

sendmail -oi -f $FROM "$@"

In this case I'm presuming that the arguments being passed to the
procmail process by the calling process include the email address of the
forwarding target recipient. Thus "$@" should be expected to expand to a
destination email address. But that depends on what arguments are
actually passed to procmail on the command line of the calling process.

Because the above recipe always runs and is a delivering recipe,
anything beyond this point will not ever be processed by procmail,
though if the intended recipient is an invalid address, the email may
bounce, and generate a bounce message back to the calling process, which
may in turn bounce the message back to the envelope sender or return
path address or to the local host postmaster if that return path address
proves to be invalid.

If you wished to have procmail continue processing recipes beyond that
point, you should use the carbon copy flag to spawn a new procmail
process to handle the forwarding, then in that case it will continue on
to the next recipe. ie:

:0c
! -f $FROM "$@"

>
> # Dump all tagged spam into separate folder
> :0
> * ^X-Spam-Status: Yes
> .Trash/

Same thing here, if you wish email to be delivered to a specific file in
the .Trash/ directory you need to supply the file name. ie:

# Dump all tagged spam into separate folder using an implied lockfile
:0:
* ^X-Spam-Status: Yes
..Trash/imap

>
> But when I sent a test spam mail to the mail server, the .Trash/ imap
> folder contains nothing, while maillog indiciated the mail is already
> been filtered.
>
> I hope the statement here is more specific.
Yep.

>
> Thanks
> Sam,

Quite welcome.
Hope this analysis helps.

--
Garen

Re: how to use procmail filter spam into imap folder

am 14.01.2007 05:58:21 von Pet

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Hi,
> [SNIP]
>>>
>>
>> Here is what I want to do written in the procmailrc:
>>
>> SHELL=/bin/sh
>> DROPPRIVS=YES
>> LINEBUF=32768
>> SENDMAILFLAGS="-oi"
>> SPAMC="/usr/local/bin/spamc"
>>
>> FROM="<$1>"
>> SHIFT=1
>>
>> :0f
>> |$SPAMC -f -U /var/run/spamd.sock
>>
>
>
>> :0
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
>> .Trash/
>> }
>
> The above recipe opens a procmail nesting block the first line of which
> turns over control of the procmail process to a different run control
> file. If you wish the control of that procmail rc file to be returned to
> the master file should it complete without delivering the email, then
> you should use INCLUDERC instead of SWITCHRC here. Basically the
> difference between calling a "subroutine", vs a "jump to location"
>
> The 2nd line ".Trash/" is a syntax error. It looks as if you wish to run
> your spamkill.rc file, then deliver the recipe to a .Trash/ directory.
>
> So in that case I would write the recipe thus:
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"
>
> :0
> .Trash/
> }
>
> In the above case, procmail will create a completely new filename for
> each separate email in the .Trash/ directory since it's being told to
> deliver the mail to a directory instead of to a file.
>
> If you wish procmail to deliver to a specific file in that directory
> instead of making up it's own file name on the fly, then you need to use
> a specific file name. ie:
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"
>
> :0:
> .Trash/spam
> }
>
>>
>> :0
>> ! -f $FROM "$@"
>
> The above will instruct procmail to forward all email reaching this
> point using sendmail. The command in this case would expand to
>
> sendmail -oi -f $FROM "$@"
>
> In this case I'm presuming that the arguments being passed to the
> procmail process by the calling process include the email address of the
> forwarding target recipient. Thus "$@" should be expected to expand to a
> destination email address. But that depends on what arguments are
> actually passed to procmail on the command line of the calling process.
>
> Because the above recipe always runs and is a delivering recipe,
> anything beyond this point will not ever be processed by procmail,
> though if the intended recipient is an invalid address, the email may
> bounce, and generate a bounce message back to the calling process, which
> may in turn bounce the message back to the envelope sender or return
> path address or to the local host postmaster if that return path address
> proves to be invalid.
>
> If you wished to have procmail continue processing recipes beyond that
> point, you should use the carbon copy flag to spawn a new procmail
> process to handle the forwarding, then in that case it will continue on
> to the next recipe. ie:
>
> :0c
> ! -f $FROM "$@"
>
>>
>> # Dump all tagged spam into separate folder
>> :0
>> * ^X-Spam-Status: Yes
>> .Trash/
>
> Same thing here, if you wish email to be delivered to a specific file in
> the .Trash/ directory you need to supply the file name. ie:
>
> # Dump all tagged spam into separate folder using an implied lockfile
> :0:
> * ^X-Spam-Status: Yes
> .Trash/imap
>
>>
>> But when I sent a test spam mail to the mail server, the .Trash/ imap
>> folder contains nothing, while maillog indiciated the mail is already
>> been filtered.
>>
>> I hope the statement here is more specific.
> Yep.
>
>>
>> Thanks
>> Sam,
>
> Quite welcome.
> Hope this analysis helps.
>

Hi,

Thank you for detailed description.
I have added updated the procmail rc file according to your suggestion
here, the spam mail still not being redirected to the Trash/imap or
Trash/spam folder.
In addition to the master procmail rc file, here is the spamkill.rc file
the process is also involved:

cat spamkill.rc
LOGFILE="/var/log/spamkill/spamkill"
UMASK=022
LOGABSTRACT="no"
VERBOSE="no"
FORMAIL="/usr/local/bin/formail"
FILTERPL="/usr/local/sbin/filter_recipients"

TO_FIELD=`/usr/local/bin/formail -zxTo:`
DATE=`date +%Y%m%d-%H%M%S`
XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`

:0 Wi
RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"

:0 Wi
OLDRECIPIENTS=|echo "$@"

SHIFT=1000

LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
$DATE $$ Orig-To: $OLDRECIPIENTS
"

:0
* RECIPIENTS ?? @ourdomain
{
LOG="$DATE $$ Sent-To: $RECIPIENTS
"

:0
! -f $FROM $RECIPIENTS
}

LOG="$DATE $$ Sent-To:
/usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
"
#the above instruction is trying to save the spam in the recpient's
#Trash directory.

#:0w
# | /usr/local/cyrus/bin/deliver -a $USER -m user/$USER
# # if not told otherwise, deliver all messages to the user's inbox

:0
/var/log/spamkill.log

Since the spamkill.rc configuraiton file also involve an external perl
script, I have also attached the perl script here for your reference:

# cat /usr/local/sbin/filter_recipients
#!/usr/bin/perl

use strict;
use DB_File;

my $mapdb = "/etc/postfix/spamkill.db";
my $spamlevel = length(shift @ARGV);

tie(my %db, 'DB_File', $mapdb, O_RDONLY, 0664, $DB_HASH)
or print "@ARGV\n" and exit(1);
foreach my $addr (@ARGV) {
$addr = lc($addr);
(my $test = $addr) =~ s/\+[^@]+//;
$test .= chr(0);
if ($db{$test} > $spamlevel or !defined $db{$test}) {
print "$addr ";
}
}
untie(%db);
print "\n";
exit(0);

Note, the spamkill.db is empty.


Thanks
Sam

Re: how to use procmail filter spam into imap folder

am 14.01.2007 05:59:27 von Pet

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Hi,
> [SNIP]
>>>
>>
>> Here is what I want to do written in the procmailrc:
>>
>> SHELL=/bin/sh
>> DROPPRIVS=YES
>> LINEBUF=32768
>> SENDMAILFLAGS="-oi"
>> SPAMC="/usr/local/bin/spamc"
>>
>> FROM="<$1>"
>> SHIFT=1
>>
>> :0f
>> |$SPAMC -f -U /var/run/spamd.sock
>>
>
>
>> :0
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
>> .Trash/
>> }
>
> The above recipe opens a procmail nesting block the first line of which
> turns over control of the procmail process to a different run control
> file. If you wish the control of that procmail rc file to be returned to
> the master file should it complete without delivering the email, then
> you should use INCLUDERC instead of SWITCHRC here. Basically the
> difference between calling a "subroutine", vs a "jump to location"
>
> The 2nd line ".Trash/" is a syntax error. It looks as if you wish to run
> your spamkill.rc file, then deliver the recipe to a .Trash/ directory.
>
> So in that case I would write the recipe thus:
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"
>
> :0
> .Trash/
> }
>
> In the above case, procmail will create a completely new filename for
> each separate email in the .Trash/ directory since it's being told to
> deliver the mail to a directory instead of to a file.
>
> If you wish procmail to deliver to a specific file in that directory
> instead of making up it's own file name on the fly, then you need to use
> a specific file name. ie:
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> INCLUDERC="/usr/local/etc/procmailrcs/spamkill.rc"
>
> :0:
> .Trash/spam
> }
>
>>
>> :0
>> ! -f $FROM "$@"
>
> The above will instruct procmail to forward all email reaching this
> point using sendmail. The command in this case would expand to
>
> sendmail -oi -f $FROM "$@"
>
> In this case I'm presuming that the arguments being passed to the
> procmail process by the calling process include the email address of the
> forwarding target recipient. Thus "$@" should be expected to expand to a
> destination email address. But that depends on what arguments are
> actually passed to procmail on the command line of the calling process.
>
> Because the above recipe always runs and is a delivering recipe,
> anything beyond this point will not ever be processed by procmail,
> though if the intended recipient is an invalid address, the email may
> bounce, and generate a bounce message back to the calling process, which
> may in turn bounce the message back to the envelope sender or return
> path address or to the local host postmaster if that return path address
> proves to be invalid.
>
> If you wished to have procmail continue processing recipes beyond that
> point, you should use the carbon copy flag to spawn a new procmail
> process to handle the forwarding, then in that case it will continue on
> to the next recipe. ie:
>
> :0c
> ! -f $FROM "$@"
>
>>
>> # Dump all tagged spam into separate folder
>> :0
>> * ^X-Spam-Status: Yes
>> .Trash/
>
> Same thing here, if you wish email to be delivered to a specific file in
> the .Trash/ directory you need to supply the file name. ie:
>
> # Dump all tagged spam into separate folder using an implied lockfile
> :0:
> * ^X-Spam-Status: Yes
> .Trash/imap
>
>>
>> But when I sent a test spam mail to the mail server, the .Trash/ imap
>> folder contains nothing, while maillog indiciated the mail is already
>> been filtered.
>>
>> I hope the statement here is more specific.
> Yep.
>
>>
>> Thanks
>> Sam,
>
> Quite welcome.
> Hope this analysis helps.
>
Hi,

Thank you for detailed description.
I have added updated the procmail rc file according to your suggestion
here, the spam mail still not being redirected to the Trash/imap or
Trash/spam folder.
In addition to the master procmail rc file, here is the spamkill.rc file
the process is also involved:

cat spamkill.rc
LOGFILE="/var/log/spamkill/spamkill"
UMASK=022
LOGABSTRACT="no"
VERBOSE="no"
FORMAIL="/usr/local/bin/formail"
FILTERPL="/usr/local/sbin/filter_recipients"

TO_FIELD=`/usr/local/bin/formail -zxTo:`
DATE=`date +%Y%m%d-%H%M%S`
XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`

:0 Wi
RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"

:0 Wi
OLDRECIPIENTS=|echo "$@"

SHIFT=1000

LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
$DATE $$ Orig-To: $OLDRECIPIENTS
"

:0
* RECIPIENTS ?? @ourdomain
{
LOG="$DATE $$ Sent-To: $RECIPIENTS
"

:0
! -f $FROM $RECIPIENTS
}

LOG="$DATE $$ Sent-To:
/usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
"
#the above instruction is trying to save the spam in the recpient's
#Trash directory.

#:0w
# | /usr/local/cyrus/bin/deliver -a $USER -m user/$USER
# # if not told otherwise, deliver all messages to the user's inbox

:0
/var/log/spamkill.log

Since the spamkill.rc configuraiton file also involve an external perl
script, I have also attached the perl script here for your reference:

# cat /usr/local/sbin/filter_recipients
#!/usr/bin/perl

use strict;
use DB_File;

my $mapdb = "/etc/postfix/spamkill.db";
my $spamlevel = length(shift @ARGV);

tie(my %db, 'DB_File', $mapdb, O_RDONLY, 0664, $DB_HASH)
or print "@ARGV\n" and exit(1);
foreach my $addr (@ARGV) {
$addr = lc($addr);
(my $test = $addr) =~ s/\+[^@]+//;
$test .= chr(0);
if ($db{$test} > $spamlevel or !defined $db{$test}) {
print "$addr ";
}
}
untie(%db);
print "\n";
exit(0);

Note, the spamkill.db is empty.


Thanks
Sam

Re: [postfix,cyrus,spamassassin] how to use procmail filter spaminto imap folder

am 14.01.2007 08:04:38 von Pet

Andrzej Adam Filip wrote:
> Pet writes:
>> I am currently using Postfix, cyurs imap, spamassassin and procmail
>> filter incoming email, and send all spam mail into a single file.
>> If I filter it into individual user's imap folder, how can I do that?
>>
>> Your suggestion is much appreciated.
>
> My recomendation:
> 1) integrate spamassassin with postfix using milter
> [ Milter support was added to Postfix 2.3.0 released 2006-07-12 ]
> 2) use (per user) sieve script to deliver incoming "tagged as spam"
> messages to separate folder e.g. spambox
> [sieve supported by cyrus IMAP]
>
hi, I searched milter in google, but could not find any useful
information about how to setup postfix, spamassassin and milter.
Can you show me some pointers?

Thanks
Sam

Re: how to use procmail filter spam into imap folder

am 14.01.2007 10:51:21 von Garen Erdoisa

Pet wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Garen Erdoisa wrote:
>>>> Pet wrote:
>>>>> Hi,
>> [SNIP]
>
> Thank you for detailed description.
> I have added updated the procmail rc file according to your suggestion
> here, the spam mail still not being redirected to the Trash/imap or
> Trash/spam folder.
> In addition to the master procmail rc file, here is the spamkill.rc file
> the process is also involved:
>
> cat spamkill.rc
> LOGFILE="/var/log/spamkill/spamkill"
> UMASK=022
> LOGABSTRACT="no"
> VERBOSE="no"
> FORMAIL="/usr/local/bin/formail"
> FILTERPL="/usr/local/sbin/filter_recipients"
>
> TO_FIELD=`/usr/local/bin/formail -zxTo:`
> DATE=`date +%Y%m%d-%H%M%S`
> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>

> :0 Wi
> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>
> :0 Wi
> OLDRECIPIENTS=|echo "$@"


# Remember that "$@" can only be expanded once in a procmail recipe, so
# you must use that expansion to capture the arguments into another
# variable if you want to use those arguments in multiple places
# elsewhere in your recipe.

#Try this instead.

:0 Wi
OLDRECIPIENTS=|echo "$@"

LOG="Debug: OLDRECIPIENTS=${OLDRECIPIENTS}
"

RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`

LOG="Debug: RECIPIENTS=${RECIPIENTS}
"

>
> SHIFT=1000

# The argument list isn't used after this point, so no need
# to shift the argument list.
SHIFT=1

>
> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
> $DATE $$ Orig-To: $OLDRECIPIENTS
> "
>
> :0
> * RECIPIENTS ?? @ourdomain
> {
> LOG="$DATE $$ Sent-To: $RECIPIENTS
> "
>
> :0
> ! -f $FROM $RECIPIENTS
> }

Ok, so the above recipe should ship the email to the listwashed
recipient list if @ourdomain is found anywhere in the list.
It will also terminate procmail processing if that rule matches.

Below would be an else condition. The recipient list didn't contain the
@ourdomain pattern

>
> LOG="$DATE $$ Sent-To:
> /usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
> "
> #the above instruction is trying to save the spam in the recpient's
> #Trash directory.

Actually, the above is just writing the 3 line string to the procmail
logfile. It's not saving any email.
If you are trying to save the email in a file do this:

:0:
/usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$

This is a delivery event, so would also terminate procmail processing at
this point. If you want to continue beyond this point, use the carbon
copy flag on it like this:

:0c:
/usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$

>
> #:0w
> # | /usr/local/cyrus/bin/deliver -a $USER -m user/$USER
> # # if not told otherwise, deliver all messages to the user's inbox
>

Hmm, sorry, but I don't debug comments. :)

> :0
> /var/log/spamkill.log

The above will write the email in the procmail pipe to a file spamkill.log
This isn't really a log file, it's an email folder, so you should
probably rename the file to indicate that so it's less confusing to you
later. Also you should use a procmail lockfile to prevent race
conditions thus:

:0:
/var/log/spamkill.log

Another thing to consider at this point is that the file must have
appropriate write permissions for the current procmail process. This may
not be root at this point since you set DROPPRIVS=yes earlier, and that
is presuming the owner was root prior to that point.

This is a delivery event, so procmail will terminate processing at this
point unless you use a carbon copy flag.

Your perl script below looks fine. I haven't done more than cursory
testing on it, but the way I read it, it should listwash arguments
passed to it on the command line vs your hash table file. If the current
spamlevel on the email is greater than the score in the hash table for
the address being evaluated, then the address will be excluded.
Different, but It works I guess. :)

Anyway, I don't have the time to fully debug your recipe, but as a
suggestion I would put a tail on your procmail logfile, then add some
more LOG lines to this recipe to dump variables to make sure those
variables contain what you think they should contain while tweaking and
debugging the recipe. Also make use of the procmail VERBOSE=yes in
places you are having trouble with as you are debugging it. The
information that returns can be usefull in debugging new recipes. Just
take it one step at a time.

>
> Since the spamkill.rc configuraiton file also involve an external perl
> script, I have also attached the perl script here for your reference:
>
> # cat /usr/local/sbin/filter_recipients
> #!/usr/bin/perl
>
> use strict;
> use DB_File;
>
> my $mapdb = "/etc/postfix/spamkill.db";
> my $spamlevel = length(shift @ARGV);
>
> tie(my %db, 'DB_File', $mapdb, O_RDONLY, 0664, $DB_HASH)
> or print "@ARGV\n" and exit(1);
> foreach my $addr (@ARGV) {
> $addr = lc($addr);
> (my $test = $addr) =~ s/\+[^@]+//;
> $test .= chr(0);
> if ($db{$test} > $spamlevel or !defined $db{$test}) {
> print "$addr ";
> }
> }
> untie(%db);
> print "\n";
> exit(0);
>
> Note, the spamkill.db is empty.
>
>
> Thanks
> Sam

Hope this helps.
--
Regards
Garen

Re: how to use procmail filter spam into imap folder

am 14.01.2007 11:19:26 von Pet

HI Garen,

Thank you for your great help.
I just realised that this method doesn't help me to filter spam into
user's cyrus imap folder eg. Trash.

With regarding to filtering spam email into user's cyrus imap folder, I
created the following procmailrc file:

PATH=/usr/local/bin:/usr/bin:/bin
DEFAULT=/mail/imap/Spam/

:0fw:spam.lock
* < 256000
|$SPAMC -f -U /var/run/spamd.sock

## handle SpamAssassin errors gracefully
:0e
{
EXITCODE=$?
}

:0
* ^X-Spam-Flag: YES
${DEFAULT}

:0
${DEFAULT}

When postfix involved this script wtih procmail, it filtered incoming
spam mail into the Spam directory, however it created IMAP folders as
cur/ new/ and tmp/. This is not cyrus folder style.

Is there any way for procmail create cyrus style folders and then filter
spam email into that folder?

Thanks
S

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet wrote:
>>>>>> Hi,
>>> [SNIP]
>>
>> Thank you for detailed description.
>> I have added updated the procmail rc file according to your suggestion
>> here, the spam mail still not being redirected to the Trash/imap or
>> Trash/spam folder.
>> In addition to the master procmail rc file, here is the spamkill.rc
>> file the process is also involved:
>>
>> cat spamkill.rc
>> LOGFILE="/var/log/spamkill/spamkill"
>> UMASK=022
>> LOGABSTRACT="no"
>> VERBOSE="no"
>> FORMAIL="/usr/local/bin/formail"
>> FILTERPL="/usr/local/sbin/filter_recipients"
>>
>> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>> DATE=`date +%Y%m%d-%H%M%S`
>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>
>
>> :0 Wi
>> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>>
>> :0 Wi
>> OLDRECIPIENTS=|echo "$@"
>
>
> # Remember that "$@" can only be expanded once in a procmail recipe, so
> # you must use that expansion to capture the arguments into another
> # variable if you want to use those arguments in multiple places
> # elsewhere in your recipe.
>
> #Try this instead.
>
> :0 Wi
> OLDRECIPIENTS=|echo "$@"
>
> LOG="Debug: OLDRECIPIENTS=${OLDRECIPIENTS}
> "
>
> RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`
>
> LOG="Debug: RECIPIENTS=${RECIPIENTS}
> "
>
>>
>> SHIFT=1000
>
> # The argument list isn't used after this point, so no need
> # to shift the argument list.
> SHIFT=1
>
>>
>> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
>> $DATE $$ Orig-To: $OLDRECIPIENTS
>> "
>>
>> :0
>> * RECIPIENTS ?? @ourdomain
>> {
>> LOG="$DATE $$ Sent-To: $RECIPIENTS
>> "
>>
>> :0
>> ! -f $FROM $RECIPIENTS
>> }
>
> Ok, so the above recipe should ship the email to the listwashed
> recipient list if @ourdomain is found anywhere in the list.
> It will also terminate procmail processing if that rule matches.
>
> Below would be an else condition. The recipient list didn't contain the
> @ourdomain pattern
>
>>
>> LOG="$DATE $$ Sent-To:
>> /usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
>> "
>> #the above instruction is trying to save the spam in the recpient's
>> #Trash directory.
>
> Actually, the above is just writing the 3 line string to the procmail
> logfile. It's not saving any email.
> If you are trying to save the email in a file do this:
>
> :0:
> /usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
>
> This is a delivery event, so would also terminate procmail processing at
> this point. If you want to continue beyond this point, use the carbon
> copy flag on it like this:
>
> :0c:
> /usr/local/mail/imap/spool/user/$TO_FIELD/Trash/$DATE-$$
>
>>
>> #:0w
>> # | /usr/local/cyrus/bin/deliver -a $USER -m user/$USER
>> # # if not told otherwise, deliver all messages to the user's inbox
>>
>
> Hmm, sorry, but I don't debug comments. :)
>
>> :0
>> /var/log/spamkill.log
>
> The above will write the email in the procmail pipe to a file spamkill.log
> This isn't really a log file, it's an email folder, so you should
> probably rename the file to indicate that so it's less confusing to you
> later. Also you should use a procmail lockfile to prevent race
> conditions thus:
>
> :0:
> /var/log/spamkill.log
>
> Another thing to consider at this point is that the file must have
> appropriate write permissions for the current procmail process. This may
> not be root at this point since you set DROPPRIVS=yes earlier, and that
> is presuming the owner was root prior to that point.
>
> This is a delivery event, so procmail will terminate processing at this
> point unless you use a carbon copy flag.
>
> Your perl script below looks fine. I haven't done more than cursory
> testing on it, but the way I read it, it should listwash arguments
> passed to it on the command line vs your hash table file. If the current
> spamlevel on the email is greater than the score in the hash table for
> the address being evaluated, then the address will be excluded.
> Different, but It works I guess. :)
>
> Anyway, I don't have the time to fully debug your recipe, but as a
> suggestion I would put a tail on your procmail logfile, then add some
> more LOG lines to this recipe to dump variables to make sure those
> variables contain what you think they should contain while tweaking and
> debugging the recipe. Also make use of the procmail VERBOSE=yes in
> places you are having trouble with as you are debugging it. The
> information that returns can be usefull in debugging new recipes. Just
> take it one step at a time.
>
>>
>> Since the spamkill.rc configuraiton file also involve an external perl
>> script, I have also attached the perl script here for your reference:
>>
>> # cat /usr/local/sbin/filter_recipients
>> #!/usr/bin/perl
>>
>> use strict;
>> use DB_File;
>>
>> my $mapdb = "/etc/postfix/spamkill.db";
>> my $spamlevel = length(shift @ARGV);
>>
>> tie(my %db, 'DB_File', $mapdb, O_RDONLY, 0664, $DB_HASH)
>> or print "@ARGV\n" and exit(1);
>> foreach my $addr (@ARGV) {
>> $addr = lc($addr);
>> (my $test = $addr) =~ s/\+[^@]+//;
>> $test .= chr(0);
>> if ($db{$test} > $spamlevel or !defined $db{$test}) {
>> print "$addr ";
>> }
>> }
>> untie(%db);
>> print "\n";
>> exit(0);
>>
>> Note, the spamkill.db is empty.
>>
>>
>> Thanks
>> Sam
>
> Hope this helps.

Re: how to use procmail filter spam into imap folder

am 14.01.2007 12:25:40 von Garen Erdoisa

Pet wrote:
> HI Garen,
>
> Thank you for your great help.
> I just realised that this method doesn't help me to filter spam into
> user's cyrus imap folder eg. Trash.
>
> With regarding to filtering spam email into user's cyrus imap folder, I
> created the following procmailrc file:
>
> PATH=/usr/local/bin:/usr/bin:/bin
> DEFAULT=/mail/imap/Spam/
>

This should point to a file instead of to a directory.
If it points to a directory, then procmail will create a directory
structure under that point, and make up it's own filenames to file the
emails under on the fly.
The email will actually end up in a file in one of those subdirectories.
This is a fall back method procmail uses so as to not lose emails if a
recipe is bad, but it may take some digging to find the emails using
this method.

Just define it as an actual file.

DEFAULT=/mail/imap/spamfolder

Note that I did not leave a trailing slash, which is where you seem to
be getting confused here.

Also, imap folders, except for the inbox, usually reside in a user's
home directory on the system, not in some other arbitrary place.
So I would just define it as:

SPAMFOLDER=${HOME}/spam

Then let the system figure out where to actually put the file.

> :0fw:spam.lock
> * < 256000
> |$SPAMC -f -U /var/run/spamd.sock

I'm assuming this is a spamassassin daemon running on a unix socket.
This recipe looks like it'll pass the email through the socket as a
filter, thus letting spamassassin add it's headers to the email. It'll
only process emails less than 256k in size. Looks ok depending on what
SPAMC is defined as.

>
> ## handle SpamAssassin errors gracefully
> :0e
> {
> EXITCODE=$?
> }
>
> :0
> * ^X-Spam-Flag: YES
> ${DEFAULT}

Try instead:
:0
* ^X-Spam-Flag: YES
${SPAMFOLDER}

>


> :0
> ${DEFAULT}

If you leave the definition for the DEFAULT folder alone, ie: don't
redefine it in your recipe, then the system will drop the email in the
users inbox. imap should know where to find it and it won't confuse your
user.

>
> When postfix involved this script wtih procmail, it filtered incoming
> spam mail into the Spam directory, however it created IMAP folders as
> cur/ new/ and tmp/. This is not cyrus folder style.
>

Yep, that was because of the trailing slash used on the DEFAULT definition.

> Is there any way for procmail create cyrus style folders and then filter
> spam email into that folder?
>

I'm not sure what you mean by cyrus style, I use Fedora Linux mostly.
However you can make foldernames by simple or complex definition schemes.

I tend to use the date command for that sort of thing.

ie:
SPAMFOLDER=${HOME}/spam.`date +%Y%m%d`

That will make a foldername like this:
/home/username/spam.20070114

So you then have auto date stampped folders created. You could set a
cron job to delete anything 30 days old. This would allow a user to dig
out emails from their date stampped spam folders for up to 30 days they
needed to.

In a cron job put something like this:

30 4 * * * find /home/username/ -type f -name 'spam.*' -mtime +30 -exec
rm -f {} \;


> Thanks
> S
>
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Garen Erdoisa wrote:
>>>> Pet wrote:
>>>>> Garen Erdoisa wrote:
>>>>>> Pet wrote:
>>>>>>> Hi,
>>>> [SNIP]

--
Garen

Re: [postfix,cyrus,spamassassin] how to use procmail filter spam into imap folder

am 14.01.2007 14:41:23 von Andrzej Adam Filip

Pet writes:

> Andrzej Adam Filip wrote:
>> Pet writes:
>>> I am currently using Postfix, cyurs imap, spamassassin and procmail
>>> filter incoming email, and send all spam mail into a single file.
>>> If I filter it into individual user's imap folder, how can I do that?
>>>
>>> Your suggestion is much appreciated.
>>
>> My recomendation:
>> 1) integrate spamassassin with postfix using milter
>> [ Milter support was added to Postfix 2.3.0 released 2006-07-12 ]
>> 2) use (per user) sieve script to deliver incoming "tagged as spam"
>> messages to separate folder e.g. spambox
>> [sieve supported by cyrus IMAP]
>>
> hi, I searched milter in google, but could not find any useful
> information about how to setup postfix, spamassassin and milter.
> Can you show me some pointers?

Sorry, I use sendmail which originally introduced milter support in
2001. Postfix added milter support in mid 2006.

I have heard that Postfix has been successfully tested with many
standard milters. There are a few milters using spamassassin,
ask at the postfix list for more specific recommendations.

I would suggest you asking specifically about MIMEDefang.org milter.
It can be used also to integrate anti-virus (e.g. clamav).

http://www.postfix.org/MILTER_README.html
Postfix before-queue Milter support

--
[pl2en: Andrew] Andrzej Adam Filip : anfi@priv.onet.pl : anfi@xl.wp.pl
Home site: http://anfi.homeunix.net/

Re: how to use procmail filter spam into imap folder

am 14.01.2007 23:07:17 von Pet Farrari

Garen Erdoisa wrote:
> Pet wrote:
>> HI Garen,
>>
>> Thank you for your great help.
>> I just realised that this method doesn't help me to filter spam into
>> user's cyrus imap folder eg. Trash.
>>
>> With regarding to filtering spam email into user's cyrus imap folder,
>> I created the following procmailrc file:
>>
>> PATH=/usr/local/bin:/usr/bin:/bin
>> DEFAULT=/mail/imap/Spam/
>>
>
> This should point to a file instead of to a directory.
> If it points to a directory, then procmail will create a directory
> structure under that point, and make up it's own filenames to file the
> emails under on the fly.
> The email will actually end up in a file in one of those subdirectories.
> This is a fall back method procmail uses so as to not lose emails if a
> recipe is bad, but it may take some digging to find the emails using
> this method.
>
> Just define it as an actual file.
>
> DEFAULT=/mail/imap/spamfolder
>
> Note that I did not leave a trailing slash, which is where you seem to
> be getting confused here.
>
> Also, imap folders, except for the inbox, usually reside in a user's
> home directory on the system, not in some other arbitrary place.
> So I would just define it as:
>
> SPAMFOLDER=${HOME}/spam
>
> Then let the system figure out where to actually put the file.
>
>> :0fw:spam.lock
>> * < 256000
>> |$SPAMC -f -U /var/run/spamd.sock
>
> I'm assuming this is a spamassassin daemon running on a unix socket.
> This recipe looks like it'll pass the email through the socket as a
> filter, thus letting spamassassin add it's headers to the email. It'll
> only process emails less than 256k in size. Looks ok depending on what
> SPAMC is defined as.
>
>>
>> ## handle SpamAssassin errors gracefully
>> :0e
>> {
>> EXITCODE=$?
>> }
>>
>> :0
>> * ^X-Spam-Flag: YES
>> ${DEFAULT}
>
> Try instead:
> :0
> * ^X-Spam-Flag: YES
> ${SPAMFOLDER}
>
>>
>
>
>> :0
>> ${DEFAULT}
>
> If you leave the definition for the DEFAULT folder alone, ie: don't
> redefine it in your recipe, then the system will drop the email in the
> users inbox. imap should know where to find it and it won't confuse your
> user.
>
>>
>> When postfix involved this script wtih procmail, it filtered incoming
>> spam mail into the Spam directory, however it created IMAP folders as
>> cur/ new/ and tmp/. This is not cyrus folder style.
>>
>
> Yep, that was because of the trailing slash used on the DEFAULT definition.
>
>> Is there any way for procmail create cyrus style folders and then
>> filter spam email into that folder?
>>
>
> I'm not sure what you mean by cyrus style, I use Fedora Linux mostly.
> However you can make foldernames by simple or complex definition schemes.
>
Thank you for your patient.

To create folder in cyrus, I'll have to use cyradm program. The folders
in each user directory will look something like below:

../ 3. 6. 9.
INBOX^Trash/ cyrus.index
.../ INBOX^Drafts/ cyrus.cache cyrus.squat
5. 8. INBOX^Sent/ cyrus.header

Another important thing is if we created these folders manually (without
the use of cyradm), the folders will not be recognised by cyrus database
(may be not in cyrus database).

However, even if I have created user^spam directory thru cyradm, but my
mail client (thunderbird) still not able to show up this folder in
Windows XP (I connect the mail server with imap port), and not in
webmail either. I tried to restart everything, like cyrus, postfix, and
thunderbird, still no go.


Thanks
Sam

> I tend to use the date command for that sort of thing.
>
> ie:
> SPAMFOLDER=${HOME}/spam.`date +%Y%m%d`
>
> That will make a foldername like this:
> /home/username/spam.20070114
>
> So you then have auto date stampped folders created. You could set a
> cron job to delete anything 30 days old. This would allow a user to dig
> out emails from their date stampped spam folders for up to 30 days they
> needed to.
>
> In a cron job put something like this:
>
> 30 4 * * * find /home/username/ -type f -name 'spam.*' -mtime +30 -exec
> rm -f {} \;
>
>
>> Thanks
>> S
>>
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet wrote:
>>>>>> Garen Erdoisa wrote:
>>>>>>> Pet wrote:
>>>>>>>> Hi,
>>>>> [SNIP]
>

Re: how to use procmail filter spam into imap folder

am 14.01.2007 23:58:48 von Garen Erdoisa

Pet Farrari wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> HI Garen,
>>>
>>> Thank you for your great help.
>>> I just realised that this method doesn't help me to filter spam into
>>> user's cyrus imap folder eg. Trash.
>>
>>[SNIP]
>>
>> I'm not sure what you mean by cyrus style, I use Fedora Linux mostly.
>> However you can make foldernames by simple or complex definition schemes.
>>
> Thank you for your patient.
>
> To create folder in cyrus, I'll have to use cyradm program. The folders
> in each user directory will look something like below:
>
> ./ 3. 6. 9. INBOX^Trash/
> cyrus.index
> ../ INBOX^Drafts/ cyrus.cache cyrus.squat
> 5. 8. INBOX^Sent/ cyrus.header
>
> Another important thing is if we created these folders manually (without
> the use of cyradm), the folders will not be recognised by cyrus database
> (may be not in cyrus database).
>
> However, even if I have created user^spam directory thru cyradm, but my
> mail client (thunderbird) still not able to show up this folder in
> Windows XP (I connect the mail server with imap port), and not in
> webmail either. I tried to restart everything, like cyrus, postfix, and
> thunderbird, still no go.

Ok, well it looks like we are having some confusion on what is meant by
the term "folder". In windows, a directory is also referred to as a folder.

Most email clients refer to folders also as a file that has a bunch of
letters in it. ergo, just a file, not a directory.

In procmail, a "Folder" is just a file.
A directory is a directory, in which files or folders are kept.

People tend to mix up the terminology alot which can create confusion
when trying to hold a technical discussion like this one.

Since this thread is mostly talking about procmail, I'm using the
procmail definition of what files and folders are in my examples.

It appears from your example above with cyrus that a "folder" is a
directory instead of a file. I'm getting that from the trailing slash on
the Cyrus folder names.

So, there is a problem here. When you tell procmail to deliver an email
to a directory, instead of to a file, procmail has to create it's own
filename on the fly to use for the email it delivers to that directory.

This filename procmail creates is probably incompatible with your Cyrus
software, so your Cyrus software can't see the files in it's directories
that were created by procmail or something along those lines.

Short of digging into this Cyrus software myself and figuring out how it
does stuff under the hood, there isn't much I can do to help you sort
out how to get procmail to dump an email into a Cyrus folder in a form
that will be compatible with your Cyrus software and how it organizes
information under the hood.

By default, procmail uses Berkley mailbox format, and just appends it's
raw emails to files when delivering an email. It's left up to another
client application to interpret the emails found in those files.

You might be able to use some tool application in Cyrus as an interface
between procmail delivery and your Cyrus folder structure to get emails
into the database where you want them.

ie:

NL="
"
# Delivery to Cyrus
CYRUSDELIVERY=/path/to/cyrusdeliveryapp
SWITCHES=""

:0 wi
|${FORMAIL} -A "X-Folder: Cyrus Delivery" |${CYRUSDELEVERY} ${SWITCHES}

:0 e
{
ERRORCODE=$?
LOG="[$$]$_: Failed Delevery to Cyrus, ERRORCODE=${ERRORCODE}${NL}"
}

:0:
${DEFAULT}

>
> [SNIP]

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 00:26:23 von Pet Farrari

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> HI Garen,
>>>>
>>>> Thank you for your great help.
>>>> I just realised that this method doesn't help me to filter spam into
>>>> user's cyrus imap folder eg. Trash.
>>>
>>> [SNIP]
>>>
>>> I'm not sure what you mean by cyrus style, I use Fedora Linux mostly.
>>> However you can make foldernames by simple or complex definition
>>> schemes.
>>>
>> Thank you for your patient.
>>
>> To create folder in cyrus, I'll have to use cyradm program. The
>> folders in each user directory will look something like below:
>>
>> ./ 3. 6. 9. INBOX^Trash/
>> cyrus.index
>> ../ INBOX^Drafts/ cyrus.cache cyrus.squat
>> 5. 8. INBOX^Sent/ cyrus.header
>>
>> Another important thing is if we created these folders manually
>> (without the use of cyradm), the folders will not be recognised by
>> cyrus database (may be not in cyrus database).
>>
>> However, even if I have created user^spam directory thru cyradm, but
>> my mail client (thunderbird) still not able to show up this folder in
>> Windows XP (I connect the mail server with imap port), and not in
>> webmail either. I tried to restart everything, like cyrus, postfix,
>> and thunderbird, still no go.
>
> Ok, well it looks like we are having some confusion on what is meant by
> the term "folder". In windows, a directory is also referred to as a folder.
>
> Most email clients refer to folders also as a file that has a bunch of
> letters in it. ergo, just a file, not a directory.
>
> In procmail, a "Folder" is just a file.
> A directory is a directory, in which files or folders are kept.
>
> People tend to mix up the terminology alot which can create confusion
> when trying to hold a technical discussion like this one.
>
> Since this thread is mostly talking about procmail, I'm using the
> procmail definition of what files and folders are in my examples.
>
> It appears from your example above with cyrus that a "folder" is a
> directory instead of a file. I'm getting that from the trailing slash on
> the Cyrus folder names.
>
> So, there is a problem here. When you tell procmail to deliver an email
> to a directory, instead of to a file, procmail has to create it's own
> filename on the fly to use for the email it delivers to that directory.
>
> This filename procmail creates is probably incompatible with your Cyrus
> software, so your Cyrus software can't see the files in it's directories
> that were created by procmail or something along those lines.
>
> Short of digging into this Cyrus software myself and figuring out how it
> does stuff under the hood, there isn't much I can do to help you sort
> out how to get procmail to dump an email into a Cyrus folder in a form
> that will be compatible with your Cyrus software and how it organizes
> information under the hood.
>
> By default, procmail uses Berkley mailbox format, and just appends it's
> raw emails to files when delivering an email. It's left up to another
> client application to interpret the emails found in those files.
>
> You might be able to use some tool application in Cyrus as an interface
> between procmail delivery and your Cyrus folder structure to get emails
> into the database where you want them.
>
> ie:
>
> NL="
> "
> # Delivery to Cyrus
> CYRUSDELIVERY=/path/to/cyrusdeliveryapp
I found out it is /usr/local/cyrus/bin/deliver

> SWITCHES=""
>
> :0 wi
> |${FORMAIL} -A "X-Folder: Cyrus Delivery" |${CYRUSDELEVERY} ${SWITCHES}
>
But I have to get the email deliver to the user's Trash folder.
In my first example, I used formail to extract the To: user email
address. Do you know how to extract the email user name from the email
address like this? I want to define the following lines in the gobal
procmailrc (I won't have individual procmailrc in /home/$USR direcotry):

CYRUSUSER=`/usr/local/bin/formail -zxTo:`
DATE=`date +%Y%m%d-%H%M%S`
XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`

#then execute this:
:0f
|$SPAMC -f -U /var/run/spamd.sock

:0:$CYRUSUSER.lock
* ^X-Spam-Level: \*\*\*\*\*
{
$DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER
}

But the above DELIVER clause doesn't describe which folder I want to
deliver the spam mail to.

BTW, if the TO: user name extracted from the formail is a virtual name,
will the $DELIVER clause still able to send mail to the right user thru
"user.$CYRUSUSER" ?

Thanks
S

> :0 e
> {
> ERRORCODE=$?
> LOG="[$$]$_: Failed Delevery to Cyrus, ERRORCODE=${ERRORCODE}${NL}"
> }
>
> :0:
> ${DEFAULT}
>
>>
>> [SNIP]
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 00:54:57 von Garen Erdoisa

Pet Farrari wrote:
> Garen Erdoisa wrote:
>> Pet Farrari wrote:
>>> Garen Erdoisa wrote:
>>>> Pet wrote:
>>>>> HI Garen,
>>>>>
>>>>> Thank you for your great help.
>>>>> I just realised that this method doesn't help me to filter spam
>>>>> into user's cyrus imap folder eg. Trash.
>>>>
>>>> [SNIP]
>>>>
>>>> I'm not sure what you mean by cyrus style, I use Fedora Linux
>>>> mostly. However you can make foldernames by simple or complex
>>>> definition schemes.
>>>>
>>> Thank you for your patient.
>>>
>>> To create folder in cyrus, I'll have to use cyradm program. The
>>> folders in each user directory will look something like below:
>>>
>>> ./ 3. 6. 9. INBOX^Trash/
>>> cyrus.index
>>> ../ INBOX^Drafts/ cyrus.cache cyrus.squat
>>> 5. 8. INBOX^Sent/ cyrus.header
>>>
>>> Another important thing is if we created these folders manually
>>> (without the use of cyradm), the folders will not be recognised by
>>> cyrus database (may be not in cyrus database).
>>>
>>> However, even if I have created user^spam directory thru cyradm, but
>>> my mail client (thunderbird) still not able to show up this folder in
>>> Windows XP (I connect the mail server with imap port), and not in
>>> webmail either. I tried to restart everything, like cyrus, postfix,
>>> and thunderbird, still no go.
>>
>> Ok, well it looks like we are having some confusion on what is meant
>> by the term "folder". In windows, a directory is also referred to as a
>> folder.
>>
>> Most email clients refer to folders also as a file that has a bunch of
>> letters in it. ergo, just a file, not a directory.
>>
>> In procmail, a "Folder" is just a file.
>> A directory is a directory, in which files or folders are kept.
>>
>> People tend to mix up the terminology alot which can create confusion
>> when trying to hold a technical discussion like this one.
>>
>> Since this thread is mostly talking about procmail, I'm using the
>> procmail definition of what files and folders are in my examples.
>>
>> It appears from your example above with cyrus that a "folder" is a
>> directory instead of a file. I'm getting that from the trailing slash
>> on the Cyrus folder names.
>>
>> So, there is a problem here. When you tell procmail to deliver an
>> email to a directory, instead of to a file, procmail has to create
>> it's own filename on the fly to use for the email it delivers to that
>> directory.
>>
>> This filename procmail creates is probably incompatible with your
>> Cyrus software, so your Cyrus software can't see the files in it's
>> directories that were created by procmail or something along those lines.
>>
>> Short of digging into this Cyrus software myself and figuring out how
>> it does stuff under the hood, there isn't much I can do to help you
>> sort out how to get procmail to dump an email into a Cyrus folder in a
>> form that will be compatible with your Cyrus software and how it
>> organizes information under the hood.
>>
>> By default, procmail uses Berkley mailbox format, and just appends
>> it's raw emails to files when delivering an email. It's left up to
>> another client application to interpret the emails found in those files.
>>
>> You might be able to use some tool application in Cyrus as an
>> interface between procmail delivery and your Cyrus folder structure to
>> get emails into the database where you want them.
>>
>> ie:
>>
>> NL="
>> "
>> # Delivery to Cyrus
>> CYRUSDELIVERY=/path/to/cyrusdeliveryapp
> I found out it is /usr/local/cyrus/bin/deliver
>
>> SWITCHES=""
>>
>> :0 wi
>> |${FORMAIL} -A "X-Folder: Cyrus Delivery" |${CYRUSDELEVERY} ${SWITCHES}
>>
> But I have to get the email deliver to the user's Trash folder.
> In my first example, I used formail to extract the To: user email
> address. Do you know how to extract the email user name from the email
> address like this? I want to define the following lines in the gobal
> procmailrc (I won't have individual procmailrc in /home/$USR direcotry):
>
> CYRUSUSER=`/usr/local/bin/formail -zxTo:`
> DATE=`date +%Y%m%d-%H%M%S`
> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>
> #then execute this:
> :0f
> |$SPAMC -f -U /var/run/spamd.sock
>
> :0:$CYRUSUSER.lock
> * ^X-Spam-Level: \*\*\*\*\*
> {
> $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER

This is a syntax error. Procmail would see the line and skip over it. A
correct form of this would be thus:

:0 wi
|$DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER

:0 E
{
ERRORCODE=$?
LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
}

Remember, that procmail recipes always start with :0 even if they are
nested inside other procmail recipes.

> }
>
> But the above DELIVER clause doesn't describe which folder I want to
> deliver the spam mail to.
>
True, there may be some sort of command line switch you can use to
specify the foldername, or you might be able to do that using plussed
folders if your Cyrus imap software supports plussed addresses. ie:

nobody@example.com would deliver to the inbox while
nobody+trash@example.com would deliver to the trash folder and
nobody+spam@example.com would deliver to the spam folder.

> BTW, if the TO: user name extracted from the formail is a virtual name,
> will the $DELIVER clause still able to send mail to the right user thru
> "user.$CYRUSUSER" ?
>

I don't see why not. I would think that it should be able to do that.
You might have to use something like your perl script to strip off cruft
from the various To: addresses to get them down to just a simple virtual
username though.

If the user has a local account, that current username running the
procmail process after you DROPPRIVS=yes will be stored in the LOGNAME
variable.

There are a number of ways to extract the Recipient addresses in
procmail. Some of those ways may require some editing of the recipient
list (stripping off real name information etc) to get the actual
username. You can use programs like perl or sed (stream edit) do do such
editing of data streams on the fly. Depending on how complex the To:
address you are looking at is, the editing can get rather complicated.
You might want to pull down a copy of spambouncer for some examples of
how to extract and stream edit various header information into procmail
variables using sed.

a quick and dirty way to get a To: address list from the email would be
something like this:
LINEBUF=30000
TOHEADER=`formail -cx To: `

This will unfold the header and extract up to 30000 characters of
information in the To: header into the TOHEADER variable.

That won't handle the case of Bcc: addresses though. LOGNAME is more
reliable, provided the end user target has an account on the box that is
handling the email.

If you can pass the username to procmail using command line arguments,
that would also be fairly reliable, however you'd have to then extract
those arguments inside your procmail recipe and use them correctly as
was previously discussed in this thread.

So the approach I would probably use for virtual addresses in procmail
is to run procmail as root, or some other privileged account, pass the
virtual username being handled to procmail using the procmail command
line arguments, then extract that virtual username inside the procmail
recipe into a variable and use that variable in your delivery to Cyrus.

In that case I would completely ignore anything in the To: header in the
email. It would be irrelevant.

>>> [SNIP]
>>

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 02:07:39 von Pet Farrari

Hi Garen,

Now I tried to solve the problem step by step.
I tried to get the cyrus DELIVER working first, but I still getting its
error:
procmail: Extraneous ignore-write-error flag ignored
procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash"


The procmail rc file is:

LOGFILE="/var/log/spamkill/spamkill"
UMASK=022
LOGABSTRACT="no"
VERBOSE="no"
FORMAIL="/usr/local/bin/formail"
FILTERPL="/usr/local/sbin/filter_recipients"

TO_FIELD=`/usr/local/bin/formail -zxTo:`
DATE=`date +%Y%m%d-%H%M%S`
XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`

:0 Wi
RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"

:0 Wi
OLDRECIPIENTS=|echo "$@"

SHIFT=1000

LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
$DATE $$ Orig-To: $OLDRECIPIENTS
"

:0
* RECIPIENTS ?? @ourdomain
{
LOG="$DATE $$ Sent-To: $RECIPIENTS
"
DELIVER="/usr/local/cyrus/bin/deliver"
CYRUSUSER="sam"
:0 wi
* ^X-Spam-Level: \*\*\*\*\*
{
| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
}

:0 E
{
ERRORCODE=$?
LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
}

:0
/var/log/spamkill.log


Thanks
Sam

Re: how to use procmail filter spam into imap folder

am 15.01.2007 04:16:07 von Pet Farrari

Hi,

In the /var/log/maillog file, the message shown that I am still getting
the error of "Can't create output folder"

I've tried different DELIVER syntax, such as:

:0 fw
|/usr/lib/cyrus/bin/deliver -e -a david -m user.david

or
:0 fw
|/usr/lib/cyrus/bin/deliver -e -a david -m user.david/

or
:0 fw
|/usr/lib/cyrus/bin/deliver -e -a david -m david

or
:0 fw
|/usr/lib/cyrus/bin/deliver -e -a david -m david/

all of these give me the same error of "can't create ouoptu folder".

Very tough. :(

Thanks
Sam

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Garen Erdoisa wrote:
>>> Pet Farrari wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet wrote:
>>>>>> HI Garen,
>>>>>>
>>>>>> Thank you for your great help.
>>>>>> I just realised that this method doesn't help me to filter spam
>>>>>> into user's cyrus imap folder eg. Trash.
>>>>>
>>>>> [SNIP]
>>>>>
>>>>> I'm not sure what you mean by cyrus style, I use Fedora Linux
>>>>> mostly. However you can make foldernames by simple or complex
>>>>> definition schemes.
>>>>>
>>>> Thank you for your patient.
>>>>
>>>> To create folder in cyrus, I'll have to use cyradm program. The
>>>> folders in each user directory will look something like below:
>>>>
>>>> ./ 3. 6. 9. INBOX^Trash/
>>>> cyrus.index
>>>> ../ INBOX^Drafts/ cyrus.cache cyrus.squat
>>>> 5. 8. INBOX^Sent/ cyrus.header
>>>>
>>>> Another important thing is if we created these folders manually
>>>> (without the use of cyradm), the folders will not be recognised by
>>>> cyrus database (may be not in cyrus database).
>>>>
>>>> However, even if I have created user^spam directory thru cyradm, but
>>>> my mail client (thunderbird) still not able to show up this folder
>>>> in Windows XP (I connect the mail server with imap port), and not in
>>>> webmail either. I tried to restart everything, like cyrus, postfix,
>>>> and thunderbird, still no go.
>>>
>>> Ok, well it looks like we are having some confusion on what is meant
>>> by the term "folder". In windows, a directory is also referred to as
>>> a folder.
>>>
>>> Most email clients refer to folders also as a file that has a bunch
>>> of letters in it. ergo, just a file, not a directory.
>>>
>>> In procmail, a "Folder" is just a file.
>>> A directory is a directory, in which files or folders are kept.
>>>
>>> People tend to mix up the terminology alot which can create confusion
>>> when trying to hold a technical discussion like this one.
>>>
>>> Since this thread is mostly talking about procmail, I'm using the
>>> procmail definition of what files and folders are in my examples.
>>>
>>> It appears from your example above with cyrus that a "folder" is a
>>> directory instead of a file. I'm getting that from the trailing slash
>>> on the Cyrus folder names.
>>>
>>> So, there is a problem here. When you tell procmail to deliver an
>>> email to a directory, instead of to a file, procmail has to create
>>> it's own filename on the fly to use for the email it delivers to that
>>> directory.
>>>
>>> This filename procmail creates is probably incompatible with your
>>> Cyrus software, so your Cyrus software can't see the files in it's
>>> directories that were created by procmail or something along those
>>> lines.
>>>
>>> Short of digging into this Cyrus software myself and figuring out how
>>> it does stuff under the hood, there isn't much I can do to help you
>>> sort out how to get procmail to dump an email into a Cyrus folder in
>>> a form that will be compatible with your Cyrus software and how it
>>> organizes information under the hood.
>>>
>>> By default, procmail uses Berkley mailbox format, and just appends
>>> it's raw emails to files when delivering an email. It's left up to
>>> another client application to interpret the emails found in those files.
>>>
>>> You might be able to use some tool application in Cyrus as an
>>> interface between procmail delivery and your Cyrus folder structure
>>> to get emails into the database where you want them.
>>>
>>> ie:
>>>
>>> NL="
>>> "
>>> # Delivery to Cyrus
>>> CYRUSDELIVERY=/path/to/cyrusdeliveryapp
>> I found out it is /usr/local/cyrus/bin/deliver
>>
>>> SWITCHES=""
>>>
>>> :0 wi
>>> |${FORMAIL} -A "X-Folder: Cyrus Delivery" |${CYRUSDELEVERY} ${SWITCHES}
>>>
>> But I have to get the email deliver to the user's Trash folder.
>> In my first example, I used formail to extract the To: user email
>> address. Do you know how to extract the email user name from the email
>> address like this? I want to define the following lines in the gobal
>> procmailrc (I won't have individual procmailrc in /home/$USR direcotry):
>>
>> CYRUSUSER=`/usr/local/bin/formail -zxTo:`
>> DATE=`date +%Y%m%d-%H%M%S`
>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>
>> #then execute this:
>> :0f
>> |$SPAMC -f -U /var/run/spamd.sock
>>
>> :0:$CYRUSUSER.lock
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER
>
> This is a syntax error. Procmail would see the line and skip over it. A
> correct form of this would be thus:
>
> :0 wi
> |$DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER
>
> :0 E
> {
> ERRORCODE=$?
> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
> }
>
> Remember, that procmail recipes always start with :0 even if they are
> nested inside other procmail recipes.
>
>> }
>>
>> But the above DELIVER clause doesn't describe which folder I want to
>> deliver the spam mail to.
>>
> True, there may be some sort of command line switch you can use to
> specify the foldername, or you might be able to do that using plussed
> folders if your Cyrus imap software supports plussed addresses. ie:
>
> nobody@example.com would deliver to the inbox while
> nobody+trash@example.com would deliver to the trash folder and
> nobody+spam@example.com would deliver to the spam folder.
>
>> BTW, if the TO: user name extracted from the formail is a virtual
>> name, will the $DELIVER clause still able to send mail to the right
>> user thru "user.$CYRUSUSER" ?
>>
>
> I don't see why not. I would think that it should be able to do that.
> You might have to use something like your perl script to strip off cruft
> from the various To: addresses to get them down to just a simple virtual
> username though.
>
> If the user has a local account, that current username running the
> procmail process after you DROPPRIVS=yes will be stored in the LOGNAME
> variable.
>
> There are a number of ways to extract the Recipient addresses in
> procmail. Some of those ways may require some editing of the recipient
> list (stripping off real name information etc) to get the actual
> username. You can use programs like perl or sed (stream edit) do do such
> editing of data streams on the fly. Depending on how complex the To:
> address you are looking at is, the editing can get rather complicated.
> You might want to pull down a copy of spambouncer for some examples of
> how to extract and stream edit various header information into procmail
> variables using sed.
>
> a quick and dirty way to get a To: address list from the email would be
> something like this:
> LINEBUF=30000
> TOHEADER=`formail -cx To: `
>
> This will unfold the header and extract up to 30000 characters of
> information in the To: header into the TOHEADER variable.
>
> That won't handle the case of Bcc: addresses though. LOGNAME is more
> reliable, provided the end user target has an account on the box that is
> handling the email.
>
> If you can pass the username to procmail using command line arguments,
> that would also be fairly reliable, however you'd have to then extract
> those arguments inside your procmail recipe and use them correctly as
> was previously discussed in this thread.
>
> So the approach I would probably use for virtual addresses in procmail
> is to run procmail as root, or some other privileged account, pass the
> virtual username being handled to procmail using the procmail command
> line arguments, then extract that virtual username inside the procmail
> recipe into a variable and use that variable in your delivery to Cyrus.
>
> In that case I would completely ignore anything in the To: header in the
> email. It would be irrelevant.
>
>>>> [SNIP]
>>>
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 05:04:52 von Garen Erdoisa

Pet Farrari wrote:
> Hi Garen,
>
> Now I tried to solve the problem step by step.
> I tried to get the cyrus DELIVER working first, but I still getting its
> error:
> procmail: Extraneous ignore-write-error flag ignored
> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash"
>
>
> The procmail rc file is:
>
> LOGFILE="/var/log/spamkill/spamkill"
> UMASK=022
> LOGABSTRACT="no"
> VERBOSE="no"
> FORMAIL="/usr/local/bin/formail"
> FILTERPL="/usr/local/sbin/filter_recipients"
>
> TO_FIELD=`/usr/local/bin/formail -zxTo:`
> DATE=`date +%Y%m%d-%H%M%S`
> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>
> :0 Wi
> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>
> :0 Wi
> OLDRECIPIENTS=|echo "$@"
>
> SHIFT=1000
>
> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
> $DATE $$ Orig-To: $OLDRECIPIENTS
> "
>
> :0
> * RECIPIENTS ?? @ourdomain
> {
> LOG="$DATE $$ Sent-To: $RECIPIENTS
> "
> DELIVER="/usr/local/cyrus/bin/deliver"
> CYRUSUSER="sam"
> :0 wi
> * ^X-Spam-Level: \*\*\*\*\*
> {
> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash

This a syntax error. Procmail will skip the above line because it
doesn't see it as a recipe since you didn't start it with :0

It should read:

:0
| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash

Weather or not the syntax is correct for the .Trash folder is correct
isn't something I can determine short of reading the Cyrus docs myself.
I'm assuming that it's correct for the moment.

> }
>
> :0 E
> {
> ERRORCODE=$?
> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
> }
>
> :0
> /var/log/spamkill.log
>
>
> Thanks
> Sam

So, the full recipe above, corrected should read:

# Note, I changed the name of the logfile to indicate it's type.
# Also see the last line of the recipe for notes there.

LOGFILE="/var/log/spamkill/spamkill.log"
UMASK=022
LOGABSTRACT="no"
VERBOSE="no"
FORMAIL="/usr/local/bin/formail"
FILTERPL="/usr/local/sbin/filter_recipients"

# Moved this here since it's a global definition
DELIVER="/usr/local/cyrus/bin/deliver"

# Define a newline variable for use in procmail log lines.
# makes the recipe a bit more human readable.
NL="
"

TO_FIELD=`/usr/local/bin/formail -zxTo:`

# Debug statement. Comment out these Debug log lines later.
LOG="[$$]$_: Debug: TO_FIELD=${TO_FIELD}${NL}"

DATE=`date +%Y%m%d-%H%M%S`
XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`

LOG="[$$]$_: Debug: XSPAMLEVEL=${XSPAMLEVEL} ${NL}"

# I changed the order here, since "$@" can only be expanded once.
:0 Wi
OLDRECIPIENTS=|echo "$@"

LOG="[$$]$_: Debug: OLDRECIPIENTS=${OLDRECIPIENTS}${NL}"

# I replaced "$@" with ${OLDRECIPIENTS} here since "$@" will not
# expand more than once.
# Also changed the style a bit.
# Note the backticks that launch an embedded shell script.
# The stdout from this script will be assigned to the RECIPIENTS
# Variable
RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`

LOG="[$$]$_: Debug: RECIPIENTS=${RECIPIENTS}${NL}"

# not needed.
# SHIFT=1000

LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
$DATE $$ Orig-To: $OLDRECIPIENTS
"

:0
* RECIPIENTS ?? @ourdomain
{

LOG="$DATE $$ Sent-To: ${RECIPIENTS}${NL}"

# Moved the DELIVER variable assignment up to the top
# since it's a global def.

CYRUSUSER="sam"

# This starts a procmail nested block, in which you can have
# other procmail recipes.
:0
* ^X-Spam-Level: \*\*\*\*\*
{
# Deliver the email to Cyrus using the Cyrus delivery program.
# If the mail is delivered successfully, procmail processing will
# stop at this point, unless the c (carbon copy) flag is also used.

:0 wi
| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash

# Else Delivery failed. So we need to handle the error condition.
:0 E
{
# Get the return code from the last program that ran
# and report it in the logfile.
ERRORCODE=$?
LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
}
}

# Alternate delivery of the email to this file using default
# procmail Berkley mailbox format.
# This is a delivery recipe, so procmail will stop processing at
# this point.
:0
/var/log/spamkill.mbox


--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 05:19:41 von Garen Erdoisa

Pet Farrari wrote:
> Hi,
>
> In the /var/log/maillog file, the message shown that I am still getting
> the error of "Can't create output folder"
>
> I've tried different DELIVER syntax, such as:
>
> :0 fw
> |/usr/lib/cyrus/bin/deliver -e -a david -m user.david

This will not work unless you use some sort of shell meta symbols on the
action line. Otherwise procmail will misinterpret the entire action line
as a list of folders and try to put a copy of the email into each of
them. That is why it needs to be written

:0 wi
|${DELIVER} -e -a david -m user.david

With at least one shell meta character set on the action line ie: ${},
procmail will interpret the action line as a shell command line instead
of a list of folder names.

Also, it's not a filter recipe, it's a delivery recipe so the filter
flag if used would be extraneous and might give you some unexpected results.

A procmail filter recipe expects to feed the email in the pipeline
through a program which will modify the email in the pipeline then
return it back to procmail for the next recipe in the set.

A procmail delivery recipe expects to deliver the mail. Upon delivery
it's done. Procmail has no further need of it, thus procmail will stop
processing any further recipes beyond that point. The only way around
that is to use the carbon copy flag if you want procmail for some reason
to continue processing even after having delivered a copy of the email
in the pipeline to some other place.
ie: either a folder or a handoff to another delivery agent.

>
> or
> :0 fw
> |/usr/lib/cyrus/bin/deliver -e -a david -m user.david/

Same here.
Should be:
:0 wi
|${DELIVER} -e -a david -m user.david

>
> or
> :0 fw
> |/usr/lib/cyrus/bin/deliver -e -a david -m david
Same here.
Should be:

:0 wi
|${DELIVER} -e -a david -m david


>
> or
> :0 fw
> |/usr/lib/cyrus/bin/deliver -e -a david -m david/
Same here.
Should be:

:0 wi
|${DELIVER} -e -a david -m david


>
> all of these give me the same error of "can't create ouoptu folder".
Yep. that's because you had no shell meta characters for procmail to
expand. See the procmailrc and procmailex man pages for more examples.

>
> Very tough. :(

Not really. What is tough at first is understanding the terminology and
syntax of procmail when you aren't used to working in it.

Once you have the syntax and terminology down, it's fairly easy to work
with. Unfortunately there are not many good tutorials out there to teach
someone how to build custom procmail recipes. I learned it the hard way
myself.

Try using VERBOSE=yes also while building and debugging new recipes.
That will give you more insight into what is actually going on under the
hood as procmail executes various recipes.


> [SNIP]

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 05:42:55 von Pet Farrari

Thanks for the help along the way. I still got the same error with
"can't create folder" at the DELIVER clause without the "Skipped"
keyword in the /var/logl/messages file.
The /var/log/spamkill/spamkill.log file shown all the debug message (
have set VERBOSE="yes") , but it looks fine, no error indicate the
DELIVER clause has error.
I guess there is special construction in the "deliver" syntax. I will
head out to look for this info first.

Thanks
S

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Hi Garen,
>>
>> Now I tried to solve the problem step by step.
>> I tried to get the cyrus DELIVER working first, but I still getting
>> its error:
>> procmail: Extraneous ignore-write-error flag ignored
>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash"
>>
>>
>> The procmail rc file is:
>>
>> LOGFILE="/var/log/spamkill/spamkill"
>> UMASK=022
>> LOGABSTRACT="no"
>> VERBOSE="no"
>> FORMAIL="/usr/local/bin/formail"
>> FILTERPL="/usr/local/sbin/filter_recipients"
>>
>> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>> DATE=`date +%Y%m%d-%H%M%S`
>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>
>> :0 Wi
>> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>>
>> :0 Wi
>> OLDRECIPIENTS=|echo "$@"
>>
>> SHIFT=1000
>>
>> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
>> $DATE $$ Orig-To: $OLDRECIPIENTS
>> "
>>
>> :0
>> * RECIPIENTS ?? @ourdomain
>> {
>> LOG="$DATE $$ Sent-To: $RECIPIENTS
>> "
>> DELIVER="/usr/local/cyrus/bin/deliver"
>> CYRUSUSER="sam"
>> :0 wi
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> This a syntax error. Procmail will skip the above line because it
> doesn't see it as a recipe since you didn't start it with :0
>
> It should read:
>
> :0
> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> Weather or not the syntax is correct for the .Trash folder is correct
> isn't something I can determine short of reading the Cyrus docs myself.
> I'm assuming that it's correct for the moment.
>
>> }
>>
>> :0 E
>> {
>> ERRORCODE=$?
>> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
>> }
>>
>> :0
>> /var/log/spamkill.log
>>
>>
>> Thanks
>> Sam
>
> So, the full recipe above, corrected should read:
>
> # Note, I changed the name of the logfile to indicate it's type.
> # Also see the last line of the recipe for notes there.
>
> LOGFILE="/var/log/spamkill/spamkill.log"
> UMASK=022
> LOGABSTRACT="no"
> VERBOSE="no"
> FORMAIL="/usr/local/bin/formail"
> FILTERPL="/usr/local/sbin/filter_recipients"
>
> # Moved this here since it's a global definition
> DELIVER="/usr/local/cyrus/bin/deliver"
>
> # Define a newline variable for use in procmail log lines.
> # makes the recipe a bit more human readable.
> NL="
> "
>
> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>
> # Debug statement. Comment out these Debug log lines later.
> LOG="[$$]$_: Debug: TO_FIELD=${TO_FIELD}${NL}"
>
> DATE=`date +%Y%m%d-%H%M%S`
> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>
> LOG="[$$]$_: Debug: XSPAMLEVEL=${XSPAMLEVEL} ${NL}"
>
> # I changed the order here, since "$@" can only be expanded once.
> :0 Wi
> OLDRECIPIENTS=|echo "$@"
>
> LOG="[$$]$_: Debug: OLDRECIPIENTS=${OLDRECIPIENTS}${NL}"
>
> # I replaced "$@" with ${OLDRECIPIENTS} here since "$@" will not
> # expand more than once.
> # Also changed the style a bit.
> # Note the backticks that launch an embedded shell script.
> # The stdout from this script will be assigned to the RECIPIENTS
> # Variable
> RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`
>
> LOG="[$$]$_: Debug: RECIPIENTS=${RECIPIENTS}${NL}"
>
> # not needed.
> # SHIFT=1000
>
> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
> $DATE $$ Orig-To: $OLDRECIPIENTS
> "
>
> :0
> * RECIPIENTS ?? @ourdomain
> {
>
> LOG="$DATE $$ Sent-To: ${RECIPIENTS}${NL}"
>
> # Moved the DELIVER variable assignment up to the top
> # since it's a global def.
>
> CYRUSUSER="sam"
>
> # This starts a procmail nested block, in which you can have
> # other procmail recipes.
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> # Deliver the email to Cyrus using the Cyrus delivery program.
> # If the mail is delivered successfully, procmail processing will
> # stop at this point, unless the c (carbon copy) flag is also used.
>
> :0 wi
> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> # Else Delivery failed. So we need to handle the error condition.
> :0 E
> {
> # Get the return code from the last program that ran
> # and report it in the logfile.
> ERRORCODE=$?
> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
> }
> }
>
> # Alternate delivery of the email to this file using default
> # procmail Berkley mailbox format.
> # This is a delivery recipe, so procmail will stop processing at
> # this point.
> :0
> /var/log/spamkill.mbox
>
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 07:11:33 von Pet Farrari

Hi Garen,

Do yo know how to make sure the deliver program is running as cyrus user
rather than spamd or root? It is under my impression that the deliver
program is not running as cyrus, so it failed to create file in the
imap/spool/user/sam/ directory.

Thanks
S
Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Hi Garen,
>>
>> Now I tried to solve the problem step by step.
>> I tried to get the cyrus DELIVER working first, but I still getting
>> its error:
>> procmail: Extraneous ignore-write-error flag ignored
>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash"
>>
>>
>> The procmail rc file is:
>>
>> LOGFILE="/var/log/spamkill/spamkill"
>> UMASK=022
>> LOGABSTRACT="no"
>> VERBOSE="no"
>> FORMAIL="/usr/local/bin/formail"
>> FILTERPL="/usr/local/sbin/filter_recipients"
>>
>> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>> DATE=`date +%Y%m%d-%H%M%S`
>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>
>> :0 Wi
>> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>>
>> :0 Wi
>> OLDRECIPIENTS=|echo "$@"
>>
>> SHIFT=1000
>>
>> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
>> $DATE $$ Orig-To: $OLDRECIPIENTS
>> "
>>
>> :0
>> * RECIPIENTS ?? @ourdomain
>> {
>> LOG="$DATE $$ Sent-To: $RECIPIENTS
>> "
>> DELIVER="/usr/local/cyrus/bin/deliver"
>> CYRUSUSER="sam"
>> :0 wi
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> This a syntax error. Procmail will skip the above line because it
> doesn't see it as a recipe since you didn't start it with :0
>
> It should read:
>
> :0
> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> Weather or not the syntax is correct for the .Trash folder is correct
> isn't something I can determine short of reading the Cyrus docs myself.
> I'm assuming that it's correct for the moment.
>
>> }
>>
>> :0 E
>> {
>> ERRORCODE=$?
>> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
>> }
>>
>> :0
>> /var/log/spamkill.log
>>
>>
>> Thanks
>> Sam
>
> So, the full recipe above, corrected should read:
>
> # Note, I changed the name of the logfile to indicate it's type.
> # Also see the last line of the recipe for notes there.
>
> LOGFILE="/var/log/spamkill/spamkill.log"
> UMASK=022
> LOGABSTRACT="no"
> VERBOSE="no"
> FORMAIL="/usr/local/bin/formail"
> FILTERPL="/usr/local/sbin/filter_recipients"
>
> # Moved this here since it's a global definition
> DELIVER="/usr/local/cyrus/bin/deliver"
>
> # Define a newline variable for use in procmail log lines.
> # makes the recipe a bit more human readable.
> NL="
> "
>
> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>
> # Debug statement. Comment out these Debug log lines later.
> LOG="[$$]$_: Debug: TO_FIELD=${TO_FIELD}${NL}"
>
> DATE=`date +%Y%m%d-%H%M%S`
> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>
> LOG="[$$]$_: Debug: XSPAMLEVEL=${XSPAMLEVEL} ${NL}"
>
> # I changed the order here, since "$@" can only be expanded once.
> :0 Wi
> OLDRECIPIENTS=|echo "$@"
>
> LOG="[$$]$_: Debug: OLDRECIPIENTS=${OLDRECIPIENTS}${NL}"
>
> # I replaced "$@" with ${OLDRECIPIENTS} here since "$@" will not
> # expand more than once.
> # Also changed the style a bit.
> # Note the backticks that launch an embedded shell script.
> # The stdout from this script will be assigned to the RECIPIENTS
> # Variable
> RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`
>
> LOG="[$$]$_: Debug: RECIPIENTS=${RECIPIENTS}${NL}"
>
> # not needed.
> # SHIFT=1000
>
> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
> $DATE $$ Orig-To: $OLDRECIPIENTS
> "
>
> :0
> * RECIPIENTS ?? @ourdomain
> {
>
> LOG="$DATE $$ Sent-To: ${RECIPIENTS}${NL}"
>
> # Moved the DELIVER variable assignment up to the top
> # since it's a global def.
>
> CYRUSUSER="sam"
>
> # This starts a procmail nested block, in which you can have
> # other procmail recipes.
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> # Deliver the email to Cyrus using the Cyrus delivery program.
> # If the mail is delivered successfully, procmail processing will
> # stop at this point, unless the c (carbon copy) flag is also used.
>
> :0 wi
> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>
> # Else Delivery failed. So we need to handle the error condition.
> :0 E
> {
> # Get the return code from the last program that ran
> # and report it in the logfile.
> ERRORCODE=$?
> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
> }
> }
>
> # Alternate delivery of the email to this file using default
> # procmail Berkley mailbox format.
> # This is a delivery recipe, so procmail will stop processing at
> # this point.
> :0
> /var/log/spamkill.mbox
>
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 07:49:08 von Garen Erdoisa

Pet Farrari wrote:
> Hi Garen,
>
> Do yo know how to make sure the deliver program is running as cyrus user
> rather than spamd or root? It is under my impression that the deliver
> program is not running as cyrus, so it failed to create file in the
> imap/spool/user/sam/ directory.
>

In sendmail I'd use /etc/aliases to map all of your virtual users to
cyrus or something along those lines...

ie:

---/etc/aliases---
....

somevirtualuser: cyrus

....
---EOF---

then run newaliases.

That would have sendmail deliver the email to the localhost cyrus username

I'm sure there is something similar in postfix or whatever other email
daemon you are using.

In sendmail, it's also possible to use the /etc/aliases file to deliver
email directly to a file, or hand off to another program at that point,
though I've never bothered messing around with those advanced uses of
that particular file. Just read about it in the sendmail docs.

> Thanks
> S
> Garen Erdoisa wrote:
>> Pet Farrari wrote:
>>> Hi Garen,
>>> [SNIP]

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 07:57:04 von Pet Farrari

Pet Farrari wrote:
> Hi Garen,
>
> Do yo know how to make sure the deliver program is running as cyrus user
> rather than spamd or root? It is under my impression that the deliver
> program is not running as cyrus, so it failed to create file in the
> imap/spool/user/sam/ directory.
>
> Thanks
> S
> Garen Erdoisa wrote:
>> Pet Farrari wrote:
>>> Hi Garen,
>>>
>>> Now I tried to solve the problem step by step.
>>> I tried to get the cyrus DELIVER working first, but I still getting
>>> its error:
>>> procmail: Extraneous ignore-write-error flag ignored
>>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash"
>>>
I just tested the deliver program alone, it produced similar error:

# su cyrus
%cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
sam: Message contains invalid header
Trash: Mailbox does not exist
%cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
sam: Message contains invalid header
user^sam^Trash: Mailbox does not exist
%cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
sam: Message contains invalid header
user.sam.Trash: Mailbox does not exist
%

I assumed if I can solve the problem with using the deliver program, I
may be able to solve the problem using it in procmail.

This is the portion of my /etc/postfix/main.cf file that involved the
procmail:

mail01.ip6.com.au:smtp inet n - n - - smtpd
-o content_filter=filter:dummy
-o cleanup_service_name=pre-cleanup
#localhost:smtp inet n - n - - smtpd
pre-cleanup unix n - n - 0 cleanup
-o alias_maps=
-o virtual_maps=
cleanup unix n - n - 0 cleanup
filter unix - n n - - pipe
flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
/usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}

Thanks
S
>>>
>>> The procmail rc file is:
>>>
>>> LOGFILE="/var/log/spamkill/spamkill"
>>> UMASK=022
>>> LOGABSTRACT="no"
>>> VERBOSE="no"
>>> FORMAIL="/usr/local/bin/formail"
>>> FILTERPL="/usr/local/sbin/filter_recipients"
>>>
>>> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>>> DATE=`date +%Y%m%d-%H%M%S`
>>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>>
>>> :0 Wi
>>> RECIPIENTS=|$FILTERPL "$XSPAMLEVEL" "$@"
>>>
>>> :0 Wi
>>> OLDRECIPIENTS=|echo "$@"
>>>
>>> SHIFT=1000
>>>
>>> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
>>> $DATE $$ Orig-To: $OLDRECIPIENTS
>>> "
>>>
>>> :0
>>> * RECIPIENTS ?? @ourdomain
>>> {
>>> LOG="$DATE $$ Sent-To: $RECIPIENTS
>>> "
>>> DELIVER="/usr/local/cyrus/bin/deliver"
>>> CYRUSUSER="sam"
>>> :0 wi
>>> * ^X-Spam-Level: \*\*\*\*\*
>>> {
>>> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>>
>> This a syntax error. Procmail will skip the above line because it
>> doesn't see it as a recipe since you didn't start it with :0
>>
>> It should read:
>>
>> :0
>> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>>
>> Weather or not the syntax is correct for the .Trash folder is correct
>> isn't something I can determine short of reading the Cyrus docs myself.
>> I'm assuming that it's correct for the moment.
>>
>>> }
>>>
>>> :0 E
>>> {
>>> ERRORCODE=$?
>>> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
>>> }
>>>
>>> :0
>>> /var/log/spamkill.log
>>>
>>>
>>> Thanks
>>> Sam
>>
>> So, the full recipe above, corrected should read:
>>
>> # Note, I changed the name of the logfile to indicate it's type.
>> # Also see the last line of the recipe for notes there.
>>
>> LOGFILE="/var/log/spamkill/spamkill.log"
>> UMASK=022
>> LOGABSTRACT="no"
>> VERBOSE="no"
>> FORMAIL="/usr/local/bin/formail"
>> FILTERPL="/usr/local/sbin/filter_recipients"
>>
>> # Moved this here since it's a global definition
>> DELIVER="/usr/local/cyrus/bin/deliver"
>>
>> # Define a newline variable for use in procmail log lines.
>> # makes the recipe a bit more human readable.
>> NL="
>> "
>>
>> TO_FIELD=`/usr/local/bin/formail -zxTo:`
>>
>> # Debug statement. Comment out these Debug log lines later.
>> LOG="[$$]$_: Debug: TO_FIELD=${TO_FIELD}${NL}"
>>
>> DATE=`date +%Y%m%d-%H%M%S`
>> XSPAMLEVEL=`$FORMAIL -zxX-Spam-Level`
>>
>> LOG="[$$]$_: Debug: XSPAMLEVEL=${XSPAMLEVEL} ${NL}"
>>
>> # I changed the order here, since "$@" can only be expanded once.
>> :0 Wi
>> OLDRECIPIENTS=|echo "$@"
>>
>> LOG="[$$]$_: Debug: OLDRECIPIENTS=${OLDRECIPIENTS}${NL}"
>>
>> # I replaced "$@" with ${OLDRECIPIENTS} here since "$@" will not
>> # expand more than once.
>> # Also changed the style a bit.
>> # Note the backticks that launch an embedded shell script.
>> # The stdout from this script will be assigned to the RECIPIENTS
>> # Variable
>> RECIPIENTS=`$FILTERPL "$XSPAMLEVEL" ${OLDRECIPIENTS}`
>>
>> LOG="[$$]$_: Debug: RECIPIENTS=${RECIPIENTS}${NL}"
>>
>> # not needed.
>> # SHIFT=1000
>>
>> LOG="$DATE $$ Level: $XSPAMLEVEL From: $FROM
>> $DATE $$ Orig-To: $OLDRECIPIENTS
>> "
>>
>> :0
>> * RECIPIENTS ?? @ourdomain
>> {
>>
>> LOG="$DATE $$ Sent-To: ${RECIPIENTS}${NL}"
>>
>> # Moved the DELIVER variable assignment up to the top
>> # since it's a global def.
>>
>> CYRUSUSER="sam"
>>
>> # This starts a procmail nested block, in which you can have
>> # other procmail recipes.
>> :0
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> # Deliver the email to Cyrus using the Cyrus delivery program.
>> # If the mail is delivered successfully, procmail processing will
>> # stop at this point, unless the c (carbon copy) flag is also used.
>>
>> :0 wi
>> | $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.Trash
>>
>> # Else Delivery failed. So we need to handle the error condition.
>> :0 E
>> {
>> # Get the return code from the last program that ran
>> # and report it in the logfile.
>> ERRORCODE=$?
>> LOG="[$$]$_: Failed delivery ERRORCODE=${ERRORCODE} ${NL}"
>> }
>> }
>>
>> # Alternate delivery of the email to this file using default
>> # procmail Berkley mailbox format.
>> # This is a delivery recipe, so procmail will stop processing at
>> # this point.
>> :0
>> /var/log/spamkill.mbox
>>
>>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 09:18:09 von Garen Erdoisa

Pet Farrari wrote:
> Pet Farrari wrote:
>> Hi Garen,
>>
>> Do yo know how to make sure the deliver program is running as cyrus
>> user rather than spamd or root? It is under my impression that the
>> deliver program is not running as cyrus, so it failed to create file
>> in the imap/spool/user/sam/ directory.
>>
>> Thanks
>> S
>> Garen Erdoisa wrote:
>>> Pet Farrari wrote:
>>>> Hi Garen,
>>>>
>>>> Now I tried to solve the problem step by step.
>>>> I tried to get the cyrus DELIVER working first, but I still getting
>>>> its error:
>>>> procmail: Extraneous ignore-write-error flag ignored
>>>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m
>>>> user.$CYRUSUSER.Trash"
>>>>
> I just tested the deliver program alone, it produced similar error:
>
> # su cyrus
> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
> sam: Message contains invalid header
> Trash: Mailbox does not exist
> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
> sam: Message contains invalid header
> user^sam^Trash: Mailbox does not exist
> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
> sam: Message contains invalid header
> user.sam.Trash: Mailbox does not exist
> %

hmm. As a guess try:
%cat test1 | /usr/local/cyrus/bin/deliver -a -e sam+Trash

Looks like you need to figure out also what the invalid header is in
your test message and get rid of it. Try to eliminate that first, then
work on the folder issue.

>
> I assumed if I can solve the problem with using the deliver program, I
> may be able to solve the problem using it in procmail.
>

This is an excellent approach. First get the command line working in a
shell environment before trying to use it in a procmail recipe.
Once it's working in the shell, it should work fine in procmail. At
least that is my experience.

> This is the portion of my /etc/postfix/main.cf file that involved the
> procmail:
>
> mail01.ip6.com.au:smtp inet n - n - - smtpd
> -o content_filter=filter:dummy
> -o cleanup_service_name=pre-cleanup
> #localhost:smtp inet n - n - - smtpd
> pre-cleanup unix n - n - 0 cleanup
> -o alias_maps=
> -o virtual_maps=
> cleanup unix n - n - 0 cleanup
> filter unix - n n - - pipe
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
> /usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}
>

Hmm, lets see: (Quotes from man procmail)

-Y Assume traditional Berkeley mailbox format.

-m Turns procmail into a general purpose mail filter. In this mode
one rcfile must be specified on the command line. After the rcfile,
procmail will accept an unlimited number of arguments. the rcfile is an
absolute path starting with /etc/procmailrcs/ without backward
references (i.e. the parent directory cannot be mentioned) procmail
will, only if no security violations are found, take on the
identity of the owner of the rcfile (or sym-bolic link). For some
advanced usage of this option you should look in the EXAMPLES section
below.

-a argument This will set $1 to be equal to argument. Each
succeeding -a argument will set the next number variable ($2, $3,
etc). It can be used to pass meta information along to procmail. This
is typi-cally done by passing along the $@x information from the
sendmail mailer rule.

(end quotes)

So, it looks like the line that calls procmail is missing the -a
argument switches for your ${sender} and ${recipient}

Acording to the man page, the line should be written as:

flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
/usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}

I haven't used postfix at all, but that sorta jumped out at me reading
the config file.

Written like this, the sender would be accessible from inside the
procmail run control file as $1 and the recipient would be in $2

> Thanks
Welcome.
> S
>>>>[SNIP]

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 09:49:33 von Pet

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Pet Farrari wrote:
>>> Hi Garen,
>>>
>>> Do yo know how to make sure the deliver program is running as cyrus
>>> user rather than spamd or root? It is under my impression that the
>>> deliver program is not running as cyrus, so it failed to create file
>>> in the imap/spool/user/sam/ directory.
>>>
>>> Thanks
>>> S
>>> Garen Erdoisa wrote:
>>>> Pet Farrari wrote:
>>>>> Hi Garen,
>>>>>
>>>>> Now I tried to solve the problem step by step.
>>>>> I tried to get the cyrus DELIVER working first, but I still getting
>>>>> its error:
>>>>> procmail: Extraneous ignore-write-error flag ignored
>>>>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m
>>>>> user.$CYRUSUSER.Trash"
>>>>>
>> I just tested the deliver program alone, it produced similar error:
>>
>> # su cyrus
>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
>> sam: Message contains invalid header
>> Trash: Mailbox does not exist
>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
>> sam: Message contains invalid header
>> user^sam^Trash: Mailbox does not exist
>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
>> sam: Message contains invalid header
>> user.sam.Trash: Mailbox does not exist
>> %
>
> hmm. As a guess try:
> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam+Trash
>
OK, found problem when I was running deliver with -D:

Jan 15 19:45:50 mail01 lmtpunix[91615]: accepted connection
Jan 15 19:45:50 mail01 lmtpunix[91615]: lmtp connection preauth'd as postman
Jan 15 19:45:50 mail01 lmtpunix[91615]: IOERROR: fstating sieve script
/mail/imap/sieve/s/sam/defaultbc: No such file or directory
.....
Jan 15 19:46:00 mail01 master[97692]: process 91493 exited, status 0
Jan 15 19:46:01 mail01 master[91629]: about to exec
/usr/local/cyrus/bin/imapd

astonishing this require seive setup. :p

Thanks
S

> Looks like you need to figure out also what the invalid header is in
> your test message and get rid of it. Try to eliminate that first, then
> work on the folder issue.
>
>>
>> I assumed if I can solve the problem with using the deliver program, I
>> may be able to solve the problem using it in procmail.
>>
>
> This is an excellent approach. First get the command line working in a
> shell environment before trying to use it in a procmail recipe.
> Once it's working in the shell, it should work fine in procmail. At
> least that is my experience.
>
>> This is the portion of my /etc/postfix/main.cf file that involved the
>> procmail:
>>
>> mail01.ip6.com.au:smtp inet n - n - -
>> smtpd
>> -o content_filter=filter:dummy
>> -o cleanup_service_name=pre-cleanup
>> #localhost:smtp inet n - n - - smtpd
>> pre-cleanup unix n - n - 0 cleanup
>> -o alias_maps=
>> -o virtual_maps=
>> cleanup unix n - n - 0 cleanup
>> filter unix - n n - - pipe
>> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
>> /usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}
>>
>
> Hmm, lets see: (Quotes from man procmail)
>
> -Y Assume traditional Berkeley mailbox format.
>
> -m Turns procmail into a general purpose mail filter. In this mode
> one rcfile must be specified on the command line. After the rcfile,
> procmail will accept an unlimited number of arguments. the rcfile is an
> absolute path starting with /etc/procmailrcs/ without backward
> references (i.e. the parent directory cannot be mentioned) procmail
> will, only if no security violations are found, take on the
> identity of the owner of the rcfile (or sym-bolic link). For some
> advanced usage of this option you should look in the EXAMPLES section
> below.
>
> -a argument This will set $1 to be equal to argument. Each
> succeeding -a argument will set the next number variable ($2, $3,
> etc). It can be used to pass meta information along to procmail. This
> is typi-cally done by passing along the $@x information from the
> sendmail mailer rule.
>
> (end quotes)
>
> So, it looks like the line that calls procmail is missing the -a
> argument switches for your ${sender} and ${recipient}
>
> Acording to the man page, the line should be written as:
>
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
> /usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}
>
> I haven't used postfix at all, but that sorta jumped out at me reading
> the config file.
>
> Written like this, the sender would be accessible from inside the
> procmail run control file as $1 and the recipient would be in $2
>
>> Thanks
> Welcome.
>> S
> >>>>[SNIP]
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 09:55:47 von Garen Erdoisa

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Pet Farrari wrote:
>>> Hi Garen,
>>>
>>> Do yo know how to make sure the deliver program is running as cyrus
>>> user rather than spamd or root? It is under my impression that the
>>> deliver program is not running as cyrus, so it failed to create file
>>> in the imap/spool/user/sam/ directory.
>>> [SNIP]
>[snip]
> (end quotes)
>
> So, it looks like the line that calls procmail is missing the -a
> argument switches for your ${sender} and ${recipient}
>
> Acording to the man page, the line should be written as:
>
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
> /usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}
>
> I haven't used postfix at all, but that sorta jumped out at me reading
> the config file.
>
> Written like this, the sender would be accessible from inside the
> procmail run control file as $1 and the recipient would be in $2
>
Ran some procmail tests to confirm this:

----/tmp/example/test.rc---
NL="
"

VERBOSE=no
HOME='/tmp/example'
ECHO=echo
FORMAIL=/usr/bin/formail
MYSCRIPT='echo "$@"'
#ARGV="$@"
TEMPFILE=/tmp/param.$$.$RANDOM

LOG="[$$]$_: Sender=$1${NL}"
LOG="[$$]$_: Recipiant=$2${NL}"

:0 Wi
ARGS=|echo "$@"

LOG="[$$]$_: ARGN=$#${NL}"
LOG="[$$]$_: ARGS=${ARGS}${NL}"

LOGABSTRACT=no
:0
/dev/null
----end of file----

----/tmp/example/message.txt----
To: nobody@example.com
From: Damian Penney
Subject: test message subject

Test message body
----end of file----

cat message.txt |procmail -Y -a sender@example.com -a
recipiant@example.com ./test.rc

[6478]./test.rc: Sender=sender@example.com
[6478]./test.rc: Recipiant=recipiant@example.com
[6478]./test.rc: ARGN=2
[6478]./test.rc: ARGS=sender@example.com recipiant@example.com

cat message.txt |procmail -Y -m ./test.rc sender@example.com
recipiant@example.com

[6486]./test.rc: Sender=sender@example.com
[6486]./test.rc: Recipiant=recipiant@example.com
[6486]./test.rc: ARGN=2
[6486]./test.rc: ARGS=sender@example.com recipiant@example.com


So it looks like those two forms of the command line usage are
equivalent which means your postfix config file is ok.

>>>>>[SNIP]
>

Weird.
--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 11:03:29 von Pet

Pet wrote:
> Garen Erdoisa wrote:
>> Pet Farrari wrote:
>>> Pet Farrari wrote:
>>>> Hi Garen,
>>>>
>>>> Do yo know how to make sure the deliver program is running as cyrus
>>>> user rather than spamd or root? It is under my impression that the
>>>> deliver program is not running as cyrus, so it failed to create file
>>>> in the imap/spool/user/sam/ directory.
>>>>
>>>> Thanks
>>>> S
>>>> Garen Erdoisa wrote:
>>>>> Pet Farrari wrote:
>>>>>> Hi Garen,
>>>>>>
>>>>>> Now I tried to solve the problem step by step.
>>>>>> I tried to get the cyrus DELIVER working first, but I still
>>>>>> getting its error:
>>>>>> procmail: Extraneous ignore-write-error flag ignored
>>>>>> procmail: Skipped "| $DELIVER -e -a $CYRUSUSER -m
>>>>>> user.$CYRUSUSER.Trash"
>>>>>>
>>> I just tested the deliver program alone, it produced similar error:
>>>
>>> # su cyrus
>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
>>> sam: Message contains invalid header
>>> Trash: Mailbox does not exist
>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
>>> sam: Message contains invalid header
>>> user^sam^Trash: Mailbox does not exist
>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
>>> sam: Message contains invalid header
>>> user.sam.Trash: Mailbox does not exist
>>> %
>>
>> hmm. As a guess try:
>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam+Trash
This command still not sending the content of test1 to my Trash folder.
>>

> OK, found problem when I was running deliver with -D:
>
> Jan 15 19:45:50 mail01 lmtpunix[91615]: accepted connection
> Jan 15 19:45:50 mail01 lmtpunix[91615]: lmtp connection preauth'd as
> postman
> Jan 15 19:45:50 mail01 lmtpunix[91615]: IOERROR: fstating sieve script
> /mail/imap/sieve/s/sam/defaultbc: No such file or directory

Just realised this is fine.
Now I don't know what is wrong. :(

Sam
> ....
> Jan 15 19:46:00 mail01 master[97692]: process 91493 exited, status 0
> Jan 15 19:46:01 mail01 master[91629]: about to exec
> /usr/local/cyrus/bin/imapd
>
> astonishing this require seive setup. :p
>
> Thanks
> S
>
>> Looks like you need to figure out also what the invalid header is in
>> your test message and get rid of it. Try to eliminate that first, then
>> work on the folder issue.
>>
>>>
>>> I assumed if I can solve the problem with using the deliver program,
>>> I may be able to solve the problem using it in procmail.
>>>
>>
>> This is an excellent approach. First get the command line working in a
>> shell environment before trying to use it in a procmail recipe.
>> Once it's working in the shell, it should work fine in procmail. At
>> least that is my experience.
>>
>>> This is the portion of my /etc/postfix/main.cf file that involved the
>>> procmail:
>>>
>>> mail01.ip6.com.au:smtp inet n - n - -
>>> smtpd
>>> -o content_filter=filter:dummy
>>> -o cleanup_service_name=pre-cleanup
>>> #localhost:smtp inet n - n - - smtpd
>>> pre-cleanup unix n - n - 0 cleanup
>>> -o alias_maps=
>>> -o virtual_maps=
>>> cleanup unix n - n - 0 cleanup
>>> filter unix - n n - - pipe
>>> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
>>> /usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}
>>>
>>
>> Hmm, lets see: (Quotes from man procmail)
>>
>> -Y Assume traditional Berkeley mailbox format.
>>
>> -m Turns procmail into a general purpose mail filter. In this
>> mode one rcfile must be specified on the command line. After the
>> rcfile, procmail will accept an unlimited number of arguments. the
>> rcfile is an absolute path starting with /etc/procmailrcs/
>> without backward references (i.e. the parent directory cannot be
>> mentioned) procmail will, only if no security violations are
>> found, take on the identity of the owner of the rcfile (or
>> sym-bolic link). For some advanced usage of this option you should
>> look in the EXAMPLES section below.
>>
>> -a argument This will set $1 to be equal to argument. Each
>> succeeding -a argument will set the next number variable ($2, $3,
>> etc). It can be used to pass meta information along to procmail.
>> This is typi-cally done by passing along the $@x information from the
>> sendmail mailer rule.
>>
>> (end quotes)
>>
>> So, it looks like the line that calls procmail is missing the -a
>> argument switches for your ${sender} and ${recipient}
>>
>> Acording to the man page, the line should be written as:
>>
>> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
>> /usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}
>>
>> I haven't used postfix at all, but that sorta jumped out at me reading
>> the config file.
>>
>> Written like this, the sender would be accessible from inside the
>> procmail run control file as $1 and the recipient would be in $2
>>
>>> Thanks
>> Welcome.
>>> S
>> >>>>[SNIP]
>>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 13:34:15 von Garen Erdoisa

Pet wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet Farrari wrote:
>>>> Pet Farrari wrote:
>>>>> Hi Garen,
>>>>>[snip]
>>>>
>>>> # su cyrus
>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
>>>> sam: Message contains invalid header
>>>> Trash: Mailbox does not exist
>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
>>>> sam: Message contains invalid header
>>>> user^sam^Trash: Mailbox does not exist
>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
>>>> sam: Message contains invalid header
>>>> user.sam.Trash: Mailbox does not exist
>>>> %
>>>
>>> hmm. As a guess try:
>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam+Trash
> This command still not sending the content of test1 to my Trash folder.
>>>
>
>> OK, found problem when I was running deliver with -D:
>>
>> Jan 15 19:45:50 mail01 lmtpunix[91615]: accepted connection
>> Jan 15 19:45:50 mail01 lmtpunix[91615]: lmtp connection preauth'd as
>> postman
>> Jan 15 19:45:50 mail01 lmtpunix[91615]: IOERROR: fstating sieve script
>> /mail/imap/sieve/s/sam/defaultbc: No such file or directory
>
> Just realised this is fine.
> Now I don't know what is wrong. :(
>

Double check your command line switches.

In reading a man page for deliver on fedora, I note that there is no
switch for -e specified in that particular man page. Abet it's an old
man page.

Looks like you should be using -m instead of -e.
ie:

deliver -a anonymous -m user.userid.mailbox

deliver -a anonymous -m user.somebody@example.net.Trash

or maybe:
deliver -a anonymous -m user.somebody+Trash@example.net

Something along those lines anyway.

Also check the ACL entries for the Trash mailbox.

(quote from man 8 deliver)

-m mailbox

Deliver to mailbox. If any userids are specified, attempts to
deliver to user.userid.mailbox for each userid. If the ACL on any
such mailbox does not grant the sender the "p" right or if -m is not
specified, then delivers to the INBOX for the userid, regardless of the
ACL on the INBOX.

If no userids are specified, attempts to deliver to mailbox. If the ACL
on mailbox does not grant the sender the "p" right, the delivery fails.

(end quote)

--
Garen



>[SNIP]

Re: how to use procmail filter spam into imap folder

am 15.01.2007 14:26:59 von Pet

Garen Erdoisa wrote:
> Pet wrote:
>> Pet wrote:
>>> Garen Erdoisa wrote:
>>>> Pet Farrari wrote:
>>>>> Pet Farrari wrote:
>>>>>> Hi Garen,
>>>>>> [snip]
>>>>>
>>>>> # su cyrus
>>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam Trash
>>>>> sam: Message contains invalid header
>>>>> Trash: Mailbox does not exist
>>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user^sam^Trash
>>>>> sam: Message contains invalid header
>>>>> user^sam^Trash: Mailbox does not exist
>>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam user.sam.Trash
>>>>> sam: Message contains invalid header
>>>>> user.sam.Trash: Mailbox does not exist
>>>>> %
>>>>
>>>> hmm. As a guess try:
>>>> %cat test1 | /usr/local/cyrus/bin/deliver -a -e sam+Trash
>> This command still not sending the content of test1 to my Trash folder.
>>>>
>>
>>> OK, found problem when I was running deliver with -D:
>>>
>>> Jan 15 19:45:50 mail01 lmtpunix[91615]: accepted connection
>>> Jan 15 19:45:50 mail01 lmtpunix[91615]: lmtp connection preauth'd as
>>> postman
>>> Jan 15 19:45:50 mail01 lmtpunix[91615]: IOERROR: fstating sieve
>>> script /mail/imap/sieve/s/sam/defaultbc: No such file or directory
>>
>> Just realised this is fine.
>> Now I don't know what is wrong. :(
>>
>
> Double check your command line switches.
>
> In reading a man page for deliver on fedora, I note that there is no
> switch for -e specified in that particular man page. Abet it's an old
> man page.
>
> Looks like you should be using -m instead of -e.
> ie:
>
> deliver -a anonymous -m user.userid.mailbox
>
> deliver -a anonymous -m user.somebody@example.net.Trash
>
> or maybe:
> deliver -a anonymous -m user.somebody+Trash@example.net
>
I just tried it, the Unix shell commandline works with your similar
command but with minor difference:
# cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
sam -m user/sam@domain.com.Trash

But when I use this command deliver the content of 57. imap mail into
the Trash folder, my windows thunderbird only indicate me there is new
mail. When I open my mail box in windows, there is only an emtpy mail
delivered to my INBOX, nothing in the Trash shown in Windows.

What s more, when I used it in procmailrc, it failed with the same error
(can't create output file).

The ACL of account sam at Trash folder is:
mamil01.xx.xx.xx> lam user/sam/Trash
sam lrswipkxtecda

Very confusing...

Thanks
sam

> Something along those lines anyway.
>
> Also check the ACL entries for the Trash mailbox.
>
> (quote from man 8 deliver)
>
> -m mailbox
>
> Deliver to mailbox. If any userids are specified, attempts to
> deliver to user.userid.mailbox for each userid. If the ACL on any
> such mailbox does not grant the sender the "p" right or if -m is not
> specified, then delivers to the INBOX for the userid, regardless of the
> ACL on the INBOX.
>
> If no userids are specified, attempts to deliver to mailbox. If the ACL
> on mailbox does not grant the sender the "p" right, the delivery fails.
>
> (end quote)
>

Re: how to use procmail filter spam into imap folder

am 15.01.2007 15:57:51 von Garen Erdoisa

Pet wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Pet wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet Farrari wrote:
>>>>>> Pet Farrari wrote:
>>>>>>> Hi Garen,
>>>>>>> [snip]
>>> Just realised this is fine.
>>> Now I don't know what is wrong. :(
>>>
>>
>> Double check your command line switches.
>>
>> In reading a man page for deliver on fedora, I note that there is no
>> switch for -e specified in that particular man page. Abet it's an old
>> man page.
>>
>> Looks like you should be using -m instead of -e.
>> ie:
>>
>> deliver -a anonymous -m user.userid.mailbox
>>
>> deliver -a anonymous -m user.somebody@example.net.Trash
>>
>> or maybe:
>> deliver -a anonymous -m user.somebody+Trash@example.net
>>
> I just tried it, the Unix shell commandline works with your similar
> command but with minor difference:
> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
> sam -m user/sam@domain.com.Trash
>
> But when I use this command deliver the content of 57. imap mail into
> the Trash folder, my windows thunderbird only indicate me there is new
> mail. When I open my mail box in windows, there is only an emtpy mail
> delivered to my INBOX, nothing in the Trash shown in Windows.
>
> What s more, when I used it in procmailrc, it failed with the same error
> (can't create output file).
>
> The ACL of account sam at Trash folder is:
> mamil01.xx.xx.xx> lam user/sam/Trash
> sam lrswipkxtecda
>
> Very confusing...

(Quote from the faq)
* plus addressing - Plus addressing allows direct delivery to a
particular mailbox (other than an INBOX). This is done in two ways.

The first way allows delviery to a subfolder of a specific user's
INBOX. This is done via an address of the form:
username+mailfolder@domain, which will deliver to the user's
INBOX.mailfolder folder (or altnamespace equivalent). This
submailbox must allow the posting user the 'p' right (generally,
this means 'anyone' must have the 'p' right), otherwise the message
will just be filed into the user's INBOX.

The second way is to form an address like
[postuser]+mailfolder@domain. This will deliver into the mailbox
'mailfolder'. [postuser] is the string specified in the imapd.conf
option of the same name, and may be the empty string. As before,
the posting user will need to have the 'p' right on the mailbox.

For both methods, if 'mailfolder' is more than one level deep, you
will need to conform to the hierarchy separator appropriate to your
site.
(end quote)

>
> Thanks
> sam
>>>> [SNIP]

--
Garen

Re: how to use procmail filter spam into imap folder

am 15.01.2007 23:36:58 von Pet Farrari

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Pet wrote:
>>>>> Garen Erdoisa wrote:
>>>>>> Pet Farrari wrote:
>>>>>>> Pet Farrari wrote:
>>>>>>>> Hi Garen,
>>>>>>>> [snip]
>>>> Just realised this is fine.
>>>> Now I don't know what is wrong. :(
>>>>
>>>
>>> Double check your command line switches.
>>>
>>> In reading a man page for deliver on fedora, I note that there is no
>>> switch for -e specified in that particular man page. Abet it's an old
>>> man page.
>>>
>>> Looks like you should be using -m instead of -e.
>>> ie:
>>>
>>> deliver -a anonymous -m user.userid.mailbox
>>>
>>> deliver -a anonymous -m user.somebody@example.net.Trash
>>>
>>> or maybe:
>>> deliver -a anonymous -m user.somebody+Trash@example.net
>>>
>> I just tried it, the Unix shell commandline works with your similar
>> command but with minor difference:
>> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
>> sam -m user/sam@domain.com.Trash
>>
>> But when I use this command deliver the content of 57. imap mail into
>> the Trash folder, my windows thunderbird only indicate me there is new
>> mail. When I open my mail box in windows, there is only an emtpy mail
>> delivered to my INBOX, nothing in the Trash shown in Windows.
>>
>> What s more, when I used it in procmailrc, it failed with the same
>> error (can't create output file).
>>
>> The ACL of account sam at Trash folder is:
>> mamil01.xx.xx.xx> lam user/sam/Trash
>> sam lrswipkxtecda
>>
>> Very confusing...
>
> (Quote from the faq)
> * plus addressing - Plus addressing allows direct delivery to a
> particular mailbox (other than an INBOX). This is done in two ways.
>
> The first way allows delviery to a subfolder of a specific user's
> INBOX. This is done via an address of the form:
> username+mailfolder@domain, which will deliver to the user's
> INBOX.mailfolder folder (or altnamespace equivalent). This
> submailbox must allow the posting user the 'p' right (generally,
> this means 'anyone' must have the 'p' right), otherwise the message
> will just be filed into the user's INBOX.
>
> The second way is to form an address like
> [postuser]+mailfolder@domain. This will deliver into the mailbox
> 'mailfolder'. [postuser] is the string specified in the imapd.conf
> option of the same name, and may be the empty string. As before,
> the posting user will need to have the 'p' right on the mailbox.
>
> For both methods, if 'mailfolder' is more than one level deep, you
> will need to conform to the hierarchy separator appropriate to your
> site.
> (end quote)
>
in the Unix shell, the following command deliver one of the messages
from my imap folder to another account in the Inbox using the following
commandline:

%cat ../sam/472. | /usr/local/cyrus/bin/deliver -a david -m
user/david@xxx.com.au.Trash

as you noticed, something is weired here, I tried to deliver it to the
Trash folder, but it end up put the message in the Inbox.

Assumed the above command mostly working, when I use to the procmail, it
still complained Can't create user output folder.

With the + sign between username and folder@domain, it doesn't work in
the unix shell, and neither it works in the procmail.

Confused...

Thanks
Sam

>>
>> Thanks
>> sam
>>>>> [SNIP]
>

Re: how to use procmail filter spam into imap folder

am 16.01.2007 01:38:21 von Pet Farrari

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Pet wrote:
>>>>> Garen Erdoisa wrote:
>>>>>> Pet Farrari wrote:
>>>>>>> Pet Farrari wrote:
>>>>>>>> Hi Garen,
>>>>>>>> [snip]
>>>> Just realised this is fine.
>>>> Now I don't know what is wrong. :(
>>>>
>>>
>>> Double check your command line switches.
>>>
>>> In reading a man page for deliver on fedora, I note that there is no
>>> switch for -e specified in that particular man page. Abet it's an old
>>> man page.
>>>
>>> Looks like you should be using -m instead of -e.
>>> ie:
>>>
>>> deliver -a anonymous -m user.userid.mailbox
>>>
>>> deliver -a anonymous -m user.somebody@example.net.Trash
>>>
>>> or maybe:
>>> deliver -a anonymous -m user.somebody+Trash@example.net
>>>
>> I just tried it, the Unix shell commandline works with your similar
>> command but with minor difference:
>> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
>> sam -m user/sam@domain.com.Trash
>>
>> But when I use this command deliver the content of 57. imap mail into
>> the Trash folder, my windows thunderbird only indicate me there is new
>> mail. When I open my mail box in windows, there is only an emtpy mail
>> delivered to my INBOX, nothing in the Trash shown in Windows.
>>
>> What s more, when I used it in procmailrc, it failed with the same
>> error (can't create output file).
>>
>> The ACL of account sam at Trash folder is:
>> mamil01.xx.xx.xx> lam user/sam/Trash
>> sam lrswipkxtecda
>>
>> Very confusing...
>
> (Quote from the faq)
> * plus addressing - Plus addressing allows direct delivery to a
> particular mailbox (other than an INBOX). This is done in two ways.
>
> The first way allows delviery to a subfolder of a specific user's
> INBOX. This is done via an address of the form:
> username+mailfolder@domain, which will deliver to the user's
> INBOX.mailfolder folder (or altnamespace equivalent). This
> submailbox must allow the posting user the 'p' right (generally,
> this means 'anyone' must have the 'p' right), otherwise the message
> will just be filed into the user's INBOX.
>
> The second way is to form an address like
> [postuser]+mailfolder@domain. This will deliver into the mailbox
> 'mailfolder'. [postuser] is the string specified in the imapd.conf
> option of the same name, and may be the empty string. As before,
> the posting user will need to have the 'p' right on the mailbox.
>
> For both methods, if 'mailfolder' is more than one level deep, you
> will need to conform to the hierarchy separator appropriate to your
> site.
> (end quote)
>
>>
>> Thanks
>> sam
>>>>> [SNIP]
>
I just tried another commandline at the unix shell, now it can deliver
to the folder I want it to be:

%cat 5. | /usr/local/cyrus/bin/deliver -r david@xxx.com.au david/Trash

BUT... when I put it in use with procmail, it failed with the same
message "Can't create output file".

Then like you said, I changed it to + sign:
$DELIVER -r sam@xxx.com.au sam+Trash
and
$DELIVER -r sam@xxx.com.au sam+Trash/
and
$DELIVER -r sam@xxx.com.au sam/Trash/

it all returned the same error. :(

S

Re: how to use procmail filter spam into imap folder

am 16.01.2007 02:20:25 von Pet Farrari

Garen Erdoisa wrote:
> Pet wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Pet wrote:
>>>>> Garen Erdoisa wrote:
>>>>>> Pet Farrari wrote:
>>>>>>> Pet Farrari wrote:
>>>>>>>> Hi Garen,
>>>>>>>> [snip]
>>>> Just realised this is fine.
>>>> Now I don't know what is wrong. :(
>>>>
>>>
>>> Double check your command line switches.
>>>
>>> In reading a man page for deliver on fedora, I note that there is no
>>> switch for -e specified in that particular man page. Abet it's an old
>>> man page.
>>>
>>> Looks like you should be using -m instead of -e.
>>> ie:
>>>
>>> deliver -a anonymous -m user.userid.mailbox
>>>
>>> deliver -a anonymous -m user.somebody@example.net.Trash
>>>
>>> or maybe:
>>> deliver -a anonymous -m user.somebody+Trash@example.net
>>>
>> I just tried it, the Unix shell commandline works with your similar
>> command but with minor difference:
>> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
>> sam -m user/sam@domain.com.Trash
>>
>> But when I use this command deliver the content of 57. imap mail into
>> the Trash folder, my windows thunderbird only indicate me there is new
>> mail. When I open my mail box in windows, there is only an emtpy mail
>> delivered to my INBOX, nothing in the Trash shown in Windows.
>>
>> What s more, when I used it in procmailrc, it failed with the same
>> error (can't create output file).
>>
>> The ACL of account sam at Trash folder is:
>> mamil01.xx.xx.xx> lam user/sam/Trash
>> sam lrswipkxtecda
>>
>> Very confusing...
>
> (Quote from the faq)
> * plus addressing - Plus addressing allows direct delivery to a
> particular mailbox (other than an INBOX). This is done in two ways.
>
> The first way allows delviery to a subfolder of a specific user's
> INBOX. This is done via an address of the form:
> username+mailfolder@domain, which will deliver to the user's
> INBOX.mailfolder folder (or altnamespace equivalent). This
> submailbox must allow the posting user the 'p' right (generally,
> this means 'anyone' must have the 'p' right), otherwise the message
> will just be filed into the user's INBOX.
>
> The second way is to form an address like
> [postuser]+mailfolder@domain. This will deliver into the mailbox
> 'mailfolder'. [postuser] is the string specified in the imapd.conf
> option of the same name, and may be the empty string. As before,
> the posting user will need to have the 'p' right on the mailbox.
>
> For both methods, if 'mailfolder' is more than one level deep, you
> will need to conform to the hierarchy separator appropriate to your
> site.
> (end quote)
>
>>
>> Thanks
>> sam
>>>>> [SNIP]
>
I suspect there is permission problem with this setup.
the master.cf file for postfix is:

....
filter unix - n n - - pipe
flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
/usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}

The master.rc is:
SHELL=/bin/sh
DROPPRIVS=YES
LINEBUF=32768
SENDMAILFLAGS="-oi"
SPAMC="/usr/local/bin/spamc"

FROM="<$1>"
SHIFT=1

:0f
|$SPAMC -f -U /var/run/spamd.sock

:0
* ^X-Spam-Level: \*\*\*\*\*
{
SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
# .Trash/
}

:0
! -f $FROM "$@"

BUT, when this master.rc file involved spamkill.rc file, I am not sure
whether it's still calling by the cyrus user as instructed by postfix's
master.cf file.

Sam

Re: how to use procmail filter spam into imap folder

am 16.01.2007 04:31:34 von Garen Erdoisa

Pet Farrari wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Garen Erdoisa wrote:
>>>> Pet wrote:
>>>>> Pet wrote:
>>>>>> Garen Erdoisa wrote:
>>>>>>> Pet Farrari wrote:
>>>>>>>> Pet Farrari wrote:
>>>>>>>>> Hi Garen,
>>>>>>>>> [snip]
>>>>> Just realised this is fine.
>>>>> Now I don't know what is wrong. :(
>>>>>
>>>>
>>>> Double check your command line switches.
>>>>
>>>> In reading a man page for deliver on fedora, I note that there is no
>>>> switch for -e specified in that particular man page. Abet it's an
>>>> old man page.
>>>>
>>>> Looks like you should be using -m instead of -e.
>>>> ie:
>>>>
>>>> deliver -a anonymous -m user.userid.mailbox
>>>>
>>>> deliver -a anonymous -m user.somebody@example.net.Trash
>>>>
>>>> or maybe:
>>>> deliver -a anonymous -m user.somebody+Trash@example.net
>>>>
>>> I just tried it, the Unix shell commandline works with your similar
>>> command but with minor difference:
>>> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver -a
>>> sam -m user/sam@domain.com.Trash
>>>
>>> But when I use this command deliver the content of 57. imap mail into
>>> the Trash folder, my windows thunderbird only indicate me there is
>>> new mail. When I open my mail box in windows, there is only an emtpy
>>> mail delivered to my INBOX, nothing in the Trash shown in Windows.
>>>
>>> What s more, when I used it in procmailrc, it failed with the same
>>> error (can't create output file).
>>>
>>> The ACL of account sam at Trash folder is:
>>> mamil01.xx.xx.xx> lam user/sam/Trash
>>> sam lrswipkxtecda
>>>
>>> Very confusing...
>>
>> (Quote from the faq)
>> * plus addressing - Plus addressing allows direct delivery to a
>> particular mailbox (other than an INBOX). This is done in two
>> ways.
>>
>> The first way allows delviery to a subfolder of a specific user's
>> INBOX. This is done via an address of the form:
>> username+mailfolder@domain, which will deliver to the user's
>> INBOX.mailfolder folder (or altnamespace equivalent). This
>> submailbox must allow the posting user the 'p' right (generally,
>> this means 'anyone' must have the 'p' right), otherwise the
>> message
>> will just be filed into the user's INBOX.
>>
>> The second way is to form an address like
>> [postuser]+mailfolder@domain. This will deliver into the mailbox
>> 'mailfolder'. [postuser] is the string specified in the
>> imapd.conf
>> option of the same name, and may be the empty string. As before,
>> the posting user will need to have the 'p' right on the mailbox.
>>
>> For both methods, if 'mailfolder' is more than one level deep,
>> you
>> will need to conform to the hierarchy separator appropriate to
>> your
>> site.
>> (end quote)
>>
>>>
>>> Thanks
>>> sam
>>>>>> [SNIP]
>>
> I suspect there is permission problem with this setup.
> the master.cf file for postfix is:
>
> ...
> filter unix - n n - - pipe
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
> /usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}
>

Try changing the above to:

flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
/usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}

or to:
flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -a ${sender} -a
${recipient} /usr/local/etc/procmailrcs/master.rc

Either one should work. The testing I did the other day indicated the
difference if the -m switch is used or not. If the -m switch is used to
specify a run control file, then anything following that on the command
line will be assigned to $1 $2 ... $9

If you don't use the -m switch, then the run control file has to be the
last item specified on the procmail command line. In that case,
arguments are assigned to $1 $2 ... $9 by preceding each argument with
the -a switch. It's really weird but that's the way it actually works
according to my tests.

The form you currently have in your postfix config file will have
$1="-a", $2="${sender}", $3="-a" and, $4="${recipient}"

Observe the following tests:

----/tmp/example/test.rc----
NL="
"

VERBOSE=no
HOME='/tmp/example'
ECHO=echo
FORMAIL=/usr/bin/formail

LOG="[$$]$_: \$1=\"$1\"${NL}"
LOG="[$$]$_: \$2=\"$2\"${NL}"
LOG="[$$]$_: \$3=\"$3\"${NL}"
LOG="[$$]$_: \$4=\"$4\"${NL}"

:0 Wi
ARGS=|echo "$@"

LOG="[$$]$_: ARGN=$#${NL}"
LOG="[$$]$_: ARGS=${ARGS}${NL}"

LOGABSTRACT=no
:0
/dev/null
----end of file----

----/tmp/example/message.txt----
To: nobody@example.com
From: "Nobody In Particular"
Subject: test message subject

Test message body
----end of file----

# With the -m switch and -a switches
# arguments after the run control file.
cat message.txt |procmail -Y -m ./test.rc -a one -a two -a three -a four
[22966]./test.rc: $1="-a"
[22966]./test.rc: $2="one"
[22966]./test.rc: $3="-a"
[22966]./test.rc: $4="two"
[22966]./test.rc: ARGN=8
[22966]./test.rc: ARGS=-a one -a two -a three -a four

# With the -m switch and without the -a switches
# arguments are after the run control file in this case
cat message.txt |procmail -Y -m ./test.rc one two three four
[22970]./test.rc: $1="one"
[22970]./test.rc: $2="two"
[22970]./test.rc: $3="three"
[22970]./test.rc: $4="four"
[22970]./test.rc: ARGN=4
[22970]./test.rc: ARGS=one two three four

# Without the -m switch and with the -a switches
# arguments come before the run control file in this case instead
# of after.
cat message.txt |procmail -Y -a one -a two -a three -a four ./test.rc
[22974]./test.rc: $1="one"
[22974]./test.rc: $2="two"
[22974]./test.rc: $3="three"
[22974]./test.rc: $4="four"
[22974]./test.rc: ARGN=4
[22974]./test.rc: ARGS=one two three four

See the difference?


> The master.rc is:
> SHELL=/bin/sh
> DROPPRIVS=YES
> LINEBUF=32768
> SENDMAILFLAGS="-oi"
> SPAMC="/usr/local/bin/spamc"
>
> FROM="<$1>"
> SHIFT=1
>
> :0f
> |$SPAMC -f -U /var/run/spamd.sock
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
> # .Trash/
> }
>
> :0
> ! -f $FROM "$@"
>
> BUT, when this master.rc file involved spamkill.rc file, I am not sure
> whether it's still calling by the cyrus user as instructed by postfix's
> master.cf file.
>
> Sam
>

--
Garen

Re: how to use procmail filter spam into imap folder

am 16.01.2007 05:08:56 von Pet Farrari

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet wrote:
>>>>>> Pet wrote:
>>>>>>> Garen Erdoisa wrote:
>>>>>>>> Pet Farrari wrote:
>>>>>>>>> Pet Farrari wrote:
>>>>>>>>>> Hi Garen,
>>>>>>>>>> [snip]
>>>>>> Just realised this is fine.
>>>>>> Now I don't know what is wrong. :(
>>>>>>
>>>>>
>>>>> Double check your command line switches.
>>>>>
>>>>> In reading a man page for deliver on fedora, I note that there is
>>>>> no switch for -e specified in that particular man page. Abet it's
>>>>> an old man page.
>>>>>
>>>>> Looks like you should be using -m instead of -e.
>>>>> ie:
>>>>>
>>>>> deliver -a anonymous -m user.userid.mailbox
>>>>>
>>>>> deliver -a anonymous -m user.somebody@example.net.Trash
>>>>>
>>>>> or maybe:
>>>>> deliver -a anonymous -m user.somebody+Trash@example.net
>>>>>
>>>> I just tried it, the Unix shell commandline works with your similar
>>>> command but with minor difference:
>>>> # cat /mail/imap/spool/user/sam/57. | /usr/local/cyrus/bin/deliver
>>>> -a sam -m user/sam@domain.com.Trash
>>>>
>>>> But when I use this command deliver the content of 57. imap mail
>>>> into the Trash folder, my windows thunderbird only indicate me there
>>>> is new mail. When I open my mail box in windows, there is only an
>>>> emtpy mail delivered to my INBOX, nothing in the Trash shown in
>>>> Windows.
>>>>
>>>> What s more, when I used it in procmailrc, it failed with the same
>>>> error (can't create output file).
>>>>
>>>> The ACL of account sam at Trash folder is:
>>>> mamil01.xx.xx.xx> lam user/sam/Trash
>>>> sam lrswipkxtecda
>>>>
>>>> Very confusing...
>>>
>>> (Quote from the faq)
>>> * plus addressing - Plus addressing allows direct delivery to a
>>> particular mailbox (other than an INBOX). This is done in two
>>> ways.
>>>
>>> The first way allows delviery to a subfolder of a specific
>>> user's
>>> INBOX. This is done via an address of the form:
>>> username+mailfolder@domain, which will deliver to the user's
>>> INBOX.mailfolder folder (or altnamespace equivalent). This
>>> submailbox must allow the posting user the 'p' right (generally,
>>> this means 'anyone' must have the 'p' right), otherwise the
>>> message
>>> will just be filed into the user's INBOX.
>>>
>>> The second way is to form an address like
>>> [postuser]+mailfolder@domain. This will deliver into the mailbox
>>> 'mailfolder'. [postuser] is the string specified in the
>>> imapd.conf
>>> option of the same name, and may be the empty string. As before,
>>> the posting user will need to have the 'p' right on the mailbox.
>>>
>>> For both methods, if 'mailfolder' is more than one level
>>> deep, you
>>> will need to conform to the hierarchy separator appropriate
>>> to your
>>> site.
>>> (end quote)
>>>
>>>>
>>>> Thanks
>>>> sam
>>>>>>> [SNIP]
>>>
>> I suspect there is permission problem with this setup.
>> the master.cf file for postfix is:
>>
>> ...
>> filter unix - n n - - pipe
>> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
>> /usr/local/etc/procmailrcs/master.rc -a ${sender} -a ${recipient}
>>
>
> Try changing the above to:
>
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -m
> /usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}
>
> or to:
> flags=Rq user=cyrus argv=/usr/local/bin/procmail -Y -a ${sender} -a
> ${recipient} /usr/local/etc/procmailrcs/master.rc
>
I have, still having the same error.
But I think the error occured regardless whether it is in the old form
or new form, because the spamkill.rc file calling "deliver" with a
hard-coded value rather then getting it from the argument:

:0 wi
| $DELIVER -a sam -m sam+Trash@xxx.com.au
## | $DELIVER -r sam@xxx.com.au sam/Trash/

Thanks
Sam

> Either one should work. The testing I did the other day indicated the
> difference if the -m switch is used or not. If the -m switch is used to
> specify a run control file, then anything following that on the command
> line will be assigned to $1 $2 ... $9
>
> If you don't use the -m switch, then the run control file has to be the
> last item specified on the procmail command line. In that case,
> arguments are assigned to $1 $2 ... $9 by preceding each argument with
> the -a switch. It's really weird but that's the way it actually works
> according to my tests.
>
> The form you currently have in your postfix config file will have
> $1="-a", $2="${sender}", $3="-a" and, $4="${recipient}"
>
> Observe the following tests:
>
> ----/tmp/example/test.rc----
> NL="
> "
>
> VERBOSE=no
> HOME='/tmp/example'
> ECHO=echo
> FORMAIL=/usr/bin/formail
>
> LOG="[$$]$_: \$1=\"$1\"${NL}"
> LOG="[$$]$_: \$2=\"$2\"${NL}"
> LOG="[$$]$_: \$3=\"$3\"${NL}"
> LOG="[$$]$_: \$4=\"$4\"${NL}"
>
> :0 Wi
> ARGS=|echo "$@"
>
> LOG="[$$]$_: ARGN=$#${NL}"
> LOG="[$$]$_: ARGS=${ARGS}${NL}"
>
> LOGABSTRACT=no
> :0
> /dev/null
> ----end of file----
>
> ----/tmp/example/message.txt----
> To: nobody@example.com
> From: "Nobody In Particular"
> Subject: test message subject
>
> Test message body
> ----end of file----
>
> # With the -m switch and -a switches
> # arguments after the run control file.
> cat message.txt |procmail -Y -m ./test.rc -a one -a two -a three -a four
> [22966]./test.rc: $1="-a"
> [22966]./test.rc: $2="one"
> [22966]./test.rc: $3="-a"
> [22966]./test.rc: $4="two"
> [22966]./test.rc: ARGN=8
> [22966]./test.rc: ARGS=-a one -a two -a three -a four
>
> # With the -m switch and without the -a switches
> # arguments are after the run control file in this case
> cat message.txt |procmail -Y -m ./test.rc one two three four
> [22970]./test.rc: $1="one"
> [22970]./test.rc: $2="two"
> [22970]./test.rc: $3="three"
> [22970]./test.rc: $4="four"
> [22970]./test.rc: ARGN=4
> [22970]./test.rc: ARGS=one two three four
>
> # Without the -m switch and with the -a switches
> # arguments come before the run control file in this case instead
> # of after.
> cat message.txt |procmail -Y -a one -a two -a three -a four ./test.rc
> [22974]./test.rc: $1="one"
> [22974]./test.rc: $2="two"
> [22974]./test.rc: $3="three"
> [22974]./test.rc: $4="four"
> [22974]./test.rc: ARGN=4
> [22974]./test.rc: ARGS=one two three four
>
> See the difference?
>
>
>> The master.rc is:
>> SHELL=/bin/sh
>> DROPPRIVS=YES
>> LINEBUF=32768
>> SENDMAILFLAGS="-oi"
>> SPAMC="/usr/local/bin/spamc"
>>
>> FROM="<$1>"
>> SHIFT=1
>>
>> :0f
>> |$SPAMC -f -U /var/run/spamd.sock
>>
>> :0
>> * ^X-Spam-Level: \*\*\*\*\*
>> {
>> SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
>> # .Trash/
>> }
>>
>> :0
>> ! -f $FROM "$@"
>>
>> BUT, when this master.rc file involved spamkill.rc file, I am not sure
>> whether it's still calling by the cyrus user as instructed by
>> postfix's master.cf file.
>>
>> Sam
>>
>

Re: how to use procmail filter spam into imap folder

am 16.01.2007 05:20:11 von Garen Erdoisa

Pet Farrari wrote:
> Garen Erdoisa wrote:
>> Pet wrote:
>>> Garen Erdoisa wrote:
>>>> Pet wrote:
>>>>> Pet wrote:
>>>>>> Garen Erdoisa wrote:
>>>>>>> Pet Farrari wrote:
>>>>>>>> Pet Farrari wrote:
>>>>>>>>> Hi Garen,
>>>>>> [SNIP]
>>
> I just tried another commandline at the unix shell, now it can deliver
> to the folder I want it to be:
>
> %cat 5. | /usr/local/cyrus/bin/deliver -r david@xxx.com.au david/Trash
>
> BUT... when I put it in use with procmail, it failed with the same
> message "Can't create output file".
>
> Then like you said, I changed it to + sign:
> $DELIVER -r sam@xxx.com.au sam+Trash
> and
> $DELIVER -r sam@xxx.com.au sam+Trash/
> and
> $DELIVER -r sam@xxx.com.au sam/Trash/
>
> it all returned the same error. :(

Did you try:

:0 wi
|$DELIVER -r david@xxx.com.au david/Trash

If that is what worked on the shell command line, it should have no
problem working from inside a procmail recipe unless there is a
permissions issue. I think that the permissions issue in this case would
be with your cyrus imap configuration in imapd.conf not with procmail
since you are doing a handoff of the email in the procmail pipeline to
another mail delivery agent. e.g.: /usr/local/cyrus/bin/deliver

So from the perspective of cyrus imap the post user (david) should have
the p (posting) rights on the Trash folder in the cyrus imapd david
account which is setup in imapd.conf and/or via an ACL entry on the
Trash folder in the david account. Alternatively, give anyone posting
privileges to any sub folder, then use procmail to make the decision as
to which folder names to use.

Also note, I noticed earlier from reading the cyrus docs that you can
configure cyrus imapd to use Berkley mailbox format or to use the cyrus
database format.

The database format has some advantages, namely speed of accessing a
particular email message body in a large collection of emails because of
it's ability to do random accesses on the database, where the Berkley
format may take some time to index down to a particular email in a large
collection since it has to read through an entire mailbox to find a
particular message in the collection.

If you are hosting virtual users and or virtual domains in your mail
server, the Cyrus database format would likely be the better one to use
since it would reduce load on the server with many people using it.

I may switch to that myself because of this discussion now that I've
read up on the docs. But it won't be any time soon. Maybe in a few
months. I'll have to study the docs a bit more and setup a test server
to play around with it a bit first. :)

--
Garen

Re: how to use procmail filter spam into imap folder

am 16.01.2007 06:58:30 von Pet Farrari

Garen Erdoisa wrote:
> Pet Farrari wrote:
>> Garen Erdoisa wrote:
>>> Pet wrote:
>>>> Garen Erdoisa wrote:
>>>>> Pet wrote:
>>>>>> Pet wrote:
>>>>>>> Garen Erdoisa wrote:
>>>>>>>> Pet Farrari wrote:
>>>>>>>>> Pet Farrari wrote:
>>>>>>>>>> Hi Garen,
>>>>>>> [SNIP]
>>>
>> I just tried another commandline at the unix shell, now it can deliver
>> to the folder I want it to be:
>>
>> %cat 5. | /usr/local/cyrus/bin/deliver -r david@xxx.com.au david/Trash
>>
>> BUT... when I put it in use with procmail, it failed with the same
>> message "Can't create output file".
>>
>> Then like you said, I changed it to + sign:
>> $DELIVER -r sam@xxx.com.au sam+Trash
>> and
>> $DELIVER -r sam@xxx.com.au sam+Trash/
>> and
>> $DELIVER -r sam@xxx.com.au sam/Trash/
>>
>> it all returned the same error. :(
>
> Did you try:
>
> :0 wi
> |$DELIVER -r david@xxx.com.au david/Trash
>
Yes, I did. still had the same error.

> If that is what worked on the shell command line, it should have no
> problem working from inside a procmail recipe unless there is a
> permissions issue. I think that the permissions issue in this case would
> be with your cyrus imap configuration in imapd.conf not with procmail
> since you are doing a handoff of the email in the procmail pipeline to
> another mail delivery agent. e.g.: /usr/local/cyrus/bin/deliver
>
> So from the perspective of cyrus imap the post user (david) should have
> the p (posting) rights on the Trash folder in the cyrus imapd david
> account which is setup in imapd.conf and/or via an ACL entry on the
> Trash folder in the david account. Alternatively, give anyone posting
> privileges to any sub folder, then use procmail to make the decision as
> to which folder names to use.
>
yes, I think it is permission problem. But I don't know hwo to change
the imapd.conf to fix this error. I have also looked thru the postfix
master.cf file, since this is where teh procmail get involved.
However, there is no obvious mis-configuration in this file.
Here is its (master.cf) content:

pickup fifo n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 nqmgr
#tlsmgr fifo - - n 300 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
slow unix - - n - 1 smtp
defer unix - - n - 0 bounce
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
smtp unix - - n - - smtp
relay unix - - n - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - n - - showq
error unix - - n - - error
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache

#
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# maildrop. See the Postfix MAILDROP_README file for details.
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
#
# The Cyrus deliver program has changed incompatibly, multiple times.
#
old-cyrus unix - n n - - pipe
flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
# Cyrus 2.1.5 (Amos Gouaux)
#cyrus unix - n n - - pipe
# user=cyrus argv=/usr/local/cyrus/bin/deliver -e -r $sender -m
$extension $user
cyrus unix - n n - - pipe
user=cyrus argv=/usr/local/mailarchiver/deliveryproxy.pl $sender $user
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail
($recipient)
ifmail unix - n n - - pipe

smtp-vfilter unix - - n - 1 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes


#127.0.0.1:10025 inet n - n - - smtpd
# -o content_filter=
# -o myhostname=localhost.xxx.com.au
# -o local_recipient_maps=
# -o relay_recipient_maps=
# -o smtpd_restriction_classes=
# -o smtpd_client_restrictions=
# -o smtpd_helo_restrictions=
# -o smtpd_sender_restrictions=
# -o smtpd_recipient_restrictions=permit_mynetworks,reject
# -o mynetworks=127.0.0.0/8
# -o receive_override_options=no_header_body_checks
# -o smtpd_authorized_xforward_hosts=127.0.0.0/8


trace unix - - n - 0 bounce
verify unix - - n - 1 verify
discard unix - - n - - discard
tlsmgr unix - - n 1000? 1 tlsmgr

mail01.xxx.com.au:smtp inet n - n - - smtpd
-o content_filter=filter:dummy
-o cleanup_service_name=pre-cleanup
#localhost:smtp inet n - n - - smtpd
pre-cleanup unix n - n - 0 cleanup
-o alias_maps=
-o virtual_maps=
cleanup unix n - n - 0 cleanup
filter unix - n n - - pipe
flags=R user=cyrus argv=/usr/local/bin/procmail -Y -m
/usr/local/etc/procmailrcs/master.rc ${sender} ${recipient}

thanks
Sam

> Also note, I noticed earlier from reading the cyrus docs that you can
> configure cyrus imapd to use Berkley mailbox format or to use the cyrus
> database format.
>
> The database format has some advantages, namely speed of accessing a
> particular email message body in a large collection of emails because of
> it's ability to do random accesses on the database, where the Berkley
> format may take some time to index down to a particular email in a large
> collection since it has to read through an entire mailbox to find a
> particular message in the collection.
>
> If you are hosting virtual users and or virtual domains in your mail
> server, the Cyrus database format would likely be the better one to use
> since it would reduce load on the server with many people using it.
>
> I may switch to that myself because of this discussion now that I've
> read up on the docs. But it won't be any time soon. Maybe in a few
> months. I'll have to study the docs a bit more and setup a test server
> to play around with it a bit first. :)
>

Re: how to use procmail filter spam into imap folder

am 17.01.2007 05:52:46 von Pet Farrari

Hi,

I just correct the error by calling the master.rc script (the
procmail.rc script), without involving script filter_recipient and
spamkill.rc. The master.rc skill then handles the procedures of calling
spamc, extract the To: field from email, and then pipe it "| deliver -r
username@domain.com username/Trash", all this works smoothly.

Thank you for all the way helping me out this /tough/ problem/

Cheers
Sam