|
|
@@ -408,6 +408,15 @@ type ClientCreatePayload struct {
|
|
|
InboundIds []int `json:"inboundIds"`
|
|
|
}
|
|
|
|
|
|
+func validateClientEmail(email string) error {
|
|
|
+ for _, r := range email {
|
|
|
+ if r == '/' || r == '\\' || r == ' ' || r < 0x20 || r == 0x7f {
|
|
|
+ return common.NewError("client email contains an invalid character:", email)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func (s *ClientService) Create(inboundSvc *InboundService, payload *ClientCreatePayload) (bool, error) {
|
|
|
if payload == nil {
|
|
|
return false, common.NewError("empty payload")
|
|
|
@@ -416,6 +425,9 @@ func (s *ClientService) Create(inboundSvc *InboundService, payload *ClientCreate
|
|
|
if strings.TrimSpace(client.Email) == "" {
|
|
|
return false, common.NewError("client email is required")
|
|
|
}
|
|
|
+ if err := validateClientEmail(client.Email); err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
if len(payload.InboundIds) == 0 {
|
|
|
return false, common.NewError("at least one inbound is required")
|
|
|
}
|
|
|
@@ -581,6 +593,9 @@ func (s *ClientService) Update(inboundSvc *InboundService, id int, updated model
|
|
|
if strings.TrimSpace(updated.Email) == "" {
|
|
|
return false, common.NewError("client email is required")
|
|
|
}
|
|
|
+ if err := validateClientEmail(updated.Email); err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
if updated.SubID == "" {
|
|
|
updated.SubID = existing.SubID
|
|
|
}
|