mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +03:00
move checking whether a message needs smtputf8 (has utf8 in any of the header sections) to package message
This commit is contained in:
@ -21,6 +21,7 @@ import (
|
||||
"net/textproto"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/text/encoding/ianaindex"
|
||||
|
||||
@ -598,6 +599,38 @@ func (p *Part) IsDSN() bool {
|
||||
(p.Parts[1].MediaSubType == "DELIVERY-STATUS" || p.Parts[1].MediaSubType == "GLOBAL-DELIVERY-STATUS")
|
||||
}
|
||||
|
||||
func hasNonASCII(r io.Reader) (bool, error) {
|
||||
br := bufio.NewReader(r)
|
||||
for {
|
||||
b, err := br.ReadByte()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if b > unicode.MaxASCII {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// NeedsSMTPUTF8 returns whether the part needs the SMTPUTF8 extension to be
|
||||
// transported, due to non-ascii in message headers.
|
||||
func (p *Part) NeedsSMTPUTF8() (bool, error) {
|
||||
if has, err := hasNonASCII(p.HeaderReader()); err != nil {
|
||||
return false, fmt.Errorf("reading header: %w", err)
|
||||
} else if has {
|
||||
return true, nil
|
||||
}
|
||||
for _, pp := range p.Parts {
|
||||
if has, err := pp.NeedsSMTPUTF8(); err != nil || has {
|
||||
return has, err
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
var ErrParamEncoding = errors.New("bad header parameter encoding")
|
||||
|
||||
// DispositionFilename tries to parse the disposition header and the "filename"
|
||||
|
Reference in New Issue
Block a user