1 ##parameters= other_adr=[], batchM=[], customized_batch={}, expand='', collapse='', subject='', text_body='', wfid=None, send_fields={}, ajax=''
2 recipients
= {'to':[], 'cc':[], 'bcc':[]}
3 if expand
or collapse
:
5 expand
= expand
.keys()[0]
6 return context
.send_email_form(other_adr
=other_adr
, expand
=expand
,
7 batchM
=batchM
, customized_batch
=customized_batch
,
8 subject
=subject
, text_body
=text_body
,
9 send_fields
=send_fields
)
11 rolesAndMembers
= dict(context
.getRecipients())
13 field
= send_fields
[role
]
14 recipients
[field
].extend( [m
.id for m
in rolesAndMembers
[role
]] )
16 for role
, b
in customized_batch
.items() :
17 field
= send_fields
[role
]
18 recipients
[field
].extend( b
)
21 other_adr
= filter(None, other_adr
)
22 if not (reduce(lambda a
, b
: a
+b
, recipients
.values()) or other_adr
) :
23 context
.setStatus(False, 'No email sent : no recipient specified.')
24 return context
.setRedirect(context
, 'object/view')
26 portal
= context
.portal_url
.getPortalObject()
27 mtool
= portal
.portal_membership
28 MailHost
= portal
.MailHost
30 from quopri
import encodestring
32 def encodeAdr(member
) :
33 name
= member
.getMemberFullName(nameBefore
=0)
34 email
= member
.getProperty('email')
35 qpName
= encodestring(name
).replace('=\n', '')
36 return '''"=?utf-8?q?%s?=" <%s>''' % (qpName
, email
)
38 sender
= mtool
.getAuthenticatedMember()
39 sender
= encodeAdr(sender
)
42 recipients
['to'].extend(other_adr
)
44 recipientsFormated
= {'to':'', 'cc':'', 'bcc':''}
45 for field
, b
in recipients
.items() :
46 formated
= map(encodeAdr
, mtool
.getMembers(b
))
47 formated
= filter(None, formated
)
48 formated
= ', '.join(formated
)
49 recipientsFormated
[field
] = formated
52 for field
in ['to', 'cc', 'bcc'] :
53 value
= recipientsFormated
[field
]
55 recipientsHeader
.append('%s: %s' % (field
.capitalize(), value
))
57 recipientsHeader
= '\n'.join(recipientsHeader
)
59 message
= context
.echange_mail_template( From
= sender
60 , recipients
= recipientsHeader
61 , Subject
= "=?utf-8?q?%s?=" % encodestring(subject
).replace('=\n', '')
62 , ContentType
= 'text/plain'
66 MailHost
.send( message
.encode('utf-8') )
69 wtool
= portal
.portal_workflow
70 email_sent
= reduce(lambda a
, b
: a
+b
, recipients
.values())
71 email_sent
.extend(other_adr
)
72 wtool
.doActionFor(context
, 'send_email', wf_id
=wfid
,
73 email_sent
=email_sent
,
76 context
.setStatus(True, 'Email sent.')
77 return context
.setRedirect(context
, 'object/view', ajax
=ajax
)