/usr/share/kopano-dagent/python/plugins/movetopublic.py is in kopano-dagent 8.5.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | import MAPI
from MAPI.Util import *
from MAPI.Time import *
from MAPI.Struct import *
from plugintemplates import *
import zconfig
class MoveToPublic(IMapiDAgentPlugin):
prioPreDelivery = 50
configfile = '/etc/kopano/movetopublic.cfg'
def __init__(self, logger):
self.rulelist = {}
IMapiDAgentPlugin.__init__(self, logger)
self.Init()
def Init(self):
config = zconfig.ZConfigParser(self.configfile,
defaultoptions={}
)
# scan max for 100 settings
for i in range(1, 100, 1):
try:
data = config.getdict('rule'+str(i), ['recipient', 'destination_folder'])
self.rulelist[data['recipient'].lower()] = data['destination_folder']
except:
break
self.logger.logDebug("*--- Rule list %s" % self.rulelist)
def PreDelivery(self, session, addrbook, store, folder, message):
props = message.GetProps([PR_RECEIVED_BY_EMAIL_ADDRESS_W], 0)
if props[0].ulPropTag != PR_RECEIVED_BY_EMAIL_ADDRESS_W:
self.logger.logError("!--- No received by emailaddress")
return MP_CONTINUE,
recipient = props[0].Value.lower()
if recipient not in self.rulelist:
self.logger.logInfo("*--- No rule for recipient '%s'" % recipient.encode('utf-8'))
return MP_CONTINUE,
publicstore = GetPublicStore(session)
if publicstore == None:
# check for company public
companyname = None
storeprops = store.GetProps([PR_MAILBOX_OWNER_ENTRYID], 0)
if storeprops[0].ulPropTag == PR_MAILBOX_OWNER_ENTRYID:
user = addrbook.OpenEntry(storeprops[0].Value, None, 0)
userprops = user.GetProps([PR_EC_COMPANY_NAME_W], 0)
if userprops[0].ulPropTag == PR_EC_COMPANY_NAME_W:
companyname = userprops[0].Value
if companyname == None:
self.logger.logError("!--- Can not open a public store")
return MP_CONTINUE,
ema = store.QueryInterface(IID_IExchangeManageStore)
publicstoreid = ema.CreateStoreEntryID(None, companyname, MAPI_UNICODE)
publicstore = session.OpenMsgStore(0, publicstoreid, None, MDB_WRITE)
publicfolders = publicstore.OpenEntry(publicstore.GetProps([PR_IPM_PUBLIC_FOLDERS_ENTRYID], 0)[0].Value, None, MAPI_MODIFY)
folderlist = self.rulelist[recipient].split('/')
if len(folderlist) == 0:
self.logger.logWarn("!--- No folders in the rule of recipient '%s'" % recipient.encode('utf-8'))
return MP_CONTINUE,
folder = publicfolders
for foldername in folderlist:
if len(foldername) > 0:
folder = folder.CreateFolder(0, foldername, "Create by Move to Public plugin", None, OPEN_IF_EXISTS)
msgnew = folder.CreateMessage(None, 0)
tags = message.GetPropList(MAPI_UNICODE)
message.CopyProps(tags, 0, None, IID_IMessage, msgnew, 0)
msgnew.SaveChanges(0)
folderid = folder.GetProps([PR_ENTRYID], 0)[0].Value
msgid = msgnew.GetProps([PR_ENTRYID], 0)[0].Value
publicstore.NotifyNewMail( NEWMAIL_NOTIFICATION(msgid, folderid, 0, None, 0) )
self.logger.logInfo("*--- Message moved to public folder '%s'" % (self.rulelist[recipient].encode('utf-8')) )
return MP_STOP_SUCCESS,
|