Skip to content

Remove "p_" from mailadresses, change subject on lists #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ More details about the sync workflow can be found in SyncWorkflow.md
- `LINUXMUSTER_MAILCOW_DOMAIN_QUOTA` - total quota of one domain. CAUTION! If this is not enough to fit all mailboxes the import will fail!!
- `LINUXMUSTER_MAILCOW_ENABLE_GAL` - whether to enable the global addressbook
- **Optional** Only use these if you know what you are doing! They are not required for normal operation!
- `LDAP-MAILCOW_API_URI` - mailcow API uri.
- `LINUXMUSTER_MAILCOW_API_URI` - mailcow API uri.
- `LINUXMUSTER_MAILCOW_DOCKERAPI_URI` - dockerapi API uri.
- `LINUXMUSTER_MAILCOW_LDAP_USER_FILTER` - users that get mail accounts, default is teachers and students, set to `"(sophomorixRole=teacher)"` to restrict to teachers
- `LINUXMUSTER_MAILCOW_LDAP_SOGO_USER_FILTER` - users that are allowed to use SOGo, defaults to teachers or students, set to `"(sophomorixRole='teacher')"` to restrict to teachers


4. Start additional container: `docker compose up -d linuxmuster-mailcow`
5. Check logs `docker compose logs -f linuxmuster-mailcow` (quit with ctrl+c). Please note: Connection errors are normal after all containers are started with `docker compose up -d`.
Expand Down
2 changes: 2 additions & 0 deletions src/ldapHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def __init__(self, ldapUri, ldapBindDn, ldapBindPassword, ldapBaseDn):

def bind(self):
try:
# uncomment to disable CERT-Check on LDAP-Server
#ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how a normal user would be able to use this. They would have to build their own docker image. If you want to add this, please make it configurable using an env variable.

self._ldapConnection = ldap.initialize(f"{self._uri}")
self._ldapConnection.set_option(ldap.OPT_REFERRALS, 0)
self._ldapConnection.simple_bind_s(self._bindDn, self._bindPassword)
Expand Down
25 changes: 20 additions & 5 deletions src/syncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _sync(self):
logging.info(" * Loading groups from AD")
ret, adLists = self._ldap.search(
self.ldapMailingListFilter,
["mail", "proxyAddresses", "distinguishedName",
["mail", "proxyAddresses", "distinguishedName", "description",
"sophomorixMailList", "sAMAccountName"]
)

Expand Down Expand Up @@ -133,6 +133,9 @@ def _sync(self):
continue

mail = mailingList["mail"]
if mail.startswith("p_"):
mail = mail[2:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. As @PLanB2008 mentioned previously, there can be conflicts by blindly doing this.
Also, it will change currently existing lists! This is unacceptable because it will break the setup for everyone who is using the lists with p_ prefix.

I could imagine adding an option to automatically create aliases without the p_ prefix, as this would not break existing setups and would have to be enabled manually.

desc = mailingList["description"]
maildomain = mail.split("@")[-1]
ret, members = self._ldap.search(
self.ldapMailingListMemberFilter.replace(
Expand All @@ -150,13 +153,13 @@ def _sync(self):
"mail": mail,
"sophomorixStatus": "U",
"sophomorixMailQuotaCalculated": 1,
"displayName": mailingList["sAMAccountName"] + " (list)"
"displayName": "Verteiler " + desc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this or make it configurable (see @PLanB2008 's comment).

}, mailcowMailboxes)
self._addAliasesFromProxyAddresses(
mailingList, mail, mailcowAliases)

self._addListFilter(mail, list(
map(lambda x: x["mail"], members)), mailcowFilters)
map(lambda x: x["mail"], members)), desc, mailcowFilters)

if mailcowDomains.queuesAreEmpty() and mailcowMailboxes.queuesAreEmpty() and mailcowAliases.queuesAreEmpty() and mailcowFilters.queuesAreEmpty():
logging.info(" * Everything up-to-date!")
Expand Down Expand Up @@ -262,9 +265,19 @@ def _addAlias(self, alias, goto, mailcowAliases):
}, alias)
pass

def _addListFilter(self, listAddress, memberAddresses, mailcowFilters):
def _addListFilter(self, listAddress, memberAddresses, description, mailcowFilters):
scriptData = "### Auto-generated mailinglist filter by linuxmuster ###\r\n\r\n"
scriptData += "require \"copy\";\r\n\r\n"
scriptData += "require \"editheader\";\r\n"
scriptData += "require \"copy\";\r\n"
scriptData += "require \"variables\";\r\n"
scriptData += "set \"addendum\" \""+description+"\";\r\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using description here instead of cn? Is there a way to alter the description from the webui?

scriptData += "# Match the entire subject ...\r\n"
scriptData += "if header :matches \"Subject\" \"*\" {\r\n"
scriptData += " # ... to get it in a match group that can then be stored in a variable:\r\n"
scriptData += " set \"subject\" \"${1}\";\r\n"
scriptData += " }\r\n"
scriptData += "deleteheader \"Subject\";\r\n"
scriptData += "addheader :last \"Subject\" \"[${addendum}] ${subject}\";\r\n"
for memberAddress in memberAddresses:
scriptData += f"redirect :copy \"{memberAddress}\";\r\n"
scriptData += "\r\ndiscard;stop;"
Expand All @@ -289,6 +302,8 @@ def _readConfig(self):
]

allowedConfigKeys = [
"LINUXMUSTER_MAILCOW_LDAP_SOGO_USER_FILTER",
"LINUXMUSTER_MAILCOW_LDAP_USER_FILTER",
"LINUXMUSTER_MAILCOW_DOCKERAPI_URI",
"LINUXMUSTER_MAILCOW_API_URI"
]
Expand Down