feat: reject messages which are too large

This commit is contained in:
James Houlahan
2021-01-12 15:51:14 +01:00
parent 4ffa62f6ca
commit 0679b99a65
5 changed files with 32 additions and 4 deletions

View File

@ -329,6 +329,12 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
su.backend.sendRecorder.setMessageID(sendRecorderMessageHash, message.ID)
log.WithField("messageID", message.ID).Debug("Draft was created successfully")
if ok, err := su.isTotalSizeOkay(message, atts); err != nil {
return err
} else if !ok {
return errors.New("message is too large")
}
// We always have to create a new draft even if there already is one,
// because clients don't necessarily save the draft before sending, which
// can lead to sending the wrong message. Also clients do not necessarily
@ -527,3 +533,18 @@ func (su *smtpUser) Logout() error {
log.Debug("SMTP client logged out user ", su.addressID)
return nil
}
func (su *smtpUser) isTotalSizeOkay(message *pmapi.Message, attachments []*pmapi.Attachment) (bool, error) {
maxUpload, err := su.storeUser.GetMaxUpload()
if err != nil {
return false, err
}
var attSize int64
for _, att := range attachments {
attSize += att.Size
}
return message.Size+attSize <= maxUpload, nil
}