mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
feat: remove dependency on go-apple-mobileconfig
This commit is contained in:
75
pkg/mobileconfig/config.go
Normal file
75
pkg/mobileconfig/config.go
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright (c) 2021 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package mobileconfig
|
||||
|
||||
import (
|
||||
"io"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Config represents an Apple mobileconfig file.
|
||||
type Config struct {
|
||||
EmailAddress string
|
||||
DisplayName string
|
||||
Identifier string
|
||||
Organization string
|
||||
AccountDescription string
|
||||
|
||||
IMAP *IMAP
|
||||
SMTP *SMTP
|
||||
|
||||
Description string
|
||||
ContentUUID string
|
||||
UUID string
|
||||
}
|
||||
|
||||
type IMAP struct {
|
||||
Hostname string
|
||||
Port int
|
||||
TLS bool
|
||||
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type SMTP struct {
|
||||
Hostname string
|
||||
Port int
|
||||
TLS bool
|
||||
|
||||
// Leave Username blank to do not use SMTP authentication.
|
||||
Username string
|
||||
// Leave Password blank to use IMAP credentials.
|
||||
Password string
|
||||
}
|
||||
|
||||
func (c *Config) WriteOut(w io.Writer) error {
|
||||
if c.ContentUUID == "" {
|
||||
uuid := uuid.New()
|
||||
c.ContentUUID = uuid.String()
|
||||
}
|
||||
|
||||
if c.UUID == "" {
|
||||
uuid := uuid.New()
|
||||
c.UUID = uuid.String()
|
||||
}
|
||||
|
||||
return template.Must(template.New("mobileconfig").Parse(mailTemplate)).Execute(w, c)
|
||||
}
|
||||
153
pkg/mobileconfig/template.go
Normal file
153
pkg/mobileconfig/template.go
Normal file
@ -0,0 +1,153 @@
|
||||
// Copyright (c) 2021 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package mobileconfig
|
||||
|
||||
const mailTemplate = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PayloadContent</key>
|
||||
<array>
|
||||
<dict>
|
||||
{{- if .AccountDescription}}
|
||||
<key>EmailAccountDescription</key>
|
||||
<string>{{.AccountDescription}}</string>
|
||||
{{- end}}
|
||||
|
||||
{{- if .IMAP}}
|
||||
<key>EmailAccountType</key>
|
||||
<string>EmailTypeIMAP</string>
|
||||
|
||||
<key>EmailAddress</key>
|
||||
<string>{{.EmailAddress}}</string>
|
||||
|
||||
<key>IncomingMailServerAuthentication</key>
|
||||
<string>EmailAuthPassword</string>
|
||||
|
||||
<key>IncomingMailServerHostName</key>
|
||||
<string>{{.IMAP.Hostname}}</string>
|
||||
|
||||
<key>IncomingMailServerPortNumber</key>
|
||||
<integer>{{.IMAP.Port}}</integer>
|
||||
|
||||
<key>IncomingMailServerUseSSL</key>
|
||||
{{- if .IMAP.TLS}}
|
||||
<true/>
|
||||
{{- else}}
|
||||
<false/>
|
||||
{{- end}}
|
||||
|
||||
<key>IncomingMailServerUsername</key>
|
||||
<string>{{.IMAP.Username}}</string>
|
||||
|
||||
<key>IncomingPassword</key>
|
||||
<string>{{.IMAP.Password}}</string>
|
||||
{{- end}}
|
||||
|
||||
{{ if .SMTP}}
|
||||
<key>OutgoingMailServerAuthentication</key>
|
||||
<string>{{if .SMTP.Username}}EmailAuthPassword{{else}}EmailAuthNone{{end}}</string>
|
||||
|
||||
<key>OutgoingMailServerHostName</key>
|
||||
<string>{{.SMTP.Hostname}}</string>
|
||||
|
||||
<key>OutgoingMailServerPortNumber</key>
|
||||
<integer>{{.SMTP.Port}}</integer>
|
||||
|
||||
<key>OutgoingMailServerUseSSL</key>
|
||||
{{- if .SMTP.TLS}}
|
||||
<true/>
|
||||
{{- else}}
|
||||
<false/>
|
||||
{{- end}}
|
||||
|
||||
{{- if .SMTP.Username}}
|
||||
<key>OutgoingMailServerUsername</key>
|
||||
<string>{{.SMTP.Username}}</string>
|
||||
{{- end}}
|
||||
|
||||
{{- if .SMTP.Password}}
|
||||
<key>OutgoingPassword</key>
|
||||
<string>{{.SMTP.Password}}</string>
|
||||
{{- else}}
|
||||
<key>OutgoingPasswordSameAsIncomingPassword</key>
|
||||
<true/>
|
||||
{{- end}}
|
||||
{{end}}
|
||||
|
||||
<key>PayloadDescription</key>
|
||||
<string>Configures email account.</string>
|
||||
|
||||
<key>PayloadDisplayName</key>
|
||||
<string>{{.DisplayName}}</string>
|
||||
|
||||
<key>PayloadIdentifier</key>
|
||||
<string>{{.Identifier}}</string>
|
||||
|
||||
{{- if .Organization}}
|
||||
<key>PayloadOrganization</key>
|
||||
<string>{{.Organization}}</string>
|
||||
{{- end}}
|
||||
|
||||
<key>PayloadType</key>
|
||||
<string>com.apple.mail.managed</string>
|
||||
|
||||
<key>PayloadUUID</key>
|
||||
<string>{{.ContentUUID}}</string>
|
||||
|
||||
<key>PayloadVersion</key>
|
||||
<integer>1</integer>
|
||||
|
||||
<key>PreventAppSheet</key>
|
||||
<false/>
|
||||
|
||||
<key>PreventMove</key>
|
||||
<false/>
|
||||
|
||||
<key>SMIMEEnabled</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</array>
|
||||
|
||||
<key>PayloadDescription</key>
|
||||
<string>{{if .Description}}{{.Description}}{{else}}Install this profile to auto configure email account for {{.EmailAddress}}.{{- end}}</string>
|
||||
|
||||
<key>PayloadDisplayName</key>
|
||||
<string>{{.DisplayName}}</string>
|
||||
|
||||
<key>PayloadIdentifier</key>
|
||||
<string>{{.Identifier}}</string>
|
||||
|
||||
{{- if .Organization}}
|
||||
<key>PayloadOrganization</key>
|
||||
<string>{{.Organization}}</string>
|
||||
{{- end}}
|
||||
|
||||
<key>PayloadRemovalDisallowed</key>
|
||||
<false/>
|
||||
|
||||
<key>PayloadType</key>
|
||||
<string>Configuration</string>
|
||||
|
||||
<key>PayloadUUID</key>
|
||||
<string>{{.UUID}}</string>
|
||||
|
||||
<key>PayloadVersion</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</plist>`
|
||||
Reference in New Issue
Block a user