from email.parser import BytesParser
from email import policy
-from .simple_cnf import SimpleCnf
# outsourced source, import required for compatiblity
from .imap_mailbox import ImapMailbox # pylint: disable=unused-import
from .mail_validator import * # pylint: disable=unused-import
of 'envelopeto' or 'received'
:raises: :py:class:`ValueError` if the choice of criterion is invalid
- In some cases this function is reusing arnied wrapper's cnf value
- preparation but for email headers.
+ ..todo:: In some cases this function is reusing arnied wrapper's cnf
+ value preparation but for email headers.
"""
if criterion == "envelopeto":
logging.debug("Updating test emails' EnvelopeTo header")
+ # TODO: the cnf value prep function from the arnied wrapper could be
+ # generalized to a shared regex replacement function e.g. in sysmisc
+ from . import arnied_wrapper
arnied_wrapper.prep_cnf_value(email_file, value, regex=regex)
elif criterion == "received":
logging.debug("Updating test emails' Received header")
% criterion)
-def create_users(usernames, **extra_params):
- """
- Create users for sending / receiving mail.
-
- The created user settings are complete with spamfilter settings and
- groupare folders. User is per default member in groups 1 (admins) and
- 2 (all). This cannot yet be changed.
-
- :param usernames: Names of users to create
- :type usernames: [str]
-
- All other params are forwarded to user config
- """
- if isinstance(usernames, str):
- usernames = [usernames,]
- default_cnf = dict(
- user_disabled="0",
- user_locale="",
- user_password="1234test",
- user_spamfilter_blacklist="",
- user_spamfilter_potential_spam_action="FOLDER",
- user_spamfilter_potential_spam_action_destaddr="",
- user_spamfilter_potential_spam_action_folder="Spamverdacht",
- # TODO: this doesn't handle situations where the child variable should not be defined
- user_spamfilter_potential_spam_threshold="1050",
- user_spamfilter_spam_action="FOLDER",
- user_spamfilter_spam_action_destaddr="",
- user_spamfilter_spam_action_folder="Spam",
- user_spamfilter_spam_deletedays="",
- # TODO: this doesn't handle situations where the child variable should not be defined
- user_spamfilter_spam_threshold="1080",
- user_spamfilter_whitelist="",
- user_groupware_folder_drafts="INBOX/Entwürfe",
- user_groupware_folder_outbox="INBOX/Gesendete Elemente",
- user_groupware_folder_trash="INBOX/Gelöschte Elemente",
- )
-
- cnf = SimpleCnf()
- for username in usernames:
- curr_cnf = default_cnf.copy()
- curr_cnf['user_fullname'] = username
- curr_cnf.update(extra_params)
- children = SimpleCnf()
- for key, value in curr_cnf.items():
- if isinstance(value, dict):
- children.add(key, children=value)
- if not isinstance(value, str):
- raise ValueError('Invalid value type for key "{}": {}'
- .format(key, type(value)))
- children.add(key, value)
- children.add('user_group_member_ref', "2")
- cnf.add('user', username, children=children, instance=-1)
- cnf.apply()
-
-
def parse_mail_file(file_name, headers_only=True, attachment_filenames=False,
raise_on_defect=False, new_message_type=False):
"""