IncomingEmail mail = getIncomingEmail();
string issueKey = matchText(mail.subject, "[A-Z][A-Z]+-[0-9]+"); // find an issue key in the subject
if(isNull(issueKey)) {
// if no issue key found, create a new issue
string [] fields = {};
fields += {"reporter", currentUserKey()};
fields += {"assignee", getUserByEmail(mail.cc[0]).key};
string newIssue = createIssue("TEST", "", "Task", mail.subject, "Minor", mail.body, {}, "", "", 0, fields);
attachAllFilesFromEmail(newIssue);
%newIssue%.watchers = getUserKeysFromEmails(mail.cc);
} else {
// if issue key found in subject, add a comment
addComment(issueKey, currentUserKey(), mail.body);
}