clarification
[Plinn.git] / event_handlers.py
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright © 2009 Benoît PIN <benoit.pin@ensmp.fr> #
5 # #
6 # This program is free software; you can redistribute it and/or #
7 # modify it under the terms of the GNU General Public License #
8 # as published by the Free Software Foundation; either version 2 #
9 # of the License, or (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the Free Software #
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
19 #######################################################################################
20 """
21 Plinn event handlers.
22
23
24
25 """
26 from zope.container.interfaces import IObjectRemovedEvent
27 from Products.CMFCore.utils import getToolByName
28 from Products.Plinn.utils import getAdapterByInterface
29 from quopri import encodestring
30
31 def reindexObjectPosition(event) :
32 event.object.reindexObject(idxs=['position'])
33
34 def handleObjectRemoved(ob, event) :
35 folder = event.oldParent
36 settings = getAdapterByInterface(folder, 'Products.Plinn.interfaces.IEmailNotificationSettings', None)
37 if settings :
38 subscribers = settings.getSubscribersFor('zope.app.container.interfaces.IObjectRemovedEvent')
39 addresses = map(encodeAdr, subscribers)
40 addresses = filter(None, addresses)
41 if not addresses :
42 return
43 addresses = ', '.join(addresses)
44 recipientsHeader = 'Bcc: %s' % addresses
45 portal = getToolByName(folder, 'portal_url').getPortalObject()
46 email_from_address = portal.email_from_address
47 subject = "Suppression d'un élément"
48 text_body = "Le document « %s » vient d'être supprimé du portail %s.\n\nIl était placé à l'url :\n%s" % \
49 (ob.title_or_id(), portal.Title(), ob.absolute_url())
50 message = folder.echange_mail_template( From = email_from_address
51 , recipients = recipientsHeader
52 , Subject = "=?utf-8?q?%s?=" % encodestring(subject).replace('=\n', '')
53 , ContentType = 'text/plain'
54 , charset = 'UTF-8'
55 , body=text_body)
56 MailHost = portal.MailHost
57 MailHost.send( message.encode('utf-8') )
58
59
60 def encodeAdr(member) :
61 name = member.getMemberFullName(nameBefore=0)
62 email = member.getProperty('email')
63 qpName = encodestring(name).replace('=\n', '')
64 return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email)