1

I'm searching for a way to let people open Trac ticket by email.

The only solution I've found so far is email2trac | https://oss.trac.surfsara.nl/email2trac/wiki The problem with this solution is that I don't want to install & setup a mailserver. I would like a less invasive solution.

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 ?

Hpatoio
  • 1,785
  • 1
  • 15
  • 22
  • 1
    Some useful discussion about this recently on the trac-users mailing list: [here](https://groups.google.com/d/msg/trac-users/Ujsf2WuG7Yc/l2Df0i-oj7AJ) and [here](https://groups.google.com/d/msg/trac-users/l9AQ57aCvgY/Fv5LmvtWoXoJ). – RjOllos Feb 11 '15 at 20:03

1 Answers1

0

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 ?

I think it would be possible yes. Certainly once you had the data from a POP3 account, you could iterate over it and create/update tickets as appropriate with the Trac API.

For the data retrieval step, you could create a new plugin, with a 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.

For some untested boilerplate to get you started...

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()

You could then have Cron tab execute this command via TracAdmin (the frequency is up to you - the below example runs every minute)

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

The find out more about plugin development, you should read this Trac wiki page.

dannymilsom
  • 2,386
  • 1
  • 18
  • 19
  • Your description is ok, but I was looking for something ready to install. I'm going to accept you question because it gave me few good inside. – Hpatoio Feb 04 '15 at 09:29