aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces/email
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-18 17:53:20 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-18 17:53:20 -0400
commite190c53b9e1c6d749277ba73074a0db02f72b1c2 (patch)
tree2a4bb3d183bd75c953072391b85bb07a6eed25da /interfaces/email
parent2fffcfc2df9369ce1a4b60225e441a81afd55cb5 (diff)
downloadbugseverywhere-e190c53b9e1c6d749277ba73074a0db02f72b1c2.tar.gz
Added new_with_comment ability to be-handle-mail.
Waiting for a response so you can get the bug ID for your initial comment is silly. Now you don't have to :)
Diffstat (limited to 'interfaces/email')
-rwxr-xr-xinterfaces/email/interactive/be-handle-mail44
-rw-r--r--interfaces/email/interactive/examples/new_with_comment11
2 files changed, 51 insertions, 4 deletions
diff --git a/interfaces/email/interactive/be-handle-mail b/interfaces/email/interactive/be-handle-mail
index b4830ce..490c733 100755
--- a/interfaces/email/interactive/be-handle-mail
+++ b/interfaces/email/interactive/be-handle-mail
@@ -34,6 +34,7 @@ import email.utils
import libbe.cmdutil, libbe.encoding, libbe.utility
import os
import os.path
+import re
import send_pgp_mime
import sys
import time
@@ -102,6 +103,24 @@ class InvalidOption (InvalidExecutionCommand):
InvalidCommand.__init__(self, msg, info, command, message)
self.option = option
+class ID (object):
+ """
+ Sometimes you want to reference the output of a command that
+ hasn't been executed yet. ID is there for situations like
+ > a = Command(msg, "new", ["create a bug"])
+ > b = Command(msg, "comment", [ID(a), "and comment on it"])
+ """
+ def __init__(self, command):
+ self.command = command
+ def extract_id(self):
+ assert self.command.ret == 0, self.command.ret
+ if self.command.command == "new":
+ regexp = re.compile("Created bug with ID (.*)")
+ else:
+ raise NotImplementedError, self.command.command
+ match = regexp.match(self.command.stdout)
+ assert len(match.groups()) == 1, str(match.groups())
+ return match.group(1)
class Command (object):
"""
@@ -130,6 +149,13 @@ class Command (object):
self.err = None
def __str__(self):
return "<command: %s %s>" % (self.command, " ".join(self.args))
+ def normalize_args(self):
+ """
+ Expand any ID placeholders in self.args.
+ """
+ for i,arg in enumerate(self.args):
+ if isinstance(arg, ID):
+ self.args[i] = arg.extract_id()
def run(self):
"""
Attempt to execute the command whose info is given in the dictionary
@@ -137,6 +163,7 @@ class Command (object):
command.
"""
assert self.ret == None, "running %s twice!" % str(self)
+ self.normalize_args()
# set stdin and catch stdout and stderr
if self.stdin != None:
new_stdin = StringIO.StringIO(self.stdin)
@@ -275,16 +302,25 @@ class Message (object):
otherwise returns a list of suggested commands to run.
"""
self.validate_subject()
- tag,command,args = self._split_subject()
- args = list(args)
+ tag,command,arg_tuple = self._split_subject()
+ args = list(arg_tuple)
commands = []
if command == "new":
body,mime_type = list(self._get_bodies_and_mime_types())[0]
- body = body.strip().split("\n", 1)[0] # only take first line
+ lines = body.strip().split("\n", 1)
+ summary = lines[0]
if "--reporter" not in args and "-r" not in args:
args = ["--reporter", self.author_addr()]+args
- args.append(body)
+ args.append(summary)
commands.append(Command(self, command, args))
+ if len(lines) == 2:
+ comment = lines[1]
+ args = ["--author", self.author_addr(),
+ "--alt-id", self.message_id(),
+ "--content-type", mime_type]
+ args.append(ID(commands[0]))
+ args.append("-")
+ commands.append(Command(self, "comment", args, stdin=comment))
elif command == "comment":
if "--author" not in args and "-a" not in args:
args = ["--author", self.author_addr()] + args
diff --git a/interfaces/email/interactive/examples/new_with_comment b/interfaces/email/interactive/examples/new_with_comment
new file mode 100644
index 0000000..8bd50aa
--- /dev/null
+++ b/interfaces/email/interactive/examples/new_with_comment
@@ -0,0 +1,11 @@
+From jdoe@example.com Fri Apr 18 11:18:58 2008
+Message-ID: <abcd@example.com>
+Date: Fri, 18 Apr 2008 12:00:00 +0000
+From: John Doe <jdoe@example.com>
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+Subject: [be-bug] new
+
+Need tests for the email interface.
+
+I think so anyway.