mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-03 05:34:26 +01:00
The lib/auth package parses Authentication-Results email headers, not general authentication mechanisms. Rename it to lib/authres to better reflect its purpose and avoid confusion with SASL/OAuth authentication code. This also aligns with the go-msgauth/authres library it wraps. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Simon Martin <simon@nasilyan.com>
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
"git.sr.ht/~rjarry/aerc/lib/authres"
|
|
"git.sr.ht/~rjarry/aerc/lib/ui"
|
|
"git.sr.ht/~rockorager/vaxis"
|
|
"github.com/mattn/go-runewidth"
|
|
)
|
|
|
|
type AuthInfo struct {
|
|
authdetails *authres.Details
|
|
showInfo bool
|
|
uiConfig *config.UIConfig
|
|
}
|
|
|
|
func NewAuthInfo(auth *authres.Details, showInfo bool, uiConfig *config.UIConfig) *AuthInfo {
|
|
return &AuthInfo{authdetails: auth, showInfo: showInfo, uiConfig: uiConfig}
|
|
}
|
|
|
|
func (a *AuthInfo) Draw(ctx *ui.Context) {
|
|
defaultStyle := a.uiConfig.GetStyle(config.STYLE_DEFAULT)
|
|
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
|
|
var text string
|
|
switch {
|
|
case a.authdetails == nil:
|
|
text = "(no header)"
|
|
ctx.Printf(0, 0, defaultStyle, "%s", text)
|
|
case a.authdetails.Err != nil:
|
|
style := a.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
text = a.authdetails.Err.Error()
|
|
ctx.Printf(0, 0, style, "%s", text)
|
|
default:
|
|
checkBounds := func(x int) bool {
|
|
return x < ctx.Width()
|
|
}
|
|
setResult := func(result authres.Result) (string, vaxis.Style) {
|
|
switch result {
|
|
case authres.ResultNone:
|
|
return "none", defaultStyle
|
|
case authres.ResultNeutral:
|
|
return "neutral", a.uiConfig.GetStyle(config.STYLE_WARNING)
|
|
case authres.ResultPolicy:
|
|
return "policy", a.uiConfig.GetStyle(config.STYLE_WARNING)
|
|
case authres.ResultPass:
|
|
return "✓", a.uiConfig.GetStyle(config.STYLE_SUCCESS)
|
|
case authres.ResultFail:
|
|
return "✗", a.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
default:
|
|
return string(result), a.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
}
|
|
}
|
|
x := 1
|
|
for i := 0; i < len(a.authdetails.Results); i++ {
|
|
if checkBounds(x) {
|
|
text, style := setResult(a.authdetails.Results[i])
|
|
if i > 0 {
|
|
text = " " + text
|
|
}
|
|
x += ctx.Printf(x, 0, style, "%s", text)
|
|
}
|
|
}
|
|
if a.showInfo {
|
|
infoText := ""
|
|
for i := 0; i < len(a.authdetails.Infos); i++ {
|
|
if i > 0 {
|
|
infoText += ","
|
|
}
|
|
infoText += a.authdetails.Infos[i]
|
|
if reason := a.authdetails.Reasons[i]; reason != "" {
|
|
infoText += reason
|
|
}
|
|
}
|
|
if checkBounds(x) && infoText != "" {
|
|
if trunc := ctx.Width() - x - 3; trunc > 0 {
|
|
text = runewidth.Truncate(infoText, trunc, "…")
|
|
ctx.Printf(x, 0, defaultStyle, " (%s)", text)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a *AuthInfo) Invalidate() {
|
|
ui.Invalidate()
|
|
}
|