imap: emits connection error on logout
implements a new connection error message. This allows the worker to emit a connection-related error message to the ui when the imap client closes the loggedOut channel. Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
parent
022bf1a11f
commit
1ace50a6b9
|
@ -288,6 +288,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||||
}
|
}
|
||||||
case *types.LabelList:
|
case *types.LabelList:
|
||||||
acct.labels = msg.Labels
|
acct.labels = msg.Labels
|
||||||
|
case *types.ConnError:
|
||||||
|
acct.logger.Printf("Connection error = %v", msg.Error)
|
||||||
|
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
|
||||||
case *types.Error:
|
case *types.Error:
|
||||||
acct.logger.Printf("%v", msg.Error)
|
acct.logger.Printf("%v", msg.Error)
|
||||||
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
|
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
|
||||||
|
|
|
@ -56,6 +56,7 @@ type IMAPWorker struct {
|
||||||
worker *types.Worker
|
worker *types.Worker
|
||||||
// Map of sequence numbers to UIDs, index 0 is seq number 1
|
// Map of sequence numbers to UIDs, index 0 is seq number 1
|
||||||
seqMap []uint32
|
seqMap []uint32
|
||||||
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
||||||
|
@ -178,14 +179,22 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.stopConnectionObserver()
|
||||||
|
|
||||||
c.Updates = w.updates
|
c.Updates = w.updates
|
||||||
w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
|
w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
|
||||||
|
|
||||||
|
w.startConnectionObserver()
|
||||||
|
|
||||||
w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
||||||
case *types.Disconnect:
|
case *types.Disconnect:
|
||||||
if w.client == nil || w.client.State() != imap.SelectedState {
|
if w.client == nil || w.client.State() != imap.SelectedState {
|
||||||
reterr = fmt.Errorf("Not connected")
|
reterr = fmt.Errorf("Not connected")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.stopConnectionObserver()
|
||||||
|
|
||||||
if err := w.client.Logout(); err != nil {
|
if err := w.client.Logout(); err != nil {
|
||||||
reterr = err
|
reterr = err
|
||||||
break
|
break
|
||||||
|
@ -271,6 +280,26 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *IMAPWorker) startConnectionObserver() {
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-w.client.LoggedOut():
|
||||||
|
w.worker.PostMessage(&types.ConnError{
|
||||||
|
Error: fmt.Errorf("Logged Out"),
|
||||||
|
}, nil)
|
||||||
|
case <-w.done:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *IMAPWorker) stopConnectionObserver() {
|
||||||
|
if w.done != nil {
|
||||||
|
close(w.done)
|
||||||
|
}
|
||||||
|
w.done = make(chan struct{})
|
||||||
|
}
|
||||||
|
|
||||||
func (w *IMAPWorker) connect() (*client.Client, error) {
|
func (w *IMAPWorker) connect() (*client.Client, error) {
|
||||||
var (
|
var (
|
||||||
conn *net.TCPConn
|
conn *net.TCPConn
|
||||||
|
|
|
@ -48,6 +48,11 @@ type Error struct {
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConnError struct {
|
||||||
|
Message
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
type Unsupported struct {
|
type Unsupported struct {
|
||||||
Message
|
Message
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue