summaryrefslogtreecommitdiff
path: root/yarns/080-import-mail.yarn
blob: 5fff4210c9460fa6c9f990e21d59900c9cef98fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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: <two@example.com>\nReferences: <one@example.com>\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: <two@example.com>\nReferences: <one@example.com>\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: <two@example.com>\nReferences: <one@example.com>\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 "."