Ticket #287: email2trac-r584_fullblog.patch
File email2trac-r584_fullblog.patch, 5.3 KB (added by thomas.moschny@…, 12 years ago) |
---|
-
email2trac.py.in
1324 1324 fd = open(path, 'rb') 1325 1325 if self.system == 'discussion': 1326 1326 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,)) 1327 1329 else: 1328 1330 s = 'Attach %s to ticket %d' %(filename, self.id) 1329 1331 self.print_unicode(s) … … 1357 1359 1358 1360 ########## Fullblog functions ################################################# 1359 1361 1360 def blog(self, msg, subject, id ):1362 def blog(self, msg, subject, id, params): 1361 1363 """ 1362 1364 The blog create/update function 1363 1365 """ … … 1371 1373 blog = FullBlogCore(self.env) 1372 1374 req = Mock(authname='anonymous', perm=MockPerm(), args={}) 1373 1375 1374 if id: 1376 ## parameters from the subject 1377 # 1378 params = self.str_to_dict((params or '').lstrip('?')) 1375 1379 1376 ## update blog 1377 # 1378 comment = BlogComment(self.env, id) 1379 comment.author = self.author 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: 1380 1404 1381 message_parts = self.get_message_parts(msg) 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)) 1382 1409 comment.comment = self.get_body_text(message_parts) 1410 comment.time = dt 1383 1411 1384 1412 if self.parameters.dry_run: 1385 1413 self.logger.info('DRY-RUN: not adding comment for blog entry "%s"' % id) 1386 1414 return 1387 blog.create_comment(req, comment)1415 warnings = blog.create_comment(req, comment) 1388 1416 1389 1417 else: 1390 ## create blog1418 ## create or update blog entry 1391 1419 # 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 1420 post.author = self.properties.get('author', params.get('author', self.author)) 1421 post.categories = self.properties.get('categories', params.get('categories', '')) 1398 1422 post.title = subject.strip() 1399 1400 message_parts = self.get_message_parts(msg) 1423 post.publish_time = dt 1401 1424 post.body = self.get_body_text(message_parts) 1402 1425 1403 1426 if self.parameters.dry_run: 1404 1427 self.logger.info('DRY-RUN: not creating blog entry "%s"' % post.title) 1405 1428 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) 1407 1439 1408 1440 1409 1441 ########## Discussion functions ############################################## … … 1695 1727 if self.get_config('components', 'tracfullblog.*') in ['enabled']: 1696 1728 self.logger.debug('Trac BLOG support enabled') 1697 1729 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*))''' 1699 1731 1700 1732 1701 1733 ## Check if DiscussionPlugin is installed … … 1739 1771 if blog_enabled: 1740 1772 if result.group('blog'): 1741 1773 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')) 1743 1775 1744 1776 if discussion_enabled: 1745 1777 ## New topic. … … 2146 2178 2147 2179 att = attachment.Attachment(self.env, 'discussion', 'ticket/%s' % (self.id,), filename) 2148 2180 2181 elif self.system == 'blog': 2182 2183 att = attachment.Attachment(self.env, 'blog', '%s' % (self.id,), filename) 2184 2149 2185 else: 2150 2186 2151 2187 att = attachment.Attachment(self.env, 'ticket', self.id, filename)