Allow to send calendar update multiple times

This commit is contained in:
Michal Horejsek
2020-10-05 15:28:11 +02:00
parent a33e414f01
commit 932928ddc8
3 changed files with 44 additions and 1 deletions

View File

@ -20,6 +20,7 @@ package smtp
import (
"crypto/sha256"
"fmt"
"strings"
"sync"
"time"
@ -48,6 +49,15 @@ func newSendRecorder() *sendRecorder {
}
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.Write([]byte(message.AddressID + message.Subject))
if message.Sender != nil {
@ -101,6 +111,10 @@ func (q *sendRecorder) isSendingOrSent(client messageGetter, hash string) (isSen
q.lock.Lock()
defer q.lock.Unlock()
if hash == "" {
return false, false
}
q.deleteExpiredKeys()
value, ok := q.hashes[hash]
if !ok {