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

@ -31,7 +31,7 @@ import (
type storeUserProvider interface {
UserID() string
GetSpace() (usedSpace, maxSpace uint, err error)
GetMaxUpload() (uint, error)
GetMaxUpload() (int64, error)
GetAddress(addressID string) (storeAddressProvider, error)

View File

@ -33,4 +33,5 @@ type storeUserProvider interface {
attachedPublicKeyName string,
parentID string) (*pmapi.Message, []*pmapi.Attachment, error)
SendMessage(messageID string, req *pmapi.SendMessageReq) error
GetMaxUpload() (int64, error)
}

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
}

View File

@ -31,11 +31,11 @@ func (store *Store) GetSpace() (usedSpace, maxSpace uint, err error) {
return uint(apiUser.UsedSpace), uint(apiUser.MaxSpace), nil
}
// GetMaxUpload returns max size of attachment in bytes.
func (store *Store) GetMaxUpload() (uint, error) {
// GetMaxUpload returns max size of message + all attachments in bytes.
func (store *Store) GetMaxUpload() (int64, error) {
apiUser, err := store.client().CurrentUser()
if err != nil {
return 0, err
}
return uint(apiUser.MaxUpload), nil
return apiUser.MaxUpload, nil
}

View File

@ -14,3 +14,9 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
* GODT-787 GODT-978 Fix IE and Bridge importing to sent not showing up in inbox (setting up flags properly).
* GODT-1006 Use correct macOS keychain name.
* GODT-1009 Set ContentID if present and not explicitly attachment.
* GODT-900 Remove \Deleted flag after re-importing the message (do not delete messages by moving to local folder and back).
* GODT-908 Do not unpause event loop if other mailbox is still fetching.
* Check deprecated status code first to better determine API error.
* GODT-732 Fix usage of fontawesome
* GODT-915 Bump go-imap dependency and remove go-imap-specialuse dependency.
* GODT-928 Reject messages which are too large.