[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.
'''
if isinstance(to, str): to = [to]
if not config:
if log: log('Must send mail but no smtp server configured.')
return
@ -58,7 +59,7 @@ def sendMail(config, to, subject, body, attachments=None, log=None):
msg = ''
if log:
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('body: %s' % body)
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
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress
if isinstance(to, basestring):
msg['To'] = to
if len(to) == 1:
msg['To'] = to[0]
else:
if len(to) == 1:
msg['To'] = to[0]
else:
msg['To'] = fromAddress
msg['Bcc'] = ', '.join(to)
to = fromAddress
msg['To'] = fromAddress
msg['Bcc'] = ', '.join(to)
to = fromAddress
# Add attachments
if 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)
if config.login:
smtpServer.login(config.login, config.password)
res = smtpServer.sendmail(fromAddress, [to], msg.as_string())
res = smtpServer.sendmail(fromAddress, to, msg.as_string())
smtpServer.quit()
if res and log:
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.
pxUserLink = Px('''
<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>
<x if="not cfg.userLink">:user.getTitle()</x>
</td>''')
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')">
<img src=":url('logout.gif')"/></a>
</td>
<x if="cfg.userLink">:user.pxUserLink</x>
<x>:user.pxUserLink</x>
</tr>
</table>
</td>