Merge branch 'cnfvar-deprecations'
[pyi2ncommon] / src / mail_utils.py
index e3339a1..64759a4 100644 (file)
@@ -45,6 +45,7 @@ from email import policy
 # outsourced source, import required for compatiblity
 from .imap_mailbox import ImapMailbox           # pylint: disable=unused-import
 from .mail_validator import *                   # pylint: disable=unused-import
+from .sysmisc import replace_file_regex
 
 log = logging.getLogger('pyi2ncommon.mail_utils')
 
@@ -61,12 +62,12 @@ 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")
-        arnied_wrapper.prep_cnf_value(email_file, value, regex=regex)
+        replace_file_regex(email_file, value, regex=regex)
     elif criterion == "received":
         logging.debug("Updating test emails' Received header")
         with open(email_file, "r") as file_handle:
@@ -80,45 +81,6 @@ def prep_email_header(email_file, value, regex=None, criterion="envelopeto"):
                          % criterion)
 
 
-def create_users(usernames, config_file, params):
-    """
-    Create cyrus users from an absolute path to a user configuration file.
-
-    :param usernames: usernames of the created users
-    :type usernames: [str]
-    :param str config_file: template config file to use for each user
-                            configuration
-    :param params: template config file to use for each user configuration
-    :type params: {str, str}
-    :raises: :py:class:`RuntimeError` if the user exists already or cannot be
-              created
-    """
-    log.info("Creating new cyrus users %s", ", ".join(usernames))
-    cyrus_user_path = params.get("cyrus_user_path",
-                                 "/datastore/imap-mails/user/")
-
-    # check for existence round
-    for username in usernames:
-        if os.path.exists(os.path.join(cyrus_user_path,
-                                       username.replace(".", "^"))):
-            raise RuntimeError("The user %s was already created" % username)
-
-    for username in usernames:
-        params["user"] = '%i: "%s"' % (-1, username)
-        params["user_fullname"] = username
-        params_regex = {"user": r'%s,(-?\d+: ".*")'}
-        arnied_wrapper.set_cnf_semidynamic([config_file],
-                                           params, params_regex)
-
-    for username in usernames:
-        if not os.path.exists(os.path.join(cyrus_user_path,
-                                           username.replace(".", "^"))):
-            raise RuntimeError("The user %s could not be created" % username)
-        else:
-            log.info("Added new user %s", username)
-    log.info("%s users successfully created!", len(usernames))
-
-
 def parse_mail_file(file_name, headers_only=True, attachment_filenames=False,
                     raise_on_defect=False, new_message_type=False):
     """