Make part encoding checks case insensitive

commands/msgview/save and commands/msgview/pipe now use case
insensitive comparisons to determine if the part is encoded as base64
or quoted-printable.
This commit is contained in:
Réouven Assouly 2019-06-15 12:28:03 +02:00 committed by Drew DeVault
parent 1b7790553e
commit dfe114b643
2 changed files with 7 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"mime/quotedprintable" "mime/quotedprintable"
"strings"
"git.sr.ht/~sircmpwn/aerc/commands" "git.sr.ht/~sircmpwn/aerc/commands"
"git.sr.ht/~sircmpwn/aerc/widgets" "git.sr.ht/~sircmpwn/aerc/widgets"
@ -25,10 +26,9 @@ func Pipe(aerc *widgets.Aerc, args []string) error {
p.Store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) { p.Store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
// email parts are encoded as 7bit (plaintext), quoted-printable, or base64 // email parts are encoded as 7bit (plaintext), quoted-printable, or base64
switch p.Part.Encoding { if strings.EqualFold(p.Part.Encoding, "base64") {
case "base64":
reader = base64.NewDecoder(base64.StdEncoding, reader) reader = base64.NewDecoder(base64.StdEncoding, reader)
case "quoted-printable": } else if strings.EqualFold(p.Part.Encoding, "quoted-printable") {
reader = quotedprintable.NewReader(reader) reader = quotedprintable.NewReader(reader)
} }

View File

@ -7,6 +7,7 @@ import (
"mime/quotedprintable" "mime/quotedprintable"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"git.sr.ht/~sircmpwn/aerc/widgets" "git.sr.ht/~sircmpwn/aerc/widgets"
@ -43,10 +44,10 @@ func Save(aerc *widgets.Aerc, args []string) error {
p.Store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) { p.Store.FetchBodyPart(p.Msg.Uid, p.Index, func(reader io.Reader) {
// email parts are encoded as 7bit (plaintext), quoted-printable, or base64 // email parts are encoded as 7bit (plaintext), quoted-printable, or base64
switch p.Part.Encoding {
case "base64": if strings.EqualFold(p.Part.Encoding, "base64") {
reader = base64.NewDecoder(base64.StdEncoding, reader) reader = base64.NewDecoder(base64.StdEncoding, reader)
case "quoted-printable": } else if strings.EqualFold(p.Part.Encoding, "quoted-printable") {
reader = quotedprintable.NewReader(reader) reader = quotedprintable.NewReader(reader)
} }