aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/action.go
blob: 0b5103fc76016448adbc3052e95373860989431e (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
// Copyright 2023 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package email

import "github.com/google/syzkaller/dashboard/dashapi"

type OldThreadInfo struct {
	ThreadType dashapi.DiscussionType
}

type MessageAction string

const (
	ActionIgnore    MessageAction = "ignore"
	ActionAppend    MessageAction = "append"
	ActionNewThread MessageAction = "new-thread"
)

func NewMessageAction(msg *Email, msgType dashapi.DiscussionType, oldThread *OldThreadInfo) MessageAction {
	if msg.InReplyTo == "" {
		// If it's not a reply, always start a new thread.
		return ActionNewThread
	}
	if oldThread != nil {
		// Sometimes patches are sent as replies to the bug report.
		// In this case, we'd better report it as a new discussion.
		if msgType == dashapi.DiscussionPatch &&
			msgType != oldThread.ThreadType {
			return ActionNewThread
		}
		// Otherwise just append the message.
		return ActionAppend
	}
	if msg.OwnEmail {
		// Most likely it's a bot's public reply to a non-public
		// patch testing request. Ignore it.
		return ActionIgnore
	}
	// If the original discussion is not recorded anywhere, it means
	// we were likely only mentioned in some further discussion.
	// Remember then only the sub-thread visible to us.
	return ActionNewThread
}