aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--widgets/account.go3
-rw-r--r--worker/imap/worker.go26
-rw-r--r--worker/types/messages.go4
3 files changed, 30 insertions, 3 deletions
diff --git a/widgets/account.go b/widgets/account.go
index beedabca..f9700301 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -202,7 +202,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
switch msg.InResponseTo().(type) {
- case *types.Connect:
+ case *types.Connect, *types.Reconnect:
acct.host.SetStatus("Listing mailboxes...")
acct.logger.Println("Listing mailboxes...")
acct.dirlist.UpdateList(func(dirs []string) {
@@ -291,6 +291,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
case *types.ConnError:
acct.logger.Printf("Connection error = %v", msg.Error)
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
+ acct.worker.PostAction(&types.Reconnect{}, nil)
case *types.Error:
acct.logger.Printf("%v", msg.Error)
acct.aerc.PushError(fmt.Sprintf("%v", msg.Error))
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index 6ad7ed29..ba53df23 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -55,8 +55,9 @@ type IMAPWorker struct {
updates chan client.Update
worker *types.Worker
// Map of sequence numbers to UIDs, index 0 is seq number 1
- seqMap []uint32
- done chan struct{}
+ seqMap []uint32
+ done chan struct{}
+ autoReconnect bool
}
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
@@ -186,6 +187,26 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
w.startConnectionObserver()
+ w.autoReconnect = true
+ w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
+ case *types.Reconnect:
+ if !w.autoReconnect {
+ reterr = fmt.Errorf("auto-reconnect is disabled; run connect to enable it")
+ break
+ }
+ c, err := w.connect()
+ if err != nil {
+ reterr = err
+ break
+ }
+
+ w.stopConnectionObserver()
+
+ c.Updates = w.updates
+ w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
+
+ w.startConnectionObserver()
+
w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
case *types.Disconnect:
if w.client == nil || w.client.State() != imap.SelectedState {
@@ -199,6 +220,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
reterr = err
break
}
+ w.autoReconnect = false
w.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
case *types.ListDirectories:
w.handleListDirectories(msg)
diff --git a/worker/types/messages.go b/worker/types/messages.go
index a5eae8d4..d8f1f568 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -68,6 +68,10 @@ type Connect struct {
Message
}
+type Reconnect struct {
+ Message
+}
+
type Disconnect struct {
Message
}