about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--aerc.go1
-rw-r--r--widgets/aerc.go19
2 files changed, 20 insertions, 0 deletions
diff --git a/aerc.go b/aerc.go
index c71c384..c5d93ac 100644
--- a/aerc.go
+++ b/aerc.go
@@ -178,4 +178,5 @@ func main() {
 			time.Sleep(16 * time.Millisecond)
 		}
 	}
+	aerc.CloseBackends()
 }
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 23dac3e..5a7914a 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -2,6 +2,7 @@ package widgets
 
 import (
 	"errors"
+	"io"
 	"log"
 	"net/url"
 	"strings"
@@ -405,3 +406,21 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
 	})
 	return nil
 }
+
+func (aerc *Aerc) CloseBackends() error {
+	var returnErr error
+	for _, acct := range aerc.accounts {
+		var raw interface{} = acct.worker.Backend
+		c, ok := raw.(io.Closer)
+		if !ok {
+			continue
+		}
+		err := c.Close()
+		if err != nil {
+			returnErr = err
+			aerc.logger.Printf("Closing backend failed for %v: %v\n",
+				acct.Name(), err)
+		}
+	}
+	return returnErr
+}