diff options
Diffstat (limited to 'lib/structure_helpers.go')
-rw-r--r-- | lib/structure_helpers.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/structure_helpers.go b/lib/structure_helpers.go index ac6950af..1b4a6e68 100644 --- a/lib/structure_helpers.go +++ b/lib/structure_helpers.go @@ -52,3 +52,30 @@ func FindFirstNonMultipart(bs *models.BodyStructure, path []int) []int { } 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" { + pathlist = append(pathlist, cur) + } 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 +} |