8
8
// Configuration is read from a .env file (or just the OS env vars directly).
9
9
// An .env file must be present in either the process working directory
10
10
// `$PWD/.env`, or in `/etc/webmention/mentionee.env`.
11
- //
11
+ //
12
12
// Configurable values are:
13
13
// - SHUTDOWN_TIMEOUT=Seconds: How long to wait for a clean shutdown after SIGINT or SIGTERM (default 120)
14
14
// - ENDPOINT=URL Path: On which path to listen for Webmentions (default /api/webmention)
15
15
// - LISTEN_ADDR=Domain with Port: Bind listener to this domain:port (default :8080)
16
16
// - ACCEPT_DOMAIN=Domain: Accept mentions if they point to this domain (e.g., the domain of your blog, required, no default)
17
17
// - NOTIFY_BY_MAIL=external, internal or no: Whether or not to enable notifications by mail (default no)
18
- // external: use an external (relay) SMTP server
19
- // internal: use builtin SMTP (deliver mail directly to the recipient)
18
+ //
20
19
// Options for external SMTP server:
21
20
// - MAIL_HOST=Domain: Domain of the outgoing mail server (no default, required)
22
21
// - MAIL_PORT=Port: Port of the outgoing mail server (no default, required)
23
22
// - MAIL_USER=Username: User to authenticate to the outgoing mail server (no default, required)
24
23
// - MAIL_PASS=Password: Password to authenticate to the outgoing mail server (no default, required)
25
24
// - MAIL_FROM=E-Mail address: Address used in the FROM header (default same as MAIL_USER)
26
25
// - MAIL_TO=E-Mail address: Address used in the TO header (default same as MAIL_FROM, or MAIL_USER if MAIL_FROM not set)
26
+ //
27
27
// Options for internal SMPT server:
28
28
// - MAIL_FROM=E-Mail address: Send emails from this address (required)
29
29
// - MAIL_TO=E-Mail address: Send emails to this email address (required)
@@ -41,6 +41,9 @@ package main
41
41
42
42
import (
43
43
"context"
44
+ "crypto/rsa"
45
+ "crypto/x509"
46
+ "encoding/pem"
44
47
"errors"
45
48
"fmt"
46
49
"log/slog"
@@ -50,14 +53,11 @@ import (
50
53
"os/signal"
51
54
"syscall"
52
55
"time"
53
- "crypto/x509"
54
- "crypto/rsa"
55
- "encoding/pem"
56
56
57
- "gopkg.in/gomail.v2"
58
- "github.com/joho/godotenv"
59
- "github.com/emersion/go-msgauth/dkim"
60
57
"github.com/cvanloo/parsenv"
58
+ "github.com/emersion/go-msgauth/dkim"
59
+ "github.com/joho/godotenv"
60
+ "gopkg.in/gomail.v2"
61
61
62
62
webmention "github.com/cvanloo/gowebmention"
63
63
"github.com/cvanloo/gowebmention/listener"
@@ -88,34 +88,34 @@ var ConfigMailExternal struct {
88
88
// For this, it needs to be authorized to send emails from the MAIL_FROM_ADDR
89
89
// domain. The following DNS entries are required:
90
90
//
91
- // - A | mail.example.com | 11.22.33.44
92
- // - MX | example.com | mail.example.com
93
- // - TXT | example.com | v=spf1 mx -all
94
- // - TXT | _dmarc.example.com | v=DMARC1; p=quarantine;
91
+ // - A | mail.example.com | 11.22.33.44
92
+ // - MX | example.com | mail.example.com
93
+ // - TXT | example.com | v=spf1 mx -all
94
+ // - TXT | _dmarc.example.com | v=DMARC1; p=quarantine;
95
95
//
96
96
// Replace example.com with your own domain, and 11.22.33.44 with the IP of the
97
97
// server on which mentionee runs.
98
98
//
99
99
// For DKIM refer to the documentation on ConfigMailDkim.
100
100
var ConfigMailInternal struct {
101
- MailFrom string `cfg:"required"`
102
- MailTo string `cfg:"required"`
103
- MailFromAddr string `cfg:"required"`
104
- MailToAddr string `cfg:"required"`
105
- MailDkimPriv string
101
+ MailFrom string `cfg:"required"`
102
+ MailTo string `cfg:"required"`
103
+ MailFromAddr string `cfg:"required"`
104
+ MailToAddr string `cfg:"required"`
105
+ MailDkimPriv string
106
106
}
107
107
108
108
// In addition to the DNS entries explained in ConfigMailInternal, you'll have
109
109
// to setup another DNS entry for DKIM verification to work.
110
110
//
111
- // - TXT | default._domainkey.example.com | v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY_HERE
111
+ // - TXT | default._domainkey.example.com | v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY_HERE
112
112
//
113
113
// "default" must be the same as in MAIL_DKIM_SELECTOR.
114
114
// You can create a pub/priv key pair using the commands:
115
115
//
116
- // openssl genrsa -out private 1024
117
- // openssl rsa -in private -pubout -out public
118
- // sed '1d;$d' public | tr -d '\n' > spublic; echo "" >> spublic
116
+ // openssl genrsa -out private 1024
117
+ // openssl rsa -in private -pubout -out public
118
+ // sed '1d;$d' public | tr -d '\n' > spublic; echo "" >> spublic
119
119
//
120
120
// MAIL_DKIM_PRIV must point to the 'private' file.
121
121
// As YOUR_PUBLIC_KEY_HERE in the above DNS entry, you must use the contents
@@ -126,19 +126,19 @@ var ConfigMailInternal struct {
126
126
// Since mentionee can only send, not receive emails, you might want to setup
127
127
// 'rua' and 'ruf' to point to a different email address:
128
128
//
129
- // - TXT | _dmarc.example.com | v=DMARC1; p=quarantine; rua=mailto:dmarc@whatever.else; ruf=mailto:dmarc-forensics@whatever.else;
129
+ // - TXT | _dmarc.example.com | v=DMARC1; p=quarantine; rua=mailto:dmarc@whatever.else; ruf=mailto:dmarc-forensics@whatever.else;
130
130
//
131
131
// For this to work, you also need an entry on the whatever.else domain:
132
132
//
133
- // - TXT | example.com._report._dmarc | v=DMARC1
133
+ // - TXT | example.com._report._dmarc | v=DMARC1
134
134
var ConfigMailDkim struct {
135
135
MailDkimSelector string `cfg:"default=default"`
136
136
MailDkimHost string `cfg:"required"`
137
137
}
138
138
139
139
const (
140
- ExitSuccess = 0
141
- ExitFailure = 1
140
+ ExitSuccess = 0
141
+ ExitFailure = 1
142
142
ExitConfigError = - 1
143
143
)
144
144
@@ -174,15 +174,15 @@ func loadConfig() (opts []webmention.ReceiverOption, listenAddr, endpoint string
174
174
}
175
175
mailer := listener.ExternalMailer {
176
176
SubjectLine : listener .DefaultSubjectLine ,
177
- Body : listener .DefaultBody ,
178
- From : from ,
179
- To : to ,
180
- Dialer : dialer ,
177
+ Body : listener .DefaultBody ,
178
+ From : from ,
179
+ To : to ,
180
+ Dialer : dialer ,
181
181
}
182
182
aggregator := & listener.ReportAggregator {
183
- SendAfterTime : 12 * time .Hour ,
183
+ SendAfterTime : 12 * time .Hour ,
184
184
SendAfterCount : - 1 ,
185
- Sender : mailer ,
185
+ Sender : mailer ,
186
186
}
187
187
opts = append (opts , webmention .WithNotifier (listener.Mailer {aggregator }))
188
188
agg = aggregator
@@ -213,38 +213,38 @@ func loadConfig() (opts []webmention.ReceiverOption, listenAddr, endpoint string
213
213
mailer := listener.InternalDKIMMailer {
214
214
InternalMailer : listener.InternalMailer {
215
215
SubjectLine : listener .DefaultSubjectLine ,
216
- Body : listener .DefaultBody ,
217
- FromAddr : ConfigMailInternal .MailFromAddr ,
218
- ToAddr : ConfigMailInternal .MailToAddr ,
219
- From : ConfigMailInternal .MailFrom ,
220
- To : ConfigMailInternal .MailTo ,
216
+ Body : listener .DefaultBody ,
217
+ FromAddr : ConfigMailInternal .MailFromAddr ,
218
+ ToAddr : ConfigMailInternal .MailToAddr ,
219
+ From : ConfigMailInternal .MailFrom ,
220
+ To : ConfigMailInternal .MailTo ,
221
221
},
222
222
DkimSignOpts : & dkim.SignOptions {
223
- Domain : ConfigMailDkim .MailDkimHost ,
223
+ Domain : ConfigMailDkim .MailDkimHost ,
224
224
Selector : ConfigMailDkim .MailDkimSelector ,
225
- Signer : pk ,
225
+ Signer : pk ,
226
226
},
227
227
}
228
228
aggregator := & listener.ReportAggregator {
229
- SendAfterTime : 12 * time .Hour ,
229
+ SendAfterTime : 12 * time .Hour ,
230
230
SendAfterCount : - 1 ,
231
- Sender : mailer ,
231
+ Sender : mailer ,
232
232
}
233
233
opts = append (opts , webmention .WithNotifier (listener.Mailer {aggregator }))
234
234
agg = aggregator
235
235
} else {
236
236
mailer := listener.InternalMailer {
237
237
SubjectLine : listener .DefaultSubjectLine ,
238
- Body : listener .DefaultBody ,
239
- FromAddr : ConfigMailInternal .MailFromAddr ,
240
- ToAddr : ConfigMailInternal .MailToAddr ,
241
- From : ConfigMailInternal .MailFrom ,
242
- To : ConfigMailInternal .MailTo ,
238
+ Body : listener .DefaultBody ,
239
+ FromAddr : ConfigMailInternal .MailFromAddr ,
240
+ ToAddr : ConfigMailInternal .MailToAddr ,
241
+ From : ConfigMailInternal .MailFrom ,
242
+ To : ConfigMailInternal .MailTo ,
243
243
}
244
244
aggregator := & listener.ReportAggregator {
245
- SendAfterTime : 12 * time .Hour ,
245
+ SendAfterTime : 12 * time .Hour ,
246
246
SendAfterCount : - 1 ,
247
- Sender : mailer ,
247
+ Sender : mailer ,
248
248
}
249
249
opts = append (opts , webmention .WithNotifier (listener.Mailer {aggregator }))
250
250
agg = aggregator
0 commit comments