From cce0110d9ec635c47b8c557e3ecaa9c0936671a2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Apr 2018 17:17:01 +0100 Subject: [PATCH] [Minor] Support authenticated users in CGP helper --- utils/cgp_rspamd.pl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/utils/cgp_rspamd.pl b/utils/cgp_rspamd.pl index 78ca89462..6851e6dd4 100644 --- a/utils/cgp_rspamd.pl +++ b/utils/cgp_rspamd.pl @@ -192,6 +192,7 @@ sub rspamd_scan { my $from; my @rcpts; my $ip; + my $user; foreach my $elt (@envelope) { if ( $elt =~ /^P\s[^<]*(<[^>]*>).*$/ ) { @@ -200,8 +201,13 @@ sub rspamd_scan { elsif ( $elt =~ /^R\s[^<]*(<[^>]*>).*$/ ) { push @rcpts, $1; } - elsif ( $elt =~ /^S .*\[(.+)\]/ ) { - $ip = $1; + elsif ( $elt =~ /^S (?:<([^>]+)>)?\s*S.*\[(.+)\]/ ) { + if ($1) { + $user = $1; + } + if ($2) { + $ip = $2; + } } } @@ -221,6 +227,10 @@ sub rspamd_scan { $headers->{IP} = $ip; } + if ($user) { + $headers->{User} = $user; + } + http_post( "http://$rspamd_host/checkv2", $data, timeout => $request_timeout, -- 2.39.5