Re: [Exim] custom-router

Etusivu
Poista viesti
Vastaa
Lähettäjä: tsh
Päiväys:  
Vastaanottaja: exim-users
Aihe: Re: [Exim] custom-router
>On Tue, 25 Mar 2003 tsh@??? wrote:
>
>> Is there any way a custom-router could access the message
>> headers and body of the address it is trying to route?
>
>Not quite sure what you mean by a "custom-router". Are you talking about
>writing a new router in C? Or just about building your own configuration
>for an existing router?
>
>In the latter case, you can get at header lines using expansion strings:
>
>$h_xxx: contains the xxx header.
>$message_headers contains a concatenation of all the header lines.
>
>The body is harder. $message_body is available, but limited in length.
>You don't really want to be loading a 100MB string.
>
>Now, what are you *really* trying to do?
>
>Philip
>
>--
>Philip Hazel            University of Cambridge Computing Service,
>ph10@???      Cambridge, England. Phone: +44 1223 334714.

>
>



Sorry, I must be going mad. I had been up and down the Expansion Variables
docs pages many times, (I even make use of the next entry - $message_id)
and still failed to see the 'message_headers' entry. Thanks.

Also, as you rightly say, why do I care about an initial
value of $runrc when I can choose my own success (1) and
failure values (2) anyway. So I'm trying to achieve the
following conditional per-recipient program (spam-analyser eventually)
activation:



=========
if the users spamdata.db exists AND
the result of the run expansion ($runrc) = 2 AND
the user's junkspam exists THEN
transport=spam_transport ELSE
transport=remote_transport.

if ($runrc = 2) THEN
add header "X-spam:"
=========



Which I'm trying to do with Exim 4.10 by:

=========
lmb_router:
  transport=${if and { \
                       {exists{/usr/exim/userspamcontrol/${local_part}/spamdata.db}} \
                       {eq {${run{/bin/csh /usr/exim/spam.csh $local_part ${spool_directory}/input/${message_id}}{}{}}$runrc}{2}} \
                       {exists{/usr/exim/userspamcontrol/${local_part}/junkspam}} \
                     } {spam_transport}{remote_smtp} \
             }


headers_add = ${if eq {$runrc} {2} {X-spam:}{}}
=========


This doesnt seem to be working as there is no evidence of headers being
added in the debug output below. I have:

Contents of spam.csh for testing:
=========
#!/bin/csh -f
#
exit(2)
=========

/usr/exim/userspamcontrol/tsh/spamdata.db    exists
/usr/exim/userspamcontrol/tsh/junkspam        doesnt exist


This results in:

---snip debug output---

remote_smtp transport entered
tsh@???
alf1.mrc-lmb.cam.ac.uk in queue_smtp_domains? no (option unset)
checking status of alf1.mrc-lmb.cam.ac.uk
locking /var/spool/eximtest/db/retry.lockfile
locked /var/spool/eximtest/db/retry.lockfile
opened hints database /var/spool/eximtest/db/retry: flags=0
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78:190223-0006mD-00
no host retry record
no message retry record
alf1.mrc-lmb.cam.ac.uk [131.111.85.78] status = usable
131.111.85.78 in serialize_hosts? no (option unset)
delivering 190223-0006mD-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
set_process_info: 26064 delivering 190223-0006mD-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
Connecting to alf1.mrc-lmb.cam.ac.uk [131.111.85.78]:25 ... connected
read response data: size=90
SMTP<< 220 alf1.mrc-lmb.cam.ac.uk ESMTP Sendmail 8.9.3 at Mon, 31 Mar 2003 17:21:14 +0100 (BST)
SMTP>> EHLO server1.mrc-lmb.cam.ac.uk

read response data: size=181
  SMTP<< 250-alf1.mrc-lmb.cam.ac.uk Hello server1.mrc-lmb.cam.ac.uk [131.111.85.23], pleased to meet you
         250-EXPN
         250-VERB
         250-8BITMIME
         250-SIZE
         250-ONEX
         250-ETRN
         250-XUSR
         250 HELP
131.111.85.78 in hosts_require_auth? no (option unset)

SMTP>> MAIL FROM:<tsh@???> SIZE=1358

