Skip to content

Commit 1e0a7a0

Browse files
committed
improve Dashboard (WIP)
add Demo Dashboard to website (WIP) add mail config AllowUnknownSenders
1 parent fec31c8 commit 1e0a7a0

90 files changed

Lines changed: 1162 additions & 1134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tasks:
3333
- npm run clean
3434
- npm run copy-docs
3535
- npm version {{.VERSION}}
36-
- npm run build
36+
- npm run build-dashboard
3737
build-npm-package:
3838
deps: [build-vue-app]
3939
cmds:

docs/guides/mail/overview.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,12 @@ folders:
237237

238238
The settings object defines global configuration options that influence server behavior.
239239

240-
| Field Name | Type | Default | Description |
241-
|-------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
242-
| maxRecipients | integer | 0 | (Optional) Maximum number of recipients per email. Use 0 for unlimited. |
243-
| autoCreateMailbox | boolean | true | (Optional) Allow create mailboxes at runtime. |
244-
| maxInboxMails | integer | 100 | (Optional) Maximum number of messages kept in the INBOX folder. Oldest mails are removed when the limit is exceeded. Use 0 to disable the limit and store messages indefinitely (not recommended). |
240+
| Field Name | Type | Default | Description |
241+
|-----------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
242+
| maxRecipients | integer | 0 | (Optional) Maximum number of recipients per email. Use 0 for unlimited. |
243+
| autoCreateMailbox | boolean | true | (Optional) Allow create mailboxes at runtime. |
244+
| maxInboxMails | integer | 100 | (Optional) Maximum number of messages kept in the INBOX folder. Oldest mails are removed when the limit is exceeded. Use 0 to disable the limit and store messages indefinitely (not recommended). |
245+
| AllowUnknownSenders | boolean | true | (Optional) If true, the server accepts any MAIL FROM: address, even if it’s not listed in the mailboxes: configuration. |
245246

246247
##### Mailbox Object Example
247248

examples/mokapi/dashboard.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ paths:
141141
schema:
142142
$ref: './mail.yml#/components/schemas/MailboxDetails'
143143
"404":
144-
description: mail not found
144+
description: mailbox not found
145145
/api/services/mail/{name}/mailboxes/{mailbox}/messages:
146146
get:
147147
summary: Retrieve mailboxes for given mail server
@@ -166,6 +166,8 @@ paths:
166166
type: array
167167
items:
168168
$ref: './mail.yml#/components/schemas/SmtpMessageInfo'
169+
"404":
170+
description: mailbox not found
169171
/api/services/mail/messages/{messageId}:
170172
get:
171173
summary: Retrieve the mail with the given messageId

