在 Trac 中通过电子邮件 POP3 打开工单

Open ticket via email POP3 in Trac

我正在寻找一种让人们通过电子邮件打开 Trac 票证的方法。

到目前为止我找到的唯一解决方案是 email2trac | https://oss.trac.surfsara.nl/email2trac/wiki 此解决方案的问题是我不想安装和设置邮件服务器。我想要一个侵入性较小的解决方案。

我在考虑一个 cron 脚本,它通过解析内容从 POP3 帐户和 open/update 票证下载消息。

这可能吗?

I was thinking about a cron script that download messages from a POP3 account and open/update tickets by parsing the content. Is this possible ?

我认为这是可能的。当然,一旦您从 POP3 帐户获得数据,您就可以迭代它并使用 Trac API.

适当地迭代 create/update 票证

对于数据检索步骤,您可以创建一个带有 Component which implements the IAdminCommandProvider interface. How you actually retrieve and parse the data is an implementation detail for you to decide, but you could probably use the email/poplib modules and follow some of the parsing structure from email2trac 的新插件。

一些未经测试的样板可以帮助您入门...

from trac.admin import IAdminCommandProvider
from trac.core import Component, implements
from trac.ticket import Ticket

def EmailToTicket(Component):
    implements(IAdminCommandProvider)

    def get_admin_commands(self):
        yield ('emailtoticket retrieve',
               'Retrieve emails from a mail server.'
               None, self._do_retrieve_email)

    def _do_retrieve_email(self):
        # TODO - log into the mail server, then parse data.
        # It would be nice to have a tuple of dictionaries, 
        # with keys like id, summary, description etc

        # iterate over the data and create/update tickets
        for email in emails:
            if 'id' in email: # assuming email is a dictionary
                self._update_ticket(email)
            else:
                self._create_ticket(email)

    def _update_ticket(self, data):
        ticket = Ticket(self.env, data[id])
        for field, value in data.iteritems():
            ticket[field] = value
        ticket.save_changes(author, comment, when)

    def _create_ticket(self, data):
        ticket = Ticket(self.env)
        for field, value in data.iteritems():
            ticket[field] = value
        ticket.insert()

然后您可以让 Cron 选项卡通过 TracAdmin 执行此命令(频率由您决定 - 下面的示例每分钟运行一次)

* * * * * trac-admin /path/to/projenv emailtoticket retrieve

想了解更多插件开发,你应该阅读this Trac wiki page