feat: keep reading past a mobile footer below a bare opt-out command, accept punctuation after a pronoun note, and refuse temporal words as name lines

This commit is contained in:
Matthew Meszaros
2026-11-03 14:11:48 +01:00
parent 1cc7e8bce5
commit cf1ffb01d7
2 changed files with 10 additions and 6 deletions
+7 -6
View File
@@ -45,7 +45,8 @@ var proseWords = wordSet("i", "me", "my", "we", "us", "our", "you", "your", "it"
"do", "would", "could", "can", "will", "if", "so", "just", "actually", "love", "like", "want", "let", "lets",
"interested", "please", "call", "send", "tell", "talk", "great", "sounds", "meeting", "demo", "price", "pricing",
"yes", "no", "sure", "ok", "okay", "maybe", "later", "today", "tomorrow", "monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday", "noon", "the", "a", "an", "at", "of", "and", "for", "to", "in", "on", "with",
"friday", "saturday", "sunday", "noon", "next", "week", "month", "year", "soon", "now", "asap", "time", "here", "there",
"the", "a", "an", "at", "of", "and", "for", "to", "in", "on", "with",
"ich", "wir", "sie", "ist", "aber", "nicht")
// commandPronouns is a pronoun note after a name: "(she/her)".
@@ -93,17 +94,17 @@ func isOptOutCommand(body string) bool {
}
// signatureOnly is a closed whitelist of what may follow the command: blank
// lines, sign-off lines, name lines, and a "--" delimiter or a whole mobile
// footer, below which nothing is read. Any other line means it is not an
// lines, whole mobile footers, sign-off lines, name lines, and a "--"
// delimiter, below which nothing is read. Any other line means it is not an
// opt-out.
func signatureOnly(lines []string) bool {
n := 0
for _, raw := range lines {
ln := strings.TrimSpace(raw)
switch {
case ln == "":
case ln == "" || commandFooters[commandText(ln)]:
continue
case ln == "--" || commandFooters[commandText(ln)]:
case ln == "--":
return true
}
if n++; n > commandMaxLines {
@@ -131,7 +132,7 @@ func ledByName(raw string, phrases map[string]bool) bool {
// nameLine is one to three capitalized name words or initials, optionally
// followed by a pronoun note; a trailing comma or period is allowed.
func nameLine(tokens []string) bool {
if len(tokens) > 0 && commandPronouns.MatchString(tokens[len(tokens)-1]) {
if len(tokens) > 0 && commandPronouns.MatchString(strings.TrimRight(tokens[len(tokens)-1], ",.")) {
tokens = tokens[:len(tokens)-1]
}
if len(tokens) == 0 || len(tokens) > 3 {
@@ -37,6 +37,7 @@ func TestIsOptOutCommandReply(t *testing.T) {
"german footer": "Stopp\n\nVon meinem iPhone gesendet",
"notice": "Remove\n\n--\nCONFIDENTIALITY NOTICE: The contents of this message are private.",
"pronouns": "STOP\nJane Doe (she/her)",
"pronouns comma": "STOP\nJane Doe (she/her),",
"sign-off name": "Stop\n\nBest regards, J. Smith",
}
for name, body := range optOut {
@@ -82,6 +83,8 @@ func TestIsOptOutCommandReply(t *testing.T) {
"title-cased": "Stop\nMeeting at Noon",
"too many lines": "Stop\nJohn\nJane\nJim\nJoe\nJack",
"footer prefix": "Stop\nSent from my iPhone because I want a demo",
"after footer": "Stop\nSent from my iPhone\nActually I'd like a demo",
"next week": "Stop\nNext Week",
}
for name, body := range notOptOut {
if IsOptOut("Re: Stop", body) {