-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenpgp.go
48 lines (41 loc) · 1.19 KB
/
openpgp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-FileCopyrightText: 2023 Dhia Gharsallaoui
// SPDX-FileCopyrightText: 2023 The go-mail Authors
//
// SPDX-License-Identifier: MIT
// Package openpgp implements a go-mail middleware to encrypt mails via OpenPGP
package openpgp
import (
"github.com/wneessen/go-mail"
)
const (
// Type is the type of Middleware
Type mail.MiddlewareType = "openpgp"
// Version is the version number of the Middleware
Version = "0.0.1"
)
// Middleware is the middleware struct for the openpgp middleware
type Middleware struct {
config *Config
}
// NewMiddleware returns a new Middleware from a given Config.
// The returned Middleware satisfies the mail.Middleware interface
func NewMiddleware(c *Config) *Middleware {
mw := &Middleware{
config: c,
}
return mw
}
// Handle is the handler method that satisfies the mail.Middleware interface
func (m *Middleware) Handle(msg *mail.Msg) *mail.Msg {
switch m.config.Scheme {
case SchemePGPInline:
return m.pgpInline(msg)
default:
m.config.Logger.Errorf("unsupported scheme %q. sending mail unencrypted", m.config.Scheme)
}
return msg
}
// Type returns the MiddlewareType for this Middleware
func (m *Middleware) Type() mail.MiddlewareType {
return Type
}