updated webclient setttings
This commit is contained in:
@@ -3,33 +3,37 @@ package webui
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"mailgoserver/internal/db"
|
||||
)
|
||||
|
||||
// webmailSignaturesPage lists a mailbox's saved signatures and the add/edit form.
|
||||
// webmailSignaturesPage lists a mailbox's saved signatures — add/edit happens in a
|
||||
// popup (webmail_settings_chrome.html's signature modal), not on this page itself.
|
||||
func (a *App) webmailSignaturesPage(w http.ResponseWriter, r *http.Request) {
|
||||
mbox := mailboxFromContext(r)
|
||||
signatures, err := a.DB.ListSignatures(mbox.ID)
|
||||
if err != nil {
|
||||
setFlash(w, "error", "Error loading signatures")
|
||||
}
|
||||
|
||||
// ?edit=<id> loads an existing signature into the form instead of a blank one.
|
||||
var editing *db.MailboxSignature
|
||||
if idStr := r.URL.Query().Get("edit"); idStr != "" {
|
||||
editing, _ = a.DB.GetSignatureByID(mbox.ID, int64(atoi(idStr)))
|
||||
aliasDefaults, err := a.DB.ListSignatureAliasDefaults(mbox.ID)
|
||||
if err != nil {
|
||||
setFlash(w, "error", "Error loading alias defaults")
|
||||
}
|
||||
|
||||
a.render(w, r, "webmail_signatures.html", M{
|
||||
"mailbox": mbox, "signatures": signatures, "editing": editing,
|
||||
"flashes": popFlashes(w, r),
|
||||
"mailbox": mbox, "signatures": signatures, "send_as_options": a.sendAsAddresses(mbox),
|
||||
"alias_defaults": aliasDefaults,
|
||||
"flashes": popFlashes(w, r), "active_section": "signatures",
|
||||
})
|
||||
}
|
||||
|
||||
// webmailSignatureSave creates a new signature, or updates one when id (a hidden
|
||||
// form field, not a path segment — this is a single form reused for add and edit) is
|
||||
// set.
|
||||
// set. default_for_email/default_new/default_reply (all optional) additionally set
|
||||
// this signature as a specific send-as alias's default — see
|
||||
// db.SetSignatureAliasDefault. The mailbox's own primary-address default is set
|
||||
// separately, via the existing per-row "Use for new"/"Use for reply/forward" buttons
|
||||
// (webmailSignatureSetDefault) — deliberately not folded into this form, since that
|
||||
// control already works and scoping it here would just be two ways to do the same
|
||||
// thing for that one address.
|
||||
func (a *App) webmailSignatureSave(w http.ResponseWriter, r *http.Request) {
|
||||
mbox := mailboxFromContext(r)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
@@ -50,14 +54,25 @@ func (a *App) webmailSignatureSave(w http.ResponseWriter, r *http.Request) {
|
||||
if id != 0 {
|
||||
err = a.DB.UpdateSignature(mbox.ID, id, name, contentHTML)
|
||||
} else {
|
||||
_, err = a.DB.CreateSignature(mbox.ID, name, contentHTML)
|
||||
id, err = a.DB.CreateSignature(mbox.ID, name, contentHTML)
|
||||
}
|
||||
if err != nil {
|
||||
a.Logger.Error("save signature for mailbox %d: %v", mbox.ID, err)
|
||||
setFlash(w, "error", "Could not save the signature")
|
||||
} else {
|
||||
setFlash(w, "success", "Signature saved")
|
||||
http.Redirect(w, r, MailboxPrefix+"/signatures", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
if forEmail := strings.TrimSpace(r.FormValue("default_for_email")); forEmail != "" {
|
||||
if r.FormValue("default_new") != "" {
|
||||
a.DB.SetSignatureAliasDefault(mbox.ID, id, forEmail, false)
|
||||
}
|
||||
if r.FormValue("default_reply") != "" {
|
||||
a.DB.SetSignatureAliasDefault(mbox.ID, id, forEmail, true)
|
||||
}
|
||||
}
|
||||
|
||||
setFlash(w, "success", "Signature saved")
|
||||
http.Redirect(w, r, MailboxPrefix+"/signatures", http.StatusFound)
|
||||
}
|
||||
|
||||
@@ -74,7 +89,8 @@ func (a *App) webmailSignatureDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// webmailSignatureSetDefault marks a signature (or, when id=0, clears the flag
|
||||
// entirely) as the mailbox's default for new messages or for reply/forward, per the
|
||||
// "which" form field ("new" or "reply").
|
||||
// "which" form field ("new" or "reply"). This is the mailbox's own primary-address
|
||||
// default — see webmailSignatureSetAliasDefault for a specific send-as alias's.
|
||||
func (a *App) webmailSignatureSetDefault(w http.ResponseWriter, r *http.Request) {
|
||||
mbox := mailboxFromContext(r)
|
||||
id := int64(atoi(r.PathValue("id")))
|
||||
@@ -86,3 +102,23 @@ func (a *App) webmailSignatureSetDefault(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
http.Redirect(w, r, MailboxPrefix+"/signatures", http.StatusFound)
|
||||
}
|
||||
|
||||
// webmailSignatureRemoveAliasDefault clears one alias's default-for-new or
|
||||
// default-for-reply override (the little x on a signature's alias-scoped badge),
|
||||
// falling back to the mailbox's own primary default for that alias again.
|
||||
func (a *App) webmailSignatureRemoveAliasDefault(w http.ResponseWriter, r *http.Request) {
|
||||
mbox := mailboxFromContext(r)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
setFlash(w, "error", "Invalid form data")
|
||||
http.Redirect(w, r, MailboxPrefix+"/signatures", http.StatusFound)
|
||||
return
|
||||
}
|
||||
forEmail := strings.TrimSpace(r.FormValue("for_email"))
|
||||
forReply := r.FormValue("for_reply") != ""
|
||||
if err := a.DB.ClearSignatureAliasDefault(mbox.ID, forEmail, forReply); err != nil {
|
||||
setFlash(w, "error", "Could not remove the alias default")
|
||||
} else {
|
||||
setFlash(w, "success", "Alias default removed")
|
||||
}
|
||||
http.Redirect(w, r, MailboxPrefix+"/signatures", http.StatusFound)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user