|
@@ -3,6 +3,7 @@ from email import encoders
|
|
|
from email.mime.base import MIMEBase
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
from email.mime.text import MIMEText
|
|
|
+from email.header import Header
|
|
|
|
|
|
|
|
|
class EmailHelper:
|
|
@@ -91,9 +92,14 @@ class EmailHelper:
|
|
|
at_index = name.find("@")
|
|
|
if at_index != -1:
|
|
|
name = name[at_index + 1 :]
|
|
|
- part.add_header("Content-Disposition", f"attachment; filename= {name}")
|
|
|
- part.add_header("Content-ID", "<0>")
|
|
|
- part.add_header("X-Attachment-Id", "0")
|
|
|
+
|
|
|
+ # 使用 RFC 2047 编码文件名
|
|
|
+ encoded_name = Header(name, "utf-8").encode()
|
|
|
+ part.add_header(
|
|
|
+ "Content-Disposition", f"attachment; filename= {encoded_name}"
|
|
|
+ )
|
|
|
+ # part.add_header("Content-ID", "<0>")
|
|
|
+ # part.add_header("X-Attachment-Id", "0")
|
|
|
encoders.encode_base64(part)
|
|
|
msg.attach(part)
|
|
|
utils.get_logger().info(f"添加附件 {name} {attachment_path} 到邮件中。")
|