91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"text/template"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
const thunderbirdTpl = `
|
||
|
<clientConfig version="1.1">
|
||
|
<emailProvider id="{{ .Domain }}">
|
||
|
<domain>{{ .Domain }}</domain>
|
||
|
<displayName>{{ .DisplayName }}</displayName>
|
||
|
<displayShortName>{{ .DisplayShortName }}</displayShortName>
|
||
|
|
||
|
{{- if .IMAPEnabled }}
|
||
|
<incomingServer type="imap">
|
||
|
<hostname>{{ .IMAPServer }}</hostname>
|
||
|
<port>{{ .IMAPPort }}</port>
|
||
|
{{- if .IMAPSSL }}
|
||
|
<socketType>SSL</socketType>
|
||
|
{{- else }}
|
||
|
<socketType>plain</socketType>
|
||
|
{{- end }}
|
||
|
<authentication>password-encrypted</authentication>
|
||
|
<username>%EMAILADDRESS%</username>
|
||
|
</incomingServer>
|
||
|
{{- end }}
|
||
|
|
||
|
{{- if .POP3Enabled }}
|
||
|
<incomingServer type="pop3">
|
||
|
<hostname>{{ .POP3Server }}</hostname>
|
||
|
<port>{{ .POP3Port }}</port>
|
||
|
{{- if .POP3SSL }}
|
||
|
<socketType>SSL</socketType>
|
||
|
{{- else }}
|
||
|
<socketType>plain</socketType>
|
||
|
{{- end }}
|
||
|
<authentication>password-cleartext</authentication>
|
||
|
<username>%EMAILADDRESS%</username>
|
||
|
</incomingServer>
|
||
|
{{- end }}
|
||
|
|
||
|
{{- if .SMTPEnabled }}
|
||
|
<outgoingServer type="smtp">
|
||
|
<hostname>{{ .SMTPServer }}</hostname>
|
||
|
<port>{{ .SMTPPort }}</port>
|
||
|
{{- if .SMTPSSL }}
|
||
|
<socketType>SSL</socketType>
|
||
|
{{- else }}
|
||
|
{{if .SMTPTLS }}
|
||
|
<socketType>STARTTLS</socketType>
|
||
|
{{- else }}
|
||
|
<socketType>plain</socketType>
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
<authentication>password-encrypted</authentication>
|
||
|
<username>%EMAILADDRESS%</username>
|
||
|
</outgoingServer>
|
||
|
{{- end }}
|
||
|
|
||
|
</emailProvider>
|
||
|
</clientConfig>
|
||
|
`
|
||
|
|
||
|
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
|