Drop any cnfvar manipulation from the generic mail utils
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Tue, 5 Apr 2022 01:44:57 +0000 (04:44 +0300)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 19 May 2022 09:13:27 +0000 (11:13 +0200)
The conclusion from previous attempts to convert any user cnfvar
manipulation to dynamic mode was that each user could be specific
to the use case where it is created so handling this in the mail
utils should be replaced by direct calls to the new cnfvar API.

src/mail_utils.py

index f07cf76..9dc1699 100644 (file)
@@ -42,7 +42,6 @@ from email.utils import parsedate_to_datetime
 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
@@ -62,11 +61,14 @@ def prep_email_header(email_file, value, regex=None, criterion="envelopeto"):
                           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")
@@ -81,61 +83,6 @@ def prep_email_header(email_file, value, regex=None, criterion="envelopeto"):
                          % 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):
     """