mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
GODT-1737: Improve logging during import
This commit is contained in:
@ -197,7 +197,7 @@ func (im *imapMailbox) labelExistingMessage(msg storeMessageProvider) error { //
|
||||
}
|
||||
|
||||
func (im *imapMailbox) importMessage(kr *crypto.KeyRing, hdr textproto.Header, body []byte, imapFlags []string, date time.Time) error { //nolint:funlen
|
||||
im.log.Info("Importing external message")
|
||||
im.log.WithField("size", len(body)).Info("Importing external message")
|
||||
|
||||
var (
|
||||
seen bool
|
||||
@ -251,6 +251,7 @@ func (im *imapMailbox) importMessage(kr *crypto.KeyRing, hdr textproto.Header, b
|
||||
|
||||
messageID, err := targetMailbox.ImportMessage(enc, seen, labelIDs, flags, time)
|
||||
if err != nil {
|
||||
log.WithField("enc.size", len(enc)).Error("Import failed")
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +90,14 @@ type ImportMsgRes struct {
|
||||
|
||||
// Import imports messages to the user's account.
|
||||
func (c *client) Import(ctx context.Context, reqs ImportMsgReqs) ([]*ImportMsgRes, error) {
|
||||
if len(reqs) == 0 {
|
||||
return nil, errors.New("missing import requests")
|
||||
}
|
||||
|
||||
if len(reqs) > MaxImportMessageRequestLength {
|
||||
log.
|
||||
WithField("count", len(reqs)).
|
||||
Warn("Importing too many messages at once.")
|
||||
return nil, errors.New("request is too long")
|
||||
}
|
||||
|
||||
@ -98,6 +105,10 @@ func (c *client) Import(ctx context.Context, reqs ImportMsgReqs) ([]*ImportMsgRe
|
||||
for _, req := range reqs {
|
||||
remainingSize -= len(req.Message)
|
||||
if remainingSize < 0 {
|
||||
log.
|
||||
WithField("count", len(reqs)).
|
||||
WithField("size", MaxImportMessageRequestLength-remainingSize).
|
||||
Warn("Importing too big message(s)")
|
||||
return nil, errors.New("request size is too big")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user