From 797b426ec6a6fc0222ff9dc94e33346abcb82663 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 19 Nov 2020 11:48:12 -0500 Subject: Add "Full name" option to settings This provides the name portion of your From header in the compose view. --- plugins/base/routes.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index f20097e..7a8b845 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -531,7 +531,19 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti } if msg.From == "" && strings.ContainsRune(ctx.Session.Username(), '@') { - msg.From = ctx.Session.Username() + settings, err := loadSettings(ctx.Session.Store()) + if err != nil { + return err + } + if settings.From != "" { + addr := mail.Address{ + Name: settings.From, + Address: ctx.Session.Username(), + } + msg.From = addr.String() + } else { + msg.From = ctx.Session.Username() + } } if ctx.Request().Method == http.MethodPost { @@ -1134,6 +1146,7 @@ const maxMessagesPerPage = 100 type Settings struct { MessagesPerPage int Signature string + From string } func loadSettings(s alps.Store) (*Settings, error) { @@ -1156,6 +1169,9 @@ func (s *Settings) check() error { if len(s.Signature) > 2048 { return fmt.Errorf("Signature must be 2048 characters or fewer") } + if len(s.From) > 512 { + return fmt.Errorf("Full name must be 512 characters or fewer") + } return nil } @@ -1176,6 +1192,7 @@ func handleSettings(ctx *alps.Context) error { return echo.NewHTTPError(http.StatusBadRequest, "invalid messages per page: %v", err) } settings.Signature = ctx.FormValue("signature") + settings.From = ctx.FormValue("from") if err := settings.check(); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err) -- cgit v1.2.3