Added getDefaultMailSender method to mail_dispatcher.
authorLennard de Rijk <ljvderijk@gmail.com>
Fri, 27 Feb 2009 23:32:37 +0000
changeset 1545 ce5d37a38091
parent 1544 5d23f0160fcd
child 1546 cc54ada3cf1b
Added getDefaultMailSender method to mail_dispatcher. Will be used to determine from which mail address we should send an email. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/mail_dispatcher.py
--- a/app/soc/logic/mail_dispatcher.py	Fri Feb 27 12:04:49 2009 +0000
+++ b/app/soc/logic/mail_dispatcher.py	Fri Feb 27 23:32:37 2009 +0000
@@ -116,3 +116,33 @@
 
   # send the message
   message.send()
+
+def getDefaultMailSender():
+  """Returns the email address 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
+    - None if there is no address to return
+  """
+
+  import logging
+
+  from google.appengine.api import users
+
+  from soc.logic.models import site as site_logic
+
+
+  site_entity = site_logic.logic.getSingleton()
+
+  if site_entity.noreply_email:
+    return site_entity.noreply_email
+
+  # use the email address of the current logged in user
+  account_entity = users.get_current_user()
+
+  if not account_entity:
+    logging.warning('Non-Authenticated user triggered getDefaultMailSender')
+    return None
+
+  return account_entity.email()