package app import ( "bytes" "log" "net/http" "text/template" "github.com/gin-gonic/gin" ) const thunderbirdTpl = ` {{ .Domain }} {{ .DisplayName }} {{ .DisplayShortName }} {{- if .IMAPEnabled }} {{ .IMAPServer }} {{ .IMAPPort }} {{- if .IMAPSSL }} SSL {{- else }} plain {{- end }} password-encrypted %EMAILADDRESS% {{- end }} {{- if .POP3Enabled }} {{ .POP3Server }} {{ .POP3Port }} {{- if .POP3SSL }} SSL {{- else }} plain {{- end }} password-cleartext %EMAILADDRESS% {{- end }} {{- if .SMTPEnabled }} {{ .SMTPServer }} {{ .SMTPPort }} {{- if .SMTPSSL }} SSL {{- else }} {{if .SMTPTLS }} STARTTLS {{- else }} plain {{- end }} {{- end }} password-encrypted %EMAILADDRESS% {{- end }} ` var thunderbirdTemplate *template.Template // https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat func RenderThunderbird(g *gin.Context) { host := g.Request.Host domain, ok := Domains[host] if !ok { g.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"}) return } var b bytes.Buffer if err := thunderbirdTemplate.Execute(&b, domain); err != nil { log.Fatal(err) } g.Header("Content-Type", "application/xml; charset=utf-8") g.String(http.StatusOK, b.String()) } // curl http://127.0.0.1:8888/.well-known/autoconfig/mail/config-v1.1.xml