[PATCH offmap v2] cmds: add 'offmap check' command
Export this patch
Add command 'check' which reports capabilities which will be used by
offmap.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
---
v2: remove quota
cmd/check.go | 39 +++++++++++++++++++++++++++++++++++++++
cmd/offmap.go | 1 +
imap/capability.go | 30 ++++++++++++++++++++++++++++++
imap/client.go | 1 -
4 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 cmd/check.go
create mode 100644 imap/capability.go
diff --git a/cmd/check.go b/cmd/check.go
new file mode 100644
index 000000000000..b7cba265136c
--- /dev/null
+++ b/cmd/check.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rockorager/offmap"
+ "git.sr.ht/~rockorager/offmap/imap"
+ "github.com/spf13/cobra"
+)
+
+func newCheckCommand() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "check",
+ Short: "check reports which capabilities of the imap server will be used",
+ RunE: check,
+ }
+ cmd.Flags().StringSliceP("account", "a", nil, "only sync the specified account(s)")
+ return cmd
+}
+
+func check(cmd *cobra.Command, args []string) error {
+ accts, err := cmd.Flags().GetStringSlice("account")
+ if err != nil {
+ return fmt.Errorf("offmap: could not parse account: %v", err)
+ }
+ cfgs, err := offmap.LoadConfig(accts)
+ if err != nil {
+ return fmt.Errorf("could not read config: %v", err)
+ }
+ for _, cfg := range cfgs {
+ fmt.Printf("Account %s\n", cfg.Name)
+ remote, err := imap.NewStore(cfg)
+ if err != nil {
+ return fmt.Errorf("could not create store: %v", err)
+ }
+ remote.Capabilities()
+ }
+ return nil
+}
diff --git a/cmd/offmap.go b/cmd/offmap.go
index 8a2176f28164..3fff3ccd4490 100644
--- a/cmd/offmap.go
+++ b/cmd/offmap.go
@@ -26,6 +26,7 @@ func main() {
cmd.AddCommand(newSyncCommand())
cmd.AddCommand(newDiffCommand())
+ cmd.AddCommand(newCheckCommand())
if err := cmd.ExecuteContext(ctx); err != nil {
log.Fatalf("%v", err)
}
diff --git a/imap/capability.go b/imap/capability.go
new file mode 100644
index 000000000000..fbd2f41238ed
--- /dev/null
+++ b/imap/capability.go
@@ -0,0 +1,30 @@
+package imap
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rockorager/offmap/log"
+)
+
+func (s *Store) Capabilities() {
+ capsUsed := []string{
+ "UIDPLUS",
+ "CONDSTORE",
+ "LIST-STATUS",
+ }
+ client := s.getConn()
+ caps, err := client.Capability()
+ if err != nil {
+ log.Errorf("could not get capabilities: %v", err)
+ return
+ }
+ for _, cap := range capsUsed {
+ _, has := caps[cap]
+ switch has {
+ case true:
+ fmt.Printf("Capability found: %s\n", cap)
+ case false:
+ fmt.Printf("Your server doesn't support '%s'\n", cap)
+ }
+ }
+}
diff --git a/imap/client.go b/imap/client.go
index c410993950d4..e45f87b68c89 100644
--- a/imap/client.go
+++ b/imap/client.go
@@ -89,7 +89,6 @@ func (s *Store) initClients() {
conn.lsc = liststatus.NewClient(c)
}
}
-
s.Lock()
s.clients[n] = conn
s.Unlock()
--
2.39.0
offmap/patches/.build.yml: SUCCESS in 2m9s
[cmds: add 'offmap check' command][0] v2 from [Tim Culverhouse][1]
[0]: https://lists.sr.ht/~rockorager/offmap/patches/37680
[1]: mailto:tim@timculverhouse.com
✓ #909479 SUCCESS offmap/patches/.build.yml https://builds.sr.ht/~rockorager/job/909479