-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BTW, note that plugins *should* be able to push their own entries
onto the $conf->{registered_commands} list.   That is, in my opinion,
much cleaner than the current parse_config() API, and may be worthwhile
as a way for future plugins to do configuration.

May need a little work, though ;)

- --j.

[EMAIL PROTECTED] writes:
> Author: felicity
> Date: Mon Oct  4 15:16:21 2004
> New Revision: 53755
> 
> Modified:
>    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Hashcash.pm
>    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Razor2.pm
> Log:
> the hashcash and razor2 plugins use the standard parser functions to
> set values from the configuration.  however since there's no way to
> deal with the errors in a standard manner right now (see bug 3869),
> set a standard-ish function in the plugin itself to deal with issues.
>  basically the same code as the parser itself.
> 
> Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Hashcash.pm
> ==============================================================================
> --- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Hashcash.pm       
> (original)
> +++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Hashcash.pm       Mon Oct 
>  4 15:16:21 2004
> @@ -68,6 +68,7 @@
>    my $conf = $opts->{conf};
>    my $key = $opts->{key};
>    my $value = $opts->{value};
> +  my $line = $opts->{line};
>  
>  =over 4
>  
> @@ -78,7 +79,11 @@
>  =cut
>  
>    if ( $key eq 'use_hashcash' ) {
> -    $conf->{use_hashcash} = $value+0; return 1;
> +    $self->handle_parser_error($opts,
> +      Mail::SpamAssassin::Conf::Parser::set_numeric_value($conf, $key, 
> $value, $line)
> +    );
> +    $self->inhibit_further_callbacks();
> +    return 1;
>    }
>  
>  =item hashcash_accept [EMAIL PROTECTED] ...
> @@ -100,7 +105,9 @@
>  =cut
>  
>    if ( $key eq 'hashcash_accept' ) {
> -    $conf->add_to_addrlist ('hashcash_accept', split (/\s+/, $value)); 
> return 1;
> +    $conf->add_to_addrlist ('hashcash_accept', split (/\s+/, $value));
> +    $self->inhibit_further_callbacks();
> +    return 1;
>    }
>  
>  =item hashcash_doublespend_path /path/to/file   (default: 
> ~/.spamassassin/hashcash_seen)
> @@ -116,7 +123,11 @@
>  =cut
>  
>    if ( $key eq 'hashcash_doublespend_path' ) {
> -    $conf->{hashcash_doublespend_path} = $value; return 1;
> +    $self->handle_parser_error($opts,
> +      Mail::SpamAssassin::Conf::Parser::set_string_value($conf, $key, 
> $value, $line)
> +    );
> +    $self->inhibit_further_callbacks();
> +    return 1;
>    }
>  
>  =item hashcash_doublespend_file_mode            (default: 0700)
> @@ -130,11 +141,47 @@
>  =cut
>  
>    if ( $key eq 'hashcash_doublespend_file_mode' ) {
> -    $conf->{hashcash_doublespend_file_mode} = $value+0; return 1;
> +    $self->handle_parser_error($opts,
> +      Mail::SpamAssassin::Conf::Parser::set_numeric_value($conf, $key, 
> $value, $line)
> +    );
> +    $self->inhibit_further_callbacks();
> +    return 1;
>    }
>  
>    return 0;
>  }
> +
> +sub handle_parser_error {
> +  my($self, $opts, $ret_value) = @_;
> +
> +  my $conf = $opts->{conf};
> +  my $key = $opts->{key};
> +  my $value = $opts->{value};
> +  my $line = $opts->{line};
> +
> +  my $msg = '';
> +
> +  if ($ret_value && $ret_value eq $Mail::SpamAssassin::Conf::INVALID_VALUE) {
> +    $msg = "config: SpamAssassin failed to parse line, ".
> +           "\"$value\" is not valid for \"$key\", ".
> +           "skipping: $line";
> +  }
> +  elsif ($ret_value && $ret_value eq 
> $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE) {
> +    $msg = "config: SpamAssassin failed to parse line, ".
> +           "no value provided for \"$key\", ".
> +           "skipping: $line";
> +  }
> +
> +  return unless $msg;
> +
> +  if ($conf->{lint_rules}) {
> +    warn $msg."\n";
> +  } else {
> +    dbg($msg);
> +  } 
> +  $conf->{errors}++;
> +  return;
> +} 
>  
>  ###########################################################################
>  
> 
> Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Razor2.pm
> ==============================================================================
> --- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Razor2.pm (original)
> +++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Razor2.pm Mon Oct  4 
> 15:16:21 2004
> @@ -87,7 +87,9 @@
>  =cut
>  
>    if ($key eq 'razor_timeout') {
> -    Mail::SpamAssassin::Conf::Parser::set_numeric_value($conf, $key, $value, 
> $line);
> +    $self->handle_parser_error($opts,
> +      Mail::SpamAssassin::Conf::Parser::set_numeric_value($conf, $key, 
> $value, $line)
> +    );
>      $self->inhibit_further_callbacks();
>      return 1;
>    }
> @@ -100,13 +102,48 @@
>  =cut
>  
>    if ($key eq 'razor_config') {
> -    Mail::SpamAssassin::Conf::Parser::set_string_value($conf, $key, $value, 
> $line);
> +    $self->handle_parser_error($opts,
> +      Mail::SpamAssassin::Conf::Parser::set_string_value($conf, $key, 
> $value, $line)
> +    );
>      $self->inhibit_further_callbacks();
>      return 1;
>    }
>  
>    return 0;
>  }
> +
> +sub handle_parser_error {
> +  my($self, $opts, $ret_value) = @_;
> +
> +  my $conf = $opts->{conf};
> +  my $key = $opts->{key};
> +  my $value = $opts->{value};
> +  my $line = $opts->{line};
> +
> +  my $msg = '';
> +
> +  if ($ret_value && $ret_value eq $Mail::SpamAssassin::Conf::INVALID_VALUE) {
> +    $msg = "config: SpamAssassin failed to parse line, ".
> +           "\"$value\" is not valid for \"$key\", ".
> +           "skipping: $line";
> +  }
> +  elsif ($ret_value && $ret_value eq 
> $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE) {
> +    $msg = "config: SpamAssassin failed to parse line, ".
> +           "no value provided for \"$key\", ".
> +           "skipping: $line";
> +  }
> +
> +  return unless $msg;
> +
> +  if ($conf->{lint_rules}) {
> +    warn $msg."\n";
> +  } else {
> +    dbg($msg);
> +  } 
> +  $conf->{errors}++;
> +  return;
> +} 
> +
>  
>  sub razor2_lookup {
>    my ($self, $permsgstatus, $fulltext) = @_;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Exmh CVS

iD8DBQFBYc/kQTcbUG5Y7woRAgkuAJ9ynN6sERrMEweAGeV6NepvcdwLfQCaAqsf
VwUBJHDV3V55WGxahmfZIV8=
=FDJi
-----END PGP SIGNATURE-----

Reply via email to