Ignore:
Timestamp:
20 Dec 2011, 09:18:02 (13 years ago)
Author:
Henrik Bettermann
Message:

Harmonize sendMail method (work in progress).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7358 r7402  
    219219        fullname = self.request.principal.title
    220220        try:
    221             email_from = self.request.principal.email
     221            email = self.request.principal.email
    222222        except AttributeError:
    223             email_from = self.config.email_admin
     223            email = self.config.email_admin
    224224        username = self.request.principal.id
    225225        usertype = getattr(self.request.principal,
    226226                           'user_type', 'system').title()
    227         body = data['body']
    228         email_to = self.config.email_admin
    229         subject = self.config.email_subject
    230227        sirp_utils = getUtility(ISIRPUtils)
    231         success = sirp_utils.sendMail(fullname,username,usertype,
    232                   self.config.name,body,email_from,email_to,subject)
     228        success = sirp_utils.sendMail(
     229                fullname,email,
     230                self.config.name_admin,self.config.email_admin,
     231                username,usertype,self.config.name,
     232                data['body'],self.config.email_subject)
    233233        if success:
    234234            self.flash('Your message has been sent.')
     
    246246    @grok.action('Send now')
    247247    def send(self, *args, **data):
    248         email_from = data['email_from']
    249         fullname = data['fullname']
    250         body = data['body']
    251         username = u'None'
    252         email_to = self.config.email_admin
    253         subject = self.config.email_subject
    254         usertype = u'Anonymous'
    255248        sirp_utils = getUtility(ISIRPUtils)
    256         success = sirp_utils.sendMail(fullname,username,usertype,
    257                   self.config.name,body,email_from,email_to,subject)
     249        success = sirp_utils.sendMail(
     250                data['fullname'],data['email_from'],
     251                self.config.name_admin,self.config.email_admin,
     252                u'None',u'Anonymous',self.config.name,
     253                data['body'],self.config.email_subject)
    258254        if success:
    259255            self.flash('Your message has been sent.')
     
    467463    @grok.action('Send message now')
    468464    def send(self, *args, **data):
    469         fullname = self.request.principal.title
    470465        try:
    471             email_from = self.request.principal.email
     466            email = self.request.principal.email
    472467        except AttributeError:
    473             email_from = self.config.email_admin
    474         username = self.request.principal.id
     468            email = self.config.email_admin
    475469        usertype = getattr(self.request.principal,
    476470                           'user_type', 'system').title()
    477         body = data['body']
    478         email_to = self.context.email
    479         subject = self.config.email_subject
    480471        sirp_utils = getUtility(ISIRPUtils)
    481         success = sirp_utils.sendMail(fullname,username,usertype,
    482                   self.config.name,body,email_from,email_to,subject)
     472        success = sirp_utils.sendMail(
     473                self.request.principal.title,email,
     474                self.context.title,self.context.email,
     475                self.request.principal.id,usertype,self.config.name,
     476                data['body'],self.config.email_subject)
    483477        if success:
    484478            self.flash('Your message has been sent.')
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py

    r7400 r7402  
    2828from email.Utils import parseaddr, formataddr
    2929
    30 def send_mail(from_name,from_email,rcpt_name,rcpt_email,subject,body,config):
     30def send_mail(from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config):
    3131    """
    3232    XXX: While this method is unicode-proof (i.e. it can handle
     
    3737
    3838    header_charset = 'ISO-8859-1'
    39     from_ = '%s <%s>' % (from_name,from_email)
    40     to_ = '%s <%s>' % (rcpt_name,rcpt_email)
    41     from_name, from_addr = parseaddr(from_)
    42     rcpt_name, rcpt_addr = parseaddr(to_)
    4339    from_name = str(Header(unicode(from_name), header_charset))
    4440    rcpt_name = str(Header(unicode(rcpt_name), header_charset))
     
    6359        server.login(config.smtp_username,config.smtp_password)
    6460    try:
    65         server.sendmail(from_email,rcpt_email,msg.as_string())
     61        server.sendmail(from_addr,rcpt_addr,msg.as_string())
    6662    except Exception, e:
    6763        # XXX: log error message
     
    7672    grok.implements(ISIRPUtils)
    7773
    78     def sendMail(self,fullname,username,usertype,portal,body,
    79                  email_from,email_to,subject):
     74    def sendMail(self,from_name,from_addr,rcpt_name,rcpt_addr,
     75                from_username,usertype,portal,body,subject):
    8076        """Send an email with data provided by forms.
    8177        """
     
    8884%s
    8985"""
    90         from_name = fullname
    91         from_email = email_from
    92         rcpt_name = 'xyz'
    93         rcpt_email = email_to
    94         body = text % (fullname,username,usertype,portal,body)
     86        body = text % (from_name,from_username,usertype,portal,body)
    9587        return send_mail(
    96             from_name,from_email,rcpt_name,rcpt_email,subject,body,config)
     88            from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config)
    9789
    9890    def fullname(self,firstname,lastname,middlename=None):
     
    139131        config = grok.getSite()['configuration']
    140132        from_name = config.name_admin
    141         from_email = config.email_admin
     133        from_addr = config.email_admin
    142134        rcpt_name = applicant.display_fullname
    143         rcpt_email = applicant.email
     135        rcpt_addr = applicant.email
    144136        body = text % (
    145137                rcpt_name, msg,config.name,username,password,login_url)
    146138        return send_mail(
    147             from_name,from_email,rcpt_name,rcpt_email,subject,body,config)
    148 
    149 
    150 
     139            from_name,from_addr,rcpt_name,rcpt_addr,subject,body,config)
Note: See TracChangeset for help on using the changeset viewer.