]> source.dussan.org Git - rspamd.git/commitdiff
* Fix URLS command
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Jun 2010 17:24:52 +0000 (21:24 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Jun 2010 17:24:52 +0000 (21:24 +0400)
perl/lib/Mail/Rspamd/Client.pm
src/plugins/surbl.c

index 5c61828682e113562f07fdb3472d7e6b4db53ddf..ad2ab7a862fd6026ccabda95315970457e3876c3 100644 (file)
@@ -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;
+                       }
                }
        }
 
index 90f2bc5fefd8fc6640f00ffe2f61f46a6d376ec2..6faaa7c8a0889aacf3752990752484fcef178b33 100644 (file)
@@ -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;
 }