~sircmpwn/aerc

ref: 282dc44aa67773b608cace43587ecd2c140689a4 aerc/worker/imap/search.go -rw-r--r-- 623 bytes View raw
282dc44aJeffas Check the subject line for lowercase re 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package imap

import (
	"git.sr.ht/~sircmpwn/getopt"
	"github.com/emersion/go-imap"
)

func parseSearch(args []string) (*imap.SearchCriteria, error) {
	criteria := imap.NewSearchCriteria()

	opts, optind, err := getopt.Getopts(args, "ruH:")
	if err != nil {
		return nil, err
	}
	for _, opt := range opts {
		switch opt.Option {
		case 'r':
			criteria.WithFlags = append(criteria.WithFlags, imap.SeenFlag)
		case 'u':
			criteria.WithoutFlags = append(criteria.WithoutFlags, imap.SeenFlag)
		case 'H':
			// TODO
		}
	}
	for _, arg := range args[optind:] {
		criteria.Header.Add("Subject", arg)
	}
	return criteria, nil
}