mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
fix: handle double charset everywhere by using our ParseMediaType
This commit is contained in:
@ -24,6 +24,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* GODT-341 Fixed flaky unittest for Store synchronization cooldown
|
* GODT-341 Fixed flaky unittest for Store synchronization cooldown
|
||||||
* Crash when failing to match necessary html element
|
* Crash when failing to match necessary html element
|
||||||
* Crash in message.combineParts when copying nil slice
|
* Crash in message.combineParts when copying nil slice
|
||||||
|
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
|
||||||
|
|
||||||
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)
|
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)
|
||||||
|
|
||||||
|
|||||||
@ -5,11 +5,12 @@
|
|||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
store "github.com/ProtonMail/proton-bridge/internal/store"
|
store "github.com/ProtonMail/proton-bridge/internal/store"
|
||||||
credentials "github.com/ProtonMail/proton-bridge/internal/users/credentials"
|
credentials "github.com/ProtonMail/proton-bridge/internal/users/credentials"
|
||||||
pmapi "github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
pmapi "github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
reflect "reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockConfiger is a mock of Configer interface
|
// MockConfiger is a mock of Configer interface
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
@ -323,7 +322,7 @@ func (ptc *PlainTextCollector) Accept(partReader io.Reader, header textproto.MIM
|
|||||||
if isFirst {
|
if isFirst {
|
||||||
if IsLeaf(header) {
|
if IsLeaf(header) {
|
||||||
mediaType, _, _ := getContentType(header)
|
mediaType, _, _ := getContentType(header)
|
||||||
disp, _, _ := mime.ParseMediaType(header.Get("Content-Disposition"))
|
disp, _, _ := ParseMediaType(header.Get("Content-Disposition"))
|
||||||
if mediaType == "text/plain" && disp != "attachment" {
|
if mediaType == "text/plain" && disp != "attachment" {
|
||||||
partData, _ := ioutil.ReadAll(partReader)
|
partData, _ := ioutil.ReadAll(partReader)
|
||||||
decodedPart := decodePart(bytes.NewReader(partData), header)
|
decodedPart := decodePart(bytes.NewReader(partData), header)
|
||||||
@ -378,7 +377,7 @@ func (bc *BodyCollector) Accept(partReader io.Reader, header textproto.MIMEHeade
|
|||||||
if isFirst {
|
if isFirst {
|
||||||
if IsLeaf(header) {
|
if IsLeaf(header) {
|
||||||
mediaType, _, _ := getContentType(header)
|
mediaType, _, _ := getContentType(header)
|
||||||
disp, _, _ := mime.ParseMediaType(header.Get("Content-Disposition"))
|
disp, _, _ := ParseMediaType(header.Get("Content-Disposition"))
|
||||||
if disp != "attachment" {
|
if disp != "attachment" {
|
||||||
partData, _ := ioutil.ReadAll(partReader)
|
partData, _ := ioutil.ReadAll(partReader)
|
||||||
decodedPart := decodePart(bytes.NewReader(partData), header)
|
decodedPart := decodePart(bytes.NewReader(partData), header)
|
||||||
@ -445,7 +444,7 @@ func (ac *AttachmentsCollector) Accept(partReader io.Reader, header textproto.MI
|
|||||||
if isFirst {
|
if isFirst {
|
||||||
if IsLeaf(header) {
|
if IsLeaf(header) {
|
||||||
mediaType, _, _ := getContentType(header)
|
mediaType, _, _ := getContentType(header)
|
||||||
disp, _, _ := mime.ParseMediaType(header.Get("Content-Disposition"))
|
disp, _, _ := ParseMediaType(header.Get("Content-Disposition"))
|
||||||
if (mediaType != "text/html" && mediaType != "text/plain") || disp == "attachment" {
|
if (mediaType != "text/html" && mediaType != "text/plain") || disp == "attachment" {
|
||||||
partData, _ := ioutil.ReadAll(partReader)
|
partData, _ := ioutil.ReadAll(partReader)
|
||||||
decodedPart := decodePart(bytes.NewReader(partData), header)
|
decodedPart := decodePart(bytes.NewReader(partData), header)
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
@ -32,6 +31,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
pmmime "github.com/ProtonMail/proton-bridge/pkg/mime"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ func TestClient_CreateAttachment(t *testing.T) {
|
|||||||
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Ok(t, checkMethodAndPath(r, "POST", "/attachments"))
|
Ok(t, checkMethodAndPath(r, "POST", "/attachments"))
|
||||||
|
|
||||||
contentType, params, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
contentType, params, err := pmmime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Expected no error while parsing request content type, got:", err)
|
t.Error("Expected no error while parsing request content type, got:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
pmmime "github.com/ProtonMail/proton-bridge/pkg/mime"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testImportReqs = []*ImportMsgReq{
|
var testImportReqs = []*ImportMsgReq{
|
||||||
@ -56,7 +57,7 @@ func TestClient_Import(t *testing.T) { // nolint[funlen]
|
|||||||
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Ok(t, checkMethodAndPath(r, "POST", "/import"))
|
Ok(t, checkMethodAndPath(r, "POST", "/import"))
|
||||||
|
|
||||||
contentType, params, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
contentType, params, err := pmmime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Expected no error while parsing request content type, got:", err)
|
t.Error("Expected no error while parsing request content type, got:", err)
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ func TestClient_Import(t *testing.T) { // nolint[funlen]
|
|||||||
t.Error("Expected no error while reading first part of request body, got:", err)
|
t.Error("Expected no error while reading first part of request body, got:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentDisp, params, err := mime.ParseMediaType(p.Header.Get("Content-Disposition"))
|
contentDisp, params, err := pmmime.ParseMediaType(p.Header.Get("Content-Disposition"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Expected no error while parsing part content disposition, got:", err)
|
t.Error("Expected no error while parsing part content disposition, got:", err)
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ func TestClient_Import(t *testing.T) { // nolint[funlen]
|
|||||||
t.Error("Expected no error while reading second part of request body, got:", err)
|
t.Error("Expected no error while reading second part of request body, got:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentDisp, params, err = mime.ParseMediaType(p.Header.Get("Content-Disposition"))
|
contentDisp, params, err = pmmime.ParseMediaType(p.Header.Get("Content-Disposition"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Expected no error while parsing part content disposition, got:", err)
|
t.Error("Expected no error while parsing part content disposition, got:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user