mirror of
https://github.com/mjl-/mox.git
synced 2024-12-25 16:03:48 +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:
parent
0871bf5219
commit
69a4995449
7 changed files with 62 additions and 53 deletions
30
apidiff.sh
30
apidiff.sh
|
@ -8,20 +8,30 @@ if ! test -d tmp/mox-$prevversion; then
|
|||
fi
|
||||
(rm -r tmp/apidiff || exit 0)
|
||||
mkdir -p tmp/apidiff/$prevversion tmp/apidiff/next
|
||||
(rm apidiff/next.txt || exit 0)
|
||||
(
|
||||
echo "Below are the incompatible changes between $prevversion and next, per package."
|
||||
echo
|
||||
) >>apidiff/next.txt
|
||||
(rm apidiff/next.txt apidiff/next.txt.new 2>/dev/null || exit 0)
|
||||
for p in $(cat apidiff/packages.txt); do
|
||||
if ! test -d tmp/mox-$prevversion/$p; then
|
||||
continue
|
||||
fi
|
||||
(cd tmp/mox-$prevversion && apidiff -w ../apidiff/$prevversion/$p.api ./$p)
|
||||
apidiff -w tmp/apidiff/next/$p.api ./$p
|
||||
(
|
||||
echo '#' $p
|
||||
apidiff -incompatible tmp/apidiff/$prevversion/$p.api tmp/apidiff/next/$p.api
|
||||
echo
|
||||
) >>apidiff/next.txt
|
||||
apidiff -incompatible tmp/apidiff/$prevversion/$p.api tmp/apidiff/next/$p.api >$p.diff
|
||||
if test -s $p.diff; then
|
||||
(
|
||||
echo '#' $p
|
||||
cat $p.diff
|
||||
echo
|
||||
) >>apidiff/next.txt.new
|
||||
fi
|
||||
rm $p.diff
|
||||
done
|
||||
if test -s apidiff/next.txt.new; then
|
||||
(
|
||||
echo "Below are the incompatible changes between $prevversion and next, per package."
|
||||
echo
|
||||
cat apidiff/next.txt.new
|
||||
) >apidiff/next.txt
|
||||
rm apidiff/next.txt.new
|
||||
else
|
||||
mv apidiff/next.txt.new apidiff/next.txt
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Below are the incompatible changes between v0.0.13 and next, per package.
|
||||
|
||||
# webhook
|
||||
- PartStructure: removed
|
||||
|
|
@ -3,6 +3,7 @@ package queue
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
|
@ -796,7 +797,7 @@ func Incoming(ctx context.Context, log mlog.Log, acc *store.Account, messageID s
|
|||
|
||||
log.Debug("composing webhook for incoming message")
|
||||
|
||||
structure, err := webhook.PartStructure(log, &part)
|
||||
structure, err := PartStructure(log, &part)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing part structure: %v", err)
|
||||
}
|
||||
|
@ -912,6 +913,38 @@ func Incoming(ctx context.Context, log mlog.Log, acc *store.Account, messageID s
|
|||
return nil
|
||||
}
|
||||
|
||||
// PartStructure returns a webhook.Structure for a parsed message part.
|
||||
func PartStructure(log mlog.Log, p *message.Part) (webhook.Structure, error) {
|
||||
parts := make([]webhook.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 webhook.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 webhook.Structure{}, err
|
||||
}
|
||||
s := webhook.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
|
||||
}
|
||||
|
||||
func isAutomated(h textproto.MIMEHeader) bool {
|
||||
l := []string{"List-Id", "List-Unsubscribe", "List-Unsubscribe-Post", "Precedence"}
|
||||
for _, k := range l {
|
||||
|
|
|
@ -82,7 +82,7 @@ func TestHookIncoming(t *testing.T) {
|
|||
tcheck(t, err, "decode incoming webhook")
|
||||
in.Meta.Received = in.Meta.Received.Local() // For TZ UTC.
|
||||
|
||||
structure, err := webhook.PartStructure(pkglog, &part)
|
||||
structure, err := PartStructure(pkglog, &part)
|
||||
tcheck(t, err, "part structure")
|
||||
|
||||
expIncoming := webhook.Incoming{
|
||||
|
|
|
@ -44,7 +44,6 @@ import (
|
|||
"github.com/mjl-/mox/store"
|
||||
"github.com/mjl-/mox/webapi"
|
||||
"github.com/mjl-/mox/webauth"
|
||||
"github.com/mjl-/mox/webhook"
|
||||
"github.com/mjl-/mox/webops"
|
||||
)
|
||||
|
||||
|
@ -1263,7 +1262,7 @@ func (s server) MessageGet(ctx context.Context, req webapi.MessageGetRequest) (r
|
|||
MailboxName: mb.Name,
|
||||
}
|
||||
|
||||
structure, err := webhook.PartStructure(log, &p)
|
||||
structure, err := queue.PartStructure(log, &p)
|
||||
xcheckf(err, "parsing structure")
|
||||
|
||||
result := webapi.MessageGetResult{
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/mjl-/mox/queue"
|
||||
"github.com/mjl-/mox/store"
|
||||
"github.com/mjl-/mox/webapi"
|
||||
"github.com/mjl-/mox/webhook"
|
||||
)
|
||||
|
||||
var ctxbg = context.Background()
|
||||
|
@ -418,7 +417,7 @@ func TestServer(t *testing.T) {
|
|||
tcheckf(t, err, "reading raw message")
|
||||
part, err := message.EnsurePart(log.Logger, true, bytes.NewReader(b.Bytes()), int64(b.Len()))
|
||||
tcheckf(t, err, "parsing raw message")
|
||||
structure, err := webhook.PartStructure(log, &part)
|
||||
structure, err := queue.PartStructure(log, &part)
|
||||
tcheckf(t, err, "part structure")
|
||||
tcompare(t, structure, msgRes.Structure)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue