[gen] appy.gen.mail.py: bugfix (management of recipients). When Config.userLink is False, still display the user name, but as non-clickable text.

This commit is contained in:
Gaetan Delannay 2014-11-14 13:19:47 +01:00
parent f3849d4f92
commit 0465fae6dc
3 changed files with 11 additions and 12 deletions

View file

@ -46,6 +46,7 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
p_log can be a function/method accepting a single string arg. p_log can be a function/method accepting a single string arg.
''' '''
if isinstance(to, str): to = [to]
if not config: if not config:
if log: log('Must send mail but no smtp server configured.') if log: log('Must send mail but no smtp server configured.')
return return
@ -58,7 +59,7 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
msg = '' msg = ''
if log: if log:
log('mail disabled%s: should send mail from %s to %d ' \ log('mail disabled%s: should send mail from %s to %d ' \
'recipient(s): %s.' % (msg, fromAddress, len(to), str(to))) 'recipient(s): %s.' % (msg, fromAddress, len(to), str(to)))
log('subject: %s' % subject) log('subject: %s' % subject)
log('body: %s' % body) log('body: %s' % body)
if attachments and log: log('%d attachment(s).' % len(attachments)) if attachments and log: log('%d attachment(s).' % len(attachments))
@ -75,15 +76,12 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
# Add the header values # Add the header values
msg['Subject'] = Header(subject, 'utf-8') msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress msg['From'] = fromAddress
if isinstance(to, basestring): if len(to) == 1:
msg['To'] = to msg['To'] = to[0]
else: else:
if len(to) == 1: msg['To'] = fromAddress
msg['To'] = to[0] msg['Bcc'] = ', '.join(to)
else: to = fromAddress
msg['To'] = fromAddress
msg['Bcc'] = ', '.join(to)
to = fromAddress
# Add attachments # Add attachments
if attachments: if attachments:
for attachment in attachments: for attachment in attachments:
@ -107,7 +105,7 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
smtpServer = smtplib.SMTP(config.server, port=config.port) smtpServer = smtplib.SMTP(config.server, port=config.port)
if config.login: if config.login:
smtpServer.login(config.login, config.password) smtpServer.login(config.login, config.password)
res = smtpServer.sendmail(fromAddress, [to], msg.as_string()) res = smtpServer.sendmail(fromAddress, to, msg.as_string())
smtpServer.quit() smtpServer.quit()
if res and log: if res and log:
log('could not send mail to some recipients. %s' % str(res), log('could not send mail to some recipients. %s' % str(res),

View file

@ -16,8 +16,9 @@ class UserWrapper(AbstractWrapper):
# Display, in the user strip, links to the User instance of the logged user. # Display, in the user strip, links to the User instance of the logged user.
pxUserLink = Px(''' pxUserLink = Px('''
<td class="userStripText" align=":dright"> <td class="userStripText" align=":dright">
<a href=":user.url"><img src=":url('user')"/> <a if="cfg.userLink" href=":user.url"><img src=":url('user')"/>
<span style="padding: 0 3px">:user.getTitle()</span></a> <span style="padding: 0 3px">:user.getTitle()</span></a>
<x if="not cfg.userLink">:user.getTitle()</x>
</td>''') </td>''')
def isSpecial(self): return self.login in self.specialUsers def isSpecial(self): return self.login in self.specialUsers

View file

@ -264,7 +264,7 @@ class AbstractWrapper(object):
<a href=":tool.url + '/performLogout'" title=":_('app_logout')"> <a href=":tool.url + '/performLogout'" title=":_('app_logout')">
<img src=":url('logout.gif')"/></a> <img src=":url('logout.gif')"/></a>
</td> </td>
<x if="cfg.userLink">:user.pxUserLink</x> <x>:user.pxUserLink</x>
</tr> </tr>
</table> </table>
</td> </td>