diff --git a/README.md b/README.md index 87de8ae..3f91e31 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ A typical configuration file looks like this: logging_conf = logging.conf strict = false check_syntax_only = false +dummy_sender_uid = mydummy +dummy_recipient_address = mydummy@example.com [LDAP] uri = ldaps://myldap.com @@ -34,7 +36,13 @@ The `strict` flag enables strict checking of the inputs. In this case the progra The `check_syntax_only` flag can be used to abort the program after loading the alias files. This option may be omitted, which set's it to false. -In the LDAP section some more variables then shown are supported. +The `dummy_sender_uid` and `dummy_recipient_address` fields are optional. +It is also possible to set one and omit the other +If set to a non-empty string the respective uid or address is used for all aliases that are defined but do not have an actual sender or recipient (this can be the case if the primary mail of a user can't be found, a group is empty, the `forbidSend` or `forbidReceive` flags are used or for the sender of an alias which only has entries of the `external_address` kind). +This can be used to make sure the alias still appears in the generated lists giving the mail processing system the ability to +react accordingly. + +In the LDAP section some more variables than shown are supported. For a complete list and some explanations see [ldap.py](mail_alias_creator/ldap.py). ## Alias defintion format diff --git a/mail_alias_creator/process.py b/mail_alias_creator/process.py index 488ffa3..5de34cc 100644 --- a/mail_alias_creator/process.py +++ b/mail_alias_creator/process.py @@ -17,7 +17,6 @@ logger: logging.Logger = logging.getLogger("process") - class AliasDefinition(AliasAddress): """Representation of one alias definition.""" @@ -72,7 +71,7 @@ def process(self, alias_address_provider: AliasAddressProvider): if recipient not in self.recipients: self.recipients.append(recipient) - def get(self, alias_address_provider: AliasAddressProvider) -> Tuple[List[str], List[str]]: + def get(self, alias_address_provider: AliasAddressProvider, for_final_result: bool = False) -> Tuple[List[str], List[str]]: """ Get the senders and recipients represented by this alias definition. @@ -82,7 +81,19 @@ def get(self, alias_address_provider: AliasAddressProvider) -> Tuple[List[str], if not self.has_been_processed: self.process(alias_address_provider) self.has_been_processed = True - return self.senders, self.recipients + + senders = self.senders + recipients = self.recipients + + if for_final_result: + dummy_sender_uid = CONFIG["main"].get("dummy_sender_uid", "") + if len(senders) == 0 and len(dummy_sender_uid) > 0: + senders = [dummy_sender_uid] + dummy_recipient_address = CONFIG["main"].get("dummy_recipient_address", "") + if len(recipients) == 0 and len(dummy_recipient_address) > 0: + recipients = [dummy_recipient_address] + + return senders, recipients class Processor(AliasAddressProvider): @@ -135,7 +146,7 @@ def process(self): logger.info("Start processing aliases.") for alias_definition in self.alias_definitions.values(): logger.info("Proccessing {}".format(alias_definition.mail)) - senders, recipients = alias_definition.get(self) + senders, recipients = alias_definition.get(self, True) for sender in senders: self.sender_aliases.append({ "sender": sender,