getDefaultMailSender now returns a tuple (name, email adress).
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 28 Feb 2009 10:25:41 +0000
changeset 1550 a872030dc3ca
parent 1549 bd07b231fe39
child 1551 78c6c14c6b63
getDefaultMailSender now returns a tuple (name, email adress). Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/helper/notifications.py
app/soc/logic/mail_dispatcher.py
--- a/app/soc/logic/helper/notifications.py	Sat Feb 28 00:41:36 2009 +0000
+++ b/app/soc/logic/helper/notifications.py	Sat Feb 28 10:25:41 2009 +0000
@@ -179,16 +179,21 @@
 
   sender = mail_dispatcher.getDefaultMailSender()
 
-  if not sender:
+  # get the default mail sender
+  default_sender = mail_dispatcher.getDefaultMailSender()
+
+  if not default_sender:
     # no valid sender found, abort
     return
+  else:
+    (sender_name, sender) = default_sender
 
   to = accounts.denormalizeAccount(notification_entity.scope.account).email()
 
   # create the message contents
   messageProperties = {
       'to_name': notification_entity.scope.name,
-      'sender_name': current_user_entity.name,
+      'sender_name': sender_name,
       'to': to,
       'sender': sender,
       'subject': force_unicode(DEF_NEW_NOTIFICATION_MSG),
@@ -213,18 +218,20 @@
   site_name = site_entity.site_name
 
   # get the default mail sender
-  sender = mail_dispatcher.getDefaultMailSender()
+  default_sender = mail_dispatcher.getDefaultMailSender()
 
-  if not sender:
+  if not default_sender:
     # no valid sender found, should not happen but abort anyway
     return
+  else:
+    (sender_name, sender) = default_sender
 
   to = accounts.denormalizeAccount(user_entity.account).email()
 
   # create the message contents
   messageProperties = {
       'to_name': user_entity.name,
-      'sender_name': site_name,
+      'sender_name': sender_name,
       'site_name': site_name,
       'to': to,
       'sender': sender,
--- a/app/soc/logic/mail_dispatcher.py	Sat Feb 28 00:41:36 2009 +0000
+++ b/app/soc/logic/mail_dispatcher.py	Sat Feb 28 10:25:41 2009 +0000
@@ -68,7 +68,6 @@
 
 from google.appengine.api import mail
 
-from soc.logic import accounts
 from soc.logic import dicts
 
 
@@ -119,31 +118,36 @@
   message.send()
 
 def getDefaultMailSender():
-  """Returns the email address that currently can be used to send emails.
+  """Returns the sender that currently can be used to send emails.
   
   Returns:
-    - If available the noreply email address from the site singleton
-    - Or the email address of the current logged in User
+    - A tuple containing (sender_name, sender_address)
+    Consisting of:
+    - If available the site name and noreply address from the site singleton
+    - Or the public name and email address of the current logged in User
     - None if there is no address to return
   """
 
   import logging
 
-  from google.appengine.api import users
-
+  from soc.logic import accounts
+  from soc.logic.models import user as user_logic
   from soc.logic.models import site as site_logic
 
-
+  # check if there is a noreply email address set
   site_entity = site_logic.logic.getSingleton()
 
   if site_entity.noreply_email:
-    return site_entity.noreply_email
+    return (site_entity.site_name, site_entity.noreply_email)
 
   # use the email address of the current logged in user
-  account_entity = users.get_current_user()
+  user_entity = user_logic.logic.getForCurrentAccount()
 
-  if not account_entity:
+  if not user_entity:
     logging.warning('Non-Authenticated user triggered getDefaultMailSender')
     return None
 
-  return accounts.denormalizeAccount(account_entity).email()
+  # denormalize the account and retrieve the email
+  sender = accounts.denormalizeAccount(account_entity).email()
+
+  return (user_entity.name, sender)