Mise à jour de la ligne du listing lors d'un écrasement.
[Plinn.git] / profiles / default / workflows / portfolio_workflow / scripts / sendNotificationEmail.py
1 ## Script (Python) "sendNotificationEmail"
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 #TODO : translate messages
11 #from Products.PlacelessTranslationService.MessageID import MessageIDFactory
12 #_ = MessageIDFactory('plinn')
13 _ = lambda x : lambda : x
14
15 portal = context.portal_url.getPortalObject()
16
17 mtool = portal.portal_membership
18
19 recipients = sci.kwargs.get('recipients', [])
20 if not recipients :
21 return []
22
23
24 MailHost = portal.MailHost
25 from quopri import encodestring
26
27 def encodeAdr(member) :
28 name = member.getMemberFullName(nameBefore=0)
29 email = member.getProperty('email')
30 qpName = encodestring(name).replace('=\n', '')
31 return '''"=?utf-8?q?%s?=" <%s>''' % (qpName, email)
32
33
34 object = sci.object
35
36 sender = mtool.getAuthenticatedMember()
37 sender = encodeAdr(sender)
38
39 recipientsFormated = map(encodeAdr, mtool.getMembers( recipients ))
40 mto = ', '.join(recipientsFormated)
41 if mto[-2:] == ', ' :
42 mto = mto[:-2]
43
44 footer = """
45 ------------
46 Document : %s
47 """ % object.absolute_url()
48
49
50 message = context.echange_mail_template( From = sender
51 , To = mto
52 , Subject = "=?utf-8?q?%s?=" % encodestring(portal.Title() + " : " + _("Document state change notificaction")()).replace('=\n', '')
53 , ContentType = 'text/plain'
54 , charset = 'UTF-8'
55 , body=sci.kwargs.get('comment', '')
56 , footer=footer)
57
58
59 MailHost.send( message )
60
61 return recipients