msgpart: factorize mime type and filename construction
Reduce code duplication. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
a4b80bcc8b
commit
9bd2e0c84f
8 changed files with 30 additions and 28 deletions
models
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/emersion/go-message/mail"
|
||||
|
@ -175,6 +176,21 @@ func (bs *BodyStructure) PartAtIndex(index []int) (*BodyStructure, error) {
|
|||
return bs.Parts[curidx].PartAtIndex(rest)
|
||||
}
|
||||
|
||||
func (bs *BodyStructure) FullMIMEType() string {
|
||||
mime := fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType)
|
||||
return strings.ToLower(mime)
|
||||
}
|
||||
|
||||
func (bs *BodyStructure) FileName() string {
|
||||
if filename, ok := bs.DispositionParams["filename"]; ok {
|
||||
return filename
|
||||
} else if filename, ok := bs.Params["name"]; ok {
|
||||
// workaround golang not supporting RFC2231 besides ASCII and UTF8
|
||||
return filename
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Envelope struct {
|
||||
Date time.Time
|
||||
Subject string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue