- Added configuration options for Stalwart hosted mail in .env.example. - Updated Docker Compose to include Stalwart service with health checks. - Introduced new API endpoints for managing mail domains and migration projects. - Enhanced Authentik blueprints for user enrollment and post-migration security. - Updated OAuth handling for Google and Microsoft migration processes. - Improved error handling and response structures in the mail API. - Added integration tests for email claiming and migration workflows.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package mail
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/api/apiresponse"
|
|
"github.com/ultisuite/ulti-backend/internal/api/apivalidate"
|
|
"github.com/ultisuite/ulti-backend/internal/mail/hosted"
|
|
)
|
|
|
|
func (h *Handler) SetHostedService(svc *hosted.Service) {
|
|
if s, ok := h.svc.(*Service); ok {
|
|
s.SetHostedService(svc)
|
|
}
|
|
}
|
|
|
|
func (h *Handler) CheckAddressAvailability(w http.ResponseWriter, r *http.Request) {
|
|
svc := h.hostedService()
|
|
if svc == nil {
|
|
apiresponse.WriteJSON(w, http.StatusOK, map[string]any{"available": true, "reason": "hosted_mail_disabled"})
|
|
return
|
|
}
|
|
local := strings.TrimSpace(r.URL.Query().Get("local"))
|
|
domain := strings.TrimSpace(r.URL.Query().Get("domain"))
|
|
if domain == "" {
|
|
domain = strings.TrimSpace(r.URL.Query().Get("domain_name"))
|
|
}
|
|
if local == "" || domain == "" {
|
|
apivalidate.WriteValidationError(w, r, apivalidate.NewValidationError(apivalidate.FieldDetail{
|
|
Field: "local", Message: "local and domain required",
|
|
}))
|
|
return
|
|
}
|
|
available, err := svc.IsAddressAvailable(r.Context(), domain, local)
|
|
if err != nil {
|
|
apiresponse.WriteJSON(w, http.StatusOK, map[string]any{"available": false, "reason": err.Error()})
|
|
return
|
|
}
|
|
apiresponse.WriteJSON(w, http.StatusOK, map[string]any{"available": available})
|
|
}
|
|
|
|
func (h *Handler) hostedService() *hosted.Service {
|
|
if s, ok := h.svc.(*Service); ok {
|
|
return s.HostedService()
|
|
}
|
|
return nil
|
|
}
|