read response data: size=42
SMTP<< 250 <tsh@???>... Sender ok
SMTP>> RCPT TO:<tsh@???>

read response data: size=50
SMTP<< 250 <tsh@???>... Recipient ok
SMTP>> DATA

read response data: size=50
SMTP<< 354 Enter mail, end with "." on a line by itself
SMTP>> writing message and terminating "."

writing data block fd=6 size=338 timeout=300
read response data: size=45
SMTP<< 250 RAA507247 Message accepted for delivery
ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address=0
transport_check_waiting entered
sequence=1 local_max=500 global_max=-1
locking /var/spool/eximtest/db/wait-remote_smtp.lockfile
locked /var/spool/eximtest/db/wait-remote_smtp.lockfile
opened hints database /var/spool/eximtest/db/wait-remote_smtp: flags=42
dbfn_read: key=alf1.mrc-lmb.cam.ac.uk
no messages waiting for alf1.mrc-lmb.cam.ac.uk
SMTP>> QUIT

set_process_info: 26064 delivering 190223-0006mD-00: just tried alf1.mrc-lmb.cam.ac.uk [131.111.85.78] for tsh@???: result OK
Leaving remote_smtp transport

---snip---


Whereas if I modify the headers_add line to expect $runrc of zero,
but dont change spam.csh:

  headers_add = ${if eq {$runrc} {0} {X-spam:}{}}
                                  |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


The log then shows the headers_add taking place.


---snip debug output---

remote_smtp transport entered
tsh@???
alf1.mrc-lmb.cam.ac.uk in queue_smtp_domains? no (option unset)
checking status of alf1.mrc-lmb.cam.ac.uk
locking /var/spool/eximtest/db/retry.lockfile
locked /var/spool/eximtest/db/retry.lockfile
opened hints database /var/spool/eximtest/db/retry: flags=0
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78:19026P-0006oS-00
no host retry record
no message retry record
alf1.mrc-lmb.cam.ac.uk [131.111.85.78] status = usable
131.111.85.78 in serialize_hosts? no (option unset)
delivering 19026P-0006oS-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
set_process_info: 26207 delivering 19026P-0006oS-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
Connecting to alf1.mrc-lmb.cam.ac.uk [131.111.85.78]:25 ... connected
read response data: size=90
SMTP<< 220 alf1.mrc-lmb.cam.ac.uk ESMTP Sendmail 8.9.3 at Mon, 31 Mar 2003 17:25:44 +0100 (BST)
SMTP>> EHLO server1.mrc-lmb.cam.ac.uk

read response data: size=181
  SMTP<< 250-alf1.mrc-lmb.cam.ac.uk Hello server1.mrc-lmb.cam.ac.uk [131.111.85.23], pleased to meet you
         250-EXPN
         250-VERB
         250-8BITMIME
         250-SIZE
         250-ONEX
         250-ETRN
         250-XUSR
         250 HELP
131.111.85.78 in hosts_require_auth? no (option unset)

SMTP>> MAIL FROM:<tsh@???> SIZE=1363

read response data: size=42
SMTP<< 250 <tsh@???>... Sender ok
SMTP>> RCPT TO:<tsh@???>

read response data: size=50
SMTP<< 250 <tsh@???>... Recipient ok
SMTP>> DATA

read response data: size=50
SMTP<< 354 Enter mail, end with "." on a line by itself
SMTP>> writing message and terminating "."

added header line(s):
X-spam:

^^^^^^^^^^^^^^^^^^^^

---
writing data block fd=6 size=352 timeout=300
read response data: size=45
SMTP<< 250 RAA507539 Message accepted for delivery
ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address=0
transport_check_waiting entered
sequence=1 local_max=500 global_max=-1
locking /var/spool/eximtest/db/wait-remote_smtp.lockfile
locked /var/spool/eximtest/db/wait-remote_smtp.lockfile
opened hints database /var/spool/eximtest/db/wait-remote_smtp: flags=42
dbfn_read: key=alf1.mrc-lmb.cam.ac.uk
no messages waiting for alf1.mrc-lmb.cam.ac.uk
SMTP>> QUIT

