Re: [Dovecot] mailtrain with dovecot antispam plugin

2008-04-24 Thread Johannes Berg

> sorry taking it off the list. Didn't want to bother the others with my 
> whining.. ;)

Heh :)

> I've briefly tested the patch you sugested and it seems to work like a 
> charm.

Thanks for testing, I have committed it.

johannes


signature.asc
Description: This is a digitally signed message part


Re: [Dovecot] mailtrain with dovecot antispam plugin

2008-04-23 Thread Hugo Monteiro

Johannes Berg wrote:

Please don't take mail private. I tend to not reply at all in that case.

Can you try this patch?

johannes

diff --git a/mailtrain.c b/mailtrain.c
index dbe770c..75c0fc8 100644
--- a/mailtrain.c
+++ b/mailtrain.c
@@ -213,7 +213,9 @@ int backend_handle_mail(struct mailbox_transaction_context 
*t,
struct istream *mailstream;
struct ostream *outstream;
int ret;
-   char *buf, *firstline;
+   char *buf;
+   const unsigned char *beginning;
+   size_t size;
int fd;
 
 	if (!ast->tmpdir) {

@@ -266,15 +268,25 @@ int backend_handle_mail(struct 
mailbox_transaction_context *t,
goto failed_to_copy;
}
 
-	firstline = i_stream_read_next_line(mailstream);

+   if (i_stream_read_data(mailstream, &beginning, &size, 5) < 0 ||
+   size < 5) {
+   ret = -1;
+   mail_storage_set_error(t->box->storage,
+  "Failed to read mail beginning");
+   goto failed_to_copy;
+   }
 
-	if (strncmp(firstline, "From ", 5) != 0)

-   if (o_stream_send_str(outstream, firstline) < 0) {
+   /* "From "? skip line */
+   if (memcmp("From ", beginning, 5) == 0) {
+   i_stream_read_next_line(mailstream);
+   } else {
+   if (o_stream_send_str(outstream, "From ") < 0) {
ret = -1;
mail_storage_set_error(t->box->storage,
   "Failed to write line to temp");
goto failed_to_copy;
}
+   }
 
 	if (o_stream_send_istream(outstream, mailstream) < 0) {

ret = -1;



  


Hello Johannes,

sorry taking it off the list. Didn't want to bother the others with my 
whining.. ;)


I've briefly tested the patch you sugested and it seems to work like a 
charm.


Thank you for your interest.

Best regards,

Hugo Monteiro.

--
ci.fct.unl.pt:~# cat .signature

Hugo Monteiro
Email: [EMAIL PROTECTED]
Telefone : +351 212948300 Ext.15307

Centro de Informática
Faculdade de Ciências e Tecnologia da
   Universidade Nova de Lisboa
Quinta da Torre   2829-516 Caparica   Portugal
Telefone: +351 212948596   Fax: +351 212948548
www.ci.fct.unl.pt [EMAIL PROTECTED]

ci.fct.unl.pt:~# _



Re: [Dovecot] mailtrain with dovecot antispam plugin

2008-04-23 Thread Johannes Berg
Please don't take mail private. I tend to not reply at all in that case.

Can you try this patch?

johannes

diff --git a/mailtrain.c b/mailtrain.c
index dbe770c..75c0fc8 100644
--- a/mailtrain.c
+++ b/mailtrain.c
@@ -213,7 +213,9 @@ int backend_handle_mail(struct mailbox_transaction_context 
*t,
struct istream *mailstream;
struct ostream *outstream;
int ret;
-   char *buf, *firstline;
+   char *buf;
+   const unsigned char *beginning;
+   size_t size;
int fd;
 
if (!ast->tmpdir) {
@@ -266,15 +268,25 @@ int backend_handle_mail(struct 
mailbox_transaction_context *t,
goto failed_to_copy;
}
 
-   firstline = i_stream_read_next_line(mailstream);
+   if (i_stream_read_data(mailstream, &beginning, &size, 5) < 0 ||
+   size < 5) {
+   ret = -1;
+   mail_storage_set_error(t->box->storage,
+  "Failed to read mail beginning");
+   goto failed_to_copy;
+   }
 
-   if (strncmp(firstline, "From ", 5) != 0)
-   if (o_stream_send_str(outstream, firstline) < 0) {
+   /* "From "? skip line */
+   if (memcmp("From ", beginning, 5) == 0) {
+   i_stream_read_next_line(mailstream);
+   } else {
+   if (o_stream_send_str(outstream, "From ") < 0) {
ret = -1;
mail_storage_set_error(t->box->storage,
   "Failed to write line to temp");
goto failed_to_copy;
}
+   }
 
if (o_stream_send_istream(outstream, mailstream) < 0) {
ret = -1;




Re: [Dovecot] mailtrain with dovecot antispam plugin

2008-04-21 Thread Johannes Berg

> I've managed to get it working with the following patch.
> There may be a better way, deeper in the code, to do it. Timo or 
> Johannes ... any sugestions?
> 
> --- dovecot-antispam/mailtrain.c2008-04-19 22:20:32.0 +0100
> +++ dovecot-antispam-qmail/mailtrain.c  2008-04-19 22:25:45.0 +0100
> @@ -274,7 +274,8 @@
> mail_storage_set_error(t->box->storage,
>"Failed to write line to 
> temp");
> goto failed_to_copy;
> -   }
> +   } else
> +   o_stream_send_str(outstream, "\n");

Interesting. I assume that i_stream_read_next_line() will strip out the
trailing [\r]\n and o_stream_send_str() doesn't add one. I would prefer
a patch using o_stream_sendv(), but I'm not sure whether to send \r\n
or \n.

johannes


signature.asc
Description: This is a digitally signed message part


Re: [Dovecot] mailtrain with dovecot antispam plugin

2008-04-19 Thread Hugo Monteiro

Hugo Monteiro wrote:

Hello all, and Johannes if you're around,


I was trying to set up the "new" antispam plugin with the mailtrain 
backend, and i was trying to use the sendmail binary that's part of a 
qmail system. The message wouldn't get sent and i kept getting exit 
error 100 from the /var/qmail/bin/sendmail binary. To try to figure 
out what was happening, i mean a fake sendmail program, which is 
nothing more than a bash script to capture the command call input.


The script is rather simple, it just places the calling parameters 
into a txt file and the stdin into another.


code is

#!/bin/bash

echo $* > /tmp/sendmail-parms.txt
exec cat<&0 >> /tmp/sendmail-msg.txt

exit 0


So i tried a retrain and went to see what those txt files had. The 
parms.txt file was fine apparently, with cat /tmp/sendmail-parms.txt i 
got


-f [EMAIL PROTECTED] [EMAIL PROTECTED]



Then i did the same to the message file, with cat 
/tmp/sendmail-msg.txt, and i got the follwing


Return-Path: <[EMAIL PROTECTED]>Delivered-To: [EMAIL PROTECTED]
Received: (qmail 21616 invoked from network); 19 Apr 2008 16:21:17 -
Received: (simscan 1.4.1 ppid 21609 pid 21611 t 0.1451s)
(scanners:  regex: 1.4.1 attach: 1.4.1 clamav: 0.92.1
/m:46/d:6803); 19 Apr 0108 16:21:17 -
Received: from femme-fatal.resnet.costabasto.com (HELO femme-fatal) 
(192.168.0.20)

 by hmonteiro.net with SMTP; 19 Apr 2008 16:21:17 -
Subject: buy some viagra HURRAY
X-DSPAM-Result: Innocent
X-DSPAM-Processed: Sat Apr 19 17:21:17 2008
X-DSPAM-Confidence: 0.4945
X-DSPAM-Probability: 0.0330
X-DSPAM-Signature: 480a1bfd216125429498786

viagra sale really HURRAY cheap! only $5!


As you can see, there is no new line in the first line. Return-Path 
and Delivered-To are set in a single line, which makes qmail-inject 
(which is later used by /var/qmail/bin/sendmail) to abort like this


cat /tmp/sendmail-msg.txt | /var/qmail/bin/sendmail -f 
[EMAIL PROTECTED] [EMAIL PROTECTED]

qmail-inject: fatal: unable to parse this line:
Return-Path: <[EMAIL PROTECTED]>Delivered-To: [EMAIL PROTECTED]

Before i go into digging the plugin code i was wondering if i'm not 
seing things clearly and thinking this is in fact a bug in the plugin 
code.


Thank you all in advance,

Hugo Monteiro.




I've managed to get it working with the following patch.
There may be a better way, deeper in the code, to do it. Timo or 
Johannes ... any sugestions?


--- dovecot-antispam/mailtrain.c2008-04-19 22:20:32.0 +0100
+++ dovecot-antispam-qmail/mailtrain.c  2008-04-19 22:25:45.0 +0100
@@ -274,7 +274,8 @@
   mail_storage_set_error(t->box->storage,
  "Failed to write line to 
temp");

   goto failed_to_copy;
-   }
+   } else
+   o_stream_send_str(outstream, "\n");

   if (o_stream_send_istream(outstream, mailstream) < 0) {
   ret = -1;


Cheers,

Hugo Monteiro.

--
ci.fct.unl.pt:~# cat .signature

Hugo Monteiro
Email: [EMAIL PROTECTED]
Telefone : +351 212948300 Ext.15307

Centro de Informática
Faculdade de Ciências e Tecnologia da
   Universidade Nova de Lisboa
Quinta da Torre   2829-516 Caparica   Portugal
Telefone: +351 212948596   Fax: +351 212948548
www.ci.fct.unl.pt [EMAIL PROTECTED]

ci.fct.unl.pt:~# _




signature.asc
Description: OpenPGP digital signature


[Dovecot] mailtrain with dovecot antispam plugin

2008-04-19 Thread Hugo Monteiro

Hello all, and Johannes if you're around,


I was trying to set up the "new" antispam plugin with the mailtrain 
backend, and i was trying to use the sendmail binary that's part of a 
qmail system. The message wouldn't get sent and i kept getting exit 
error 100 from the /var/qmail/bin/sendmail binary. To try to figure out 
what was happening, i mean a fake sendmail program, which is nothing 
more than a bash script to capture the command call input.


The script is rather simple, it just places the calling parameters into 
a txt file and the stdin into another.


code is

#!/bin/bash

echo $* > /tmp/sendmail-parms.txt
exec cat<&0 >> /tmp/sendmail-msg.txt

exit 0


So i tried a retrain and went to see what those txt files had. The 
parms.txt file was fine apparently, with cat /tmp/sendmail-parms.txt i got


-f [EMAIL PROTECTED] [EMAIL PROTECTED]



Then i did the same to the message file, with cat /tmp/sendmail-msg.txt, 
and i got the follwing


Return-Path: <[EMAIL PROTECTED]>Delivered-To: [EMAIL PROTECTED]
Received: (qmail 21616 invoked from network); 19 Apr 2008 16:21:17 -
Received: (simscan 1.4.1 ppid 21609 pid 21611 t 0.1451s)
(scanners:  regex: 1.4.1 attach: 1.4.1 clamav: 0.92.1
/m:46/d:6803); 19 Apr 0108 16:21:17 -
Received: from femme-fatal.resnet.costabasto.com (HELO femme-fatal) 
(192.168.0.20)

 by hmonteiro.net with SMTP; 19 Apr 2008 16:21:17 -
Subject: buy some viagra HURRAY
X-DSPAM-Result: Innocent
X-DSPAM-Processed: Sat Apr 19 17:21:17 2008
X-DSPAM-Confidence: 0.4945
X-DSPAM-Probability: 0.0330
X-DSPAM-Signature: 480a1bfd216125429498786

viagra sale really HURRAY cheap! only $5!


As you can see, there is no new line in the first line. Return-Path and 
Delivered-To are set in a single line, which makes qmail-inject (which 
is later used by /var/qmail/bin/sendmail) to abort like this


cat /tmp/sendmail-msg.txt | /var/qmail/bin/sendmail -f [EMAIL PROTECTED] 
[EMAIL PROTECTED]

qmail-inject: fatal: unable to parse this line:
Return-Path: <[EMAIL PROTECTED]>Delivered-To: [EMAIL PROTECTED]

Before i go into digging the plugin code i was wondering if i'm not 
seing things clearly and thinking this is in fact a bug in the plugin code.


Thank you all in advance,

Hugo Monteiro.


--
ci.fct.unl.pt:~# cat .signature

Hugo Monteiro
Email: [EMAIL PROTECTED]
Telefone : +351 212948300 Ext.15307

Centro de Informática
Faculdade de Ciências e Tecnologia da
   Universidade Nova de Lisboa
Quinta da Torre   2829-516 Caparica   Portugal
Telefone: +351 212948596   Fax: +351 212948548
www.ci.fct.unl.pt [EMAIL PROTECTED]

ci.fct.unl.pt:~# _




signature.asc
Description: OpenPGP digital signature