Changeset 585 for trunk/email2trac.py.in


Ignore:
Timestamp:
02/06/12 12:04:50 (11 years ago)
Author:
bas
Message:

added blog patch from Thomas Moschny, closes #287,#235,#175

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r582 r585  
    13251325            if self.system == 'discussion':
    13261326                att = attachment.Attachment(self.env, 'discussion', 'topic/%s' % (self.id,))
     1327            elif self.system == 'blog':
     1328                att = attachment.Attachment(self.env, 'blog', '%s' % (self.id,))
    13271329            else:
    13281330                s = 'Attach %s to ticket %d' %(filename, self.id)
     
    13581360########## Fullblog functions  #################################################
    13591361
    1360     def blog(self, msg, subject, id):
     1362    def blog(self, msg, subject, id, params):
    13611363        """
    13621364        The blog create/update function
     
    13721374        req = Mock(authname='anonymous', perm=MockPerm(), args={})
    13731375
    1374         if id:
    1375 
    1376             ## update blog
    1377             #
    1378             comment = BlogComment(self.env, id)
    1379             comment.author = self.author
    1380 
    1381             message_parts = self.get_message_parts(msg)
     1376        ## parameters from the subject
     1377        #
     1378        params = self.str_to_dict((params or '').lstrip('?'))
     1379
     1380        ## preferably get the time from the email date header, or else
     1381        #  use current date and time
     1382        date = email.Utils.parsedate_tz(msg.get('date'))
     1383        if date:
     1384            dt = util.datefmt.to_datetime(email.Utils.mktime_tz(date), util.datefmt.utc)
     1385        else:
     1386            self.logger.warn("No valid date header found")
     1387            dt = util.datefmt.to_datetime(None, util.datefmt.utc)
     1388
     1389        ## blog entry affected
     1390        #
     1391        self.id = id or util.datefmt.format_datetime(dt, "%Y%m%d%H%M%S", util.datefmt.utc)
     1392
     1393        ## check wether a blog post exists
     1394        #
     1395        post = BlogPost(self.env, self.id)
     1396        force_update = self.properties.get('update', params.get('update'))
     1397
     1398        ## message parts
     1399        #
     1400        message_parts = self.get_message_parts(msg)
     1401        message_parts = self.unique_attachment_names(message_parts)
     1402
     1403        if post.get_versions() and not force_update:
     1404
     1405            ## add comment to blog entry
     1406            #
     1407            comment = BlogComment(self.env, self.id)
     1408            comment.author = self.properties.get('author', params.get('author', self.author))
    13821409            comment.comment = self.get_body_text(message_parts)
     1410            comment.time = dt
    13831411
    13841412            if self.parameters.dry_run:
    13851413                self.logger.info('DRY-RUN: not adding comment for blog entry "%s"' % id)
    13861414                return
    1387             blog.create_comment(req, comment)
     1415            warnings = blog.create_comment(req, comment)
    13881416
    13891417        else:
    1390             ## create blog
    1391             #
    1392             import time
    1393             post = BlogPost(self.env, 'blog_'+time.strftime("%Y%m%d%H%M%S", time.gmtime()))
    1394 
    1395             #post = BlogPost(self.env, blog._get_default_postname(self.env))
    1396            
    1397             post.author = self.author
     1418            ## create or update blog entry
     1419            #
     1420            post.author = self.properties.get('author', params.get('author', self.author))
     1421            post.categories = self.properties.get('categories', params.get('categories', ''))
    13981422            post.title = subject.strip()
    1399 
    1400             message_parts = self.get_message_parts(msg)
     1423            post.publish_time = dt
    14011424            post.body = self.get_body_text(message_parts)
    14021425           
     
    14041427                self.logger.info('DRY-RUN: not creating blog entry "%s"' % post.title)
    14051428                return
    1406             blog.create_post(req, post, self.author, u'Created by email2trac', False)
     1429            warnings = blog.create_post(req, post, self.author, u'Created by email2trac', False)
     1430
     1431        ## check for problems
     1432        #
     1433        if warnings:
     1434            raise TracError(', '.join('blog:%s:%s' % (w[0], w[1]) for w in warnings))
     1435       
     1436        ## all seems well, attach attachments
     1437        #
     1438        self.attach_attachments(message_parts)
    14071439
    14081440
     
    16961728            self.logger.debug('Trac BLOG support enabled')
    16971729            blog_enabled = True
    1698             blog_regex = '''|(?P<blog>blog:(?P<blog_id>\w*))'''
     1730            blog_regex = '''|(?P<blog>blog(?P<blog_params>[?][^:]*)?:(?P<blog_id>\S*))'''
    16991731
    17001732
     
    17401772                if result.group('blog'):
    17411773                    self.system = 'blog'
    1742                     self.blog(m, subject[result.end('blog'):], result.group('blog_id'))
     1774                    self.blog(m, subject[result.end('blog'):], result.group('blog_id'), result.group('blog_params'))
    17431775
    17441776            if discussion_enabled:
     
    21462178
    21472179                att = attachment.Attachment(self.env, 'discussion', 'ticket/%s' % (self.id,), filename)
     2180
     2181            elif self.system == 'blog':
     2182
     2183                att = attachment.Attachment(self.env, 'blog', '%s' % (self.id,), filename)
    21482184
    21492185            else:
Note: See TracChangeset for help on using the changeset viewer.