persistant message compose

This commit is contained in:
2026-08-16 14:05:59 +01:00
parent 71758786cb
commit f02b344512
20 changed files with 1418 additions and 85 deletions
+65
View File
@@ -593,6 +593,71 @@ func TestWebmailMoveAndDeleteMessage(t *testing.T) {
}
}
// TestWebmailMessageDeletePermanentOverride confirms the permanent=1 form field lets
// a message not already under Trash be deleted outright in one step (see
// webmail_folder.html/webmail_message.html's 3-way Trash/Delete Permanently/Cancel
// prompt) — skipping the usual "goes to Trash first" default, without needing to
// delete it twice.
func TestWebmailMessageDeletePermanentOverride(t *testing.T) {
app := newTestApp(t)
mux := app.Mux()
domains, _ := app.DB.ListDomains()
mailboxID := createTestMailboxWithPassword(t, app, "permdel@example.com", domains[0].ID, "permdel-password-1!")
cookie := webmailLoginSession(t, app, mailboxID)
uid := storeTestMessage(t, app, mailboxID, "Drafts", "a@example.com", "throwaway draft", "body")
uidStr := strconv.FormatInt(uid, 10)
req := httptest.NewRequest(http.MethodPost, MailboxPrefix+"/mail/Drafts/"+uidStr+"/delete", strings.NewReader("permanent=1"))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.AddCookie(cookie)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
if rec.Code != http.StatusFound {
t.Fatalf("delete permanent=1: status=%d", rec.Code)
}
gone, err := app.DB.GetMessageByUID(mailboxID, uid)
if err != nil || gone != nil {
t.Fatalf("expected the message permanently gone (never routed through Trash), got %+v (err=%v)", gone, err)
}
inTrash, err := app.DB.ListMessagesInFolder(mailboxID, "Trash")
if err != nil || len(inTrash) != 0 {
t.Fatalf("expected nothing in Trash, got %d (err=%v)", len(inTrash), err)
}
}
// TestWebmailBulkDeletePermanent confirms the delete-permanent bulk action removes
// every selected message outright, regardless of its current folder, rather than
// moving it to Trash first.
func TestWebmailBulkDeletePermanent(t *testing.T) {
app := newTestApp(t)
mux := app.Mux()
domains, _ := app.DB.ListDomains()
mailboxID := createTestMailboxWithPassword(t, app, "bulkpermdel@example.com", domains[0].ID, "bulkpermdel-password-1!")
cookie := webmailLoginSession(t, app, mailboxID)
uidA := storeTestMessage(t, app, mailboxID, "Drafts", "a@example.com", "draft one", "body a")
uidB := storeTestMessage(t, app, mailboxID, "Drafts", "b@example.com", "draft two", "body b")
form := url.Values{"action": {"delete-permanent"}, "uid": {strconv.FormatInt(uidA, 10), strconv.FormatInt(uidB, 10)}}
req := httptest.NewRequest(http.MethodPost, MailboxPrefix+"/mail/Drafts/bulk", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.AddCookie(cookie)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
if rec.Code != http.StatusFound {
t.Fatalf("bulk delete-permanent: status=%d", rec.Code)
}
remaining, err := app.DB.ListMessagesInFolder(mailboxID, "Drafts")
if err != nil || len(remaining) != 0 {
t.Fatalf("expected both drafts permanently gone, got %d (err=%v)", len(remaining), err)
}
inTrash, err := app.DB.ListMessagesInFolder(mailboxID, "Trash")
if err != nil || len(inTrash) != 0 {
t.Fatalf("expected nothing routed through Trash, got %d (err=%v)", len(inTrash), err)
}
}
// TestWebmailMessageAccessControlAcrossMailboxes confirms one mailbox owner can't
// view another mailbox's message by guessing its UID, even in a folder name they
// both happen to have.