| 1 |
package config |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strings" |
| 6 |
"sync/atomic" |
| 7 |
|
| 8 |
"git.sr.ht/~rjarry/aerc/lib/log" |
| 9 |
"github.com/go-ini/ini" |
| 10 |
) |
| 11 |
|
| 12 |
var convertersConfig atomic.Pointer[map[string]string] |
| 13 |
|
| 14 |
func Converters() map[string]string { |
| 15 |
return *convertersConfig.Load() |
| 16 |
} |
| 17 |
|
| 18 |
func parseConverters(file *ini.File) (map[string]string, error) { |
| 19 |
conf := make(map[string]string) |
| 20 |
converters, err := file.GetSection("multipart-converters") |
| 21 |
if err != nil { |
| 22 |
goto out |
| 23 |
} |
| 24 |
|
| 25 |
for mimeType, command := range converters.KeysHash() { |
| 26 |
mimeType = strings.ToLower(mimeType) |
| 27 |
if mimeType == "text/plain" { |
| 28 |
return nil, fmt.Errorf( |
| 29 |
"multipart-converters: text/plain is reserved") |
| 30 |
} |
| 31 |
if !strings.HasPrefix(mimeType, "text/") { |
| 32 |
return nil, fmt.Errorf( |
| 33 |
"multipart-converters: %q: only text/* MIME types are supported", |
| 34 |
mimeType) |
| 35 |
} |
| 36 |
conf[mimeType] = command |
| 37 |
} |
| 38 |
|
| 39 |
out: |
| 40 |
log.Debugf("aerc.conf: [multipart-converters] %#v", conf) |
| 41 |
return conf, nil |
| 42 |
} |