gump-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject cvs commit: jakarta-gump/python/gump model.py nag.py mailer.py conf.py
Date Tue, 21 Oct 2003 16:15:53 GMT
ajack       2003/10/21 09:15:53

  Modified:    python/gump model.py nag.py mailer.py conf.py
  Log:
  Major updates to mailing and nagging:
  
  1) Env TO/FROM comes from gump@`hostname`, body TO/FROM from nag info.
  2) Cope w/ e-mail addresses X X <xxxx> in envelopes
  3) Allow SMTP to other ports
  4) Added some tests.
  
  Revision  Changes    Path
  1.39      +16 -4     jakarta-gump/python/gump/model.py
  
  Index: model.py
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/python/gump/model.py,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- model.py	20 Oct 2003 23:58:37 -0000	1.38
  +++ model.py	21 Oct 2003 16:15:52 -0000	1.39
  @@ -141,11 +141,23 @@
       if self.deliver:
         if not self.scratchdir: self.scratchdir=os.path.join(self.basedir,"scratch")
   
  +    # Allow per workspace overrides
  +    
       if not self.logurl: self.logurl = default.logurl
  +    # Sending e-mail address
       if not self.email: self.email = default.email
  -    if not self.mailinglist: self.mailinglist = default.mailinglist
  +    # Sending server
  +    if not self.mailinglist: self.mailinglist = default.mailinglist    
  +    # Mail server
       if not self.mailserver: self.mailserver = default.mailserver
  +    # Get mailport as an int
  +    if not self.mailport: 
  +        self.mailport = default.mailport
  +    else:
  +        self.mailport = int(self.mailport)
  +    # Mail subject prefix
       if not self.prefix: self.prefix = default.prefix
  +    # Mail .sig
       if not self.signature: self.signature = default.signature
   
       
  
  
  
  1.19      +32 -26    jakarta-gump/python/gump/nag.py
  
  Index: nag.py
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/python/gump/nag.py,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- nag.py	18 Oct 2003 22:20:27 -0000	1.18
  +++ nag.py	21 Oct 2003 16:15:52 -0000	1.19
  @@ -76,9 +76,13 @@
   from gump.document import getContextAbsoluteUrl
   
   def nag(workspace,context,moduleFilterList=None,projectFilterList=None):
  +    #
  +    # Nag about the workspace (if it needs it)
  +    #
       if STATUS_FAILED==context.status:
           nagWorkspace(workspace,context)
       
  +    # For all modules...
       for mctxt in context:
           mname=mctxt.name
           if Module.list.has_key(mname):
  @@ -103,8 +107,8 @@
                   
   def nagWorkspace(workspace,context):
       """ Nag for the workspace """
  -    content=getContent(workspace, context, "Workspace ... \n")
  -    email=EmailMessage(workspace.prefix+': Gump Workspace Problem ',content)
  +    content=getContent(workspace, context, "There is a workspace problem... \n")
  +    email=EmailMessage([workspace.mailinglist],workspace.email,workspace.prefix+': Gump
Workspace Problem ',content)
       mail([ workspace.mailinglist ],workspace.email,email,workspace.mailserver)
     
   def nagProject(workspace,context,module,mctxt,project,pctxt):
  @@ -114,29 +118,24 @@
       #
       # Form the content...
       #
  -    content+="----------------------------------------------------\n"
       content+=getContent(workspace,mctxt,"Module: " + module.name + "\n")
  -    content+="\n\n\n"
  -    content+="----------------------------------------------------\n"
       content+=getContent(workspace,pctxt,"Project: " + project.name + "\n"    )
  -    content+="\n\n\n"
           
  +    #
  +    # Form the sujhect
  +    #
  +    subject=workspace.prefix+': '+module.name+'/'+project.name+' '+lower(stateName(pctxt.status))
  +    
       nags=0
       for nagEntry in project.nag:
           try:
               #
               # Form and send the e-mail...
               #
  -            email=EmailMessage(workspace.prefix+': '+module.name+'/'+project.name+' '+stateName(pctxt.status),content)
               toaddr=getattr(nagEntry,'to',workspace.mailinglist)
  -            #fromaddr=getattr(nagEntry,'from',workspace.mailinglist)
  -            fromaddr=workspace.email
  -        
  -            # We send to a list, but a list of one is fine..
  -            toaddrs=[ workspace.mailinglist ] # :TODO: toaddr -> to users...
  -        
  -            # Fire ...
  -            mail(toaddrs,fromaddr,email,workspace.mailserver) 
  +            fromaddr=getattr(nagEntry,'from',workspace.mailinglist)
  +            
  +            sendEmail(workspace,workspace.mailinglist,workspace.mailinglist,subject,content)
               
               nags+=1
           except Exception, details:
  @@ -146,16 +145,24 @@
               
       # Belt and braces (nag to us if not nag to them)
       if not nags:
  -        email=EmailMessage(workspace.prefix+': '+module.name+'/'+project.name+' '+stateName(pctxt.status),content)
  -        toaddr=workspace.mailinglist
  -        fromaddr=workspace.email
  -        
  -        # We send to a list, but a list of one is fine..
  -        toaddrs=[ workspace.mailinglist ] # :TODO: toaddr -> to users...
  -        
  -        # Fire ...
  -        mail(toaddrs,fromaddr,email,workspace.mailserver) 
  -    
  +        sendEmail(workspace,workspace.mailinglist,workspace.mailinglist,subject,content)
  +            
  +def sendEmail(workspace, toaddr, fromaddr, subject, content):
  +    #
  +    # We send to a list, but a list of one is fine..
  +    #
  +    toaddrs=[ toaddr ]
  +            
  +    #
  +    # Form the user visable part ...
  +    #
  +    email=EmailMessage( toaddrs, \
  +                        fromaddr, \
  +                        subject, \
  +                        content)                            
  +    # Fire ...
  +    mail(toaddrs,fromaddr,email,workspace.mailserver) 
  +            
   def getContent(workspace,context,message=''):
       content=''
       
  @@ -192,7 +199,6 @@
           content+="\n\nWork Items:\n"
           for workitem in context.worklist:
               content+=workitem.overview()+"\n"            
  -  
       
       return content
       
  
  
  
  1.5       +70 -18    jakarta-gump/python/gump/mailer.py
  
  Index: mailer.py
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/python/gump/mailer.py,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mailer.py	20 Oct 2003 13:51:41 -0000	1.4
  +++ mailer.py	21 Oct 2003 16:15:52 -0000	1.5
  @@ -69,28 +69,70 @@
   import smtplib, string
           
   class EmailMessage:
  -	def __init__(self,subject,text):
  -		self.subject=subject
  -		self.text=text
           
  -def mail(toaddrs,fromaddr,message,server='localhost'):
  -    """E-mail"""
  -    # Add the From: and To: headers at the start!
  -    data = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s%s"
  -       	% (	fromaddr, 
  -       		string.join(toaddrs, ", "),
  -       		message.subject,
  -       		message.text,
  -       		default.signature))
  +	# A *list* if recipients
  +	# A single sender
  +	# The subject
  +    # The text of the message (the main bodypart)
  +    def __init__(self,toaddrs,fromaddr,subject,text,signature=None):
  +        self.toaddrs=toaddrs
  +        self.fromaddr=fromaddr
  +        self.subject=subject
  +        self.text=text
  +		
  +		# The signature
  +        self.signature=signature
  +		
  +		# Defaults
  +        if not self.signature:
  +            self.signature=default.signature
  +
  +    #
  +    # Serialize for sending
  +    #
  +    def getSerialized(self):
  +        """E-mail"""
  +        # Add the From: and To: headers at the start!
  +        data = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s%s"
  +           	% (	self.fromaddr, 
  +           		string.join(self.toaddrs, ", "),
  +                self.subject,
  +           		self.text,
  +           		default.signature))
  +           		
  +        return data;
  +     
  +#
  +#	Send an e-mail to a list of addresses, from an address, with content.
  +#	Use the specified server/port.
  +#   
  +def mail(toaddrs,fromaddr,message,server='localhost',port=25):
  +    #
  +    # Sanitize e-mail addresses
  +    #
  +    sane_toaddrs=[]
  +    for toaddr in toaddrs:
  +        sane_toaddrs.append(sanitizeAddress(toaddr))
  +        
  +    sane_fromaddr = sanitizeAddress(fromaddr)
  +    
  +    #
  +    # Get servialized data for e-mail bodyparts...
  +    #
  +    if isinstance(message,EmailMessage):
  +        data = message.getSerialized()
  +    else:
  +        data = EmailMessage(toaddrs,fromaddr,'',str(message)).getSerialized()
       
       try:
           #
           # Attach to the SMTP server to send....
           #
  -        server = smtplib.SMTP(server)
  +        server = smtplib.SMTP(server,port)
           server.set_debuglevel(1)
  -        server.sendmail(fromaddr, toaddrs, data)
  +        server.sendmail(sane_fromaddr, sane_toaddrs, data)
           server.quit()
  +        
       except Exception, details:
           log.error("Failed to send e-mail: " + str(details))
           log.error("Server :" + str(server))
  @@ -99,6 +141,14 @@
           log.error("------------------------------------------------------")
           log.error(data)
       
  +def sanitizeAddress(addr):
  +    parts=addr.split('<')
  +    if len(parts) > 1:
  +        addr=parts[1]
  +    parts=addr.split('>')
  +    addr=parts[0]
  +    return addr
  +    
   if __name__=='__main__':
   
     # init logging
  @@ -107,10 +157,12 @@
     #set verbosity to show all messages of severity >= default.logLevel
     log.setLevel(default.logLevel)
      
  -  email=EmailMessage('There','Hi')
  +  # email=EmailMessage('There','Hi')
  +  
  +  # mail([default.email],default.email,email,default.mailserver)
  +  
  +  # mail([ 'ajack@trysybase.com' ],default.email,email,default.mailserver)
     
  -  mail([default.email],default.email,email,default.mailserver)
  +  print sanitizeAddress('Adam Jack <ajack@trysybase.com>')
     
  -  mail([ 'ajack@trysybase.com' ],default.email,email,default.mailserver)
     
  -  
  \ No newline at end of file
  
  
  
  1.31      +4 -3      jakarta-gump/python/gump/conf.py
  
  Index: conf.py
  ===================================================================
  RCS file: /home/cvs/jakarta-gump/python/gump/conf.py,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- conf.py	20 Oct 2003 23:58:37 -0000	1.30
  +++ conf.py	21 Oct 2003 16:15:52 -0000	1.31
  @@ -103,6 +103,7 @@
       email = 'gump@' + gumpfullhost
       mailinglist = 'gump@jakarta.apache.org'
       mailserver = 'mail.apache.org'
  +    mailport = 25
       prefix = '[GUMPY@' + gumphost + ']'
       signature="\r\n--\r\nGump http://jakarta.apache.org/gump\n" \
           + '[' + gumpfullhost + "]\n"
  
  
  

Mime
View raw message