aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/parser.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-03-22 10:47:53 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-03-22 12:00:50 +0100
commit9ad9ef29caa52714dd5faff167e4b61643e40a7e (patch)
treee67bad1ef453035a5f2f507f313ebfa4f7eb7ab9 /pkg/email/parser.go
parent4d9d915eae5984d25a3e7f557106935546a6563f (diff)
dashboard/app: slightly relax command parsing
Users have misspelled test: multiple times. Accept commands without the colon.
Diffstat (limited to 'pkg/email/parser.go')
-rw-r--r--pkg/email/parser.go61
1 files changed, 51 insertions, 10 deletions
diff --git a/pkg/email/parser.go b/pkg/email/parser.go
index ce652c5da..2566ae1d5 100644
--- a/pkg/email/parser.go
+++ b/pkg/email/parser.go
@@ -25,12 +25,28 @@ type Email struct {
Subject string
From string
Cc []string
- Body string // text/plain part
- Patch string // attached patch, if any
- Command string // command to bot (#syz is stripped)
- CommandArgs string // arguments for the command
+ Body string // text/plain part
+ Patch string // attached patch, if any
+ Command Command // command to bot
+ CommandArgs string // arguments for the command
}
+type Command int
+
+const (
+ CmdUnknown Command = iota
+ CmdNone
+ CmdUpstream
+ CmdFix
+ CmdDup
+ CmdUnDup
+ CmdTest
+ CmdInvalid
+ CmdUnCC
+
+ cmdTest5
+)
+
const commandPrefix = "#syz "
var groupsLinkRe = regexp.MustCompile("\nTo view this discussion on the web visit" +
@@ -87,7 +103,8 @@ func Parse(r io.Reader, ownEmails []string) (*Email, error) {
return nil, err
}
bodyStr := string(body)
- patch, cmd, cmdArgs := "", "", ""
+ cmd := CmdNone
+ patch, cmdArgs := "", ""
if !fromMe {
for _, a := range attachments {
_, patch, _ = ParsePatch(string(a))
@@ -176,9 +193,10 @@ func CanonicalEmail(email string) string {
// extractCommand extracts command to syzbot from email body.
// Commands are of the following form:
// ^#syz cmd args...
-func extractCommand(body []byte) (cmd, args string) {
+func extractCommand(body []byte) (cmd Command, args string) {
cmdPos := bytes.Index(append([]byte{'\n'}, body...), []byte("\n"+commandPrefix))
if cmdPos == -1 {
+ cmd = CmdNone
return
}
cmdPos += len(commandPrefix)
@@ -195,18 +213,41 @@ func extractCommand(body []byte) (cmd, args string) {
if cmdEnd1 := bytes.IndexByte(body[cmdPos:], ' '); cmdEnd1 != -1 && cmdEnd1 < cmdEnd {
cmdEnd = cmdEnd1
}
- cmd = string(body[cmdPos : cmdPos+cmdEnd])
+ switch string(body[cmdPos : cmdPos+cmdEnd]) {
+ default:
+ cmd = CmdUnknown
+ case "":
+ cmd = CmdNone
+ case "upstream":
+ cmd = CmdUpstream
+ case "fix", "fix:":
+ cmd = CmdFix
+ case "dup", "dup:":
+ cmd = CmdDup
+ case "undup":
+ cmd = CmdUnDup
+ case "test", "test:":
+ cmd = CmdTest
+ case "invalid":
+ cmd = CmdInvalid
+ case "uncc", "uncc:":
+ cmd = CmdUnCC
+ case "test_5_arg_cmd":
+ cmd = cmdTest5
+ }
// Some email clients split text emails at 80 columns are the transformation is irrevesible.
// We try hard to restore what was there before.
// For "test:" command we know that there must be 2 tokens without spaces.
// For "fix:"/"dup:" we need a whole non-empty line of text.
switch cmd {
- case "test:":
+ case CmdTest:
args = extractArgsTokens(body[cmdPos+cmdEnd:], 2)
- case "test_5_arg_cmd":
+ case cmdTest5:
args = extractArgsTokens(body[cmdPos+cmdEnd:], 5)
- case "fix:", "dup:":
+ case CmdFix, CmdDup:
args = extractArgsLine(body[cmdPos+cmdEnd:])
+ case CmdUnknown:
+ args = extractArgsLine(body[cmdPos:])
}
return
}