Ticket #365: email2trac.patch
File email2trac.patch, 4.0 KB (added by anonymous, 9 years ago) |
---|
-
email2trac
old new 1547 1547 ## Get dissussion API component. 1548 1548 # 1549 1549 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) 1551 1552 1552 1553 ## Get forum for new topic. 1553 1554 # 1554 forum = api.get_forum(context, self.id)1555 forum = context.forum 1555 1556 1556 1557 if not forum: 1557 1558 self.logger.error("ERROR: Replied forum doesn't exist") … … 1568 1569 ## Add topic to DB and commit it. 1569 1570 # 1570 1571 self._add_topic(api, context, topic) 1571 self.db.commit()1572 1572 1573 1573 def discussion_topic_reply(self, content, subject): 1574 1574 … … 1582 1582 ## Get dissussion API component. 1583 1583 # 1584 1584 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) 1586 1587 1587 1588 ## Get replied topic. 1588 1589 # 1589 topic = api.get_topic(context, self.id)1590 topic = context.topic 1590 1591 1591 1592 if not topic: 1592 1593 self.logger.error("ERROR: Replied topic doesn't exist") … … 1603 1604 ## Add message to DB and commit it. 1604 1605 # 1605 1606 self._add_message(api, context, message) 1606 self.db.commit()1607 1607 1608 1608 def discussion_message_reply(self, content, subject): 1609 1609 … … 1617 1617 ## Get dissussion API component. 1618 1618 # 1619 1619 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) 1621 1622 1622 1623 ## Get replied message. 1623 1624 # 1624 message = api.get_message(context, self.id)1625 message = context.message 1625 1626 1626 1627 if not message: 1627 1628 self.logger.error("ERROR: Replied message doesn't exist") … … 1638 1639 ## Add message to DB and commit it. 1639 1640 # 1640 1641 self._add_message(api, context, message) 1641 self.db.commit()1642 1642 1643 def _create_context(self, content, subject):1643 def _create_context(self, api, args, content, subject): 1644 1644 1645 1645 ## Import modules. 1646 1646 # 1647 1647 from trac.mimeview import Context 1648 1648 from trac.web.api import Request 1649 from trac.web.session import Session 1649 1650 from trac.perm import PermissionCache 1650 1651 1651 1652 ## TODO: Read server base URL from config. … … 1671 1672 req.authname = self.author 1672 1673 req.perm = PermissionCache(self.env, self.author) 1673 1674 req.locale = None 1675 req.args = args 1676 req.session = Session(env, req) 1674 1677 1675 1678 ## Create and return context. 1676 1679 # 1677 1680 context = Context.from_request(req) 1678 1681 context.realm = 'discussion-email2trac' 1679 context. cursor = self.db.cursor()1682 context.db = self.env.get_db_cnx() 1680 1683 context.content = content 1681 1684 context.subject = subject 1682 1685 … … 1686 1689 context.content_parts = self.unique_attachment_names( 1687 1690 context.content_parts) 1688 1691 1692 api._prepare_context(context) 1693 1689 1694 return context 1690 1695 1691 1696 def _add_topic(self, api, context, topic): … … 1703 1708 1704 1709 ## Add a new topic. 1705 1710 # 1706 api.add_topic(context, topic)1711 new_topic_id = api.add_topic(context, topic) 1707 1712 1708 1713 ## Get inserted topic with new ID. 1709 1714 # 1710 topic = api.get_topic _by_time(context, topic['time'])1715 topic = api.get_topic(context, new_topic_id) 1711 1716 1712 1717 ## Attach attachments. 1713 1718 # … … 1734 1739 1735 1740 ## Add message. 1736 1741 # 1737 api.add_message(context, message)1742 new_msg_id = api.add_message(context, message) 1738 1743 1739 1744 ## Get inserted message with new ID. 1740 1745 # 1741 message = api.get_message _by_time(context, message['time'])1746 message = api.get_message(context, new_msg_id) 1742 1747 1743 1748 ## Attach attachments. 1744 1749 #