Changeset 309


Ignore:
Timestamp:
02/02/10 16:39:19 (14 years ago)
Author:
bas
Message:

email2trac.py.in:

  • added inline properties patch. To set ticket fields within an email, eg:

@owner: bas

Will set the owner of the ticket to bas, closes #171

  • Display a warning if it is a blog message and the plugin is not installed, see #175


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r305 r309  
    227227                        self.STRIP_QUOTES = 0
    228228
     229                self.properties = dict()
     230                if parameters.has_key('inline_properties'):
     231                        self.INLINE_PROPERTIES = int(parameters['inline_properties'])
     232                else:
     233                        self.INLINE_PROPERTIES = 0
     234
    229235                if parameters.has_key('use_textwrap'):
    230236                        self.USE_TEXTWRAP = int(parameters['use_textwrap'])
     
    529535
    530536        def save_email_for_debug(self, message, tempfile=False):
     537
    531538                if tempfile:
    532539                        import tempfile
     
    544551                except OSError:
    545552                        pass
     553
     554                message_parts = self.get_message_parts(message)
     555                message_parts = self.unique_attachment_names(message_parts)
     556                body_text = self.body_text(message_parts)
     557                self.debug_body(body_text, True)
     558                self.debug_attachments(message_parts)
    546559
    547560        def str_to_dict(self, s):
     
    725738                                tkt['resolution'] = ''
    726739
    727                 # Must we update some ticket fields properties
     740                # Must we update some ticket fields properties via subjectline
    728741                #
    729742                if update_fields:
     
    733746                message_parts = self.unique_attachment_names(message_parts)
    734747
     748                # Must we update some ticket fields properties via body_text
     749                #
     750                if self.properties:
     751                                self.update_ticket_fields(tkt, self.properties)
     752
    735753                if self.EMAIL_HEADER:
    736754                        message_parts.insert(0, self.email_header_txt(m))
     
    738756                body_text = self.body_text(message_parts)
    739757
    740                 if body_text.strip() or update_fields:
     758                if body_text.strip() or update_fields or self.properties:
    741759                        if self.DRY_RUN:
    742760                                print 'DRY_RUN: tkt.save_changes(self.author, body_text, ticket_change_number) ', self.author, cnum
     
    845863                        head = self.email_header_txt(msg)
    846864
    847                                        
    848865                message_parts = self.get_message_parts(msg)
     866
     867                # Must we update some ticket fields properties via body_text
     868                #
     869                if self.properties:
     870                                self.update_ticket_fields(tkt, self.properties)
     871
    849872                if self.DEBUG:
    850873                        print 'TD: self.get_message_parts ',
     
    947970                        blog.create_post(req, post, self.author, u'Created by email2trac', False)
    948971
     972        def save_message_for_debug(self):
     973                """
     974                Save the messages. So we can use it for debug purposes
     975                """
     976               
    949977
    950978        def parse(self, fp):
     
    962990
    963991                if self.DEBUG > 1:        # save the entire e-mail message text
    964                         message_parts = self.get_message_parts(m)
    965                         message_parts = self.unique_attachment_names(message_parts)
    966992                        self.save_email_for_debug(m, True)
    967                         body_text = self.body_text(message_parts)
    968                         self.debug_body(body_text, True)
    969                         self.debug_attachments(message_parts)
    970993
    971994                self.db = self.env.get_db_cnx()
     
    10301053
    10311054                if result:
    1032                         if result.group('blog') and blog_enabled:
    1033                                 self.blog(result.group('blog_id'))
     1055                        if result.group('blog'):
     1056                                if blog_enabled:
     1057                                        self.blog(result.group('blog_id'))
     1058                                else:
     1059                                        if self.DEBUG:
     1060                                                print "Fullblog plugin is not installed"
     1061                                                return
    10341062
    10351063                        # update ticket + fields
     
    11141142                return ('\n'.join(body))
    11151143
     1144        def inline_properties(self, text):
     1145                """
     1146                Parse text if we use inline keywords to set ticket fields
     1147                """
     1148                if self.DEBUG:
     1149                        print 'TD: inline_properties function'
     1150
     1151                properties = dict()
     1152                body = list()
     1153
     1154                INLINE_EXP = re.compile('\s*[@]\s*([a-zA-Z]+)\s*:(.*)$')
     1155
     1156                for line in text.splitlines():
     1157                        match = INLINE_EXP.match(line)
     1158                        if match:
     1159                                print match.groups()
     1160                                keyword, value = match.groups()
     1161                                self.properties[keyword] = value.strip()
     1162                        else:
     1163                                body.append(line)
     1164                               
     1165                return '\n'.join(body)
     1166
     1167
    11161168        def wrap_text(self, text, replace_whitespace = False):
    11171169                """
     
    11441196                body parts are returned as strings, attachments are returned as tuples of (filename, Message object)
    11451197                """
    1146                 message_parts = []
     1198                message_parts = list()
    11471199       
    11481200                ALTERNATIVE_MULTIPART = False
     
    12121264                                if self.STRIP_QUOTES:
    12131265                                        body_text = self.strip_quotes(body_text)
     1266
     1267                                if self.INLINE_PROPERTIES:
     1268                                        body_text = self.inline_properties(body_text)
    12141269
    12151270                                if self.USE_TEXTWRAP:
Note: See TracChangeset for help on using the changeset viewer.