summaryrefslogtreecommitdiff
path: root/service/pixelated/application.py
diff options
context:
space:
mode:
authorJefferson Stachelski <jstachel@thoughtworks.com>2015-10-14 19:21:44 -0300
committerJefferson Stachelski <jstachel@thoughtworks.com>2015-10-14 19:21:44 -0300
commit96ce1b5810ed1a1a9c6072ed2ed57fdb8f44360b (patch)
tree504c335f32871d810e18297225f8619536497d63 /service/pixelated/application.py
parent3863e28bf593591b1b323f8b848233b9e6a1947b (diff)
issue #484 - Add welcome mail for new accounts
Make a logic to add the welcome mail in INBOX when the user log into account at the first time
Diffstat (limited to 'service/pixelated/application.py')
-rw-r--r--service/pixelated/application.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index 528b55d7..aa48135f 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -19,10 +19,13 @@ from twisted.internet import defer
from twisted.internet import ssl
from OpenSSL import SSL
from OpenSSL import crypto
+from email import message_from_file
+import os
+from pixelated.adapter.model.mail import InputMail
from pixelated.config import arguments
from pixelated.config.services import Services
-from pixelated.config.leap import initialize_leap
+from pixelated.config.leap import initialize_leap, CREATE_WELCOME_MAIL
from pixelated.config import logger
from pixelated.config.site import PixelatedSite
from pixelated.resources.loading_page import LoadingResource
@@ -74,10 +77,23 @@ def _ssl_options(sslkey, sslcert):
return options
+def welcome_mail(leap_session):
+ print 'CREATE_WELCOME_MAIL e %s' % str(CREATE_WELCOME_MAIL())
+
+ if CREATE_WELCOME_MAIL():
+ current_path = os.path.dirname(os.path.abspath(__file__))
+ with open(os.path.join(current_path, 'assets', 'welcome.mail')) as mail_template_file:
+ mail_template = message_from_file(mail_template_file)
+
+ input_mail = InputMail.from_python_mail(mail_template)
+
+ leap_session.mail_store.add_mail('INBOX', input_mail.raw)
+ return leap_session
+
+
def initialize():
args = arguments.parse_user_agent_args()
logger.init(debug=args.debug)
-
loading_app = reactor.listenTCP(args.port, PixelatedSite(LoadingResource()), interface=args.host)
deferred = initialize_leap(args.leap_provider_cert,
@@ -86,6 +102,7 @@ def initialize():
args.organization_mode,
args.leap_home)
+ deferred.addCallback(welcome_mail)
deferred.addCallback(
lambda leap_session: start_user_agent(
loading_app,