forked from Silverfish/proton-bridge
Allow to send calendar update multiple times
This commit is contained in:
@ -11,6 +11,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* Bump crypto version to v0.0.0-20200818122824-ed5d25e28db8
|
* Bump crypto version to v0.0.0-20200818122824-ed5d25e28db8
|
||||||
* GODT-785 Clear separation of different message IDs in integration tests.
|
* GODT-785 Clear separation of different message IDs in integration tests.
|
||||||
|
|
||||||
|
* Bump crypto version to v0.0.0-20200818122824-ed5d25e28db8.
|
||||||
|
* GODT-374 Allow to send calendar update multiple times.
|
||||||
|
|
||||||
## [IE 1.1.1] Danube (beta 2020-09-xx) [Bridge 1.4.1] Forth (beta 2020-09-xx)
|
## [IE 1.1.1] Danube (beta 2020-09-xx) [Bridge 1.4.1] Forth (beta 2020-09-xx)
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package smtp
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -48,6 +49,15 @@ func newSendRecorder() *sendRecorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *sendRecorder) getMessageHash(message *pmapi.Message) string {
|
func (q *sendRecorder) getMessageHash(message *pmapi.Message) string {
|
||||||
|
// Outlook Calendar updates has only headers (no body) and thus have always
|
||||||
|
// the same hash. If the message is type of calendar, the "is sending"
|
||||||
|
// check to avoid potential duplicates is skipped. Duplicates should not
|
||||||
|
// be a problem in this case as calendar updates are small.
|
||||||
|
contentType := message.Header.Get("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "text/calendar") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
_, _ = h.Write([]byte(message.AddressID + message.Subject))
|
_, _ = h.Write([]byte(message.AddressID + message.Subject))
|
||||||
if message.Sender != nil {
|
if message.Sender != nil {
|
||||||
@ -101,6 +111,10 @@ func (q *sendRecorder) isSendingOrSent(client messageGetter, hash string) (isSen
|
|||||||
q.lock.Lock()
|
q.lock.Lock()
|
||||||
defer q.lock.Unlock()
|
defer q.lock.Unlock()
|
||||||
|
|
||||||
|
if hash == "" {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
|
||||||
q.deleteExpiredKeys()
|
q.deleteExpiredKeys()
|
||||||
value, ok := q.hashes[hash]
|
value, ok := q.hashes[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@ -349,6 +349,32 @@ func TestSendRecorder_getMessageHash(t *testing.T) {
|
|||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{ // Different content type - calendar
|
||||||
|
&pmapi.Message{
|
||||||
|
Header: mail.Header{
|
||||||
|
"Content-Type": []string{"text/calendar"},
|
||||||
|
},
|
||||||
|
AddressID: "address123",
|
||||||
|
Subject: "Subject #1",
|
||||||
|
Sender: &mail.Address{
|
||||||
|
Address: "from@pm.me",
|
||||||
|
},
|
||||||
|
ToList: []*mail.Address{
|
||||||
|
{Address: "to@pm.me"},
|
||||||
|
},
|
||||||
|
CCList: []*mail.Address{},
|
||||||
|
BCCList: []*mail.Address{},
|
||||||
|
Body: "body",
|
||||||
|
Attachments: []*pmapi.Attachment{
|
||||||
|
{
|
||||||
|
Name: "att1",
|
||||||
|
MIMEType: "image/png",
|
||||||
|
Size: 12345,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
tc := tc // bind
|
tc := tc // bind
|
||||||
@ -382,12 +408,13 @@ func TestSendRecorder_isSendingOrSent(t *testing.T) {
|
|||||||
{"hash", &pmapi.Message{Type: pmapi.MessageTypeDraft, Time: time.Now().Unix()}, nil, true, false},
|
{"hash", &pmapi.Message{Type: pmapi.MessageTypeDraft, Time: time.Now().Unix()}, nil, true, false},
|
||||||
{"hash", &pmapi.Message{Type: pmapi.MessageTypeSent}, nil, false, true},
|
{"hash", &pmapi.Message{Type: pmapi.MessageTypeSent}, nil, false, true},
|
||||||
{"hash", &pmapi.Message{Type: pmapi.MessageTypeInboxAndSent}, nil, false, true},
|
{"hash", &pmapi.Message{Type: pmapi.MessageTypeInboxAndSent}, nil, false, true},
|
||||||
|
{"", &pmapi.Message{Type: pmapi.MessageTypeInboxAndSent}, nil, false, false},
|
||||||
}
|
}
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
tc := tc // bind
|
tc := tc // bind
|
||||||
t.Run(fmt.Sprintf("%d / %v / %v / %v", i, tc.hash, tc.message, tc.err), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%d / %v / %v / %v", i, tc.hash, tc.message, tc.err), func(t *testing.T) {
|
||||||
messageGetter := &testSendRecorderGetMessageMock{message: tc.message, err: tc.err}
|
messageGetter := &testSendRecorderGetMessageMock{message: tc.message, err: tc.err}
|
||||||
isSending, wasSent := q.isSendingOrSent(messageGetter, "hash")
|
isSending, wasSent := q.isSendingOrSent(messageGetter, tc.hash)
|
||||||
assert.Equal(t, tc.wantIsSending, isSending, "isSending does not match")
|
assert.Equal(t, tc.wantIsSending, isSending, "isSending does not match")
|
||||||
assert.Equal(t, tc.wantWasSent, wasSent, "wasSent does not match")
|
assert.Equal(t, tc.wantWasSent, wasSent, "wasSent does not match")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user