forked from Silverfish/proton-bridge
feat: reject messages which are too large
This commit is contained in:
@ -31,7 +31,7 @@ import (
|
|||||||
type storeUserProvider interface {
|
type storeUserProvider interface {
|
||||||
UserID() string
|
UserID() string
|
||||||
GetSpace() (usedSpace, maxSpace uint, err error)
|
GetSpace() (usedSpace, maxSpace uint, err error)
|
||||||
GetMaxUpload() (uint, error)
|
GetMaxUpload() (int64, error)
|
||||||
|
|
||||||
GetAddress(addressID string) (storeAddressProvider, error)
|
GetAddress(addressID string) (storeAddressProvider, error)
|
||||||
|
|
||||||
|
|||||||
@ -33,4 +33,5 @@ type storeUserProvider interface {
|
|||||||
attachedPublicKeyName string,
|
attachedPublicKeyName string,
|
||||||
parentID string) (*pmapi.Message, []*pmapi.Attachment, error)
|
parentID string) (*pmapi.Message, []*pmapi.Attachment, error)
|
||||||
SendMessage(messageID string, req *pmapi.SendMessageReq) error
|
SendMessage(messageID string, req *pmapi.SendMessageReq) error
|
||||||
|
GetMaxUpload() (int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -329,6 +329,12 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
|
|||||||
su.backend.sendRecorder.setMessageID(sendRecorderMessageHash, message.ID)
|
su.backend.sendRecorder.setMessageID(sendRecorderMessageHash, message.ID)
|
||||||
log.WithField("messageID", message.ID).Debug("Draft was created successfully")
|
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,
|
// 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
|
// because clients don't necessarily save the draft before sending, which
|
||||||
// can lead to sending the wrong message. Also clients do not necessarily
|
// 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)
|
log.Debug("SMTP client logged out user ", su.addressID)
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -31,11 +31,11 @@ func (store *Store) GetSpace() (usedSpace, maxSpace uint, err error) {
|
|||||||
return uint(apiUser.UsedSpace), uint(apiUser.MaxSpace), nil
|
return uint(apiUser.UsedSpace), uint(apiUser.MaxSpace), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMaxUpload returns max size of attachment in bytes.
|
// GetMaxUpload returns max size of message + all attachments in bytes.
|
||||||
func (store *Store) GetMaxUpload() (uint, error) {
|
func (store *Store) GetMaxUpload() (int64, error) {
|
||||||
apiUser, err := store.client().CurrentUser()
|
apiUser, err := store.client().CurrentUser()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return uint(apiUser.MaxUpload), nil
|
return apiUser.MaxUpload, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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-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-1006 Use correct macOS keychain name.
|
||||||
* GODT-1009 Set ContentID if present and not explicitly attachment.
|
* 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user