From 2581146ee7c9433c80e2c4ab5370b7fde966e4f1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 24 Jun 2010 21:24:52 +0400 Subject: [PATCH] * Fix URLS command --- perl/lib/Mail/Rspamd/Client.pm | 75 +++++++++++++++++++++------------- src/plugins/surbl.c | 11 ++--- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/perl/lib/Mail/Rspamd/Client.pm b/perl/lib/Mail/Rspamd/Client.pm index 5c6182868..ad2ab7a86 100644 --- a/perl/lib/Mail/Rspamd/Client.pm +++ b/perl/lib/Mail/Rspamd/Client.pm @@ -932,36 +932,53 @@ sub _do_rspamc_command { my $cur_metric; my @lines = split (/^/, $in); - foreach my $line (@lines) { - if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+)!) { - $metrics{$1} = { - isspam => $2, - score => $3 + 0, - threshold => $4 + 0, - symbols => [], - urls => [], - messages => [], - }; - $cur_metric = $1; - } - elsif ($line =~ /^Symbol: (\S+);\s*(.+)${EOL}$/ && $cur_metric) { - # Line with parameters - my $symref = $metrics{$cur_metric}->{'symbols'}; - push(@$symref, "$1($2)"); - } - elsif ($line =~ /^Symbol: (\S+)/ && $cur_metric) { - my $symref = $metrics{$cur_metric}->{'symbols'}; - push(@$symref, $1); - } - elsif ($line =~ /^Urls: (.+)$/ && $cur_metric) { - @{ $metrics{$cur_metric}->{'urls'} } = split /,\s+/, $1; - } - elsif ($line =~ /^Message: (.+)/ && $cur_metric) { - my $symref = $metrics{$cur_metric}->{'messages'}; - push(@$symref, $1); + if (lc $self->{'command'} eq 'urls') { + $metrics{'default'} = { + isspam => 'false', + score => 0, + threshold => 0, + symbols => [], + urls => [], + messages => [], + }; + foreach my $line (@lines) { + if ($line =~ /^Urls: (.+)$/) { + @{ $metrics{'default'}->{'urls'} } = split /,\s+/, $1; + } } - elsif ($line =~ /^${EOL}$/) { - last; + } + else { + foreach my $line (@lines) { + if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+)!) { + $metrics{$1} = { + isspam => $2, + score => $3 + 0, + threshold => $4 + 0, + symbols => [], + urls => [], + messages => [], + }; + $cur_metric = $1; + } + elsif ($line =~ /^Symbol: (\S+);\s*(.+)${EOL}$/ && $cur_metric) { + # Line with parameters + my $symref = $metrics{$cur_metric}->{'symbols'}; + push(@$symref, "$1($2)"); + } + elsif ($line =~ /^Symbol: (\S+)/ && $cur_metric) { + my $symref = $metrics{$cur_metric}->{'symbols'}; + push(@$symref, $1); + } + elsif ($line =~ /^Urls: (.+)$/ && $cur_metric) { + @{ $metrics{$cur_metric}->{'urls'} } = split /,\s+/, $1; + } + elsif ($line =~ /^Message: (.+)/ && $cur_metric) { + my $symref = $metrics{$cur_metric}->{'messages'}; + push(@$symref, $1); + } + elsif ($line =~ /^${EOL}$/) { + last; + } } } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 90f2bc5fe..6faaa7c8a 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -813,7 +813,7 @@ surbl_filter (struct worker_task *task) return 0; } -static int +static gboolean urls_command_handler (struct worker_task *task) { GList *cur; @@ -835,13 +835,13 @@ urls_command_handler (struct worker_task *task) cur = g_list_next (cur); } - buflen += sizeof (RSPAMD_REPLY_BANNER " 0 OK" CRLF CRLF "URLs: "); + buflen += sizeof (RSPAMD_REPLY_BANNER " 0 OK" CRLF CRLF "Urls: "); outbuf = memory_pool_alloc (task->task_pool, buflen * sizeof (char)); r = rspamd_snprintf (outbuf, buflen, "%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, "OK"); - r += rspamd_snprintf (outbuf + r, buflen - r - 2, "URLs: "); + r += rspamd_snprintf (outbuf + r, buflen - r - 2, "Urls: "); cur = g_list_first (task->urls); @@ -869,11 +869,12 @@ urls_command_handler (struct worker_task *task) g_tree_destroy (url_tree); if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, TRUE)) { - return -1; + return FALSE; } msg_info ("msg ok, id: <%s>, %d urls extracted", task->message_id, num); + task->state = STATE_REPLY; - return 0; + return TRUE; } -- 2.39.5