9 "github.com/mjl-/bstore"
11 "github.com/mjl-/mox/store"
14func cmdExportMaildir(c *cmd) {
15 c.params = "[-single] dst-dir account-path [mailbox]"
16 c.help = `Export one or all mailboxes from an account in maildir format.
18Export bypasses a running mox instance. It opens the account mailbox/message
19database file directly. This may block if a running mox instance also has the
20database open, e.g. for IMAP connections. To export from a running instance, use
21the accounts web page or webmail.
24 c.flag.BoolVar(&single, "single", false, "export single mailbox, without any children. disabled if mailbox isn't specified.")
26 xcmdExport(false, single, args, c)
29func cmdExportMbox(c *cmd) {
30 c.params = "[-single] dst-dir account-path [mailbox]"
31 c.help = `Export messages from one or all mailboxes in an account in mbox format.
33Using mbox is not recommended. Maildir is a better format.
35Export bypasses a running mox instance. It opens the account mailbox/message
36database file directly. This may block if a running mox instance also has the
37database open, e.g. for IMAP connections. To export from a running instance, use
38the accounts web page or webmail.
40For mbox export, "mboxrd" is used where message lines starting with the magic
41"From " string are escaped by prepending a >. All ">*From " are escaped,
42otherwise reconstructing the original could lose a ">".
45 c.flag.BoolVar(&single, "single", false, "export single mailbox, without any children. disabled if mailbox isn't specified.")
47 xcmdExport(true, single, args, c)
50func xcmdExport(mbox, single bool, args []string, c *cmd) {
51 if len(args) != 2 && len(args) != 3 {
64 dbpath := filepath.Join(accountDir, "index.db")
65 db, err := bstore.Open(context.Background(), dbpath, &bstore.Options{Timeout: 5 * time.Second, Perm: 0660}, store.DBTypes...)
66 xcheckf(err, "open database %q", dbpath)
68 if err := db.Close(); err != nil {
69 log.Printf("closing db after export: %v", err)
73 a := store.DirArchiver{Dir: dst}
74 err = store.ExportMessages(context.Background(), c.log, db, accountDir, a, !mbox, mailbox, !single)
75 xcheckf(err, "exporting messages")
77 xcheckf(err, "closing archiver")