Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Fix the issue of importing email passwords

lotk749b4e44efd1
diff --git a/core/internal/controller/mail_boxes/mail_boxes_v1_export_mailbox.go b/core/internal/controller/mail_boxes/mail_boxes_v1_export_mailbox.go
index 7212f86b..04e64fdf 100644
--- a/core/internal/controller/mail_boxes/mail_boxes_v1_export_mailbox.go
+++ b/core/internal/controller/mail_boxes/mail_boxes_v1_export_mailbox.go
@@ -73,8 +73,11 @@ func (c *ControllerV1) ExportMailbox(ctx context.Context, req *v1.ExportMailboxR
if r == nil {
return nil, gerror.New("Unable to obtain the request context")
}
- r.Response.Header().Set("Content-Type", contentType)
+
+ g.Log().Debug(ctx, "contentType:", contentType)
+ r.Response.Header().Set("Content-Type", "application/octet-stream")
r.Response.Header().Set("Content-Disposition", "attachment; filename="+fileName)
+
r.Response.Write([]byte(content))
_ = public.WriteLog(ctx, public.LogParams{
diff --git a/core/internal/service/mail_boxes/mail_boxes.go b/core/internal/service/mail_boxes/mail_boxes.go
index 66c4c3db..313f4937 100644
--- a/core/internal/service/mail_boxes/mail_boxes.go
+++ b/core/internal/service/mail_boxes/mail_boxes.go
@@ -317,13 +317,14 @@ func AddImport(ctx context.Context, mailbox *v1.Mailbox) (err error) {
err = fmt.Errorf("Decode password failed: %w", err)
return
}
- }
- mailbox.Password, err = PasswdMD5Crypt(ctx, mailbox.Password)
- if err != nil {
- err = fmt.Errorf("Generate password md5-crypt failed: %w", err)
- return
+ mailbox.Password, err = PasswdMD5Crypt(ctx, mailbox.Password)
+ if err != nil {
+ err = fmt.Errorf("Generate password md5-crypt failed: %w", err)
+ return
+ }
}
+
} else {
mailbox.PasswordEncode = PasswdEncode(ctx, mailbox.Password)
@@ -360,3 +361,32 @@ func NormalizeMailboxes() (err error) {
return
}
+
+// TestPasswordHandling 测试密码处理逻辑
+func TestPasswordHandling(ctx context.Context, email string) error {
+ // 查询邮箱信息
+ var mailbox v1.Mailbox
+ err := g.DB().Model("mailbox").Where("username", email).Scan(&mailbox)
+ if err != nil {
+ return fmt.Errorf("Failed to query mailbox: %w", err)
+ }
+
+ // 尝试解密密码
+ decodedPassword, err := PasswdDecode(ctx, mailbox.PasswordEncode)
+ if err != nil {
+ return fmt.Errorf("Failed to decode password: %w", err)
+ }
+
+ // 重新加密
+ reEncryptedPassword, err := PasswdMD5Crypt(ctx, decodedPassword)
+ if err != nil {
+ return fmt.Errorf("Failed to re-encrypt password: %w", err)
+ }
+
+ // 比较是否一致
+ if mailbox.Password != reEncryptedPassword {
+ return fmt.Errorf("Password mismatch: stored=%s, re-encrypted=%s", mailbox.Password, reEncryptedPassword)
+ }
+
+ return nil
+}