fix: crash when removing account while messages are being returned

This commit is contained in:
James Houlahan
2020-05-19 09:04:30 +02:00
parent 4d2baa6b85
commit cb8a15a9fd
8 changed files with 60 additions and 37 deletions

View File

@ -18,6 +18,7 @@
package pmapi
import (
"errors"
"fmt"
"strings"
@ -116,7 +117,7 @@ func (l AddressList) Main() *Address {
return addr
}
}
return l[0] // Should not happen.
return nil
}
// ByEmail gets an address by email. Returns nil if no address is found.
@ -218,10 +219,14 @@ func (c *client) UnlockAddresses(passphrase []byte) (err error) {
return
}
func (c *client) KeyRingForAddressID(addrID string) *pmcrypto.KeyRing {
addr := c.addresses.ByID(addrID)
if addr == nil {
addr = c.addresses.Main()
func (c *client) KeyRingForAddressID(addrID string) (*pmcrypto.KeyRing, error) {
if addr := c.addresses.ByID(addrID); addr != nil {
return addr.KeyRing(), nil
}
return addr.KeyRing()
if addr := c.addresses.Main(); addr != nil {
return addr.KeyRing(), nil
}
return nil, errors.New("no such address ID")
}

View File

@ -157,7 +157,7 @@ type Client interface {
CreateAttachment(att *Attachment, r io.Reader, sig io.Reader) (created *Attachment, err error)
DeleteAttachment(attID string) (err error)
KeyRingForAddressID(string) (kr *pmcrypto.KeyRing)
KeyRingForAddressID(string) (kr *pmcrypto.KeyRing, err error)
GetPublicKeysForEmail(string) ([]PublicKey, bool, error)
}

View File

@ -433,11 +433,12 @@ func (mr *MockClientMockRecorder) IsConnected() *gomock.Call {
}
// KeyRingForAddressID mocks base method
func (m *MockClient) KeyRingForAddressID(arg0 string) *crypto.KeyRing {
func (m *MockClient) KeyRingForAddressID(arg0 string) (*crypto.KeyRing, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "KeyRingForAddressID", arg0)
ret0, _ := ret[0].(*crypto.KeyRing)
return ret0
ret1, _ := ret[1].(error)
return ret0, ret1
}
// KeyRingForAddressID indicates an expected call of KeyRingForAddressID