Skip to content

Commit 44aee5c

Browse files
refactor: retention policy config
1 parent b6f4268 commit 44aee5c

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ python_executable: python3
9999
100100
# Retention policy for envelopes and attachment files
101101
retention:
102-
# # Retention policy for envelopes in database
103-
# envelope_count: # (0, 100, 250, ...)
104-
# envelope_age: # (5m, 5h45m, ...)
102+
# Retention policy for envelopes in database
103+
envelope_count: # (0, 100, 250, ...)
104+
envelope_age: # (5m, 5h45m, ...)
105105
106-
# # Retention policy for attachment files on disk
107-
# attachment_size: # (100 MB, 1 GB, ...)
106+
# Retention policy for attachment files on disk
107+
attachment_size: # (100 MB, 1 GB, ...)
108108
109109
# HTTP server
110110
http:
@@ -276,6 +276,6 @@ make dev-web
276276
- feat: read [mbox](https://access.redhat.com/articles/6167512) files
277277
- feat: CRUD endpoints
278278
- feat: IMAP for viewing mail
279-
- feat: JSON API
279+
- feat: OpenAPI
280280
- feat: Windows installer
281281
- fix: chrome keeps thinking some HTTP pages are French

config/config.go

+33-24
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@ type Config struct {
5555
}
5656

5757
type Raw struct {
58-
Debug bool `koanf:"debug"`
59-
TimeFormat string `koanf:"time_format"`
60-
MaxPayloadSize string `koanf:"max_payload_size"`
61-
DataDirectory string `koanf:"data_directory"`
62-
PythonExecutable string `koanf:"python_executable"`
63-
RetentionEnvelopeCount *int `koanf:"retention.envelope_count"`
64-
RetentionEnvelopeAge *string `koanf:"retention.envelope_age"`
65-
RetentionAttachmentSize *string `koanf:"retention.attachment_size"`
66-
SMTPDisable bool `koanf:"smtp.disable"`
67-
SMTPHost string `koanf:"smtp.host"`
68-
SMTPPort uint16 `koanf:"smtp.port"`
69-
SMTPUsername string `koanf:"smtp.username"`
70-
SMTPPassword string `koanf:"smtp.password"`
71-
HTTPDisable bool `koanf:"http.disable"`
72-
HTTPHost string `koanf:"http.host"`
73-
HTTPPort uint16 `koanf:"http.port"`
74-
HTTPUsername string `koanf:"http.username"`
75-
HTTPPassword string `koanf:"http.password"`
76-
HTTPURL string `koanf:"http.url"`
58+
Debug bool `koanf:"debug"`
59+
TimeFormat string `koanf:"time_format"`
60+
MaxPayloadSize string `koanf:"max_payload_size"`
61+
DataDirectory string `koanf:"data_directory"`
62+
PythonExecutable string `koanf:"python_executable"`
63+
RetentionEnvelopeCount string `koanf:"retention.envelope_count"`
64+
RetentionEnvelopeAge string `koanf:"retention.envelope_age"`
65+
RetentionAttachmentSize string `koanf:"retention.attachment_size"`
66+
SMTPDisable bool `koanf:"smtp.disable"`
67+
SMTPHost string `koanf:"smtp.host"`
68+
SMTPPort uint16 `koanf:"smtp.port"`
69+
SMTPUsername string `koanf:"smtp.username"`
70+
SMTPPassword string `koanf:"smtp.password"`
71+
HTTPDisable bool `koanf:"http.disable"`
72+
HTTPHost string `koanf:"http.host"`
73+
HTTPPort uint16 `koanf:"http.port"`
74+
HTTPUsername string `koanf:"http.username"`
75+
HTTPPassword string `koanf:"http.password"`
76+
HTTPURL string `koanf:"http.url"`
7777
// IMAPDisable bool `koanf:"imap.disable"`
7878
// IMAPHost string `koanf:"imap.host"`
7979
// IMAPPort uint16 `koanf:"imap.port"`
@@ -187,17 +187,26 @@ func (p Parser) Parse(raw Raw) (Config, error) {
187187

188188
var config *models.Config
189189
{
190+
var envelopeCount *int
191+
if raw.RetentionEnvelopeCount != "" {
192+
count, err := strconv.Atoi(raw.RetentionEnvelopeCount)
193+
if err != nil {
194+
return Config{}, err
195+
}
196+
197+
envelopeCount = &count
198+
}
190199
var attachmentsSize *int64
191-
if raw.RetentionAttachmentSize != nil {
192-
size, err := bytes.Parse(*raw.RetentionAttachmentSize)
200+
if raw.RetentionAttachmentSize != "" {
201+
size, err := bytes.Parse(raw.RetentionAttachmentSize)
193202
if err != nil {
194203
return Config{}, err
195204
}
196205
attachmentsSize = &size
197206
}
198207
var envelopeAge *time.Duration
199-
if raw.RetentionEnvelopeAge != nil {
200-
age, err := time.ParseDuration(*raw.RetentionEnvelopeAge)
208+
if raw.RetentionEnvelopeAge != "" {
209+
age, err := time.ParseDuration(raw.RetentionEnvelopeAge)
201210
if err != nil {
202211
return Config{}, err
203212
}
@@ -206,7 +215,7 @@ func (p Parser) Parse(raw Raw) (Config, error) {
206215

207216
config = &models.Config{
208217
RetentionPolicy: models.ConfigRetentionPolicy{
209-
EnvelopeCount: raw.RetentionEnvelopeCount,
218+
EnvelopeCount: envelopeCount,
210219
AttachmentSize: attachmentsSize,
211220
EnvelopeAge: envelopeAge,
212221
MinAge: 5 * time.Minute,

0 commit comments

Comments
 (0)