mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 01:56:44 +00:00
Import encrypted messages as is
This commit is contained in:
@ -67,6 +67,14 @@ func (req *ImportReq) WriteTo(w *multipart.Writer) (err error) {
|
||||
if _, err = fw.Write(msg.Body); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Adding new line to properly fetch the whole body on the API side.
|
||||
// The reason is the bug in PHP: https://bugs.php.net/bug.php?id=75923
|
||||
// Messages generated by PM already have it but importing already
|
||||
// encrypted messages might not have it.
|
||||
if _, err = fw.Write([]byte("\r\n")); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@ -127,7 +127,7 @@ func TestClient_Import(t *testing.T) { // nolint[funlen]
|
||||
t.Error("Expected no error while reading second part body, got:", err)
|
||||
}
|
||||
|
||||
if string(b) != string(testImportReqs[0].Body) {
|
||||
if string(b) != string(testImportReqs[0].Body)+"\r\n" {
|
||||
t.Errorf("Invalid message body: expected %v but got %v", string(testImportReqs[0].Body), string(b))
|
||||
}
|
||||
|
||||
|
||||
@ -253,6 +253,10 @@ func (m *Message) HasLabelID(labelID string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *Message) IsEncrypted() bool {
|
||||
return strings.HasPrefix(m.Header.Get("Content-Type"), "multipart/encrypted") || m.IsBodyEncrypted()
|
||||
}
|
||||
|
||||
func (m *Message) IsBodyEncrypted() bool {
|
||||
trimmedBody := strings.TrimSpace(m.Body)
|
||||
return strings.HasPrefix(trimmedBody, MessageHeader) &&
|
||||
|
||||
Reference in New Issue
Block a user