上周碰见捕获捕网易邮箱大师邮件客户端外发的附件,文件名偶尔会有乱码的问题。但是同样的文件使用foxmail外发文件,终端捕获的附件文件名就不是乱码。这里记录一下。
网易邮箱大师
先看一下网易邮箱大师的报文(已隐去部分信息)。
Date: Thu, 13 Oct 2022 10:32:16 +0800
From: 761508152 <[email protected]>
To: =?utf-8?Q?xxxx=40outlook.com?= <[email protected]>
Message-ID: <[email protected]>
Subject: qwe123
X-Mailer: MailMasterPC/4.17.5.1008 (Win7)
X-CUSTOM-MAIL-MASTER-SENT-ID: 76E8AD06-0227-45CB-A733-9FE3A74754B3
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=_mailmaster-634778b1_0_29_="
--=_mailmaster-634778b1_0_29_=
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
PGh0bWw+DQo8aGVhZD4NCiAgICA8bWV0YSBodHRwLWVxdWl2PSdDb250ZW50LVR5cGUnIGNvbnRl
bnQ9J3RleHQvaHRtbDsgY2hhcnNldD1VVEYtOCc+DQo8L2hlYWQ+DQo8Ym9keT4NCjxzdHlsZT4N
CiAgICBmb250ew0KICAgICAgICBsaW5lLWhlaWdodDogMS42Ow0KICAgIH0NCiAgICB1bCxvbHsN
CiAgICAgICAgcGFkZGluZy1sZWZ0OiAyMHB4Ow0KICAgICAgICBsaXN0LXN0eWxlLXBvc2l0aW9u
OiBpbnNpZGU7DQogICAgfQ0KPC9zdHlsZT4NCjxkaXYgc3R5bGUgPSAnZm9udC1mYW1pbHk65b6u
6L2v6ZuF6buRLFZlcmRhbmEsJnF1b3Q7TWljcm9zb2Z0IFlhaGVpJnF1b3Q7LFNpbVN1bixzYW5z
LXNlcmlmO2ZvbnQtc2l6ZToxNHB4OyBsaW5lLWhlaWdodDoxLjY7Jz4NCiAgICA8ZGl2ID48L2Rp
dj48ZGl2PgogICAgPGRpdj4KICAgICAgICA8c3Bhbj4KICAgICAgICAgICAgPGJyPgogICAgICAg
IDwvc3Bhbj4KICAgIDwvZGl2Pg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ZzogMCAwIDAgMTBweDsgY29sb3I6ICMzMTM1M2I7Ij48ZGl2IHN0
eWxlPSJmb250LXNpemU6IDE2cHg7Zm9udC13ZWlnaHQ6Ym9sZDsgd2lkdGg6MTAwJTsgd2hpdGUt
c3BhY2U6IG5vd3JhcDsgb3ZlcmZsb3c6aGlkZGVuO3RleHQtb3ZlcmZsb3c6IGVsbGlwc2lzOyI+
NzYxNTA4MTUyPC9kaXY+PC90ZD48L3RyPjx0ciB3aWR0aD0iMTAwJSIgc3R5bGU9ImZvbnQtc2l6
ZTogMTRweCAhaW1wb3J0YW50OyB3aWR0aDogMTAwJTsiPjx0ZCBjb2xzcGFuPSIyIiBzdHlsZT0i
cGFkZGluZzoxMHB4IDAgMCAwOyBmb250LXNpemU6MTRweCAhaW1wb3J0YW50OyB3aWR0aDogMTAw
JTsiPjxkaXYgc3R5bGU9IndpZHRoOiAxMDAlO2ZvbnQtc2l6ZTogMTRweCAhaW1wb3J0YW50O3dv
cmQtd3JhcDpicmVhay13b3JkO3dvcmQtYnJlYWs6YnJlYWstYWxsOyI+NzYxNTA4MTUyQHFxLmNv
bTwvZGl2PjwvdGQ+PC90cj48L3Rib2R5PjwvdGFibGU+PC9hPgogICAgICAgIDwvZGl2PgogICAg
PC9kaXY+CiA8L2Rpdj4KPC9kaXY+PCEtLfCfmIAtLT4NCjwvZGl2Pg0KPC9ib2R5Pg0KPC9odG1s
Pg==
--=_mailmaster-634778b1_0_29_=
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;
name="=?utf-8?B?MTExMTExMTExMTExMTEx5rWL6K+V5paH5Lu2c3Nzc3Nzc2hlbGxvc3Nzc3Nz?=
=?utf-8?B?c3Nzc3NzLmRvY3g=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?utf-8?B?MTExMTExMTExMTExMTEx5rWL6K+V5paH5Lu2c3Nzc3Nzc2hlbGxvc3Nzc3Nz?=
=?utf-8?B?c3Nzc3NzLmRvY3g=?="
UEsDBBQAAgAIAAAAAABObTaBagEAAMcCAAAQAAAAZG9jUHJvcHNcYXBwLnhtbJ1Sy07DMBC8I/EP
Ue6tkyKhqtoaoSLEgZfUtD1b9iaxcGzLNoj+PRvShiBu+LQz6x3NrA03n53JPjBE7ew6L+dFnqGV
TmnbrPNddT9b5llMwiphnMV1fsSY3/DLC3gNzmNIGmNGEjau8zYlv2IsyhY7EefUttSpXehEIhga
5upaS7xz8r1Dm9iiKK4Zfia0CtXMj4L5oLj6SP8VVU72/uK+OnrS41Bh541IyJ/7STNXLnXARhYq
l4SpdIe8JHoE8CoajD03FHBwQUV+BWwoYNOKIGSi/fFyCWwC4dZ7o6VItFj+pGVw0dUpe/l2m/Xj
......
--=_mailmaster-634778b1_0_29_=
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;
name="111111111111111AABBCCDDssssssshellossssssssssss.docx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="111111111111111AABBCCDDssssssshellossssssssssss.docx"
UEsDBBQAAgAIAAAAAABObTaBagEAAMcCAAAQAAAAZG9jUHJvcHNcYXBwLnhtbJ1Sy07DMBC8I/EP
Ue6tkyKhqtoaoSLEgZfUtD1b9iaxcGzLNoj+PRvShiBu+LQz6x3NrA03n53JPjBE7ew6L+dFnqGV
TmnbrPNddT9b5llMwiphnMV1fsSY3/DLC3gNzmNIGmNGEjau8zYlv2IsyhY7EefUttSpXehEIhga
......
--=_mailmaster-634778b1_0_29_=--
文件名信息是这两条,
中文文件名:filename="=?utf-8?B?MTExMTExMTExMTExMTEx5rWL6K+V5paH5Lu2c3Nzc3Nzc2hlbGxvc3Nzc3Nz?= =?utf-8?B?c3Nzc3NzLmRvY3g=?="
非中文文件名:filename="111111111111111AABBCCDDssssssshellossssssssssss.docx"
可以看到对于非中文的文件名,报文中是直接展示的,而中文文件名,使用的的是base64的编码(Content-Transfer-Encoding: base64
此字段已经说明),对于较长的中文文件名来说,网易邮箱大师客户端在处理上选则将其分隔成了多块。而我的程序中只是将头部字符串编码格式和尾部标记给移除了导致长的文件名会出现乱码。至于文件名多长会被分割,大概数了一下算是扩展名是41个字符,长度超过41个字符便会被分割。
Foxmail
foxmail中长的中文名不会被分割:=?GB18030?B?MTExMTExMTExMTExMTExsuLK1M7EvP5zc3Nzc3NzaGVsbG9zc3Nzc3Nzc3Nzc3MxMTExMTExMTExMTExMTGy4srUzsS8/nNzc3Nzc3NoZWxsb3Nzc3Nzc3Nzc3Nzcy5kb2N4?=
。