List: amavis-tech
Subject: amavis architecture
From: Roman Hlynovskiy <roman.hlynovskiy () gmail ! com>
Date: 2006-02-13 12:27:11
Message-ID: afa4ab8a0602130427p74a76585v () mail ! gmail ! com
[Download RAW message or body]
Hello, everyone!
I started to write a patch for amavis in order to pass corectly messages,
created by broken php-mailers which send messages with raw 8-bit data
the main idea is that the patch is trying to guess encoding for raw 8-bit
data in header and encodes it with method specified in hdr_encoding_qb
whatever it's possible.
for now it's somehow working and changing headers, but the problem I have
encountered is that headers, changed by my code
are unseen by spamassassin (i.e it's processing original headers) and
messages get high points, but the final message comes with modified by my
code headers.
i putted my code just before call to check_header_validity
if ($recode_modifies_headers)
{
my($curr_head);
for my $next_head (@{$msginfo->orig_header}, "\n")
{
if ($next_head =~ /^[ \t]/)
{
$curr_head .= $next_head; #
folded
} else { # new
header
if (defined($curr_head))
{
# obsolete rfc822 syntax allowed whitespace before
colon
my($field_name, $field_body) = $curr_head =~ /^([!-9;-\176]+)[
\t]*:(.*)\z/s ? ($1, $2) : (undef,
$curr_head);
if ($field_body =~ /^(.*?)([\200-\377])(.*)\z/s and $field_name !~
/^X-/) { # header data contains 8-bit
headers
do_log(4, "RECODE: detected 8-bit data: '$field_body' in
'$field_name' header");
# detect
charset
my $charset =
Lingua::DetectCharset::Detect($field_body);
my
($t1,$t2);
if (($charset eq 'KOI' and $charset = 'koi8-r') or ($charset eq
'WIN' and $charset = 'windows-1251'))
{
my($hdr_edits) =
$msginfo->header_edits;
if (!$hdr_edits)
{
$hdr_edits =
Amavis::Out::EditHeader->new;
$msginfo->header_edits($hdr_edits);
}
my($qb) =
c('hdr_encoding_qb');
# does not help. subj still gets ecnoded
0A
# on 01.02.06 added /g. see if it
helps
$field_body =~
s/\r//g;
if (uc($qb) eq 'Q')
{
if ($field_name =~ /^from|to|cc|bcc|reply-to$/i and $field_body
=~ /(.+)\s*</) {
$t1 =
$1;
$t2 = q_encode($t1, $qb,
$charset);
$field_body =~
s/$t1/$t2/;
} else
{
$field_body = q_encode($field_body, $qb,
$charset);
}
} elsif (uc($qb) eq 'B')
{
if ($field_name =~ /^from|to|cc|bcc|reply-to$/i and $field_body
=~ /(.+)\s*</) {
$t1 =
$1;
$t2 = q_encode($t1, $qb,
$charset);
$field_body =~
s/$t1/$t2/;
} else
{
$field_body = MIME::Words::encode_mimeword($field_body, $qb,
$charset);
}
} else
{
# someone specified unknown encoding. skip
encoding
next;
}
$hdr_edits->delete_header("$field_name");
$hdr_edits->append_header("$field_name",
"$field_body");
}
}
}
last if $next_head eq $eol; # end-of-header
reached
$curr_head =
$next_head;
}
}
}
if (grep {!lookup(0,$_,@{ca('bypass_header_checks_maps')})} @recips) {
# rest of code
could someone point a way to somehow "flush" my changes to a messages after
those modifications?
--
...WBR, Roman Hlynovskiy
[Attachment #3 (text/html)]
Hello, everyone!<br>
<br>
I started to write a patch for amavis in order to pass corectly
messages, created by broken php-mailers which send messages with raw
8-bit data<br>
the main idea is that the patch is trying to guess encoding for raw
8-bit data in header and encodes it with method specified in
hdr_encoding_qb<br>
whatever it's possible.<br>
<br>
for now it's somehow working and changing headers, but the problem I have encountered \
is that headers, changed by my code<br> are unseen by spamassassin (i.e it's \
processing original headers) and messages get high points, but the final message \
comes with modified by my code headers.<br>
i putted my code just before call to check_header_validity<br>
<br>
if ($recode_modifies_headers)
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
my($curr_head);   \
; & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
for my $next_head
(@{$msginfo->orig_header}, "\n")
{ & \
nbsp; &nb \
sp;
<br>
if ($next_head =~ /^[ \t]/)
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
$curr_head .= $next_head; #
folded &n \
bsp; &nbs \
p; \
<br>
} else { # new
header &n \
bsp; &nbs \
p; \
&n \
bsp;
<br>
if (defined($curr_head))
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
# obsolete rfc822
syntax allowed whitespace before
colon &nb \
sp;   \
;
<br>
my($field_name,
$field_body) = $curr_head =~ /^([!-9;-\176]+)[ \t]*:(.*)\z/s ? ($1, $2)
> (undef,
$curr_head); &n \
bsp; &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
if ($field_body =~
/^(.*?)([\200-\377])(.*)\z/s and $field_name !~ /^X-/) { # header data
contains 8-bit
headers & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
do_log(4,
"RECODE: detected 8-bit data: '$field_body' in '$field_name'
header");
<br>
# detect
charset & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
my $charset =
Lingua::DetectCharset::Detect($field_body); & \
nbsp; &nb \
sp;
<br>
my
($t1,$t2); &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
if (($charset eq
'KOI' and $charset = 'koi8-r') or ($charset eq 'WIN' and $charset =
'windows-1251'))
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
;
<br>
&n \
bsp; &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
my($hdr_edits) =
$msginfo->header_edits; \
&n \
bsp; &nbs \
p;
<br>
if
(!$hdr_edits)
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
$hdr_edits =
Amavis::Out::EditHeader->new; \
&n \
bsp; &nbs \
p;
<br>
$msginfo->header_edits($hdr_edits); \
&n \
bsp; &nbs \
p;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
&n \
bsp; &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
my($qb) =
c('hdr_encoding_qb');   \
; & \
nbsp; &nb \
sp;
<br>
&n \
bsp; &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
# does not
help. subj still gets ecnoded
0A \
&n \
bsp;
<br>
# on
01.02.06 added /g. see if it
helps &nb \
sp;   \
; & \
nbsp;
<br>
$field_body =~
s/\r//g; \
&n \
bsp; &nbs \
p; \
<br>
if
(uc($qb) eq 'Q')
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
if
($field_name =~ /^from|to|cc|bcc|reply-to$/i and $field_body =~
/(.+)\s*</)
{
<br>
$t1 =
$1;   \
; & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
$t2 = q_encode($t1, $qb,
$charset); &nbs \
p; \
&n \
bsp;
<br>
$field_body =~
s/$t1/$t2/; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
}
else
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
$field_body = q_encode($field_body, $qb,
$charset); &nbs \
p; \
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
} elsif
(uc($qb) eq 'B')
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
if
($field_name =~ /^from|to|cc|bcc|reply-to$/i and $field_body =~
/(.+)\s*</) {<br>
$t1 =
$1;   \
; & \
nbsp; &nb \
sp;   \
; & \
nbsp;
<br>
$t2 = q_encode($t1, $qb,
$charset); &nbs \
p; \
&n \
bsp;
<br>
$field_body =~
s/$t1/$t2/; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
}
else
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
$field_body = MIME::Words::encode_mimeword($field_body, $qb,
$charset);
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
} else
{ & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
#
someone specified unknown encoding. skip
encoding \
&n \
bsp;
<br>
next; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
$hdr_edits->delete_header("$field_name"); &n \
bsp; &nbs \
p; \
<br>
$hdr_edits->append_header("$field_name",
"$field_body"); & \
nbsp; &nb \
sp;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
; \
<br> last if $next_head eq
$eol; # end-of-header
reached & \
nbsp; &nb \
sp;
<br>
$curr_head =
$next_head; &nb \
sp;   \
; & \
nbsp; &nb \
sp;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
;
<br>
} & \
nbsp; &nb \
sp;   \
; & \
nbsp; &nb \
sp;   \
;
<br>
&n \
bsp; &nbs \
p; \
&n \
bsp; &nbs \
p; \
<br>
if (grep {!lookup(0,$_,@{ca('bypass_header_checks_maps')})} \
@recips) {<br> # rest of code<br clear="all"><br>
could someone point a way to somehow "flush" my changes to a messages after \
those modifications?<br> <br>
<br>-- <br>...WBR, Roman Hlynovskiy
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
AMaViS-tech mailing list
AMaViS-tech@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amavis-tech
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic