Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-lists with one element produce "Unrecognized command" error #47

Closed
lilyball opened this issue May 11, 2022 · 4 comments
Closed

test-lists with one element produce "Unrecognized command" error #47

lilyball opened this issue May 11, 2022 · 4 comments
Labels
Milestone

Comments

@lilyball
Copy link

If I have a test-list with a single element, check-sieve produces an "Unrecognized command" error for the test identifier. The only exceptions are for true and false. Adding a second element fixes this, but shouldn't be necessary. The Sieve grammar defines a test-list as containing 1 or more tests, not 2 or more.

It's also a bit surprising that the error says "Unrecognized command" instead of something like "unrecognized test".

This bug is new in version 0.7, version 0.6 accepts this syntax without comment. Version 0.6 also uses the correct "Unrecognized test" warning if I put an actual bogus test in there, as opposed to 0.7's "Unrecognized command".

Example:

if anyof (not true) {
  keep;
} else {
  discard;
}

This produces Unrecognized command "not".

@lilyball
Copy link
Author

This may seem like a bit of an edge case, as allof and anyof are pointless if they only are given one test, but I ran into this when parsing my existing sieve rules as it turns out I snuck a not(address :is …) in there instead of not address :is …. My mailserver handled this just fine, and check-sieve 0.6 allowed it as well. This probably should be rejected on the basis that not is defined as not <test1: test> but with a different error specific to not.

Incidentally, when playing with how parens are handled, it turns out that if address :is (true) { keep; } is accepted. This suggests that check-sieve is not validating the expected arguments in the way I thought it would, so maybe not («test») should be accepted too like it was in v0.6 🤷‍♀️.

@dburkart
Copy link
Owner

Thanks for the test case! This is obviously wrong. In v0.6, we have the following AST:

Mail Sieve
    Branch
        Condition
            Test (anyof)
                Test (not)
                    Test (exists)
                        String List
                            String ("From")
                            String ("Date")
        Block
            Command (discard)

If I comment out the offending validation code, we see that the AST looks quite different in 0.7:

Mail Sieve
    Branch
        Condition
            Test (anyof)
                Test ($COMMAND_RESULT)
                    Command (not)
                        Test (exists)
                            String List
                                String ("From")
                                String ("Date")
        Block
            Command (discard)

The second one is quite a big departure. It looks like this is fallout from issue #40, which aimed to support RFC 6558. This RFC added the notion of a "testable action", which is an action which doubles as an action and uses the result as a test. From the RFC:

This creates a new type of Sieve action, a "testable action". The
usage as a test is exactly the same as for an action, and it doubles
as an action and a test of the action's result at the same time. See
Section 3.2 for an example of how this test can be used.

However, it seems I neglected to adhere to the next paragraph, which states:

Note that defining this new testable action does not change the
definitions of any other actions -- it does not imply that other
actions can be used as tests. Future extensions might define other
testable actions, but those specifications would be responsible for
clearly specifying that.

@dburkart dburkart added the bug label May 12, 2022
@dburkart dburkart added this to the Version 0.8 milestone May 12, 2022
@dburkart
Copy link
Owner

Incidentally, when playing with how parens are handled, it turns out that if address :is (true) { keep; } is accepted. This suggests that check-sieve is not validating the expected arguments in the way I thought it would, so maybe not («test») should be accepted too like it was in v0.6 🤷‍♀️.

The above behavior is due to true / false being special-cased in the grammar (which is not great). Adhering to a strict interpretation of the RFCs as far as I can tell would mean not allowing parenthesis around individual tests (for grouping purposes, as opposed to define a test-list).

My guess is that grouping parenthesis around a single test case is allowed as a sort of UI affordance, since some people may prefer to group their conditions similar to C-style syntax. Given that there are quite a few test-cases in RFCs that have grouping parenthesis, I'm leaning towards making this more lax.

dburkart pushed a commit that referenced this issue May 13, 2022
This fixes issue #47, which was a regression from attempting to allow
the convert command to be used as a test. We now simply add the convert
command to our test map to ensure it can be used that way.

Additionally, we make a change to allow laxer usage of parenthesis. This
is allowed by many (if not all) mail programs, since it is sometimes
more readable to encapsulate an entire test in parenthesis.
@dburkart
Copy link
Owner

This should be fixed now! And this also led me to discover a false positive test case (issue #48), so thank you!

dburkart added a commit that referenced this issue May 13, 2022
This fixes issue #47, which was a regression from attempting to allow
the convert command to be used as a test. We now simply add the convert
command to our test map to ensure it can be used that way.

Additionally, we make a change to allow laxer usage of parenthesis. This
is allowed by many (if not all) mail programs, since it is sometimes
more readable to encapsulate an entire test in parenthesis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants