diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-02-19 19:24:55 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-02-19 19:39:03 +0200 |
commit | 257bfcb994a8cd823376157cea4347ec515b3fad (patch) | |
tree | 3286587bbeb3ad2fcfb0280b76d696bf401f400b | |
parent | 79d126e6f956b75fc0a8acfffba80f8457bf879d (diff) | |
download | distix-257bfcb994a8cd823376157cea4347ec515b3fad.tar.gz |
Add support to import from a Maildir
-rw-r--r-- | distixlib/plugins/import_mail_plugin.py | 24 | ||||
-rw-r--r-- | yarns/080-import-mail.yarn | 17 | ||||
-rw-r--r-- | yarns/900-implements.yarn | 15 |
3 files changed, 56 insertions, 0 deletions
diff --git a/distixlib/plugins/import_mail_plugin.py b/distixlib/plugins/import_mail_plugin.py index 13bb5b0..6f5af05 100644 --- a/distixlib/plugins/import_mail_plugin.py +++ b/distixlib/plugins/import_mail_plugin.py @@ -43,6 +43,9 @@ class ImportMailPlugin(cliapp.Plugin): self.app.add_subcommand( 'import-mbox', self.import_mbox, arg_synopsis='REPO FILE') + self.app.add_subcommand( + 'import-maildir', self.import_maildir, arg_synopsis='REPO MAILDIR') + def import_mail(self, args): repo_dirname, mail_filename = self._parse_command_line(args) msg = self._read_mail_message(mail_filename) @@ -169,6 +172,27 @@ class ImportMailPlugin(cliapp.Plugin): if filenames: repo.commit_changes(filenames, self.commit_msg) + def import_maildir(self, args): + repo_dirname, maildirname = self._parse_command_line(args) + maildir = mailbox.Maildir(maildirname, factory=None) + repo = distixlib.Repository(repo_dirname) + repo.require_clean_working_tree() + ticket_store = repo.open_ticket_store(distixlib.tickets_dir_name) + all_tickets = ticket_store.get_tickets() + cache = _MessageIdCache() + filenames = [] + if self.app.settings['quiet']: + progress = _QuietProgressReporter() + else: + progress = _MboxProgressReporter(len(maildir)) + with contextlib.closing(maildir), progress: + for msg in maildir: + progress.next_msg() + filenames += self._import_msg_to_ticket_store( + repo, ticket_store, all_tickets, msg, cache) + if filenames: + repo.commit_changes(filenames, self.commit_msg) + class _MessageIdCache(object): diff --git a/yarns/080-import-mail.yarn b/yarns/080-import-mail.yarn index 7c1e24c..d458deb 100644 --- a/yarns/080-import-mail.yarn +++ b/yarns/080-import-mail.yarn @@ -63,6 +63,23 @@ Next, import an mbox. THEN attempt succeeded AND output matches "^[0-9a-f]{32} 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 "^[0-9a-f]{32} 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 diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index 221ba9e..d5ca4bf 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -94,6 +94,21 @@ content. printf "$MATCH_2" > "$DATADIR/$MATCH_1" +Maildir creation +---------------- + +We need to create a maildir with mails in it. + + IMPLEMENTS GIVEN maildir (\S+) containing a mail with subject "(.+)" + dirname="$DATADIR/$MATCH_1" + mkdir -p "$dirname/new" "$dirname/cur" "$dirname/tmp" + cat <<EOF > "$dirname/new/message" + From: user@example.com + Subject: $MATCH_2 + + Message body goes here. + EOF + File tests ----------- |