Skip to content

Commit

Permalink
Merge of PR #108
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Mar 28, 2024
1 parent 2c9c8ea commit 8c396b9
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/sievelib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml

release:
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ The following extensions are also supported:
* Copying Without Side Effects (`RFC 3894 <https://tools.ietf.org/html/rfc3894>`_)
* Body (`RFC 5173 <https://tools.ietf.org/html/rfc5173>`_)
* Vacation (`RFC 5230 <http://tools.ietf.org/html/rfc5230>`_)
* Seconds parameter for Vacation (`RFC 6131 <https://datatracker.ietf.org/doc/html/rfc6131>`_)
* Relational (`RFC 5231 <https://tools.ietf.org/html/rfc5231>`_)
* Imap4flags (`RFC 5232 <https://tools.ietf.org/html/rfc5232>`_)
* Regular expression (`Draft <https://datatracker.ietf.org/doc/html/draft-murchison-sieve-regex-08/>`_)

The following extensions are partially supported:

Expand Down
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pre-commit
black
pylint
pytest


10 changes: 0 additions & 10 deletions sievelib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
"""sievelib."""

from pkg_resources import get_distribution, DistributionNotFound


try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
# package is not installed
pass
13 changes: 12 additions & 1 deletion sievelib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def __str__(self):
match_type = {
"name": "match-type",
"values": [":is", ":contains", ":matches"],
"extension_values": {":count": "relational", ":value": "relational"},
"extension_values": {
":count": "relational",
":value": "relational",
":regex": "regex",
},
"extra_arg": {
"type": "string",
"values": ['"gt"', '"ge"', '"lt"', '"le"', '"eq"', '"ne"'],
Expand Down Expand Up @@ -977,6 +981,13 @@ class VacationCommand(ActionCommand):
"extra_arg": {"type": "number"},
"required": False,
},
{
"name": "seconds",
"type": ["tag"],
"extension_values": {":seconds": "vacation-seconds"},
"extra_arg": {"type": "number"},
"required": False,
},
{
"name": "from",
"type": ["tag"],
Expand Down
92 changes: 91 additions & 1 deletion sievelib/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ def test_vacationext_with_multiline(self):
--foo--
.
;
"""
)

def test_vacation_seconds(self):
self.compilation_ok(
"""
require ["vacation", "vacation-seconds"];
vacation :seconds 10 :addresses ["[email protected]"] "Gone";
"""
)

Expand All @@ -595,7 +603,7 @@ def test_fileinto_create(self):

def test_imap4flags_extension(self):
self.compilation_ok(
b"""
rb"""
require ["fileinto", "imap4flags", "variables"];
if size :over 1M {
addflag "MyFlags" "Big";
Expand Down Expand Up @@ -831,6 +839,14 @@ def test_missing_comma_in_test_list(self):
self.compilation_ko(
b"""
if allof(anyof(address "From" "example.com") header "Subject" "Example") { stop; }
"""
)

def test_vacation_seconds_no_arg(self):
self.compilation_ko(
"""
require ["vacation", "vacation-seconds"];
vacation :seconds :addresses ["[email protected]"] "Gone";
"""
)

Expand Down Expand Up @@ -1071,5 +1087,79 @@ def test_fileinto_with_copy(self):
)


class RegexMatchTestCase(SieveTest):
def test_header_regex(self):
self.compilation_ok(
b"""require "regex";
if header :regex "Subject" "^Test" {
discard;
}
"""
)

def test_header_regex_no_middle(self):
self.compilation_ko(
b"""require "regex";
if header "Subject" :regex "^Test" {
discard;
}
"""
)

def test_envelope_regex(self):
self.compilation_ok(
b"""require ["regex","envelope"];
if envelope :regex "from" "^test@example\\.org$" {
discard;
}
"""
)

def test_envelope_regex_no_middle(self):
self.compilation_ko(
b"""require "regex";
if envelope "from" :regex "^test@example\\.org$" {
discard;
}
"""
)

def test_address_regex(self):
self.compilation_ok(
b"""require "regex";
if address :regex "from" "^test@example\\.org$" {
discard;
}
"""
)

def test_address_regex_no_middle(self):
self.compilation_ko(
b"""require "regex";
if address "from" :regex "^test@example\\.org$" {
discard;
}
"""
)

def test_body_raw_regex(self):
self.compilation_ok(
b"""require ["body", "regex"];
if body :raw :regex "Sample" {
discard;
}
"""
)

def test_body_content_regex(self):
self.compilation_ok(
b"""require ["body", "regex"];
if body :content "text" :regex "Sample" {
discard;
}
"""
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 8c396b9

Please sign in to comment.