mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 12:24:38 +03:00
webmail: add export functionality
per mailbox, or for all mailboxes, in maildir/mbox format, in tar/tgz/zip archive or without archive format for single mbox, single or recursive. the webaccount already had an option to export all mailboxes, it now looks similar to the webmail version.
This commit is contained in:
@ -19,18 +19,20 @@ func TestExport(t *testing.T) {
|
||||
// Set up an account, add 2 messages to different 2 mailboxes. export as tar/zip
|
||||
// and maildir/mbox. check there are 2 files in the repo, no errors.txt.
|
||||
|
||||
log := mlog.New("export", nil)
|
||||
|
||||
os.RemoveAll("../testdata/store/data")
|
||||
mox.ConfigStaticPath = filepath.FromSlash("../testdata/store/mox.conf")
|
||||
mox.MustLoadConfig(true, false)
|
||||
acc, err := OpenAccount(pkglog, "mjl")
|
||||
tcheck(t, err, "open account")
|
||||
defer func() {
|
||||
acc.Close()
|
||||
err := acc.Close()
|
||||
log.Check(err, "closing account")
|
||||
acc.CheckClosed()
|
||||
}()
|
||||
defer Switchboard()()
|
||||
|
||||
log := mlog.New("export", nil)
|
||||
|
||||
msgFile, err := CreateMessageTemp(pkglog, "mox-test-export")
|
||||
tcheck(t, err, "create temp")
|
||||
@ -52,7 +54,7 @@ func TestExport(t *testing.T) {
|
||||
|
||||
archive := func(archiver Archiver, maildir bool) {
|
||||
t.Helper()
|
||||
err = ExportMessages(ctxbg, log, acc.DB, acc.Dir, archiver, maildir, "")
|
||||
err = ExportMessages(ctxbg, log, acc.DB, acc.Dir, archiver, maildir, "", true)
|
||||
tcheck(t, err, "export messages")
|
||||
err = archiver.Close()
|
||||
tcheck(t, err, "archiver close")
|
||||
@ -68,16 +70,17 @@ func TestExport(t *testing.T) {
|
||||
archive(DirArchiver{filepath.FromSlash("../testdata/exportmaildir")}, true)
|
||||
archive(DirArchiver{filepath.FromSlash("../testdata/exportmbox")}, false)
|
||||
|
||||
const defaultMailboxes = 6 // Inbox, Drafts, etc
|
||||
if r, err := zip.NewReader(bytes.NewReader(maildirZip.Bytes()), int64(maildirZip.Len())); err != nil {
|
||||
t.Fatalf("reading maildir zip: %v", err)
|
||||
} else if len(r.File) != 2*3+2 {
|
||||
t.Fatalf("maildir zip, expected 2*3 dirs, and 2 files, got %d files", len(r.File))
|
||||
} else if len(r.File) != defaultMailboxes*3+2 {
|
||||
t.Fatalf("maildir zip, expected %d*3 dirs, and 2 files, got %d files", defaultMailboxes, len(r.File))
|
||||
}
|
||||
|
||||
if r, err := zip.NewReader(bytes.NewReader(mboxZip.Bytes()), int64(mboxZip.Len())); err != nil {
|
||||
t.Fatalf("reading mbox zip: %v", err)
|
||||
} else if len(r.File) != 2 {
|
||||
t.Fatalf("maildir zip, 2 files, got %d files", len(r.File))
|
||||
} else if len(r.File) != defaultMailboxes {
|
||||
t.Fatalf("maildir zip, expected %d files, got %d files", defaultMailboxes, len(r.File))
|
||||
}
|
||||
|
||||
checkTarFiles := func(r io.Reader, n int) {
|
||||
@ -101,8 +104,8 @@ func TestExport(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
checkTarFiles(&maildirTar, 2*3+2)
|
||||
checkTarFiles(&mboxTar, 2)
|
||||
checkTarFiles(&maildirTar, defaultMailboxes*3+2)
|
||||
checkTarFiles(&mboxTar, defaultMailboxes)
|
||||
|
||||
checkDirFiles := func(dir string, n int) {
|
||||
t.Helper()
|
||||
@ -120,5 +123,5 @@ func TestExport(t *testing.T) {
|
||||
}
|
||||
|
||||
checkDirFiles(filepath.FromSlash("../testdata/exportmaildir"), 2)
|
||||
checkDirFiles(filepath.FromSlash("../testdata/exportmbox"), 2)
|
||||
checkDirFiles(filepath.FromSlash("../testdata/exportmbox"), defaultMailboxes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user