examples/mokapi/services_http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export let apps = [
521521
operations: [
522522
{
523523
method: "get",
524-
summary: "Add a new pet to the store",
524+
summary: "Get books from the store",
525525
operationId: "listBooks",
526526
responses: [
527527
{

images/alpha.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WORKDIR webui
99
COPY ./docs ./src/assets/docs
1010

1111
RUN npm install
12-
RUN npm run build
12+
RUN npm run build-dashboard
1313

1414
FROM golang:1.25.5-alpine AS gobuild
1515

kafka/request_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func Test_Offset(t *testing.T) {
203203
require.Equal(t, b, buf.Bytes())
204204
}
205205

206-
func Test_ApiVersion(t *testing.T) {
206+
func Test_ApiVersion_Version_Newer(t *testing.T) {
207207
req := &kafka.Request{
208208
Host: "",
209209
Header: &kafka.Header{
@@ -226,3 +226,29 @@ func Test_ApiVersion(t *testing.T) {
226226
err = result.Read(r)
227227
require.NoError(t, err)
228228
}
229+
230+
func Test_ApiVersion_Tagged(t *testing.T) {
231+
req := &kafka.Request{
232+
Host: "",
233+
Header: &kafka.Header{
234+
Size: 0,
235+
ApiKey: kafka.ApiVersions,
236+
ApiVersion: 3,
237+
CorrelationId: 0,
238+
},
239+
Message: &apiVersion.Request{
240+
TagFields: map[int64]string{3: "abc"},
241+
},
242+
}
243+
var buf bytes.Buffer
244+
w := bufio.NewWriter(&buf)
245+
err := req.Write(w)
246+
require.NoError(t, err)
247+
err = w.Flush()
248+
require.NoError(t, err)
249+
250+
r := bufio.NewReader(&buf)
251+
result := &kafka.Request{}
252+
err = result.Read(r)
253+
require.NoError(t, err)
254+
}

providers/mail/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"gopkg.in/yaml.v3"
87
"mokapi/config/dynamic"
98
"mokapi/smtp"
109
"regexp"
10+
11+
"gopkg.in/yaml.v3"
1112
)
1213

1314
var serverNamePattern = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
@@ -42,9 +43,10 @@ type Server struct {
4243
}
4344

4445
type Settings struct {
45-
MaxRecipients int `yaml:"maxRecipients" json:"maxRecipients"`
46-
AutoCreateMailbox bool `yaml:"autoCreateMailbox" json:"autoCreateMailbox"`
47-
MaxInboxMails int `yaml:"maxInboxMails" json:"maxInboxMails"`
46+
MaxRecipients int `yaml:"maxRecipients" json:"maxRecipients"`
47+
AutoCreateMailbox bool `yaml:"autoCreateMailbox" json:"autoCreateMailbox"`
48+
MaxInboxMails int `yaml:"maxInboxMails" json:"maxInboxMails"`
49+
AllowUnknownSenders bool `yaml:"allowUnknownSenders" json:"allowUnknownSenders"`
4850
}
4951

5052
type MailboxConfig struct {
@@ -125,7 +127,7 @@ func (c *Config) Parse(_ *dynamic.Config, _ dynamic.Reader) error {
125127
func (c *Config) UnmarshalYAML(value *yaml.Node) error {
126128
type alias Config
127129
tmp := alias(*c)
128-
tmp.Settings = &Settings{AutoCreateMailbox: true}
130+
tmp.Settings = &Settings{AutoCreateMailbox: true, AllowUnknownSenders: true}
129131
err := value.Decode(&tmp)
130132
*c = Config(tmp)
131133
return err
@@ -135,7 +137,7 @@ func (c *Config) UnmarshalJSON(b []byte) error {
135137
dec := json.NewDecoder(bytes.NewReader(b))
136138
type alias Config
137139
tmp := alias(*c)
138-
tmp.Settings = &Settings{AutoCreateMailbox: true}
140+
tmp.Settings = &Settings{AutoCreateMailbox: true, AllowUnknownSenders: true}
139141
err := dec.Decode(&tmp)
140142
*c = Config(tmp)
141143
return err

providers/mail/smtp_handler.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package mail
22

33
import (
44
"fmt"
5-
log "github.com/sirupsen/logrus"
65
"mokapi/engine/common"
76
"mokapi/runtime/events"
87
"mokapi/runtime/monitor"
98
"mokapi/smtp"
109
"time"
10+
11+
log "github.com/sirupsen/logrus"
1112
)
1213

1314
type Handler struct {
@@ -89,8 +90,10 @@ func (h *Handler) serveMail(rw smtp.ResponseWriter, r *smtp.MailRequest, ctx *sm
8990
if len(h.config.Mailboxes) > 0 {
9091

9192
if m, ok := h.store.Mailboxes[r.From]; !ok {
92-
h.writeErrorResponse(rw, r, smtp.AddressRejected, fmt.Sprintf("Unknown mailbox %v", r.From))
93-
return
93+
if !h.AllowUnknownSenders() {
94+
h.writeErrorResponse(rw, r, smtp.AddressRejected, fmt.Sprintf("Unknown mailbox %v", r.From))
95+
return
96+
}
9497
} else if len(m.Username) > 0 && len(ctx.Auth) == 0 {
9598
h.writeErrorResponse(rw, r, smtp.AuthRequired, "")
9699
return
@@ -151,3 +154,10 @@ func (h *Handler) writeRuleResponse(rw smtp.ResponseWriter, r smtp.Request, resp
151154
l.Error = response.Message
152155
_ = rw.Write(res)
153156
}
157+
158+
func (h *Handler) AllowUnknownSenders() bool {
159+
if h.config.Settings == nil {
160+
return true
161+
}
162+
return h.config.Settings.AllowUnknownSenders
163+
}

providers/mail/smtp_handler_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package mail_test
33
import (
44
"context"
55
"encoding/base64"
6-
"github.com/stretchr/testify/require"
76
"mokapi/engine/enginetest"
87
"mokapi/providers/mail"
98
"mokapi/runtime/events/eventstest"
109
"mokapi/smtp"
1110
"mokapi/smtp/smtptest"
1211
"testing"
1312
"time"
13+
14+
"github.com/stretchr/testify/require"
1415
)
1516

1617
func TestHandler_ServeSMTP(t *testing.T) {
@@ -71,11 +72,12 @@ func TestHandler_ServeSMTP(t *testing.T) {
7172
},
7273
},
7374
{
74-
name: "mail invalid mailbox",
75+
name: "mail unknown mailbox with not allowing unknown mailbox",
7576
config: &mail.Config{
7677
Mailboxes: map[string]*mail.MailboxConfig{
7778
"bob@foo.bar": {},
7879
},
80+
Settings: &mail.Settings{AllowUnknownSenders: false},
7981
},
8082
test: func(t *testing.T, h *mail.Handler, s *mail.Store, _ *eventstest.Handler) {
8183
ctx := smtp.NewClientContext(context.Background(), "")
@@ -85,6 +87,22 @@ func TestHandler_ServeSMTP(t *testing.T) {
8587
require.Equal(t, &exp, r.Result)
8688
},
8789
},
90+
{
91+
name: "mail unknown mailbox and allowing unknown mailbox",
92+
config: &mail.Config{
93+
Mailboxes: map[string]*mail.MailboxConfig{
94+
"bob@foo.bar": {},
95+
},
96+
Settings: &mail.Settings{AllowUnknownSenders: true},
97+
},
98+
test: func(t *testing.T, h *mail.Handler, s *mail.Store, _ *eventstest.Handler) {
99+
ctx := smtp.NewClientContext(context.Background(), "")
100+
r := sendMail(t, h, ctx)
101+
exp := smtp.Ok
102+
exp.Message = "OK"
103+
require.Equal(t, exp, r.Result)
104+
},
105+
},
88106
{
89107
name: "mail valid mailbox",
90108
config: &mail.Config{

server/server_mail.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"fmt"
5-
log "github.com/sirupsen/logrus"
65
"mokapi/config/dynamic"
76
engine "mokapi/engine/common"
87
"mokapi/imap"
@@ -13,6 +12,8 @@ import (
1312
"mokapi/smtp"
1413
"net"
1514
"sync"
15+
16+
log "github.com/sirupsen/logrus"
1617
)
1718

1819
type MailServer interface {
@@ -75,10 +76,7 @@ func (m *MailManager) startServers(cfg *runtime.MailInfo) error {
7576
}
7677
h := cfg.Handler(m.app.Monitor.Mail, m.eventEmitter, m.app.Events)
7778
for _, server := range cfg.Servers {
78-
_, port, err := net.SplitHostPort(server.Host)
79-
if err != nil {
80-
return err
81-
}
79+
_, port, _ := net.SplitHostPort(server.Host)
8280

8381
switch server.Protocol {
8482
case "smtp":

0 commit comments

Comments
 (0)