fix: allow overriding sign via contact settings if set

This commit is contained in:
James Houlahan
2020-08-25 16:29:51 +02:00
parent ef2ace0afe
commit 3916ddc8e4
3 changed files with 30 additions and 31 deletions

View File

@ -95,9 +95,8 @@ func (b *sendPreferencesBuilder) shouldEncrypt() bool {
return false
}
func (b *sendPreferencesBuilder) withSign() {
v := true
b.sign = &v
func (b *sendPreferencesBuilder) withSign(sign bool) {
b.sign = &sign
}
func (b *sendPreferencesBuilder) withSignDefault() {
@ -258,7 +257,7 @@ func (b *sendPreferencesBuilder) setInternalPGPSettings(
// We always encrypt and sign internal mail.
b.withEncrypt(true)
b.withSign()
b.withSign(true)
// We use a custom scheme for internal messages.
b.withScheme(pmInternal)
@ -369,7 +368,7 @@ func (b *sendPreferencesBuilder) setExternalPGPSettingsWithWKDKeys(
// We always encrypt and sign external mail if WKD keys are present.
b.withEncrypt(true)
b.withSign()
b.withSign(true)
// If the contact has a specific Scheme preference, we set it (otherwise we
// leave it unset to allow it to be filled in with the default value later).
@ -402,13 +401,13 @@ func (b *sendPreferencesBuilder) setExternalPGPSettingsWithoutWKDKeys(
) (err error) {
b.withEncrypt(vCardData.Encrypt)
if !vCardData.SignMissing && vCardData.Sign {
b.withSign()
if vCardData.SignIsSet {
b.withSign(vCardData.Sign)
}
// Sign must be enabled whenever encrypt is.
if vCardData.Sign || vCardData.Encrypt {
b.withSign()
if vCardData.Encrypt {
b.withSign(true)
}
// If the contact has a specific Scheme preference, we set it (otherwise we
@ -479,7 +478,7 @@ func (b *sendPreferencesBuilder) setEncryptionPreferences(mailSettings pmapi.Mai
}
if b.shouldEncrypt() {
b.withSign()
b.withSign(true)
}
// If undefined, default to the user mail setting "Default PGP scheme".

View File

@ -243,7 +243,7 @@ func TestPreferencesBuilder(t *testing.T) {
{
name: "external with sign enabled",
contactMeta: &ContactMetadata{Sign: true},
contactMeta: &ContactMetadata{Sign: true, SignIsSet: true},
receivedKeys: []pmapi.PublicKey{},
isInternal: false,
mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, DraftMIMEType: "text/html"},
@ -272,7 +272,7 @@ func TestPreferencesBuilder(t *testing.T) {
{
name: "external with pinned contact public key, encrypted and signed",
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true},
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true, SignIsSet: true},
receivedKeys: []pmapi.PublicKey{},
isInternal: false,
mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, DraftMIMEType: "text/html"},
@ -287,7 +287,7 @@ func TestPreferencesBuilder(t *testing.T) {
{
name: "external with pinned contact public key, encrypted and signed using contact-specific pgp-inline",
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true, Scheme: pgpInline},
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true, Scheme: pgpInline, SignIsSet: true},
receivedKeys: []pmapi.PublicKey{},
isInternal: false,
mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, DraftMIMEType: "text/html"},
@ -302,7 +302,7 @@ func TestPreferencesBuilder(t *testing.T) {
{
name: "external with pinned contact public key, encrypted and signed using global pgp-inline",
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true},
contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true, SignIsSet: true},
receivedKeys: []pmapi.PublicKey{},
isInternal: false,
mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage, DraftMIMEType: "text/html"},

View File

@ -27,13 +27,13 @@ import (
)
type ContactMetadata struct {
Email string
Keys []string
Scheme string
Sign bool
SignMissing bool
Encrypt bool
MIMEType string
Email string
Keys []string
Scheme string
Sign bool
SignIsSet bool
Encrypt bool
MIMEType string
}
const (
@ -72,22 +72,22 @@ func GetContactMetadataFromVCards(cards []pmapi.Card, email string) (contactMeta
// Warn: ParseBool treats 1, T, True, true as true and 0, F, Fale, false as false.
// However PMEL declares 'true' is true, 'false' is false. every other string is true
encrypt, _ := strconv.ParseBool(parsedCard.GetValueByGroup(FieldPMEncrypt, group))
var sign, signMissing bool
var sign, signIsSet bool
if len(parsedCard[FieldPMSign]) == 0 {
signMissing = true
signIsSet = false
} else {
sign, _ = strconv.ParseBool(parsedCard.GetValueByGroup(FieldPMSign, group))
signMissing = false
signIsSet = true
}
mimeType := parsedCard.GetValueByGroup(FieldPMMIMEType, group)
return &ContactMetadata{
Email: email,
Keys: keys,
Scheme: scheme,
Sign: sign,
SignMissing: signMissing,
Encrypt: encrypt,
MIMEType: mimeType,
Email: email,
Keys: keys,
Scheme: scheme,
Sign: sign,
SignIsSet: signIsSet,
Encrypt: encrypt,
MIMEType: mimeType,
}, nil
}
return &ContactMetadata{}, nil