diff options
author | Reto Brunner <reto@labrat.space> | 2020-06-19 17:58:08 +0200 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-07-27 09:19:27 +0200 |
commit | c574a838fa89bf46bf7188442f400b206b04df95 (patch) | |
tree | 89c40ba4a7f5f5a2e67ca8fb225f7d5d3eb319ad /worker | |
parent | 494bd674a98bc9f2889acad0fda3ff4c77c641b5 (diff) | |
download | aerc-c574a838fa89bf46bf7188442f400b206b04df95.tar.gz |
Remove hard coded bodystruct path everywhere
Aerc usually used the path []int{1} if it didn't know what the proper path is. However this only works for multipart messages and breaks if it isn't one. This patch removes all the hard coding and extracts the necessary helpers to lib.
Diffstat (limited to 'worker')
-rw-r--r-- | worker/lib/parse.go | 10 | ||||
-rw-r--r-- | worker/maildir/search.go | 8 |
2 files changed, 11 insertions, 7 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go index ded7a83..a14a6d3 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -21,8 +21,9 @@ var dateRe = regexp.MustCompile(`(((Mon|Tue|Wed|Thu|Fri|Sat|Sun))[,]?\s[0-9]{1,2 `([0-9]{4})\s([0-9]{2}):([0-9]{2})(:([0-9]{2}))?\s([\+|\-][0-9]{4})\s?`) func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) { - if len(index) < 1 { - return nil, fmt.Errorf("no part to read") + if len(index) == 0 { + // non multipart, simply return everything + return bufReader(e) } if mpr := e.MultipartReader(); mpr != nil { idx := 0 @@ -41,10 +42,7 @@ func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) { } } } - if index[0] != 1 { - return nil, fmt.Errorf("cannont return non-first part of non-multipart") - } - return bufReader(e) + return nil, fmt.Errorf("FetchEntityPartReader: unexpected code reached") } //TODO: the UI doesn't seem to like readers which aren't buffers diff --git a/worker/maildir/search.go b/worker/maildir/search.go index 005f6fa..ad3a45f 100644 --- a/worker/maildir/search.go +++ b/worker/maildir/search.go @@ -10,6 +10,7 @@ import ( "git.sr.ht/~sircmpwn/getopt" + "git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/models" ) @@ -138,7 +139,12 @@ func (w *Worker) searchKey(key uint32, criteria *searchCriteria, } if parts&BODY > 0 { // TODO: select which part to search, maybe look for text/plain - reader, err := message.NewBodyPartReader([]int{1}) + mi, err := message.MessageInfo() + if err != nil { + return false, err + } + path := lib.FindFirstNonMultipart(mi.BodyStructure, nil) + reader, err := message.NewBodyPartReader(path) if err != nil { return false, err } |