diff options
author | Sebastien Binet <s@sbinet.org> | 2023-12-14 16:20:36 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | de3255182263fb8203e761f483a17533c6a38a05 (patch) | |
tree | 8077f3960d0c0c9f3c23e9b60562bd0cce7bc63b /lib/structure_helpers.go | |
parent | 6f8f3d718c8b0303d16d9bfae2770a031678df59 (diff) | |
download | aerc-de3255182263fb8203e761f483a17533c6a38a05.tar.gz |
lib: introduce FindMIMEPart, adapt Find{Plain,Calendar}text
introduce a general FindMIMEPart function to find a message part with
the given MIME type.
reimplement FindPlaintext and FindCalendartext in terms of this new
FindMIMEPart function.
Signed-off-by: Sebastien Binet <s@sbinet.org>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/structure_helpers.go')
-rw-r--r-- | lib/structure_helpers.go | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/lib/structure_helpers.go b/lib/structure_helpers.go index 0189dc8a..7b5865a2 100644 --- a/lib/structure_helpers.go +++ b/lib/structure_helpers.go @@ -6,14 +6,16 @@ import ( "git.sr.ht/~rjarry/aerc/models" ) -func FindPlaintext(bs *models.BodyStructure, path []int) []int { +// FindMIMEPart finds the first message part with the provided MIME type. +// FindMIMEPart recurses inside multipart containers. +func FindMIMEPart(mime string, bs *models.BodyStructure, path []int) []int { for i, part := range bs.Parts { cur := append(path, i+1) //nolint:gocritic // intentional append to different slice - if part.FullMIMEType() == "text/plain" { + if part.FullMIMEType() == mime { return cur } if strings.ToLower(part.MIMEType) == "multipart" { - if path := FindPlaintext(part, cur); path != nil { + if path := FindMIMEPart(mime, part, cur); path != nil { return path } } @@ -21,19 +23,12 @@ func FindPlaintext(bs *models.BodyStructure, path []int) []int { return nil } +func FindPlaintext(bs *models.BodyStructure, path []int) []int { + return FindMIMEPart("text/plain", bs, path) +} + func FindCalendartext(bs *models.BodyStructure, path []int) []int { - for i, part := range bs.Parts { - cur := append(path, i+1) //nolint:gocritic // intentional append to different slice - if part.FullMIMEType() == "text/calendar" { - return cur - } - if strings.ToLower(part.MIMEType) == "multipart" { - if path := FindCalendartext(part, cur); path != nil { - return path - } - } - } - return nil + return FindMIMEPart("text/calendar", bs, path) } func FindFirstNonMultipart(bs *models.BodyStructure, path []int) []int { |