realis--
[Plinn.git] / profiles / photo / workflows / member_workflow / scripts / after_reject.py
1 ## Script (Python) "after_reject"
2 ##bind container=container
3 ##bind context=context
4 ##bind namespace=
5 ##bind script=script
6 ##bind subpath=traverse_subpath
7 ##parameters=sci
8 ##title=
9 ##
10 from Products.CMFCore.utils import getToolByName
11 mtool = getToolByName(context, 'portal_membership')
12 portal = context.portal_url.getPortalObject()
13 MailHost = portal.MailHost
14 from quopri import encodestring
15
16 def encodeAdr(member) :
17 name = member.getMemberFullName(nameBefore=0)
18 email = member.getProperty('email')
19 qpName = encodestring(name).replace('=\n', '')
20 return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email)
21
22
23 member = sci.object
24
25 sender = mtool.getAuthenticatedMember()
26 sender = encodeAdr(sender)
27 mto = encodeAdr(member)
28
29 subject = sci.kwargs.get('subject', '').strip()
30 body = sci.kwargs.get('body', '').strip()
31
32 if not (subject and body) :
33 raise ValueError, "You must send a consitent email to reject the membership request."
34
35 mtool.removeMembers(memberIds = [member.getId()])
36
37 message = context.echange_mail_template( From = sender
38 , To = mto
39 , Subject = "=?utf-8?q?%s?=" % encodestring(subject).replace('=\n', '')
40 , ContentType = 'text/plain'
41 , charset = 'UTF-8'
42 , body= body
43 )
44
45 MailHost.send( message )