87555fdc4d
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"git.dcglab.co.uk/steve/emcli/internal/store"
|
|
)
|
|
|
|
// accountShow renders one account's configuration. The password is never shown.
|
|
func accountShow(st *store.Store, rest []string, out, errOut io.Writer) int {
|
|
if len(rest) == 0 {
|
|
fmt.Fprintln(errOut, "usage: emcli account show <name>")
|
|
return 2
|
|
}
|
|
if len(rest) > 1 {
|
|
fmt.Fprintf(errOut, "unexpected argument %q\n", rest[1])
|
|
return 2
|
|
}
|
|
a, err := st.GetAccount(rest[0])
|
|
if err != nil {
|
|
fmt.Fprintf(errOut, "show: %v\n", err)
|
|
return 1
|
|
}
|
|
onOff := func(b bool) string {
|
|
if b {
|
|
return "enabled"
|
|
}
|
|
return "disabled"
|
|
}
|
|
smtp := "-"
|
|
if a.SMTPHost != "" {
|
|
smtp = fmt.Sprintf("%s:%d (%s)", a.SMTPHost, a.SMTPPort, a.SMTPSecurity)
|
|
}
|
|
subj := a.SubjectRegex
|
|
if subj == "" {
|
|
subj = "(none)"
|
|
}
|
|
// Labels padded to the width of the longest ("outbound whitelist:") so
|
|
// every value aligns in one column.
|
|
const lbl = "%-19s %s\n"
|
|
fmt.Fprintf(out, lbl, "name:", a.Name)
|
|
fmt.Fprintf(out, lbl, "mode:", a.Mode)
|
|
fmt.Fprintf(out, lbl, "imap:", fmt.Sprintf("%s:%d (%s)", a.IMAPHost, a.IMAPPort, a.IMAPSecurity))
|
|
fmt.Fprintf(out, lbl, "smtp:", smtp)
|
|
fmt.Fprintf(out, lbl, "username:", a.Username)
|
|
fmt.Fprintf(out, lbl, "send-from:", a.SendFrom())
|
|
fmt.Fprintf(out, lbl, "subject filter:", subj)
|
|
fmt.Fprintf(out, lbl, "inbound whitelist:", onOff(a.WhitelistInEnabled))
|
|
fmt.Fprintf(out, lbl, "outbound whitelist:", onOff(a.WhitelistOutEnabled))
|
|
return 0
|
|
}
|