Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

feat: add privacy mode to prevent email content from being viewed in the user dashboar

Jonas Kanindae1b9a3b567fa
diff --git a/internal/handlers/admin_handler.go b/internal/handlers/admin_handler.go
index c3df23b..4ff452a 100644
--- a/internal/handlers/admin_handler.go
+++ b/internal/handlers/admin_handler.go
@@ -35,6 +35,7 @@ import (
"github.com/jkaninda/posta/internal/services/cache"
"github.com/jkaninda/posta/internal/services/eventbus"
"github.com/jkaninda/posta/internal/services/seeder"
+ "github.com/jkaninda/posta/internal/services/settings"
"github.com/jkaninda/posta/internal/storage/repositories"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
@@ -51,6 +52,7 @@ type AdminHandler struct {
bus *eventbus.EventBus
seeder *seeder.Seeder
embeddedWorker bool
+ emailSettings *settings.Provider
}
type AdminCreateUserRequest struct {
Body struct {
@@ -121,6 +123,10 @@ func NewAdminHandler(db *gorm.DB, c *cache.Cache, userRepo *repositories.UserRep
return &AdminHandler{db: db, cache: c, userRepo: userRepo, keyRepo: keyRepo, emailRepo: emailRepo, whDeliveryRepo: whDeliveryRepo, inspector: inspector, bus: bus, seeder: seeder, embeddedWorker: embeddedWorker}
}
+func (h *AdminHandler) SetEmailSettings(s *settings.Provider) {
+ h.emailSettings = s
+}
+
// CreateUser allows admins to create a new user.
func (h *AdminHandler) CreateUser(c *okapi.Context, req *AdminCreateUserRequest) error {
role := models.UserRole(req.Body.Role)
@@ -233,6 +239,10 @@ func (h *AdminHandler) ListAllEmails(c *okapi.Context, req *ListRequest) error {
return c.AbortInternalServerError("failed to list emails")
}
+ if h.emailSettings == nil || !h.emailSettings.EmailContentVisibility() {
+ redactEmails(emails)
+ }
+
return paginated(c, emails, total, page, size)
}
diff --git a/internal/handlers/email_handler.go b/internal/handlers/email_handler.go
index 504e938..6b26194 100644
--- a/internal/handlers/email_handler.go
+++ b/internal/handlers/email_handler.go
@@ -33,6 +33,7 @@ import (
"github.com/jkaninda/posta/internal/services/cache"
"github.com/jkaninda/posta/internal/services/email"
"github.com/jkaninda/posta/internal/services/eventbus"
+ "github.com/jkaninda/posta/internal/services/settings"
"github.com/jkaninda/posta/internal/storage/repositories"
)
@@ -41,6 +42,7 @@ type EmailHandler struct {
emailRepo *repositories.EmailRepository
bus *eventbus.EventBus
cache *cache.Cache
+ settings *settings.Provider
}
type SendEmailRequest struct {
Body email.SendRequest `json:"body"`
@@ -71,6 +73,29 @@ func NewEmailHandler(service *email.Service, emailRepo *repositories.EmailReposi
}
}
+func (h *EmailHandler) SetSettings(s *settings.Provider) { h.settings = s }
+
+// redactContent returns true if email body content should be hidden.
+func (h *EmailHandler) redactContent() bool {
+ if h.settings != nil && h.settings.EmailContentVisibility() {
+ return false
+ }
+ return true
+}
+
+const redactedPlaceholder = "[redacted]"
+
+func redactEmail(em *models.Email) {
+ em.HTMLBody = redactedPlaceholder
+ em.TextBody = redactedPlaceholder
+}
+
+func redactEmails(emails []models.Email) {
+ for i := range emails {
+ redactEmail(&emails[i])
+ }
+}
+
func (h *EmailHandler) Send(c *okapi.Context, req *SendEmailRequest) error {
userID := c.GetInt("user_id")
apiKeyID := c.GetInt("api_key_id")
@@ -176,6 +201,10 @@ func (h *EmailHandler) List(c *okapi.Context, req *ListRequest) error {
return c.AbortInternalServerError("failed to list emails")
}
+ if h.redactContent() {
+ redactEmails(emails)
+ }
+
return paginated(c, emails, total, page, size)
}
@@ -190,6 +219,10 @@ func (h *EmailHandler) Get(c *okapi.Context, req *GetEmailRequest) error {
return c.AbortNotFound("email not found")
}
+ if h.redactContent() {
+ redactEmail(em)
+ }
+
return ok(c, em)
}
diff --git a/internal/routes/routes.go b/internal/routes/routes.go
index e7b44e7..8fffba0 100644
--- a/internal/routes/routes.go
+++ b/internal/routes/routes.go
@@ -208,6 +208,10 @@ func InitRoutes(app *okapi.Okapi, db *gorm.DB, redisClient *redis.Client, cfg *c
},
}
+ // Email content privacy
+ r.h.email.SetSettings(settingsProvider)
+ r.h.admin.SetEmailSettings(settingsProvider)
+
if cronManager != nil {
r.h.cron = handlers.NewCronHandler(cronManager)
}
diff --git a/internal/services/seeder/settings.go b/internal/services/seeder/settings.go
index 58e0781..2fd0b6d 100644
--- a/internal/services/seeder/settings.go
+++ b/internal/services/seeder/settings.go
@@ -50,6 +50,7 @@ func SeedDefaultSettings(repo *repositories.SettingRepository) {
{Key: "login_rate_limit_window_minutes", Value: "15", Type: "int"},
{Key: "audit_log_retention_days", Value: "90", Type: "int"},
{Key: "webhook_delivery_retention_days", Value: "30", Type: "int"},
+ {Key: "email_content_visibility", Value: "false", Type: "bool"},
}
for i := range defaults {
diff --git a/internal/services/settings/provider.go b/internal/services/settings/provider.go
index e1fbfbf..9d7ab70 100644
--- a/internal/services/settings/provider.go
+++ b/internal/services/settings/provider.go
@@ -144,3 +144,6 @@ func (p *Provider) LoginRateLimitCount() int {
func (p *Provider) LoginRateLimitWindowMinutes() int {
return p.GetInt("login_rate_limit_window_minutes", 15)
}
+func (p *Provider) EmailContentVisibility() bool {
+ return p.GetBool("email_content_visibility", false)
+}
diff --git a/web/src/views/admin/Settings.vue b/web/src/views/admin/Settings.vue
index b40673f..0c3fb82 100644
--- a/web/src/views/admin/Settings.vue
+++ b/web/src/views/admin/Settings.vue
@@ -28,9 +28,10 @@ const settingMeta: Record<string, { label: string; description: string; category
retention_days: { label: 'Email Log Retention (days)', description: 'How long to keep email logs before cleanup.', category: 'Retention' },
audit_log_retention_days: { label: 'Audit Log Retention (days)', description: 'How long to keep audit/event logs.', category: 'Retention' },
webhook_delivery_retention_days: { label: 'Webhook Delivery Retention (days)', description: 'How long to keep webhook delivery logs.', category: 'Retention' },
+ email_content_visibility: { label: 'Email Content Visibility', description: 'When enabled, email body content (HTML/Text) is visible in the dashboard. When disabled, content is redacted for privacy.', category: 'Privacy' },
}
-const categories = ['General', 'Security', 'Limits', 'Retention']
+const categories = ['General', 'Security', 'Privacy', 'Limits', 'Retention']
function settingsByCategory(category: string) {
return settings.value.filter(s => {
diff --git a/web/src/views/emails/EmailDetail.vue b/web/src/views/emails/EmailDetail.vue
index 1268061..adac4b4 100644
--- a/web/src/views/emails/EmailDetail.vue
+++ b/web/src/views/emails/EmailDetail.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { ref, onMounted } from 'vue'
+import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { emailsApi } from '../../api/emails'
import { useNotificationStore } from '../../stores/notification'
@@ -12,6 +12,9 @@ const loading = ref(true)
const retrying = ref(false)
const email = ref<Email | null>(null)
const activeTab = ref<'html' | 'text'>('html')
+const contentRedacted = computed(() =>
+ email.value?.html_body === '[redacted]' && email.value?.text_body === '[redacted]'
+)
onMounted(async () => {
try {
@@ -156,23 +159,32 @@ function parseHeaders(json: string): Record<string, string> | null {
</div>
<div class="card">
- <div class="card-header">
- <div class="tabs" style="margin-bottom: 0;">
- <button class="tab" :class="{ active: activeTab === 'html' }" @click="activeTab = 'html'">HTML Preview</button>
- <button class="tab" :class="{ active: activeTab === 'text' }" @click="activeTab = 'text'">Text Content</button>
+ <template v-if="contentRedacted">
+ <div class="card-body" style="text-align: center; padding: 48px 24px;">
+ <span class="mdi mdi-eye-off" style="font-size: 48px; color: var(--text-muted); display: block; margin-bottom: 12px;"></span>
+ <h3 style="margin: 0 0 8px; color: var(--text-secondary);">Content Hidden</h3>
+ <p style="color: var(--text-muted); margin: 0;">Email body content is not available, email content disabled for privacy.</p>
</div>
- </div>
- <div class="card-body">
- <iframe
- v-if="activeTab === 'html'"
- :srcdoc="email.html_body"
- style="width: 100%; min-height: 400px; border: 1px solid var(--border-primary); border-radius: var(--radius)"
- ></iframe>
- <pre
- v-else
- style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; color: var(--text-secondary); line-height: 1.6"
- >{{ email.text_body }}</pre>
- </div>
+ </template>
+ <template v-else>
+ <div class="card-header">
+ <div class="tabs" style="margin-bottom: 0;">
+ <button class="tab" :class="{ active: activeTab === 'html' }" @click="activeTab = 'html'">HTML Preview</button>
+ <button class="tab" :class="{ active: activeTab === 'text' }" @click="activeTab = 'text'">Text Content</button>
+ </div>
+ </div>
+ <div class="card-body">
+ <iframe
+ v-if="activeTab === 'html'"
+ :srcdoc="email.html_body"
+ style="width: 100%; min-height: 400px; border: 1px solid var(--border-primary); border-radius: var(--radius)"
+ ></iframe>
+ <pre
+ v-else
+ style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; color: var(--text-secondary); line-height: 1.6"
+ >{{ email.text_body }}</pre>
+ </div>
+ </template>
</div>
</template>