Ticket #365: email2trac.patch

File email2trac.patch, 4.0 KB (added by anonymous, 9 years ago)

patch for email2trac v2.8.8

  • email2trac

    old new  
    15471547        ## Get dissussion API component.
    15481548        #
    15491549        api = self.env[DiscussionApi]
    1550         context = self._create_context(content, subject)
     1550        args = {'forum' : self.id}
     1551        context = self._create_context(api, args, content, subject)
    15511552
    15521553        ## Get forum for new topic.
    15531554        #
    1554         forum = api.get_forum(context, self.id)
     1555        forum = context.forum
    15551556
    15561557        if not forum:
    15571558            self.logger.error("ERROR: Replied forum doesn't exist")
     
    15681569        ## Add topic to DB and commit it.
    15691570        #
    15701571        self._add_topic(api, context, topic)
    1571         self.db.commit()
    15721572
    15731573    def discussion_topic_reply(self, content, subject):
    15741574
     
    15821582        ## Get dissussion API component.
    15831583        #
    15841584        api = self.env[DiscussionApi]
    1585         context = self._create_context(content, subject)
     1585        args = {'topic' : self.id}
     1586        context = self._create_context(api, args, content, subject)
    15861587
    15871588        ## Get replied topic.
    15881589        #
    1589         topic = api.get_topic(context, self.id)
     1590        topic = context.topic
    15901591
    15911592        if not topic:
    15921593            self.logger.error("ERROR: Replied topic doesn't exist")
     
    16031604        ## Add message to DB and commit it.
    16041605        #
    16051606        self._add_message(api, context, message)
    1606         self.db.commit()
    16071607
    16081608    def discussion_message_reply(self, content, subject):
    16091609
     
    16171617        ## Get dissussion API component.
    16181618        #
    16191619        api = self.env[DiscussionApi]
    1620         context = self._create_context(content, subject)
     1620        args = {'message' : self.id}
     1621        context = self._create_context(api, args, content, subject)
    16211622
    16221623        ## Get replied message.
    16231624        #
    1624         message = api.get_message(context, self.id)
     1625        message = context.message
    16251626
    16261627        if not message:
    16271628            self.logger.error("ERROR: Replied message doesn't exist")
     
    16381639        ## Add message to DB and commit it.
    16391640        #
    16401641        self._add_message(api, context, message)
    1641         self.db.commit()
    16421642
    1643     def _create_context(self, content, subject):
     1643    def _create_context(self, api, args, content, subject):
    16441644
    16451645        ## Import modules.
    16461646        #
    16471647        from trac.mimeview import Context
    16481648        from trac.web.api import Request
     1649        from trac.web.session import Session
    16491650        from trac.perm import PermissionCache
    16501651
    16511652        ## TODO: Read server base URL from config.
     
    16711672        req.authname = self.author
    16721673        req.perm = PermissionCache(self.env, self.author)
    16731674        req.locale = None
     1675        req.args = args
     1676        req.session = Session(env, req)
    16741677
    16751678        ## Create and return context.
    16761679        #
    16771680        context = Context.from_request(req)
    16781681        context.realm = 'discussion-email2trac'
    1679         context.cursor = self.db.cursor()
     1682        context.db = self.env.get_db_cnx()
    16801683        context.content = content
    16811684        context.subject = subject
    16821685
     
    16861689        context.content_parts = self.unique_attachment_names(
    16871690          context.content_parts)
    16881691
     1692        api._prepare_context(context)
     1693
    16891694        return context
    16901695
    16911696    def _add_topic(self, api, context, topic):
     
    17031708
    17041709        ## Add a new topic.
    17051710        #
    1706         api.add_topic(context, topic)
     1711        new_topic_id = api.add_topic(context, topic)
    17071712
    17081713        ## Get inserted topic with new ID.
    17091714        #
    1710         topic = api.get_topic_by_time(context, topic['time'])
     1715        topic = api.get_topic(context, new_topic_id)
    17111716
    17121717        ## Attach attachments.
    17131718        #
     
    17341739
    17351740        ## Add message.
    17361741        #
    1737         api.add_message(context, message)
     1742        new_msg_id = api.add_message(context, message)
    17381743
    17391744        ## Get inserted message with new ID.
    17401745        #
    1741         message = api.get_message_by_time(context, message['time'])
     1746        message = api.get_message(context, new_msg_id)
    17421747
    17431748        ## Attach attachments.
    17441749        #