mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 22:14:40 +03:00
move func PartStructure from webhook to queue, so it isn't tracked anymore for apidiff changes
the types in webhook should be subjected to apidiff'ing, this was a shared function. it is better off in package queue. also change the apidiff script so it leaves apidiff/next.txt empty when there aren't any changes. makes it easier to rotate the files after releases where nothing changed (a common occurrence).
This commit is contained in:
@ -8,12 +8,7 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mjl-/mox/message"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
)
|
||||
|
||||
// OutgoingEvent is an activity for an outgoing delivery. Either generated by the
|
||||
@ -145,35 +140,3 @@ type Structure struct {
|
||||
DecodedSize int64 // Size of content after decoding content-transfer-encoding. For text and HTML parts, this can be larger than the data returned since this size includes \r\n line endings.
|
||||
Parts []Structure // Subparts of a multipart message, possibly recursive.
|
||||
}
|
||||
|
||||
// PartStructure returns a Structure for a parsed message part.
|
||||
func PartStructure(log mlog.Log, p *message.Part) (Structure, error) {
|
||||
parts := make([]Structure, len(p.Parts))
|
||||
for i := range p.Parts {
|
||||
var err error
|
||||
parts[i], err = PartStructure(log, &p.Parts[i])
|
||||
if err != nil && !errors.Is(err, message.ErrParamEncoding) {
|
||||
return Structure{}, err
|
||||
}
|
||||
}
|
||||
disp, filename, err := p.DispositionFilename()
|
||||
if err != nil && errors.Is(err, message.ErrParamEncoding) {
|
||||
log.Debugx("parsing disposition/filename", err)
|
||||
} else if err != nil {
|
||||
return Structure{}, err
|
||||
}
|
||||
s := Structure{
|
||||
ContentType: strings.ToLower(p.MediaType + "/" + p.MediaSubType),
|
||||
ContentTypeParams: p.ContentTypeParams,
|
||||
ContentID: p.ContentID,
|
||||
ContentDisposition: strings.ToLower(disp),
|
||||
Filename: filename,
|
||||
DecodedSize: p.DecodedSize,
|
||||
Parts: parts,
|
||||
}
|
||||
// Replace nil map with empty map, for easier to use JSON.
|
||||
if s.ContentTypeParams == nil {
|
||||
s.ContentTypeParams = map[string]string{}
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user