Add "Full name" option to settings
This provides the name portion of your From header in the compose view.
This commit is contained in:
parent
51498a2dc3
commit
797b426ec6
2 changed files with 28 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -13,10 +13,19 @@
|
|||
<div class="container">
|
||||
<main class="settings">
|
||||
<form method="post">
|
||||
<div class="action-group">
|
||||
<label for="from">Full name</label>
|
||||
<input
|
||||
type="text"
|
||||
name="from"
|
||||
id="from"
|
||||
value="{{.Settings.From}}"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="action-group">
|
||||
<label for="signature">Message signature</label>
|
||||
<textarea
|
||||
type="number"
|
||||
name="signature"
|
||||
id="signature"
|
||||
rows="5"
|
||||
|
|
Loading…
Reference in a new issue