-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
package smtp | ||
|
||
import ( | ||
"github.com/awakari/int-email/service/writer" | ||
"github.com/emersion/go-smtp" | ||
"github.com/awakari/int-email/service/writer" | ||
"github.com/emersion/go-smtp" | ||
) | ||
|
||
type backend struct { | ||
svcWriter writer.Service | ||
rcpts map[string]bool | ||
dataLimit int64 | ||
svcWriter writer.Service | ||
rcpts map[string]bool | ||
dataLimit int64 | ||
} | ||
|
||
func NewBackend(svcWriter writer.Service, rcpts map[string]bool, dataLimit int64) smtp.Backend { | ||
return backend{ | ||
svcWriter: svcWriter, | ||
rcpts: rcpts, | ||
dataLimit: dataLimit, | ||
} | ||
return backend{ | ||
svcWriter: svcWriter, | ||
rcpts: rcpts, | ||
dataLimit: dataLimit, | ||
} | ||
} | ||
|
||
func (b backend) NewSession(c *smtp.Conn) (s smtp.Session, err error) { | ||
s = newSession(b.svcWriter, b.rcpts, b.dataLimit) | ||
return | ||
connState, tlsOk := c.TLSConnectionState() | ||
switch { | ||
case tlsOk && connState.Version != 0: | ||
s = newSession(b.svcWriter, b.rcpts, b.dataLimit) | ||
default: | ||
err = smtp.ErrAuthRequired | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
package smtp | ||
|
||
import ( | ||
"fmt" | ||
"github.com/emersion/go-smtp" | ||
"log/slog" | ||
"fmt" | ||
"github.com/emersion/go-smtp" | ||
"log/slog" | ||
) | ||
|
||
type backendLogging struct { | ||
b smtp.Backend | ||
log *slog.Logger | ||
b smtp.Backend | ||
log *slog.Logger | ||
} | ||
|
||
func NewBackendLogging(b smtp.Backend, log *slog.Logger) smtp.Backend { | ||
return backendLogging{ | ||
b: b, | ||
log: log, | ||
} | ||
return backendLogging{ | ||
b: b, | ||
log: log, | ||
} | ||
} | ||
|
||
func (bl backendLogging) NewSession(c *smtp.Conn) (s smtp.Session, err error) { | ||
s, err = bl.b.NewSession(c) | ||
switch err { | ||
case nil: | ||
bl.log.Debug(fmt.Sprintf("backend.NewSession(%+v)", c.Server())) | ||
s = NewSessionLogging(s, bl.log) | ||
default: | ||
bl.log.Error(fmt.Sprintf("backend.NewSession(%+v): err=%s", c.Server(), err)) | ||
} | ||
return | ||
tlsState, tlsOk := c.TLSConnectionState() | ||
s, err = bl.b.NewSession(c) | ||
switch err { | ||
case nil: | ||
bl.log.Debug(fmt.Sprintf("backend.NewSession(%s, %+v, %t)", c.Hostname(), tlsState, tlsOk)) | ||
s = NewSessionLogging(s, bl.log) | ||
default: | ||
bl.log.Error(fmt.Sprintf("backend.NewSession(%s, %+v, %t): err=%s", c.Hostname(), tlsState, tlsOk, err)) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/kelseyhightower/envconfig" | ||
"time" | ||
"github.com/kelseyhightower/envconfig" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
Api ApiConfig | ||
Log struct { | ||
Level int `envconfig:"LOG_LEVEL" default:"-4" required:"true"` | ||
} | ||
Api ApiConfig | ||
Log struct { | ||
Level int `envconfig:"LOG_LEVEL" default:"-4" required:"true"` | ||
} | ||
} | ||
|
||
type ApiConfig struct { | ||
Smtp struct { | ||
Host string `envconfig:"API_SMTP_HOST" required:"true"` | ||
Port uint16 `envconfig:"API_SMTP_PORT" default:"25" required:"true"` | ||
Data struct { | ||
Limit uint32 `envconfig:"API_SMTP_DATA_LIMIT" default:"1048576" required:"true"` | ||
} | ||
Recipients struct { | ||
Names []string `envconfig:"API_SMTP_RECIPIENTS_NAMES" default:"publish" required:"true"` | ||
Limit uint16 `envconfig:"API_SMTP_RECIPIENTS_LIMIT" default:"100" required:"true"` | ||
} | ||
Timeout struct { | ||
Read time.Duration `envconfig:"API_SMTP_TIMEOUT_READ" default:"1m" required:"true"` | ||
Write time.Duration `envconfig:"API_SMTP_TIMEOUT_WRITE" default:"1m" required:"true"` | ||
} | ||
} | ||
EventType EventTypeConfig | ||
Interests struct { | ||
Uri string `envconfig:"API_INTERESTS_URI" required:"true" default:"subscriptions-proxy:50051"` | ||
DetailsUriPrefix string `envconfig:"API_INTERESTS_DETAILS_URI_PREFIX" required:"true" default:"https://awakari.com/sub-details.html?id="` | ||
} | ||
Reader ReaderConfig | ||
Writer struct { | ||
Backoff time.Duration `envconfig:"API_WRITER_BACKOFF" default:"10s" required:"true"` | ||
BatchSize uint32 `envconfig:"API_WRITER_BATCH_SIZE" default:"16" required:"true"` | ||
Cache WriterCacheConfig | ||
Uri string `envconfig:"API_WRITER_URI" default:"resolver:50051" required:"true"` | ||
} | ||
Smtp struct { | ||
Host string `envconfig:"API_SMTP_HOST" required:"true"` | ||
Port uint16 `envconfig:"API_SMTP_PORT" default:"587" required:"true"` | ||
Data struct { | ||
Limit uint32 `envconfig:"API_SMTP_DATA_LIMIT" default:"1048576" required:"true"` | ||
} | ||
Recipients struct { | ||
Names []string `envconfig:"API_SMTP_RECIPIENTS_NAMES" default:"publish" required:"true"` | ||
Limit uint16 `envconfig:"API_SMTP_RECIPIENTS_LIMIT" default:"100" required:"true"` | ||
} | ||
Timeout struct { | ||
Read time.Duration `envconfig:"API_SMTP_TIMEOUT_READ" default:"1m" required:"true"` | ||
Write time.Duration `envconfig:"API_SMTP_TIMEOUT_WRITE" default:"1m" required:"true"` | ||
} | ||
} | ||
EventType EventTypeConfig | ||
Interests struct { | ||
Uri string `envconfig:"API_INTERESTS_URI" required:"true" default:"subscriptions-proxy:50051"` | ||
DetailsUriPrefix string `envconfig:"API_INTERESTS_DETAILS_URI_PREFIX" required:"true" default:"https://awakari.com/sub-details.html?id="` | ||
} | ||
Reader ReaderConfig | ||
Writer struct { | ||
Backoff time.Duration `envconfig:"API_WRITER_BACKOFF" default:"10s" required:"true"` | ||
BatchSize uint32 `envconfig:"API_WRITER_BATCH_SIZE" default:"16" required:"true"` | ||
Cache WriterCacheConfig | ||
Uri string `envconfig:"API_WRITER_URI" default:"resolver:50051" required:"true"` | ||
} | ||
} | ||
|
||
type WriterCacheConfig struct { | ||
Size uint32 `envconfig:"API_WRITER_CACHE_SIZE" default:"100" required:"true"` | ||
Ttl time.Duration `envconfig:"API_WRITER_CACHE_TTL" default:"24h" required:"true"` | ||
Size uint32 `envconfig:"API_WRITER_CACHE_SIZE" default:"100" required:"true"` | ||
Ttl time.Duration `envconfig:"API_WRITER_CACHE_TTL" default:"24h" required:"true"` | ||
} | ||
|
||
type ReaderConfig struct { | ||
UriEventBase string `envconfig:"API_READER_URI_EVT_BASE" default:"https://awakari.com/pub-msg.html?id=" required:"true"` | ||
UriEventBase string `envconfig:"API_READER_URI_EVT_BASE" default:"https://awakari.com/pub-msg.html?id=" required:"true"` | ||
} | ||
|
||
type EventTypeConfig struct { | ||
Self string `envconfig:"API_EVENT_TYPE_SELF" required:"true" default:"com_awakari_email_v1"` | ||
Self string `envconfig:"API_EVENT_TYPE_SELF" required:"true" default:"com_awakari_email_v1"` | ||
} | ||
|
||
func NewConfigFromEnv() (cfg Config, err error) { | ||
err = envconfig.Process("", &cfg) | ||
return | ||
err = envconfig.Process("", &cfg) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ securityContext: {} | |
|
||
service: | ||
type: LoadBalancer | ||
port: 465 | ||
port: 587 | ||
|
||
ingress: | ||
enabled: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters