Files
mailblog/configuration.go
Laurent Ulrich 10ebdaad4a zz
2025-08-20 08:56:37 +02:00

78 lines
2.0 KiB
Go

package main
import (
"fmt"
"regexp"
"strconv"
)
type MailBoxConfiguration struct {
Server string
Port string
User string
Password string
SSL string
InBox string
}
type BlogConfiguration struct {
Title string
ShortName string
MailBox MailBoxConfiguration
}
func (configuration *BlogConfiguration) Prompt() error {
var err error
configuration.Title, err = prompt("Blog Title", nil, "", configuration.Title, false)
if err != nil {
return err
}
configuration.ShortName, err = prompt("Blog Short Name (only letters and numbers, no special signes)", nil, "blog", configuration.ShortName, false)
if err != nil {
return err
}
if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(configuration.ShortName) {
return fmt.Errorf("short same invalid")
}
/*
configuration.WWWRoot, err = prompt("Web Root directory", nil, fmt.Sprintf("/var/www/html/%s", configuration.ShortName), configuration.WWWRoot, false)
if err != nil {
return err
}
*/
configuration.MailBox.Server, err = prompt("IMAP Server Hostname or IP", nil, "", configuration.MailBox.Server, false)
if err != nil {
return err
}
configuration.MailBox.Port, err = prompt("IMAP Server Port", nil, "993", configuration.MailBox.Port, false)
if err != nil {
return err
}
_, err = strconv.ParseUint(configuration.MailBox.Port, 10, 16)
if err != nil {
return fmt.Errorf("imap server port invalid")
}
configuration.MailBox.User, err = prompt("IMAP User Login", nil, "", configuration.MailBox.User, false)
if err != nil {
return err
}
configuration.MailBox.Password, err = prompt("IMAP User Password", nil, "", configuration.MailBox.Password, false)
if err != nil {
return err
}
options := [...]string{"SSL/TLS", "StartTLS", "NoTLS"}
configuration.MailBox.SSL, err = prompt("IMAP SSL/TLS", options[:], "SSL/TLS", configuration.MailBox.SSL, false)
if err != nil {
return err
}
configuration.MailBox.InBox, err = prompt("IMAP INBOX", nil, "INBOX", configuration.MailBox.InBox, false)
if err != nil {
return err
}
return nil
}