Allow also YAML filters
This commit is contained in:
parent
a9faa5a3c2
commit
768eaf3675
1 changed files with 10 additions and 2 deletions
|
@ -13,6 +13,11 @@ import imaplib
|
|||
import email
|
||||
from signal import signal, SIGINT
|
||||
import json
|
||||
from yaml import load, dump
|
||||
try:
|
||||
from yaml import CLoader as Loader, CDumper as Dumper
|
||||
except ImportError:
|
||||
from yaml import Loader, Dumper
|
||||
import re
|
||||
import codecs
|
||||
import time
|
||||
|
@ -40,7 +45,10 @@ class ImapFilter:
|
|||
self._init_log()
|
||||
signal(SIGINT, self._signal_handler)
|
||||
with open(self.config['filters_file'], 'r', encoding='UTF-8') as filters_file:
|
||||
self.config['mailboxes'] = json.load(filters_file)
|
||||
if '.json' in self.config['filters_file'].lower():
|
||||
self.config['mailboxes'] = json.load(filters_file)
|
||||
elif '.yaml' in self.config['filters_file'].lower() or '.yml' in self.config['filters_file'].lower():
|
||||
self.config['mailboxes'] = load(filters_file, Loader=Loader)
|
||||
if len(self.config['mailboxes']) == 0:
|
||||
self._log.error(
|
||||
"Filters file is empty. Use --help to see more details."
|
||||
|
@ -393,7 +401,7 @@ class ImapFilter:
|
|||
)
|
||||
@click.option(
|
||||
'--filters-file', '-F', required=True,
|
||||
help='JSON file containing a list of dictionaries with the filter rules.'
|
||||
help='JSON or YAML file containing a list of dictionaries with the filter rules.'
|
||||
)
|
||||
@click_config_file.configuration_option()
|
||||
def __main__(**kwargs):
|
||||
|
|
Loading…
Reference in a new issue