Skip to content

Commit

Permalink
Merge pull request #16 from stuvusIT/dummyForEmpty
Browse files Browse the repository at this point in the history
feat(result): Add option to fill empty alias with dummys
  • Loading branch information
neumantm authored Jan 26, 2024
2 parents 9015f13 + e4c6867 commit 14b7fa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
[LDAP]
uri = ldaps://myldap.com
Expand All @@ -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
Expand Down
19 changes: 15 additions & 4 deletions mail_alias_creator/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

logger: logging.Logger = logging.getLogger("process")


class AliasDefinition(AliasAddress):
"""Representation of one alias definition."""

Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 14b7fa9

Please sign in to comment.