Importing e-mails ================= Distix needs to import e-mails. E-mails be fed to it one-by-one by a mail transport agent, or in mail folders by the user. In the latter, especially, distix needs to be careful about handling mails that have already been imported once. Let's start with the simple case of importing a single e-mail. Mail transport agents will feed the e-mail to distix via a pipe, so distix will read the e-mail from its standard input. SCENARIO import one email WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MAIL1 containing "From: foo@example.com\nSubject: bar\n\nyo\n" WHEN user attempts to run distix import-mail REPO MAIL1 THEN attempt succeeded AND everything in REPO is committed to git WHEN user changes working directory to REPO AND user attempts to run distix list THEN attempt succeeded AND output matches "^bar$" Import one email twice. It should result in the mail existing only once in the ticket. SCENARIO import one email twice WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MAIL1 containing "From: foo@example.com\nSubject: bar\n\nyo\n" WHEN user attempts to run distix import-mail REPO MAIL1 THEN attempt succeeded AND everything in REPO is committed to git AND repository REPO has 1 ticket AND repository REPO has one copy of message in MAIL1 WHEN user attempts to run distix import-mail REPO MAIL1 THEN attempt succeeded AND everything in REPO is committed to git AND repository REPO has 1 ticket AND repository REPO has one copy of message in MAIL1 Next, import an mbox. SCENARIO import mbox WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MBOX containing "From foo@example.com Mon Mar 19 09:46:32 2012\nFrom: foo@example.com\nSubject: bar\n\nyo\n" WHEN user attempts to run distix import-mbox REPO MBOX THEN attempt succeeded AND everything in REPO is committed to git WHEN user changes working directory to REPO AND user attempts to run distix list THEN attempt succeeded AND output matches "^bar$" Next, import a Maildir. SCENARIO import Maildir WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN maildir MAILDIR containing a mail with subject "bar" WHEN user attempts to run distix import-maildir REPO MAILDIR THEN attempt succeeded AND everything in REPO is committed to git WHEN user changes working directory to REPO AND user attempts to run distix list THEN attempt succeeded AND output matches "^bar$" When importing e-mails, distix needs to automatically recognise when they belong existing tickets: if the new mail refers to a mail in an existing ticket, put the new mail to that ticket and don't open a new one. The referring is done with the `In-Reply-To` and `References` headers. SCENARIO import mails for the same ticket WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MSG1 containing "From: foo@example.com\nSubject: bar\nMessage-Id: one@example.com\n\nyo\n" WHEN user attempts to run distix import-mail REPO MSG1 THEN attempt succeeded GIVEN file MSG2 containing "From: foo2@example.com\nSubject: blerf\nMessage-Id: \nReferences: \n\nyo\n" WHEN user attempts to run distix import-mail REPO MSG2 THEN attempt succeeded WHEN user changes working directory to REPO AND user attempts to run distix list THEN attempt succeeded AND output matches "^bar$" AND output doesn't match "^blerf$" Ditto, but for mailboxes. SCENARIO import mailboxes with mails for the same ticket WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MBOX1 containing "From foo@example.com Mon Mar 19 09:46:32 2012\nFrom: foo@example.com\nSubject: bar\nMessage-Id: one@example.com\n\nyo\n" WHEN user attempts to run distix import-mbox REPO MBOX1 THEN attempt succeeded GIVEN file MBOX2 containing "From foo@example.com Mon Mar 19 09:46:32 2012\nFrom: foo2@example.com\nSubject: blerf\nMessage-Id: \nReferences: \n\nyo\n" WHEN user attempts to run distix import-mbox REPO MBOX2 THEN attempt succeeded WHEN user changes working directory to REPO AND user attempts to run distix list THEN attempt succeeded AND output matches "^bar$" AND output doesn't match "^blerf$" When users send new mails to tickets that are already closed, the "status" key needs to get updated. In other words, a ticket that has the metadata "status=closed" should lose that. SCENARIO ticket gets re-opened upon importing new mail WHEN user attempts to run distix init REPO THEN attempt succeeded GIVEN file MBOX1 containing "From foo@example.com Mon Mar 19 09:46:32 2012\nFrom: foo@example.com\nSubject: bar\nMessage-Id: one@example.com\n\nyo\n" WHEN user attempts to run distix import-mbox REPO MBOX1 THEN attempt succeeded GIVEN file MBOX2 containing "From foo@example.com Mon Mar 19 09:46:32 2012\nFrom: foo2@example.com\nSubject: blerf\nMessage-Id: \nReferences: \n\nyo\n" WHEN user sets all tickets in REPO to status=closed AND user attempts to run distix import-mbox REPO MBOX2 status= THEN attempt succeeded WHEN user changes working directory to REPO AND user attempts to run distix list status!=closed THEN attempt succeeded AND output matches "."