1 # -*- coding: utf-8 -*-
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
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()
31 if minfo
.getTitle().strip() != "":
32 systitle
=minfo
.getTitle().strip()
33 if minfo
.getOrganisation().strip() != "":
34 systitle
="%s @ %s"%(systitle
, minfo
.getOrganisation().strip())
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):
57 self
._contenttype
= "text/plain"
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
):
75 def setFromAddr(self
, fromAddr
):
78 self
._fromAddr
= fromAddr
84 def setToList(self
, toList
):
93 def setCCList(self
, ccList
):
102 def setSubject(self
, subject
):
105 self
._subject
= subject
111 def setBody(self
, body
):
120 def send( notification
, fromAddress
="" ):
121 info
= HelperMaKaCInfo
.getMaKaCInfoInstance()
122 if fromAddress
.strip() == "":
123 fromAddr
= "%s <%s>"%(info
.getTitle(), info
.getSupportEmail())
125 fromAddr
= notification
.getFromAddr()
126 toAddr
= str(notification
.getDestination().getEmail())
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
):
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:
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(), \
155 maildata
= { "fromAddr": "Indico Mailer<%s>"%HelperMaKaCInfo
.getMaKaCInfoInstance().getNoReplyEmail(returnSupport
=True), "toList": [self
._user
.getEmail()], "subject": _("[%s] Confirmation request")%getSubjectIndicoTitle
(), "body": text
}
156 GenericMailer
.send(GenericNotification(maildata
))
158 class sendAccountCreationModeration
:
160 def __init__( self
, user
):
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:
171 """% (name
,urlHandlers
.UHUserDetails
.getURL( self
._user
))
172 maildata
= { "fromAddr": "Indico Mailer<%s>" % minfo
.getNoReplyEmail(returnSupport
=True), "toList": minfo
.getAdminEmails(), "subject": _("[Indico] New account creation request"), "body": text
}
173 GenericMailer
.send(GenericNotification(maildata
))
175 class sendAccountCreationNotification
:
177 def __init__( self
, user
):
181 minfo
= HelperMaKaCInfo
.getMaKaCInfoInstance()
182 name
= self
._user
.getStraightFullName()
183 text
= """Dear Administrator,
184 %s has created a new account in Indico.
186 """ % (name
,urlHandlers
.UHUserDetails
.getURL( self
._user
))
187 maildata
= { "fromAddr": "Indico Mailer<%s>" % minfo
.getSupportEmail(), "toList": minfo
.getAdminEmails(), "subject": _("[Indico] New account creation"), "body": text
}
188 GenericMailer
.send(GenericNotification(maildata
))
190 class sendAccountActivated
:
192 def __init__( self
, user
):
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 Mailer<%s>"%minfo
.getNoReplyEmail(returnSupport
=True), "toList": [self
._user
.getEmail()], "subject": _("[%s] Registration accepted")%getSubjectIndicoTitle
(), "body": text
}
205 GenericMailer
.send(GenericNotification(maildata
))
209 def __init__( self
, user
):
213 idList
= self
._user
.getIdentityList()
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
])
222 text
= _("Sorry, we did not find your login.\nPlease, create one here:\n%s")%urlHandlers
.UHUserDetails
.getURL(self
._user
)
224 text
= _("Please, find your login and password:")
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>"%HelperMaKaCInfo
.getMaKaCInfoInstance().getNoReplyEmail(returnSupport
=True), "toList": [self
._user
.getEmail()], "subject": _("[%s] Login Information")%getSubjectIndicoTitle
(), "body": text
}
232 GenericMailer
.send(GenericNotification(maildata
))