aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-08-18 21:05:00 +0200
committerRobin Jarry <robin@jarry.cc>2023-08-26 21:41:05 +0200
commitd620a75f347a88d152e2dc63014178fb9ca2bb73 (patch)
tree11710a05ad1685c5e0b43781d4b15db164747f6d
parent109244fef13aba5d7a9e670b7b1a0745249e643d (diff)
downloadaerc-d620a75f347a88d152e2dc63014178fb9ca2bb73.tar.gz
aerc-d620a75f347a88d152e2dc63014178fb9ca2bb73.zip
wizard: autofill improvements
* Do not determine the IMAP server based on the email domain. It will most of the time be incorrect. * Only mirror the email address in usernames if they are unset. * Only mirror the IMAP username & password into their SMTP counterparts if these are unset. * Try to guess the SMTP server based on the IMAP server only if the former is empty. * Only display the password warning if the user did type a password. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--widgets/account-wizard.go48
1 files changed, 30 insertions, 18 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index 897abc53..ffbdb28b 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -105,32 +105,37 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard {
}
// Autofill some stuff for the user
- wizard.email.OnChange(func(_ *ui.TextInput) {
+ wizard.email.OnFocusLost(func(_ *ui.TextInput) {
value := wizard.email.String()
- wizard.sourceUsername.Set(value)
- wizard.outgoingUsername.Set(value)
- if strings.ContainsRune(value, '@') {
- server := value[strings.IndexRune(value, '@')+1:]
- wizard.sourceServer.Set(server)
- wizard.outgoingServer.Set(server)
+ if wizard.sourceUsername.String() == "" {
+ wizard.sourceUsername.Set(value)
+ }
+ if wizard.outgoingUsername.String() == "" {
+ wizard.outgoingUsername.Set(value)
}
wizard.sourceUri()
wizard.outgoingUri()
})
wizard.sourceServer.OnChange(func(_ *ui.TextInput) {
- sourceServerURI := wizard.sourceServer.String()
- outgoingServerURI := sourceServerURI
- if strings.HasPrefix(sourceServerURI, "imap.") {
- outgoingServerURI = strings.Replace(sourceServerURI, "imap.", "smtp.", 1)
- }
- wizard.outgoingServer.Set(outgoingServerURI)
wizard.sourceUri()
+ })
+ wizard.sourceServer.OnFocusLost(func(_ *ui.TextInput) {
+ src := wizard.sourceServer.String()
+ out := wizard.outgoingServer.String()
+ if out == "" && strings.HasPrefix(src, "imap.") {
+ out = strings.Replace(src, "imap.", "smtp.", 1)
+ wizard.outgoingServer.Set(out)
+ }
wizard.outgoingUri()
})
wizard.sourceUsername.OnChange(func(_ *ui.TextInput) {
- wizard.outgoingUsername.Set(wizard.sourceUsername.String())
wizard.sourceUri()
- wizard.outgoingUri()
+ })
+ wizard.sourceUsername.OnFocusLost(func(_ *ui.TextInput) {
+ if wizard.outgoingUsername.String() == "" {
+ wizard.outgoingUsername.Set(wizard.sourceUsername.String())
+ wizard.outgoingUri()
+ }
})
var once sync.Once
wizard.sourcePassword.OnChange(func(_ *ui.TextInput) {
@@ -139,9 +144,11 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard {
wizard.outgoingUri()
})
wizard.sourcePassword.OnFocusLost(func(_ *ui.TextInput) {
- once.Do(func() {
- showPasswordWarning(aerc)
- })
+ if wizard.sourcePassword.String() != "" {
+ once.Do(func() {
+ showPasswordWarning(aerc)
+ })
+ }
})
wizard.outgoingServer.OnChange(func(_ *ui.TextInput) {
wizard.outgoingUri()
@@ -150,6 +157,11 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard {
wizard.outgoingUri()
})
wizard.outgoingPassword.OnChange(func(_ *ui.TextInput) {
+ if wizard.outgoingPassword.String() != "" {
+ once.Do(func() {
+ showPasswordWarning(aerc)
+ })
+ }
wizard.outgoingUri()
})