mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 16:17:03 +00:00
feat: compute size before upload
This commit is contained in:
@ -20,9 +20,11 @@
|
|||||||
package smtp
|
package smtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"mime"
|
"mime"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"strings"
|
"strings"
|
||||||
@ -319,6 +321,12 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
|
|||||||
return nil
|
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)
|
su.backend.sendRecorder.addMessage(sendRecorderMessageHash)
|
||||||
message, atts, err := su.storeUser.CreateDraft(kr, message, attReaders, attachedPublicKey, attachedPublicKeyName, parentID)
|
message, atts, err := su.storeUser.CreateDraft(kr, message, attReaders, attachedPublicKey, attachedPublicKeyName, parentID)
|
||||||
if err != nil {
|
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)
|
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
|
||||||
@ -534,7 +536,7 @@ func (su *smtpUser) Logout() error {
|
|||||||
return nil
|
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()
|
maxUpload, err := su.storeUser.GetMaxUpload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -542,8 +544,14 @@ func (su *smtpUser) isTotalSizeOkay(message *pmapi.Message, attachments []*pmapi
|
|||||||
|
|
||||||
var attSize int64
|
var attSize int64
|
||||||
|
|
||||||
for _, att := range attachments {
|
for i := range attReaders {
|
||||||
attSize += att.Size
|
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
|
return message.Size+attSize <= maxUpload, nil
|
||||||
|
|||||||
@ -2,23 +2,28 @@
|
|||||||
"users": {
|
"users": {
|
||||||
"user": {
|
"user": {
|
||||||
"ID": "1",
|
"ID": "1",
|
||||||
"Name": "user"
|
"Name": "user",
|
||||||
|
"MaxUpload": 26214400
|
||||||
},
|
},
|
||||||
"user2fa": {
|
"user2fa": {
|
||||||
"ID": "2",
|
"ID": "2",
|
||||||
"Name": "user2fa"
|
"Name": "user2fa",
|
||||||
|
"MaxUpload": 26214400
|
||||||
},
|
},
|
||||||
"userAddressWithCapitalLetter": {
|
"userAddressWithCapitalLetter": {
|
||||||
"ID": "3",
|
"ID": "3",
|
||||||
"Name": "userAddressWithCapitalLetter"
|
"Name": "userAddressWithCapitalLetter",
|
||||||
|
"MaxUpload": 26214400
|
||||||
},
|
},
|
||||||
"userMoreAddresses": {
|
"userMoreAddresses": {
|
||||||
"ID": "4",
|
"ID": "4",
|
||||||
"Name": "userMoreAddresses"
|
"Name": "userMoreAddresses",
|
||||||
|
"MaxUpload": 26214400
|
||||||
},
|
},
|
||||||
"userDisabledPrimaryAddress": {
|
"userDisabledPrimaryAddress": {
|
||||||
"ID": "5",
|
"ID": "5",
|
||||||
"Name": "userDisabledPrimaryAddress"
|
"Name": "userDisabledPrimaryAddress",
|
||||||
|
"MaxUpload": 26214400
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"addresses": {
|
"addresses": {
|
||||||
|
|||||||
@ -5,6 +5,17 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
### 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
|
### 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-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.
|
* GODT-908 Do not unpause event loop if other mailbox is still fetching.
|
||||||
* Check deprecated status code first to better determine API error.
|
* 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