aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/base/public/settings.html37
-rw-r--r--plugins/base/routes.go10
-rw-r--r--session.go46
-rw-r--r--themes/alps/settings.html24
-rw-r--r--themes/sourcehut/settings.html68
5 files changed, 183 insertions, 2 deletions
diff --git a/plugins/base/public/settings.html b/plugins/base/public/settings.html
index 7acacb5..da950e4 100644
--- a/plugins/base/public/settings.html
+++ b/plugins/base/public/settings.html
@@ -9,9 +9,46 @@
<h2>Settings</h2>
<form method="post" action="">
+ <label for="from">Full name:</label>
+ <input type="text" name="from" id="from" value="{{.Settings.From}}">
+ <br><br>
+
+ <label for="signature">Message signature:</label>
+ <textarea name="signature" id="signature" rows="5">{{.Settings.Signature}}</textarea>
+ <br><br>
+
+ <label for="smtp_username">Custom SMTP Username (optional):</label>
+ <input type="text" name="smtp_username" id="smtp_username" value="{{.Settings.SMTPUsername}}" placeholder="Leave empty to use login username">
+ <br>
+ <small>Use this if your SMTP server requires different credentials than your email login</small>
+ <br><br>
+
+ <label for="smtp_password">Custom SMTP Password (optional):</label>
+ <input type="password" name="smtp_password" id="smtp_password" value="{{.Settings.SMTPPassword}}" placeholder="Leave empty to use login password">
+ <br>
+ <small>Use this if your SMTP server requires different credentials than your email login</small>
+ <br><br>
+
+ <label for="subscriptions">Subscribed folders:</label>
+ <select name="subscriptions" id="subscriptions" multiple>
+ {{ $subs := .Subscriptions }}
+ {{ range .Mailboxes }}
+ {{ if and (ne .Name "INBOX") (not (.HasAttr "\\Noselect")) }}
+ <option
+ value="{{.Name}}"
+ {{ if $subs.Has .Name }}
+ selected
+ {{ end }}
+ >{{.Name}}</option>
+ {{ end }}
+ {{ end }}
+ </select>
+ <br><br>
+
<label for="messages_per_page">Messages per page:</label>
<input type="number" name="messages_per_page" id="messages_per_page" required value="{{.Settings.MessagesPerPage}}">
<br><br>
+
<input type="submit" value="Save">
</form>
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 623a5cc..4640c93 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -1243,6 +1243,8 @@ type Settings struct {
Signature string
From string
Subscriptions []string
+ SMTPUsername string
+ SMTPPassword string
}
func loadSettings(s alps.Store) (*Settings, error) {
@@ -1268,6 +1270,12 @@ func (s *Settings) check() error {
if len(s.From) > 512 {
return fmt.Errorf("Full name must be 512 characters or fewer")
}
+ if len(s.SMTPUsername) > 255 {
+ return fmt.Errorf("SMTP username must be 255 characters or fewer")
+ }
+ if len(s.SMTPPassword) > 255 {
+ return fmt.Errorf("SMTP password must be 255 characters or fewer")
+ }
return nil
}
@@ -1311,6 +1319,8 @@ func handleSettings(ctx *alps.Context) error {
}
settings.Signature = ctx.FormValue("signature")
settings.From = ctx.FormValue("from")
+ settings.SMTPUsername = ctx.FormValue("smtp_username")
+ settings.SMTPPassword = ctx.FormValue("smtp_password")
params, err := ctx.FormParams()
if err != nil {
diff --git a/session.go b/session.go
index a85bff6..f241b6a 100644
--- a/session.go
+++ b/session.go
@@ -112,7 +112,23 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
}
defer c.Close()
- auth := sasl.NewPlainClient("", s.username, s.password)
+ // Try to get custom SMTP credentials from user settings
+ smtpUsername := s.username
+ smtpPassword := s.password
+
+ // Load settings to check for custom SMTP credentials
+ if settings, err := s.loadSMTPSettings(); err == nil {
+ // Use custom username if provided, otherwise keep login username
+ if settings.SMTPUsername != "" {
+ smtpUsername = settings.SMTPUsername
+ }
+ // Use custom password if provided, otherwise keep login password
+ if settings.SMTPPassword != "" {
+ smtpPassword = settings.SMTPPassword
+ }
+ }
+
+ auth := sasl.NewPlainClient("", smtpUsername, smtpPassword)
if err := c.Auth(auth); err != nil {
return AuthError{err}
}
@@ -128,6 +144,34 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
return nil
}
+// SMTPSettings represents custom SMTP authentication settings
+type SMTPSettings struct {
+ SMTPUsername string
+ SMTPPassword string
+}
+
+// loadSMTPSettings is a helper method to load SMTP settings for this session
+func (s *Session) loadSMTPSettings() (*SMTPSettings, error) {
+ const settingsKey = "base.settings"
+ var fullSettings struct {
+ MessagesPerPage int
+ Signature string
+ From string
+ Subscriptions []string
+ SMTPUsername string
+ SMTPPassword string
+ }
+
+ if err := s.Store().Get(settingsKey, &fullSettings); err != nil {
+ return nil, err
+ }
+
+ return &SMTPSettings{
+ SMTPUsername: fullSettings.SMTPUsername,
+ SMTPPassword: fullSettings.SMTPPassword,
+ }, nil
+}
+
// SetHTTPBasicAuth adds an Authorization header field to the request with
// this session's credentials.
func (s *Session) SetHTTPBasicAuth(req *http.Request) {
diff --git a/themes/alps/settings.html b/themes/alps/settings.html
index 61e76e6..c845055 100644
--- a/themes/alps/settings.html
+++ b/themes/alps/settings.html
@@ -33,6 +33,30 @@
</div>
<div class="action-group">
+ <label for="smtp_username">Custom SMTP Username (optional)</label>
+ <input
+ type="text"
+ name="smtp_username"
+ id="smtp_username"
+ value="{{.Settings.SMTPUsername}}"
+ placeholder="Leave empty to use login username"
+ />
+ <small>Use this if your SMTP server requires different credentials than your email login</small>
+ </div>
+
+ <div class="action-group">
+ <label for="smtp_password">Custom SMTP Password (optional)</label>
+ <input
+ type="password"
+ name="smtp_password"
+ id="smtp_password"
+ value="{{.Settings.SMTPPassword}}"
+ placeholder="Leave empty to use login password"
+ />
+ <small>Use this if your SMTP server requires different credentials than your email login</small>
+ </div>
+
+ <div class="action-group">
<label for="subscriptions">Subscribed folders</label>
<select name="subscriptions" id="subscriptions" multiple>
{{ $subs := .Subscriptions }}
diff --git a/themes/sourcehut/settings.html b/themes/sourcehut/settings.html
index c197789..43228af 100644
--- a/themes/sourcehut/settings.html
+++ b/themes/sourcehut/settings.html
@@ -12,6 +12,72 @@
<div class="container">
<form method="post" class="col-md-12">
<div class="form-group">
+ <label for="from">Full name:</label>
+ <input
+ type="text"
+ name="from"
+ id="from"
+ class="form-control"
+ value="{{.Settings.From}}"
+ placeholder="Your display name for outgoing emails"
+ />
+ </div>
+
+ <div class="form-group">
+ <label for="signature">Message signature:</label>
+ <textarea
+ name="signature"
+ id="signature"
+ class="form-control"
+ rows="5"
+ placeholder="Optional signature to append to your emails"
+ >{{.Settings.Signature}}</textarea>
+ </div>
+
+ <div class="form-group">
+ <label for="smtp_username">Custom SMTP Username (optional):</label>
+ <input
+ type="text"
+ name="smtp_username"
+ id="smtp_username"
+ class="form-control"
+ value="{{.Settings.SMTPUsername}}"
+ placeholder="Leave empty to use login username"
+ />
+ <small class="form-text text-muted">Use this if your SMTP server requires different credentials than your email login</small>
+ </div>
+
+ <div class="form-group">
+ <label for="smtp_password">Custom SMTP Password (optional):</label>
+ <input
+ type="password"
+ name="smtp_password"
+ id="smtp_password"
+ class="form-control"
+ value="{{.Settings.SMTPPassword}}"
+ placeholder="Leave empty to use login password"
+ />
+ <small class="form-text text-muted">Use this if your SMTP server requires different credentials than your email login</small>
+ </div>
+
+ <div class="form-group">
+ <label for="subscriptions">Subscribed folders:</label>
+ <select name="subscriptions" id="subscriptions" class="form-control" multiple>
+ {{ $subs := .Subscriptions }}
+ {{ range .Mailboxes }}
+ {{ if and (ne .Name "INBOX") (not (.HasAttr "\\Noselect")) }}
+ <option
+ value="{{.Name}}"
+ {{ if $subs.Has .Name }}
+ selected
+ {{ end }}
+ >{{.Name}}</option>
+ {{ end }}
+ {{ end }}
+ </select>
+ </div>
+
+ <div class="form-group">
<label for="messages_per_page">Messages per page:</label>
<input
type="number"
@@ -21,6 +87,7 @@
class="form-control"
value="{{.Settings.MessagesPerPage}}" />
</div>
+
<div class="pull-right">
<a
href="/"
@@ -34,5 +101,4 @@
</form>
</div>
-
{{template "foot.html"}}