Repository navigation
fix(email): 修复重建 Date 邮件头时丢失时区 - #355
Merged
Jinnrry merged 1 commit intoAug 17, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Date邮件头时保留时区偏移。YYYY-MM-DD HH:MM:SS格式,并维持原有的本地时区解释方式。问题
NewEmailFromReader会把 RFC 5322Date邮件头解析成time.Time,随后却使用time.DateTime格式保存。该格式不包含时区偏移。BuildBytes重建邮件时,又使用time.Local解释同一个墙上时间,因此可能改变这个时间所代表的绝对时刻。例如,输入时间
Sun, 09 Aug 2026 11:51:08 +0000可能被重建成Sun, 09 Aug 2026 11:51:08 +0800,使邮件头表示的绝对时刻向前偏移 8 小时,最终导致邮件客户端把刚收到的邮件显示为约 8 小时前发送。NewEmailFromModel也存在相同问题,因为它同样会把SendDate格式化为不含时区偏移的字符串。修复方式
使用 RFC3339 保存解析得到的时间和模型时间,从而保留时区偏移。
BuildBytes重建邮件时优先按 RFC3339 解析;如果解析失败,再回退到历史无时区格式,确保数据库中已有的旧邮件仍能正常读取和重建。测试
models.Email.SendDate重建后仍表示同一个绝对时刻。time.Local正常重建。已执行: