Skip to content

Commit

Permalink
replace ToASCII with mime base64
Browse files Browse the repository at this point in the history
it fixes non ascii attach names such as cyrillic
  • Loading branch information
Alexfilus committed Jun 26, 2021
1 parent 8b689f5 commit d9fb44a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 95 deletions.
5 changes: 3 additions & 2 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ func (p *Part) setupMIMEHeaders() transferEncoding {
if p.ContentID != "" {
p.Header.Set(hnContentID, coding.ToIDHeader(p.ContentID))
}
fileName := mime.BEncoding.Encode("utf-8", p.FileName)
if p.ContentType != "" {
// Build content type header.
param := make(map[string]string)
for k, v := range p.ContentTypeParams {
param[k] = v
}
setParamValue(param, hpCharset, p.Charset)
setParamValue(param, hpName, stringutil.ToASCII(p.FileName))
setParamValue(param, hpName, fileName)
setParamValue(param, hpBoundary, p.Boundary)
if mt := mime.FormatMediaType(p.ContentType, param); mt != "" {
p.ContentType = mt
Expand All @@ -114,7 +115,7 @@ func (p *Part) setupMIMEHeaders() transferEncoding {
if p.Disposition != "" {
// Build disposition header.
param := make(map[string]string)
setParamValue(param, hpFilename, stringutil.ToASCII(p.FileName))
setParamValue(param, hpFilename, fileName)
if !p.FileModDate.IsZero() {
setParamValue(param, hpModDate, p.FileModDate.Format(time.RFC822))
}
Expand Down
45 changes: 0 additions & 45 deletions internal/stringutil/unicode.go

This file was deleted.

48 changes: 0 additions & 48 deletions internal/stringutil/unicode_test.go

This file was deleted.

0 comments on commit d9fb44a

Please sign in to comment.