Bug 4192 - require_version doesn't work as expected
Summary: require_version doesn't work as expected
Status: RESOLVED FIXED
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Rules (show other bugs)
Version: 3.0.2
Hardware: Other other
: P5 minor
Target Milestone: 3.0.3
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-14 13:18 UTC by Wolfgang Zeikat
Modified: 2005-04-24 11:05 UTC (History)
0 users



Attachment Type Modified Status Actions Submitter/CLA Status
suggested patch patch None Theo Van Dinter [HasCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Zeikat 2005-03-14 13:18:20 UTC
I have a problem restricting a config file to be used only in versions > 3

I put

if (version < 3.000000)
require_version 3.00
endif

at the beginning of the config file. 2.64 simply ignores the if and endif lines
and skips the config file, which is what I want. So does 3.00002, which is not
what I want - and not what I expected:
configuration file "/etc/spamassassin/test.cf" requires version 3.00 of
SpamAssassin, but this is code version 3.000002.

this is SA installed from a debian package:
  Installed: 3.0.2-1

see also
http://www.rulesemporium.com/forums/showthread.php?s=dc9546ff91252eee23136adf643bf80f&threadid=108
Comment 1 Theo Van Dinter 2005-03-14 13:21:08 UTC
Subject: Re:   New: require_version doesn't work as expected

On Mon, Mar 14, 2005 at 01:18:21PM -0800, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> I have a problem restricting a config file to be used only in versions > 3
> 
> at the beginning of the config file. 2.64 simply ignores the if and endif lines
> and skips the config file, which is what I want. So does 3.00002, which is not
> what I want - and not what I expected:
> configuration file "/etc/spamassassin/test.cf" requires version 3.00 of
> SpamAssassin, but this is code version 3.000002.

The docs are quite clear about this:

       require_version n.nnnnnn
           Indicates that the entire file, from this line on, requires
           a certain version of SpamAssassin to run.  If a different
           (older or newer) version of SpamAssassin tries to read the
           configuration from this file, it will output a warning instead,
           and ignore it.

           Note: The version used is in the internal SpamAssassin version
           format which is "x.yyyzzz", where x is major version, y is
           minor version, and z is maintenance version.  So 3.0.0 is
           3.000000, and 3.4.80 is 3.004080.

Comment 2 Wolfgang Zeikat 2005-03-14 15:10:34 UTC
I want to make files useable in versions >= 3 without knowing the precise
n.nnnnnn version, I have read the docs.


Comment 3 Bob Menschel 2005-03-15 19:49:09 UTC
The docs are equally clear: 
> if (conditional perl expression)
>  Used to support conditional interpretation of the configuration file. Lines
between this and a corresponding endif line, will be ignored unless the
conditional expression evaluates as true (in the perl sense; that is, defined
and non-0).

I read this to mean that if a require_version line is inside a false if/endif,
the require_version line would be ignored because of that false condition. Is
that a wrong interpretation?

Bob Menschel
Comment 4 Theo Van Dinter 2005-03-16 05:07:52 UTC
Subject: Re:  require_version doesn't work as expected

On Tue, Mar 15, 2005 at 07:49:09PM -0800, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> The docs are equally clear: 
> > if (conditional perl expression)
> >  Used to support conditional interpretation of the configuration file. Lines
> between this and a corresponding endif line, will be ignored unless the
> conditional expression evaluates as true (in the perl sense; that is, defined
> and non-0).
> 
> I read this to mean that if a require_version line is inside a false if/endif,
> the require_version line would be ignored because of that false condition. Is
> that a wrong interpretation?

Oh!  I see what you're saying.  I was so focused on the error message that I
missed the big picture.  Sorry.

Ok, so the answer at the moment is: require_version is a specially treated
"preprocessed" config option, so the if blocks don't apply to it.

That said, I don't see a reason why they shouldn't be usable in the way you're
trying to use them.  I committed a patch to trunk (r157740) to fix this.  I'll
put the patch up on the ticket in a minute and reassign to the 3.0.3 queue.

Comment 5 Theo Van Dinter 2005-03-16 05:10:44 UTC
reaiming
Comment 6 Theo Van Dinter 2005-03-16 05:11:57 UTC
Created attachment 2704 [details]
suggested patch

simply moves the "skip_parsing" check up 1 block above require_version.
Comment 7 Justin Mason 2005-03-16 11:10:00 UTC
yeah, quite right.  +1
Comment 8 Daryl C. W. O'Shea 2005-03-16 11:19:09 UTC
This will requrie a documentation change.  Currently it reads "[require_version]
Indicates that the entire file, from this line on, requires a certain version of
SpamAssassin to run."

Now it's really "the current block, or the rest of the file if found outside of
an IF block."

Other than that +1.


As an aside, the reporter doesn't need the require_version tag at all to do what
he wants to do.  He simply needs to put his 3.x statements inside the IF block
and use "if (version > 2.999999)".
Comment 9 Theo Van Dinter 2005-03-16 16:29:31 UTC
Subject: Re:  require_version doesn't work as expected

On Wed, Mar 16, 2005 at 11:19:10AM -0800, bugzilla-daemon@bugzilla.spamassassin.org wrote:
> This will requrie a documentation change.  Currently it reads "[require_version]
> Indicates that the entire file, from this line on, requires a certain version of
> SpamAssassin to run."
> 
> Now it's really "the current block, or the rest of the file if found outside of
> an IF block."

It's still the entire file.  The blocks are still controlable by the if
statement, assuming v3 or higher.

> As an aside, the reporter doesn't need the require_version tag at all to do what
> he wants to do.  He simply needs to put his 3.x statements inside the IF block
> and use "if (version > 2.999999)".

2.x didn't have the if/endif, so it'll just plow through and try using
them.  I think that's the only reason you'd ever do the

	if ... { require_version ...  }

thing is to have config files that work with 2.x and 3.x at the same time.

Comment 10 Theo Van Dinter 2005-04-24 19:05:50 UTC
committed.  r164515