Ticket #116: email2trac_blog.patch

File email2trac_blog.patch, 2.2 KB (added by lucas.eisenzimmer@…, 15 years ago)

Patch for adding blog creating/updating capabilities

Line 
1*** email2trac_orig.py  2008-10-13 11:29:33.000000000 +0200
2--- email2trac.py       2009-01-19 10:21:44.000000000 +0100
3***************
4*** 839,851 ****
5                else:
6                        self.notification = 0
7 
8!               # Must we update existing tickets
9!               #
10!               if self.TICKET_UPDATE > 0:
11!                       if self.ticket_update(m, spam_msg):
12!                               return True
13 
14!               self.new_ticket(m, spam_msg)
15 
16        def strip_signature(self, text):
17                """
18--- 839,894 ----
19                else:
20                        self.notification = 0
21 
22!               # Find out if this is a ticket or a blog
23!               if not m['Subject']:
24!                       return False
25!               else:
26!                       subject  = self.email_to_unicode(m['Subject'])         
27!
28!               TICKET_RE=re.compile(r"""
29!                                       (?P<blog>blog:(?P<blog_id>\w*))
30!                                       |(?P<ticket>\#(?P<ticket_id>[0-9]*):)
31!                                       """, re.VERBOSE)
32!               
33!               result =  TICKET_RE.search(subject)
34!
35!       
36!               print "action:"
37!               if result:
38!                       if result.group('blog'):
39!                               if result.group('blog_id'):
40!                                       # update blog
41!                                       blog = FullBlogCore(self.env)
42!
43!                                       comment = BlogComment(self.env, result.group('blog_id'))
44!                                       comment.author = self.author
45!                                       comment.comment = self.get_body_text(m)
46!
47!                                       blog.create_comment('', comment)
48!
49!                               else:
50!                                       # create blog
51!                                       blog = FullBlogCore(self.env)
52!                                       import time
53!
54!                                       post = BlogPost(self.env, time.strftime("%Y%m%d%H%M%S", time.gmtime()))
55!                                       post.author = self.author
56!                                       post.title = self.email_to_unicode(m['Subject'])
57!                                       post.body = self.get_body_text(m)
58 
59!                                       blog.create_post('', post, 'Ein Autor', u'Ein Blog-Text', False)
60!
61!                       else:
62!                               if result.group('ticket_id') and self.TICKET_UPDATE:
63!                                       # update ticket
64!                                       self.ticket_update(m, spam_msg)
65!                                       print "ticket update"
66!                               else:
67!                                       # create ticket
68!                                       self.new_ticket(m, spam_msg)
69!                                       print "ticket create"
70!               else:
71!                       print "nothing"
72 
73        def strip_signature(self, text):
74                """
75***************
76*** 1266,1271 ****
77--- 1309,1319 ----
78                        from trac.web.href import Href
79                        from trac import config as trac_config
80                        from trac import util
81+
82+                       # blog enhancements
83+                       from tracfullblog.core import FullBlogCore
84+                       from tracfullblog.model import BlogPost, BlogComment
85+
86                        #
87                        # return  util.text.to_unicode(str)
88                        #