Code

remove unnecessary brackets
[roundup.git] / roundup / mailgw.py
index fb7b6a2e3ee796065580c80a38e2e8cf8ea7f080..38b3e370e217d66706a6416973b65269649fbc2c 100644 (file)
@@ -86,6 +86,7 @@ from email.Header import decode_header
 from roundup import configuration, hyperdb, date, password, rfc2822, exceptions
 from roundup.mailer import Mailer, MessageSendError
 from roundup.i18n import _
+from roundup.hyperdb import iter_roles
 
 try:
     import pyme, pyme.core, pyme.gpgme
@@ -163,24 +164,6 @@ def gpgh_sigs(sig):
         yield sig
         sig = sig.next
 
-
-def iter_roles(roles):
-    ''' handle the text processing of turning the roles list
-        into something python can use more easily
-    '''
-    for role in [x.lower().strip() for x in roles.split(',')]:
-        yield role
-
-def user_has_role(db, userid, role_list):
-    ''' see if the given user has any roles that appear
-        in the role_list
-    '''
-    for role in iter_roles(db.user.get(userid, 'roles')):
-        if role in iter_roles(role_list):
-            return True
-    return False
-
-
 def check_pgp_sigs(sig, gpgctx, author):
     ''' Theoretically a PGP message can have several signatures. GPGME
         returns status on all signatures in a linked list. Walk that
@@ -263,6 +246,10 @@ class Message(mimetools.Message):
 
     def getheader(self, name, default=None):
         hdr = mimetools.Message.getheader(self, name, default)
+        # TODO are there any other False values possible?
+        # TODO if not hdr: return hdr
+        if hdr is None:
+            return None
         if not hdr:
             return ''
         if hdr:
@@ -586,7 +573,8 @@ class MailGW:
         fcntl.flock(f.fileno(), FCNTL.LOCK_UN)
         return 0
 
-    def do_imap(self, server, user='', password='', mailbox='', ssl=0):
+    def do_imap(self, server, user='', password='', mailbox='', ssl=0,
+            cram=0):
         ''' Do an IMAP connection
         '''
         import getpass, imaplib, socket
@@ -612,7 +600,10 @@ class MailGW:
             return 1
 
         try:
-            server.login(user, password)
+            if cram:
+                server.login_cram_md5(user, password)
+            else:
+                server.login(user, password)
         except imaplib.IMAP4.error, e:
             self.logger.exception('IMAP login failure')
             return 1
@@ -910,7 +901,7 @@ Emails to Roundup trackers must include a Subject: line!
 
         # if we've not found a valid classname prefix then force the
         # scanning to handle there being a leading delimiter
-        title_re = r'(?P<title>%s[^%s]+)'%(
+        title_re = r'(?P<title>%s[^%s]*)'%(
             not matches['classname'] and '.' or '', delim_open)
         m = re.match(title_re, tmpsubject.strip(), re.IGNORECASE)
         if m:
@@ -1239,6 +1230,9 @@ Subject was: "%(subject)s"
         if (title and properties.has_key('title') and not
                 issue_props.has_key('title')):
             issue_props['title'] = title
+        if (nodeid and properties.has_key('title') and not
+                config['MAILGW_SUBJECT_UPDATES_TITLE']):
+            issue_props['title'] = cl.get(nodeid,'title')
 
         #
         # handle message-id and in-reply-to
@@ -1256,8 +1250,8 @@ Subject was: "%(subject)s"
         # or we will skip PGP processing
         def pgp_role():
             if self.instance.config.PGP_ROLES:
-                return user_has_role(self.db, author,
-                    self.instance.config.PGP_ROLES)
+                return self.db.user.has_role(author,
+                    iter_roles(self.instance.config.PGP_ROLES))
             else:
                 return True