aerc/lib/structure_helpers.go
Koni Marti e92573c5d7 lib: fix tests for 386 platforms
Tests in lib/structure_helpers_test.go pass on amd64 platforms but fail
on 386 platforms. This can be reproduced with the following steps:

1. Create a Dockerfile in aerc's source folder:

	FROM i386/alpine:edge

	RUN apk update && apk upgrade
	RUN apk add --no-cache go make scdoc

	WORKDIR aerc

	COPY . .

	RUN make

	CMD make tests

2. Build the image:
	$ docker buildx build --platform=linux/386 -t test .

3. Run the image:
	$ docker run --rm --platform=linux/386 -it test

The test in lib/structure_helpers_test.go will fail.

If the same above steps are done with this patch applied, all tests pass.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:15:26 +02:00

84 lines
1.8 KiB
Go

package lib
import (
"strings"
"git.sr.ht/~rjarry/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 FindCalendartext(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) == "calendar" {
return cur
}
if strings.ToLower(part.MIMEType) == "multipart" {
if path := FindCalendartext(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 cur
} else if mimetype == "multipart" {
if path := FindFirstNonMultipart(part, cur); path != nil {
return path
}
}
}
return nil
}
func FindAllNonMultipart(bs *models.BodyStructure, path []int, pathlist [][]int) [][]int {
for i, part := range bs.Parts {
cur := append(path, i+1)
mimetype := strings.ToLower(part.MIMEType)
if mimetype != "multipart" {
tmp := make([]int, len(cur))
copy(tmp, cur)
pathlist = append(pathlist, tmp)
} else if mimetype == "multipart" {
if sub := FindAllNonMultipart(part, cur, nil); len(sub) > 0 {
pathlist = append(pathlist, sub...)
}
}
}
return pathlist
}
func EqualParts(a []int, b []int) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}