Changeset 260


Ignore:
Timestamp:
03/25/09 14:37:24 (15 years ago)
Author:
bas
Message:

email2trac.py.in:

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r259 r260  
    77     Reported by: hju att jochenkuhl dot de
    88     Author by: Bas van der Vlies
     9
     10   * added FullBlogPlugin support. So we can update/create the blogs via email, #116
     11     Authors: Bas van der Vlies & lucas dot eisenzimmer at t-systems-mms dot com
    912
    10132009-01-30
  • trunk/debian/changelog

    r259 r260  
    66
    77 * implemented workflow for tickets that are reopend, closes #70
    8    Reported by: hju att jochenkuhl dot de
     8   Reported by: hju at jochenkuhl dot de
    99   Author by: Bas van der Vlies
     10
     11 * added FullBlogPlugin support. So we can update/create the blogs
     12   via email, #116
     13   Authors: Bas van der Vlies & lucas dot eisenzimmer at t-systems-mms dot com
    1014
    1115 -- root <root@subtrac2.rc.sara.nl>  Tue, 24 Mar 2009 15:26:08 +0100
  • trunk/email2trac.py.in

    r258 r260  
    600600                                        print  'ticket_field\t %s = %s' %(field,  ticket[field])
    601601                                       
    602         def ticket_update(self, m, spam):
     602        def ticket_update(self, m, id, spam):
    603603                """
    604604                If the current email is a reply to an existing ticket, this function
     
    607607                """
    608608                if self.DEBUG:
    609                         print "TD: ticket_update"
     609                        print "TD: ticket_update: %s" %id
    610610
    611611                if not m['Subject']:
     
    614614                        subject  = self.email_to_unicode(m['Subject'])
    615615
    616                 # [hic] #1529: Re: LRZ
    617                 # [hic] #1529?owner=bas,priority=medium: Re: LRZ
    618                 #
    619                 TICKET_RE = re.compile(r"""
    620                                         (?P<ticketnr>[#][0-9]+:)
    621                                         |(?P<ticketnr_fields>[#][\d]+\?.*?:)
    622                                         """, re.VERBOSE)
    623 
    624                 result =  TICKET_RE.search(subject)
    625                 if not result:
    626                         return False
    627 
    628616                # Must we update ticket fields
    629617                #
    630618                update_fields = dict()
    631619                try:
    632                         nr, keywords = string.split(result.group('ticketnr_fields'), '?')
     620                        id, keywords = string.split(id, '?')
    633621                        update_fields = self.str_to_dict(keywords)
    634622
    635623                        # Strip '#'
    636624                        #
    637                         self.id = int(nr[1:])
    638 
    639                 except AttributeError:
     625                        self.id = int(id[1:])
     626
     627                except ValueError:
    640628                        # Strip '#' and ':'
    641629                        #
    642                         nr = result.group('ticketnr')
    643                         self.id = int(nr[1:-1])
     630                        self.id = int(id[1:-1])
    644631
    645632
     
    856843                        self.notify(tkt, True)
    857844
     845
     846        def blog(self, id):
     847                """
     848                The blog create/update function
     849                """
     850                # import the modules
     851                #
     852                from tracfullblog.core import FullBlogCore
     853                from tracfullblog.model import BlogPost, BlogCommen
     854
     855                # instantiate blog core
     856                blog = FullBlogCore(self.env)
     857                req = ''
     858               
     859                if id:
     860
     861                        # update blog
     862                        #
     863                        comment = BlogComment(self.env, result.group('blog_id'))
     864                        comment.author = self.author
     865                        comment.comment = self.get_body_text(m)
     866                        blog.create_comment(req, comment)
     867
     868                else:
     869                        # create blog
     870                        #
     871                        import time
     872                        post = BlogPost(self.env, 'blog_'+time.strftime("%Y%m%d%H%M%S", time.gmtime()))
     873
     874                        #post = BlogPost(self.env, blog._get_default_postname(self.env))
     875                       
     876                        post.author = self.author
     877                        post.title = self.email_to_unicode(m['Subject'])
     878                        post.body = self.get_body_text(m)
     879                       
     880                        blog.create_post(req, post, self.author, u'Created by email2trac', False)
     881
     882
    858883        def parse(self, fp):
    859884                global m
     
    911936                        self.notification = 0
    912937
    913                 # Must we update existing tickets
    914                 #
    915                 if self.TICKET_UPDATE > 0:
    916                         if self.ticket_update(m, spam_msg):
    917                                 return True
    918 
    919                 self.new_ticket(m, spam_msg)
     938                print self.get_config('components', 'tracext.google.ads.*')
     939
     940                # Check if  FullBlogPlugin is installed
     941                #
     942                blog_enabled = None
     943                if self.get_config('components', 'tracfullblog.*') in ['enabled']:
     944                        blog_enabled = True
     945                       
     946                # Find out if this is a ticket or a blog
     947                if not m['Subject']:
     948                        return False
     949                else:
     950                        subject  = self.email_to_unicode(m['Subject'])         
     951
     952                #
     953                # [hic] #1529: Re: LRZ
     954                # [hic] #1529?owner=bas,priority=medium: Re: LRZ
     955                #
     956                TICKET_RE = re.compile(r"""
     957                        (?P<blog>blog:(?P<blog_id>\w*))
     958                        |(?P<ticket_id>[#][\d]+:)
     959                        |(?P<ticket_fields>[#][\d]+\?.*?:)
     960                        """, re.VERBOSE)
     961
     962                result =  TICKET_RE.search(subject)
     963
     964                if result:
     965                        if result.group('blog') and blog_enabled:
     966                                self.blog(result.group('blog_id'))
     967
     968                        # update ticket + fields
     969                        #
     970                        if result.group('ticket_fields') and self.TICKET_UPDATE:
     971                                self.ticket_update(m, result.group('ticket_fields'), spam_msg)
     972
     973                        # Update ticket
     974                        #
     975                        elif result.group('ticket_id') and self.TICKET_UPDATE:
     976                                self.ticket_update(m, result.group('ticket_id'), spam_msg)
     977
     978                # Create ticket
     979                #
     980                else:
     981                        self.new_ticket(m, spam_msg)
    920982
    921983        def strip_signature(self, text):
     
    14831545                        from trac import config as trac_config
    14841546                        from trac import util
     1547
     1548
    14851549                        #
    14861550                        # return  util.text.to_unicode(str)
Note: See TracChangeset for help on using the changeset viewer.