Skip to content

Commit

Permalink
feat: add size to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNotGoodName committed Dec 24, 2021
1 parent a059c0c commit 1c70ce1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Configuration file at `~/.smtpbridge.yml`.

```yaml
port: 1025
size: 26214400 # 25 MB

bridges:
- name: test bridge
Expand Down
1 change: 1 addition & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type Config struct {
Port string `json:"port" mapstructure:"port"`
Size int `json:"size" mapstructure:"size"`
Bridges []Bridge `json:"bridges" mapstructure:"bridges"`
ConfigEndpoints []ConfigEndpoint `json:"endpoints" mapstructure:"endpoints"`
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ to quickly create a Cobra application.`,
messageSVC := service.NewMessage(bridgeSVC, messageREPO)

// Init smtp server
server := smtp.New(authSVC, messageSVC)
server := smtp.New(authSVC, messageSVC, config.Size)

// Start smtp server
server.Start(":" + config.Port)
Expand All @@ -70,6 +70,9 @@ func init() {
serverCmd.Flags().String("port", "1025", "port for smtp server")
viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))

serverCmd.Flags().Int("size", 1024*1024*25, "max message size in bytes")
viper.BindPFlag("size", serverCmd.Flags().Lookup("size"))

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
4 changes: 2 additions & 2 deletions left/smtp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type SMTP struct {
s *smtp.Server
}

func New(authSVC app.AuthServicePort, messageSVC app.MessageServicePort) SMTP {
func New(authSVC app.AuthServicePort, messageSVC app.MessageServicePort, size int) SMTP {
b := newBackend(authSVC, messageSVC)
s := smtp.NewServer(b)

Expand All @@ -38,7 +38,7 @@ func New(authSVC app.AuthServicePort, messageSVC app.MessageServicePort) SMTP {
s.Domain = "localhost"
s.ReadTimeout = 10 * time.Second
s.WriteTimeout = 10 * time.Second
s.MaxMessageBytes = 1024 * 1024 * 25 // TODO: put this in config
s.MaxMessageBytes = size
s.MaxRecipients = 50
s.AllowInsecureAuth = true

Expand Down

0 comments on commit 1c70ce1

Please sign in to comment.