diff --git a/internal/smtp/user.go b/internal/smtp/user.go index 39655e17..62d31407 100644 --- a/internal/smtp/user.go +++ b/internal/smtp/user.go @@ -20,9 +20,11 @@ package smtp import ( + "bytes" "encoding/base64" "fmt" "io" + "io/ioutil" "mime" "net/mail" "strings" @@ -319,6 +321,12 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader return nil } + if ok, err := su.isTotalSizeOkay(message, attReaders); err != nil { + return err + } else if !ok { + return errors.New("message is too large") + } + su.backend.sendRecorder.addMessage(sendRecorderMessageHash) message, atts, err := su.storeUser.CreateDraft(kr, message, attReaders, attachedPublicKey, attachedPublicKeyName, parentID) if err != nil { @@ -329,12 +337,6 @@ 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 @@ -534,7 +536,7 @@ func (su *smtpUser) Logout() error { return nil } -func (su *smtpUser) isTotalSizeOkay(message *pmapi.Message, attachments []*pmapi.Attachment) (bool, error) { +func (su *smtpUser) isTotalSizeOkay(message *pmapi.Message, attReaders []io.Reader) (bool, error) { maxUpload, err := su.storeUser.GetMaxUpload() if err != nil { return false, err @@ -542,8 +544,14 @@ func (su *smtpUser) isTotalSizeOkay(message *pmapi.Message, attachments []*pmapi var attSize int64 - for _, att := range attachments { - attSize += att.Size + for i := range attReaders { + b, err := ioutil.ReadAll(attReaders[i]) + if err != nil { + return false, err + } + + attSize += int64(len(b)) + attReaders[i] = bytes.NewBuffer(b) } return message.Size+attSize <= maxUpload, nil diff --git a/test/accounts/fake.json b/test/accounts/fake.json index 60bea18a..79ba3742 100644 --- a/test/accounts/fake.json +++ b/test/accounts/fake.json @@ -2,23 +2,28 @@ "users": { "user": { "ID": "1", - "Name": "user" + "Name": "user", + "MaxUpload": 26214400 }, "user2fa": { "ID": "2", - "Name": "user2fa" + "Name": "user2fa", + "MaxUpload": 26214400 }, "userAddressWithCapitalLetter": { "ID": "3", - "Name": "userAddressWithCapitalLetter" + "Name": "userAddressWithCapitalLetter", + "MaxUpload": 26214400 }, "userMoreAddresses": { "ID": "4", - "Name": "userMoreAddresses" + "Name": "userMoreAddresses", + "MaxUpload": 26214400 }, "userDisabledPrimaryAddress": { "ID": "5", - "Name": "userDisabledPrimaryAddress" + "Name": "userDisabledPrimaryAddress", + "MaxUpload": 26214400 } }, "addresses": { diff --git a/unreleased.md b/unreleased.md index 2f8de02f..efdd11bd 100644 --- a/unreleased.md +++ b/unreleased.md @@ -5,6 +5,17 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) ## Unreleased ### Added +* GODT-958 Release notes per eaach update channel. +* GODT-906 Handle RFC2047-encoded content transfer encoding values. +* GODT-875 Added GUI dialog on force update. +* GODT-820 Added GUI notification on impossibility of update installation (both silent and manual). +* GODT-870 Added GUI notification on error during silent update. +* GODT-805 Added GUI notification on update available. +* GODT-804 Added GUI notification on silent update installed (promt to restart). +* GODT-275 Added option to disable autoupdates in settings (default autoupdate is enabled). +* GODT-874 Added manual triggers to Updater module. +* GODT-851 Added support of UID EXPUNGE. +* GODT-928 Reject messages which are too large. ### Removed @@ -17,6 +28,3 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * 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.