set_process_info: 26207 delivering 19026P-0006oS-00: just tried alf1.mrc-lmb.cam.ac.uk [131.111.85.78] for tsh@???: result OK
Leaving remote_smtp transport

---snip---


Furthermore, if I replace the 'transport=' with a 'condition='
as below, the $runrc then seems to propagate to the headers_add line
in the expected (by me) way

  condition=${if and { \
                       {exists{/usr/exim/userspamcontrol/${local_part}/spamdata.db}} \
                       {eq {${run{/bin/csh /usr/exim/spam.csh $local_part ${spool_directory}/input/${message_id}}{}{}}$runrc}{2}} \
                       {exists{/usr/exim/userspamcontrol/${local_part}/junkspam}} \
                     } {true}{true} \
             }
#now have to force a transport
  transport=remote_smtp


  headers_add = ${if eq {$runrc} {2} {X-spam:}{}}
                                  |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


---snip debug output---

remote_smtp transport entered
tsh@???
alf1.mrc-lmb.cam.ac.uk in queue_smtp_domains? no (option unset)
checking status of alf1.mrc-lmb.cam.ac.uk
locking /var/spool/eximtest/db/retry.lockfile
locked /var/spool/eximtest/db/retry.lockfile
opened hints database /var/spool/eximtest/db/retry: flags=0
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78
dbfn_read: key=T:alf1.mrc-lmb.cam.ac.uk:131.111.85.78:1902DK-0006rl-00
no host retry record
no message retry record
alf1.mrc-lmb.cam.ac.uk [131.111.85.78] status = usable
131.111.85.78 in serialize_hosts? no (option unset)
delivering 1902DK-0006rl-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
set_process_info: 26414 delivering 1902DK-0006rl-00 to alf1.mrc-lmb.cam.ac.uk [131.111.85.78] (tsh@???)
Connecting to alf1.mrc-lmb.cam.ac.uk [131.111.85.78]:25 ... connected
read response data: size=90
SMTP<< 220 alf1.mrc-lmb.cam.ac.uk ESMTP Sendmail 8.9.3 at Mon, 31 Mar 2003 17:32:54 +0100 (BST)
SMTP>> EHLO server1.mrc-lmb.cam.ac.uk

read response data: size=181
  SMTP<< 250-alf1.mrc-lmb.cam.ac.uk Hello server1.mrc-lmb.cam.ac.uk [131.111.85.23], pleased to meet you
         250-EXPN
         250-VERB
         250-8BITMIME
         250-SIZE
         250-ONEX
         250-ETRN
         250-XUSR
         250 HELP
131.111.85.78 in hosts_require_auth? no (option unset)

SMTP>> MAIL FROM:<tsh@???> SIZE=1364

read response data: size=42
SMTP<< 250 <tsh@???>... Sender ok
SMTP>> RCPT TO:<tsh@???>

read response data: size=50
SMTP<< 250 <tsh@???>... Recipient ok
SMTP>> DATA

read response data: size=50
SMTP<< 354 Enter mail, end with "." on a line by itself
SMTP>> writing message and terminating "."

added header line(s):
X-spam:

^^^^^^^^^^^^^^^^^^^^

---
writing data block fd=6 size=353 timeout=300
read response data: size=45
SMTP<< 250 RAA494989 Message accepted for delivery
ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address=0
transport_check_waiting entered
sequence=1 local_max=500 global_max=-1
locking /var/spool/eximtest/db/wait-remote_smtp.lockfile
locked /var/spool/eximtest/db/wait-remote_smtp.lockfile
opened hints database /var/spool/eximtest/db/wait-remote_smtp: flags=42
dbfn_read: key=alf1.mrc-lmb.cam.ac.uk
no messages waiting for alf1.mrc-lmb.cam.ac.uk
SMTP>> QUIT

set_process_info: 26414 delivering 1902DK-0006rl-00: just tried alf1.mrc-lmb.cam.ac.uk [131.111.85.78] for tsh@???: result OK
Leaving remote_smtp transport
---snip---


I am (as ever) mystified...

The reason for thinking in terms of a custom router is that
I was concerned about the overheads of starting up a new program
with the $run facility. I think I'll forget about that for a while!


Cheers,
Terry.