Skip to content

Commit f73c59a

Browse files
authored
Merge pull request #120 from QHivert/notify_feat
Add Notify Extension
2 parents 842ba8d + 3db1ce8 commit f73c59a

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The following extensions are also supported:
4343
* Relational (`RFC 5231 <https://tools.ietf.org/html/rfc5231>`_)
4444
* Imap4flags (`RFC 5232 <https://tools.ietf.org/html/rfc5232>`_)
4545
* Regular expression (`Draft <https://datatracker.ietf.org/doc/html/draft-murchison-sieve-regex-08/>`_)
46+
* Notifications (`RFC 5435 <https://datatracker.ietf.org/doc/html/rfc5435>`_)
4647

4748
The following extensions are partially supported:
4849

sievelib/commands.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ def check_next_arg(
463463
return False
464464
if self.iscomplete(atype, avalue):
465465
return False
466+
466467

467468
if self.curarg is not None and "extra_arg" in self.curarg:
468469
condition = atype in self.curarg["extra_arg"]["type"] and (
@@ -726,6 +727,44 @@ class RemoveflagCommand(ActionCommand):
726727
]
727728
extension = "imap4flags"
728729

730+
class NotifyCommand(ActionCommand):
731+
"""
732+
Notify extension
733+
734+
https://datatracker.ietf.org/doc/html/rfc5435
735+
"""
736+
extension = "enotify"
737+
args_definition = [
738+
{
739+
"name": "from",
740+
"type": ["tag"],
741+
"values": [":from"],
742+
"required": False,
743+
"extra_arg": {"type": "string", "required": True}
744+
},
745+
{
746+
"name": "importance",
747+
"type": ["tag"],
748+
"values": [":importance"],
749+
"required": False,
750+
"extra_arg": {"type": "string", "required": True}
751+
},
752+
{
753+
"name": "options",
754+
"type": ["tag"],
755+
"values": [":options"],
756+
"required": False,
757+
"extra_arg": {"type": "stringlist", "required": True}
758+
},
759+
{
760+
"name": "message",
761+
"type": ["tag"],
762+
"values": [":message"],
763+
"required": False,
764+
"extra_arg": {"type": "string", "required": True}
765+
},
766+
{"name": "method", "type": ["string"], "required": True},
767+
]
729768

730769
class TestCommand(Command):
731770
"""Indermediate class to represent "test" commands"""

sievelib/tests/test_factory.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,31 @@ def test_address_list_args(self):
703703
""",
704704
)
705705

706+
def test_notify_action(self):
707+
self.fs.addfilter(
708+
"test",
709+
[
710+
(
711+
"from",
712+
":contains",
713+
714+
)
715+
],
716+
[("notify", ":importance", "1", ":message", "This is probably very important", "mailto:[email protected]")],
717+
)
718+
719+
output = io.StringIO()
720+
self.fs.tosieve(output)
721+
self.assertEqual(
722+
output.getvalue(),
723+
"""require ["enotify"];
724+
725+
# Filter: test
726+
if anyof (header :contains "from" "[email protected]") {
727+
notify :importance "1" :message "This is probably very important" "mailto:[email protected]";
728+
}
729+
"""
730+
)
706731

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

sievelib/tests/test_parser.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ def test_body_extension(self):
663663
"""
664664
)
665665

666+
def test_notify_extension(self):
667+
self.compilation_ok(
668+
b"""require ["enotify", "fileinto", "variables"];
669+
670+
if header :contains "from" "[email protected]" {
671+
notify :importance "1"
672+
:message "This is probably very important"
673+
674+
# Don't send any further notifications
675+
stop;
676+
}
677+
"""
678+
)
666679

667680
class InvalidSyntaxes(SieveTest):
668681
def test_nested_comments(self):
@@ -850,6 +863,19 @@ def test_vacation_seconds_no_arg(self):
850863
"""
851864
)
852865

866+
def test_notify_extension_importance_no_args(self):
867+
self.compilation_ko(
868+
b"""require ["enotify", "fileinto", "variables"];
869+
870+
if header :contains "from" "[email protected]" {
871+
notify :importance
872+
:message "This is probably very important";
873+
874+
# Don't send any further notifications
875+
stop;
876+
}
877+
"""
878+
)
853879

854880
class LanguageRestrictions(SieveTest):
855881
def test_unknown_control(self):

0 commit comments

Comments
 (0)