package widgets import ( "errors" "fmt" "net" "net/url" "os" "os/exec" "path" "strconv" "strings" "time" "github.com/gdamore/tcell" "github.com/go-ini/ini" "github.com/kyoh86/xdg" "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib/ui" ) const ( CONFIGURE_BASICS = iota CONFIGURE_INCOMING = iota CONFIGURE_OUTGOING = iota CONFIGURE_COMPLETE = iota ) const ( IMAP_OVER_TLS = iota IMAP_STARTTLS = iota IMAP_INSECURE = iota ) const ( SMTP_OVER_TLS = iota SMTP_STARTTLS = iota SMTP_INSECURE = iota ) type AccountWizard struct { ui.Invalidatable aerc *Aerc conf *config.AercConfig step int steps []*ui.Grid focus int temporary bool testing bool // CONFIGURE_BASICS accountName *ui.TextInput email *ui.TextInput fullName *ui.TextInput basics []ui.Interactive // CONFIGURE_INCOMING imapUsername *ui.TextInput imapPassword *ui.TextInput imapServer *ui.TextInput imapMode int imapStr *ui.Text imapUrl url.URL incoming []ui.Interactive // CONFIGURE_OUTGOING smtpUsername *ui.TextInput smtpPassword *ui.TextInput smtpServer *ui.TextInput smtpMode int smtpStr *ui.Text smtpUrl url.URL copySent bool outgoing []ui.Interactive // CONFIGURE_COMPLETE complete []ui.Interactive } func NewAccountWizard(conf *config.AercConfig, aerc *Aerc) *AccountWizard { wizard := &AccountWizard{ accountName: ui.NewTextInput("").Prompt("> "), aerc: aerc, conf: conf, temporary: false, copySent: true, email: ui.NewTextInput("").Prompt("> "), fullName: ui.NewTextInput("").Prompt("> "), imapPassword: ui.NewTextInput("").Prompt("] ").Password(true), imapServer: ui.NewTextInput("").Prompt("> "), imapStr: ui.NewText("imaps://"), imapUsername: ui.NewTextInput("").Prompt("> "), smtpPassword: ui.NewTextInput("").Prompt("] ").Password(true), smtpServer: ui.NewTextInput("").Prompt("> "), smtpStr: ui.NewText("smtps://"), smtpUsername: ui.NewTextInput("").Prompt("> "), } // Autofill some stuff for the user wizard.email.OnChange(func(_ *ui.TextInput) { value := wizard.email.String() wizard.imapUsername.Set(value) wizard.smtpUsername.Set(value) if strings.ContainsRune(value, '@') { server := value[strings.IndexRune(value, '@')+1:] wizard.imapServer.Set(server) wizard.smtpServer.Set(server) } wizard.imapUri() wizard.smtpUri() }) wizard.imapServer.OnChange(func(_ *ui.TextInput) { imapServerURI := wizard.imapServer.String() smtpServerURI := imapServerURI if strings.HasPrefix(imapServerURI, "imap.") { smtpServerURI = strings.Replace(imapServerURI, "imap.", "smtp.", 1) } wizard.smtpServer.Set(smtpServerURI) wizard.imapUri() wizard.smtpUri() }) wizard.imapUsername.OnChange(func(_ *ui.TextInput) { wizard.smtpUsername.Set(wizard.imapUsername.String()) wizard.imapUri() wizard.smtpUri() }) wizard.imapPassword.OnChange(func(_ *ui.TextInput) { wizard.smtpPassword.Set(wizard.imapPassword.String()) wizard.imapUri() wizard.smtpUri() }) wizard.smtpServer.OnChange(func(_ *ui.TextInput) { wizard.smtpUri() }) wizard.smtpUsername.OnChange(func(_ *ui.TextInput) { wizard.smtpUri() }) wizard.smtpPassword.OnChange(func(_ *ui.TextInput) { wizard.smtpUri() }) basics := ui.NewGrid().Rows([]ui.GridSpec{ {ui.SIZE_EXACT, 8}, // Introduction {ui.SIZE_EXACT, 1}, // Account name (label) {ui.SIZE_EXACT, 1}, // (input) {ui.SIZE_EXACT, 1}, // Padding {ui.SIZE_EXACT, 1}, // Full name (label) {ui.SIZE_EXACT, 1}, // (input) {ui.SIZE_EXACT, 1}, // Padding {ui.SIZE_EXACT, 1}, // Email address (label) {ui.SIZE_EXACT, 1}, // (input) {ui.SIZE_WEIGHT, 1}, }).Columns([]ui.GridSpec{ {ui.SIZE_WEIGHT, 1}, }) basics.AddChild( ui.NewText("\nWelcome to aerc! Let's configure your account.\n\n" + "This wizard supports basic I
Forwarded message from {{(index .OriginalFrom 0).Name}} on {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}:
{{wrapText .OriginalText 72}}