all repos — listfix @ 2044a2da03d78e4dcc1e90897231eb07c684e2b1

Postfix Mailing List Software; Maintained on behalf the of Agency Economy Incorporated NFP.

listfix/args.py (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
import re

re_email_arg = re.compile("([^<>\"\s]+)@(\S+\.[^<>\"\s]+)")

class Args:

    def __init__(self, args):
        self.args = []
        self.command = None

        if (type(args) is list):
            if (len(args) >= 2):
                self.args = args
                self.command = args[1]
            else:
                raise IndexError("Missing command argument.")
        else:
            raise TypeError("Arguments should be of list type.")

    def get_command(self):
        return self.command

    def get_list_email(self):
        if (len(self.args) < 3):
            raise IndexError(f"Missing argument(s) for '{self.command}' command.")

        if (not re_email_arg.match(self.args[2])):
            raise ValueError(f"Invalid argument value: {self.args[2]}")

        return self.args[2]

    def get_list_name(self):
        if (len(self.args) < 4):
            raise IndexError(f"Missing argument(s) for '{self.command}' command.")

        return self.args[3]

    def get_recipient_email(self):
        if (len(self.args) < 4):
            raise IndexError(f"Missing argument(s) for '{self.command}' command.")

        if (not re_email_arg.match(self.args[3])):
            raise ValueError(f"Invalid argument value: {self.args[3]}")

        return self.args[3]

    def get_recipient_name(self):
        if (len(self.args) < 5):
            raise IndexError(f"Missing argument(s) for '{self.command}' command.")

        return self.args[4]