- [kopano](src/kopano/plugin/movetopublicldap.py) Include Kopano copyright and license.

master
mlan 2021-01-11 20:08:00 +01:00
parent 6e32101634
commit 36cd823be8
4 changed files with 22 additions and 10 deletions

View File

@ -470,7 +470,7 @@ kopanoResourceType: publicFolder:Public Stores/public
``` ```
messages to `public@example.com` will be delivered to the public store in `Public Stores/public`. messages to `public@example.com` will be delivered to the public store in `Public Stores/public`.
The central [attribute](https://documentation.kopano.io/kopanocore_administrator_manual/appendix_b.html#appendix-b-ldap-attribute-description) is `kopanoResourceType: publicFolder:Public Stores/public`. It contains a token and a folder name. The token match is case sensitive and there must be a colon `:` separating The central [attribute](https://documentation.kopano.io/kopanocore_administrator_manual/appendix_b.html#appendix-b-ldap-attribute-description) is `kopanoResourceType: publicFolder:Public Stores/public`. It contains a token and a folder name. The token match is case sensitive and there must be a colon `:` separating
the token and the public folder name. The folder name can contain space and the token and the public folder name. The folder name can contain space and
sub folders, which are distinguished using a forward slash `/`. sub folders, which are distinguished using a forward slash `/`.
@ -483,7 +483,7 @@ ldap_public_folder_attribute = kopanoResourceType
ldap_public_folder_attribute_token = publicFolder ldap_public_folder_attribute_token = publicFolder
``` ```
As with other parameters, environment variables can be used to define them: `LDAP_PUBLIC_FOLDER_ATTRIBUTE=kopanoResourceType` and `LDAP_PUBLIC_FOLDER_ATTRIBUTE_TOKEN=publicFolder`. As with other parameters, environment variables can be used to define them: `LDAP_PUBLIC_FOLDER_ATTRIBUTE=kopanoResourceType` and `LDAP_PUBLIC_FOLDER_ATTRIBUTE_TOKEN=publicFolder`.
## Shared folders ## Shared folders

View File

@ -16,6 +16,7 @@ LDAP_GROUPOU=groups
LDAP_GROUPOBJ=kopano-group LDAP_GROUPOBJ=kopano-group
LDAP_TEST_USER=demo LDAP_TEST_USER=demo
LDAP_TEST_USERPW=demo LDAP_TEST_USERPW=demo
LDAP_TEST_USERAS=trial
LDAP_TEST_ADMIN=admin LDAP_TEST_ADMIN=admin
LDAP_TEST_ADMINPW=admin LDAP_TEST_ADMINPW=admin
LDAP_TEST_GROUP=team LDAP_TEST_GROUP=team

View File

@ -149,6 +149,7 @@ userPassword: $(LDAP_TEST_USERPW)
telephoneNumber: 0123 123456789 telephoneNumber: 0123 123456789
title: First User title: First User
kopanoAccount: 1 kopanoAccount: 1
kopanoAliases: $(LDAP_TEST_USERAS)@$(MAIL_DOMAIN)
kopanoEnabledFeatures: imap kopanoEnabledFeatures: imap
kopanoEnabledFeatures: pop3 kopanoEnabledFeatures: pop3
endef endef

View File

@ -1,6 +1,10 @@
""" movetopublicldap.py # SPDX-License-Identifier: AGPL-3.0-only
""" (c) 2019 Kopano
This is an LDAP lookup extension to the move to public plugin. movetopublicldap.py
This is an LDAP lookup extension to the move to public plugin movetopublic.py.
The changes to the original work are highlihgted below.
The move to public plugin moves incoming messages to a folder in the public The move to public plugin moves incoming messages to a folder in the public
store. If folders are missing they will be created. store. If folders are missing they will be created.
@ -40,7 +44,8 @@ import ldap
import os.path import os.path
class KConfigParser(ZConfigParser): class KConfigParser(ZConfigParser):
""" Extends zconfig.ZConfigParser to also allow !directive in cfg files """ """ Extends zconfig.ZConfigParser to also allow !directive in cfg files.
Change type addition. """
def __init__(self, configfile, defaultconfig={}): def __init__(self, configfile, defaultconfig={}):
self.config = configparser.ConfigParser(defaults=defaultconfig, self.config = configparser.ConfigParser(defaults=defaultconfig,
delimiters=('='), comment_prefixes=('#', '!')) delimiters=('='), comment_prefixes=('#', '!'))
@ -70,7 +75,8 @@ class MoveToPublic(IMapiDAgentPlugin):
self.readconfig(self.CONFIGFILES, self.DEFAULTCONFIG) self.readconfig(self.CONFIGFILES, self.DEFAULTCONFIG)
def readconfig(self, configfiles=CONFIGFILES, defaultconfig=DEFAULTCONFIG): def readconfig(self, configfiles=CONFIGFILES, defaultconfig=DEFAULTCONFIG):
""" Reads ldap.cfg and movetopublicldap.cfg into self.config """ """ Reads ldap.cfg and movetopublicldap.cfg into self.config.
Change type addition. """
options = [opt.split('_', 1)[1] for opt in defaultconfig.keys()] options = [opt.split('_', 1)[1] for opt in defaultconfig.keys()]
config = None config = None
for configfile in configfiles: for configfile in configfiles:
@ -87,7 +93,8 @@ class MoveToPublic(IMapiDAgentPlugin):
return self.config return self.config
def searchfilter(self, recipient): def searchfilter(self, recipient):
""" (&(uid=recipient)(kopanoResourceType=publicFolder:*)) """ """ (&(uid=recipient)(kopanoResourceType=publicFolder:*)).
Change type addition. """
return ("(&({}={})({}={}:*))" return ("(&({}={})({}={}:*))"
.format(self.config['user_unique_attribute'], .format(self.config['user_unique_attribute'],
recipient, recipient,
@ -96,8 +103,8 @@ class MoveToPublic(IMapiDAgentPlugin):
def searchquery(self, recipient): def searchquery(self, recipient):
""" Query a LDAP/AD driectory server to lookup recipient using """ Query a LDAP/AD driectory server to lookup recipient using
search_base and return public_folder_attribute search_base and return public_folder_attribute.
""" Change type addition. """
if not self.config or not self.config['uri']: if not self.config or not self.config['uri']:
self.logger.logError(("!--- ldap_uri is not defined." self.logger.logError(("!--- ldap_uri is not defined."
" Please check {}" .format(self.CONFIGFILES))) " Please check {}" .format(self.CONFIGFILES)))
@ -133,7 +140,8 @@ class MoveToPublic(IMapiDAgentPlugin):
return result return result
def publicfolder(self, recipient): def publicfolder(self, recipient):
""" Check for ldap_public_folder_attribute_token and return folder """ """ Check for ldap_public_folder_attribute_token and return folder.
Change type addition. """
destination_folder = [] destination_folder = []
result = self.searchquery(recipient) result = self.searchquery(recipient)
if result: if result:
@ -149,6 +157,8 @@ class MoveToPublic(IMapiDAgentPlugin):
return destination_folder return destination_folder
def PreDelivery(self, session, addrbook, store, folder, message): def PreDelivery(self, session, addrbook, store, folder, message):
""" Original code from movetopublic.py with call to self.publicfolder().
Change type modification. """
props = message.GetProps([PR_RECEIVED_BY_EMAIL_ADDRESS_W], 0) props = message.GetProps([PR_RECEIVED_BY_EMAIL_ADDRESS_W], 0)
if props[0].ulPropTag != PR_RECEIVED_BY_EMAIL_ADDRESS_W: if props[0].ulPropTag != PR_RECEIVED_BY_EMAIL_ADDRESS_W: