about summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/structure_helpers.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/structure_helpers.go b/lib/structure_helpers.go
new file mode 100644
index 0000000..21159a2
--- /dev/null
+++ b/lib/structure_helpers.go
@@ -0,0 +1,38 @@
+package lib
+
+import (
+	"strings"
+
+	"git.sr.ht/~sircmpwn/aerc/models"
+)
+
+func FindPlaintext(bs *models.BodyStructure, path []int) []int {
+	for i, part := range bs.Parts {
+		cur := append(path, i+1)
+		if strings.ToLower(part.MIMEType) == "text" &&
+			strings.ToLower(part.MIMESubType) == "plain" {
+			return cur
+		}
+		if strings.ToLower(part.MIMEType) == "multipart" {
+			if path := FindPlaintext(part, cur); path != nil {
+				return path
+			}
+		}
+	}
+	return nil
+}
+
+func FindFirstNonMultipart(bs *models.BodyStructure, path []int) []int {
+	for i, part := range bs.Parts {
+		cur := append(path, i+1)
+		mimetype := strings.ToLower(part.MIMEType)
+		if mimetype != "multipart" {
+			return path
+		} else if mimetype == "multipart" {
+			if path := FindFirstNonMultipart(part, cur); path != nil {
+				return path
+			}
+		}
+	}
+	return nil
+}