forward,recall: fix charsets in part attachment
Fix charset to UTF-8 in part attachments. The forward and recall commands fetch message parts with the go-message package which decodes to UTF-8. Hence, we should set the charset of the part attachment to utf-8 and not just copying over the one from the original message. Reported-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
d2f4f12f66
commit
c6561d32a8
3 changed files with 23 additions and 4 deletions
|
@ -198,12 +198,13 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
}
|
}
|
||||||
store.FetchBodyPart(msg.Uid, p, func(reader io.Reader) {
|
store.FetchBodyPart(msg.Uid, p, func(reader io.Reader) {
|
||||||
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
|
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
|
||||||
name, ok := bs.Params["name"]
|
params := lib.SetUtf8Charset(bs.Params)
|
||||||
|
name, ok := params["name"]
|
||||||
if !ok {
|
if !ok {
|
||||||
name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
|
name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
|
||||||
}
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
composer.AddPartAttachment(name, mime, bs.Params, reader)
|
composer.AddPartAttachment(name, mime, params, reader)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,12 +204,13 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
}
|
}
|
||||||
msg.FetchBodyPart(p, func(reader io.Reader) {
|
msg.FetchBodyPart(p, func(reader io.Reader) {
|
||||||
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
|
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
|
||||||
name, ok := bs.Params["name"]
|
params := lib.SetUtf8Charset(bs.Params)
|
||||||
|
name, ok := params["name"]
|
||||||
if !ok {
|
if !ok {
|
||||||
name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
|
name = fmt.Sprintf("%s_%s_%d", bs.MIMEType, bs.MIMESubType, rand.Uint64())
|
||||||
}
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
composer.AddPartAttachment(name, mime, bs.Params, reader)
|
composer.AddPartAttachment(name, mime, params, reader)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.sr.ht/~rjarry/aerc/logging"
|
||||||
"github.com/emersion/go-message/mail"
|
"github.com/emersion/go-message/mail"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -134,3 +136,18 @@ func (pa *PartAttachment) WriteTo(w *mail.Writer) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetUtf8Charset sets the charset in a params map to UTF-8.
|
||||||
|
func SetUtf8Charset(origParams map[string]string) map[string]string {
|
||||||
|
params := make(map[string]string)
|
||||||
|
for k, v := range origParams {
|
||||||
|
switch strings.ToLower(k) {
|
||||||
|
case "charset":
|
||||||
|
logging.Infof("substitute charset %s with utf-8", v)
|
||||||
|
params[k] = "utf-8"
|
||||||
|
default:
|
||||||
|
params[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue