ebb9803e58001f0c46d90a1a747d1d35de179558
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright © 2009 Benoît PIN <benoit.pin@ensmp.fr> #
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. #
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. #
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 #######################################################################################
23 $Id: event_handlers.py 1517 2009-06-30 12:54:52Z pin $
24 $URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/event_handlers.py $
26 from zope
.app
.container
.interfaces
import IObjectRemovedEvent
27 from Products
.CMFCore
.utils
import getToolByName
28 from Products
.Plinn
.utils
import getAdapterByInterface
29 from quopri
import encodestring
31 def reindexObjectPosition(event
) :
32 event
.object.reindexObject(idxs
=['position'])
34 def handleObjectRemoved(ob
, event
) :
35 folder
= event
.oldParent
36 settings
= getAdapterByInterface(folder
, 'Products.Plinn.interfaces.IEmailNotificationSettings', None)
38 subscribers
= settings
.getSubscribersFor('zope.app.container.interfaces.IObjectRemovedEvent')
39 addresses
= map(encodeAdr
, subscribers
)
40 addresses
= filter(None, addresses
)
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'
56 MailHost
= portal
.MailHost
57 MailHost
.send( message
.encode('utf-8') )
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
)