Debian Codegraph @

classify.go

raw symbols SCIP
1 package reply
2
3 import (
4 re2 "github.com/dlclark/regexp2"
5 )
6
7 const (
8 delimiter = "d"
9 embedded = "b"
10 empty = "e"
11 header = "h"
12 quote = "q"
13 signature = "s"
14 text = "t"
15 )
16
17 func classifyLine(line string) string {
18 if isEmptyLine(line) {
19 return empty
20 }
21
22 if isDelimiter(line) {
23 return delimiter
24 }
25
26 if isSignature(line) {
27 return signature
28 }
29
30 if isEmbeddedEmail(line) {
31 return embedded
32 }
33
34 if isHeader(line) {
35 return header
36 }
37
38 if isQuote(line) {
39 return quote
40 }
41
42 return text
43 }
44
45 func isEmptyLine(line string) bool {
46 ok, _ := re2.MustCompile(`^[[:blank:]]*$`, re2.RE2).MatchString(line)
47 return ok
48 }
49
50 func isQuote(line string) bool {
51 ok, _ := re2.MustCompile(`^[[:blank:]]*>`, re2.RE2).MatchString(line)
52 return ok
53 }
54
55 func isDelimiter(line string) bool {
56 ok, _ := re2.MustCompile(`^[[:blank:]]*([_,=+~#*ᐧ—]+|[\-]{4,}|[\-]+[[:blank:]])[[:blank:]]*$`, re2.RE2).MatchString(line)
57 return ok
58 }
59
60 func isSignature(line string) bool {
61 // remove any markdown links
62 stripped, _ := re2.MustCompile(`\[([^\]]+)\]\([^\)]+\)`, re2.RE2).Replace(line, "$1", 0, -1)
63 for _, r := range patterns["SIGNATURE_REGEXES"] {
64 ok, _ := r.MatchString(stripped)
65 if ok {
66 return true
67 }
68 }
69
70 return false
71 }
72
73 func isHeader(line string) bool {
74 for _, r := range patterns["EMAIL_HEADER_REGEXES"] {
75 ok, _ := r.MatchString(line)
76 if ok {
77 return true
78 }
79 }
80
81 return false
82 }
83
84 func isEmbeddedEmail(line string) bool {
85 for _, r := range patterns["EMBEDDED_REGEXES"] {
86 ok, _ := r.MatchString(line)
87 if ok {
88 return true
89 }
90 }
91
92 return false
93 }