[FIX] Error reports
[cds-indico.git] / indico / MaKaC / webinterface / mail.py
blob6678aaf19b77585f05683b983cad5535d6943ec0
1 # -*- coding: utf-8 -*-
2 ##
3 ##
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
6 ##
7 ## CDS Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 2 of the
10 ## License, or (at your option) any later version.
12 ## CDS Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 from MaKaC.common.mail import GenericMailer
22 from MaKaC.webinterface import urlHandlers
23 from MaKaC.common.info import HelperMaKaCInfo
24 from MaKaC.common import Config
25 from MaKaC.i18n import _
28 def getSubjectIndicoTitle():
29 minfo=HelperMaKaCInfo.getMaKaCInfoInstance()
30 systitle="Indico"
31 if minfo.getTitle().strip() != "":
32 systitle=minfo.getTitle().strip()
33 if minfo.getOrganisation().strip() != "":
34 systitle="%s @ %s"%(systitle, minfo.getOrganisation().strip())
35 return systitle
37 class personMail:
39 def send(addto, addcc, addfrom, subject, body):
40 addto = addto.replace("\r\n","")
41 tolist = addto.split(",")
42 cclist = addcc.split(",")
43 maildata = { "fromAddr": addfrom, "toList": tolist, "ccList": cclist, "subject": subject, "body": body }
44 GenericMailer.send(GenericNotification(maildata))
45 send = staticmethod( send )
48 class GenericNotification :
50 def __init__(self, data=None):
51 if data is None :
52 self._fromAddr = ""
53 self._toList = []
54 self._ccList = []
55 self._subject = ""
56 self._body = ""
57 self._contenttype = "text/plain"
58 else :
59 self._fromAddr = data.get("fromAddr","")
60 self._toList = data.get("toList",[])
61 self._ccList = data.get("ccList",[])
62 self._subject = data.get("subject","")
63 self._body = data.get("body","")
64 self._contenttype = data.get("content-type","text/plain")
66 def getContentType(self):
67 return self._contenttype
69 def setContentType(self, contentType):
70 self._contenttype = contentType
72 def getFromAddr(self):
73 return self._fromAddr
75 def setFromAddr(self, fromAddr):
76 if fromAddr is None :
77 return False
78 self._fromAddr = fromAddr
79 return True
81 def getToList(self):
82 return self._toList
84 def setToList(self, toList):
85 if toList is None :
86 return False
87 self._toList = toList
88 return True
90 def getCCList(self):
91 return self._ccList
93 def setCCList(self, ccList):
94 if ccList is None :
95 return False
96 self._ccList = ccList
97 return True
99 def getSubject(self):
100 return self._subject
102 def setSubject(self, subject):
103 if subject is None :
104 return False
105 self._subject = subject
106 return True
108 def getBody(self):
109 return self._body
111 def setBody(self, body):
112 if body is None :
113 return False
114 self._body = body
115 return True
118 class Mailer:
120 def send( notification, fromAddress="" ):
121 info = HelperMaKaCInfo.getMaKaCInfoInstance()
122 if fromAddress.strip() == "":
123 fromAddr = "%s <%s>"%(info.getTitle(), Config.getInstance().getSupportEmail())
124 else:
125 fromAddr = notification.getFromAddr()
126 toAddr = str(notification.getDestination().getEmail())
127 text = """%s
129 Indico project <http://indico-software.org/>
130 """%(notification.getMsg())
131 maildata = { "fromAddr": fromAddr, "toList": [toAddr], "subject": "[Indico] %s"%notification.getSubject(), "body": text }
132 GenericMailer.send(GenericNotification(maildata))
133 send = staticmethod( send )
136 class sendConfirmationRequest:
138 def __init__( self, user ):
139 self._user = user
141 def send( self ):
142 text = _("""Welcome to Indico,
143 You have created a new account on the Indico conference management system.
145 In order to activate your new account and being able to be authenticated by the system, please open on your web browser the following URL:
147 %s?userId=%s&key=%s
149 Once you've done it, your account will be fully operational so you can log in and start using the system normally.
151 Thank you for using our system.
152 """)%(urlHandlers.UHActiveAccount.getURL(), \
153 self._user.getId(), \
154 self._user.getKey())
155 maildata = { "fromAddr": "Indico Mailer <%s>" % Config.getInstance().getNoReplyEmail(), "toList": [self._user.getEmail()], "subject": _("[%s] Confirmation request")%getSubjectIndicoTitle(), "body": text }
156 GenericMailer.send(GenericNotification(maildata))
158 class sendAccountCreationModeration:
160 def __init__( self, user ):
161 self._user = user
163 def send( self ):
164 minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
165 name = self._user.getStraightFullName()
166 text = """ Dear Administrator,
167 %s has created a new account in Indico.
169 In order to activate it, please go to this URL:
170 <%s>
171 """% (name,urlHandlers.UHUserDetails.getURL( self._user ))
172 maildata = { "fromAddr": "Indico Mailer <%s>" % Config.getInstance().getNoReplyEmail(), "toList": minfo.getAdminEmails(), "subject": _("[Indico] New account creation request"), "body": text }
173 GenericMailer.send(GenericNotification(maildata))
175 class sendAccountCreationNotification:
177 def __init__( self, user ):
178 self._user = user
180 def send( self ):
181 minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
182 name = self._user.getStraightFullName()
183 text = """Dear Administrator,
184 %s has created a new account in Indico.
185 <%s>
186 """ % (name,urlHandlers.UHUserDetails.getURL( self._user ))
187 maildata = { "fromAddr": "Indico Mailer <%s>" % Config.getInstance().getSupportEmail(), "toList": minfo.getAdminEmails(), "subject": _("[Indico] New account creation"), "body": text }
188 GenericMailer.send(GenericNotification(maildata))
190 class sendAccountActivated:
192 def __init__( self, user ):
193 self._user = user
195 def send( self ):
196 minfo=HelperMaKaCInfo.getMaKaCInfoInstance()
197 text = _("""Welcome to Indico,
198 Your registration has been accepted by the site administrator.
200 You can now login using the following username: %s
202 Thank you for using Indico.
203 """)%(self._user.getIdentityList()[0].getLogin())
204 maildata = { "fromAddr": "Indico Maile r<%s>"%Config.getInstance().getNoReplyEmail(), "toList": [self._user.getEmail()], "subject": _("[%s] Registration accepted")%getSubjectIndicoTitle(), "body": text }
205 GenericMailer.send(GenericNotification(maildata))
207 class sendLoginInfo:
209 def __init__( self, user ):
210 self._user = user
212 def send (self ):
213 idList = self._user.getIdentityList()
214 logins = []
215 for id in idList:
216 try:
217 pw = id.password
218 except AttributeError, e:
219 pw = _(" Sorry, you are using your NICE credentials to login into Indico. Please contact the CERN helpdesk in case you do not remember your password (helpdesk@cern.ch).")
220 logins.append( [id.getAuthenticatorTag(), id.getLogin(),pw])
221 if logins == []:
222 text = _("Sorry, we did not find your login.\nPlease, create one here:\n%s")%urlHandlers.UHUserDetails.getURL(self._user)
223 else:
224 text = _("Please, find your login and password:")
225 for l in logins:
226 text += "\n\n==================\n"
227 text += _("system:%s\n")%l[0]
228 text += _("Login:%s\n")%l[1]
229 text += _("Password:%s\n")%l[2]
230 text += "==================\n"
231 maildata = { "fromAddr": "Indico Mailer<%s>"%Config.getInstance().getNoReplyEmail(), "toList": [self._user.getEmail()], "subject": _("[%s] Login Information")%getSubjectIndicoTitle(), "body": text }
232 GenericMailer.send(GenericNotification(maildata))