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:
Mechiel Lukkien
2024-12-07 13:57:07 +01:00
parent 0871bf5219
commit 69a4995449
7 changed files with 62 additions and 53 deletions

View File

@ -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
}