From 41665b0865eb90f34687a6139a9b39b9a6eda99b Mon Sep 17 00:00:00 2001 From: Stephen Hu <812791840@qq.com> Date: Tue, 25 Nov 2025 10:03:37 +0800 Subject: [PATCH] Refactor: Email parser use with to handle buffer (#11496) ### What problem does this PR solve? Email parser use with to handle buffer ### Type of change - [x] Refactoring --- rag/app/email.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rag/app/email.py b/rag/app/email.py index 2e95eceec..6f3e30ab4 100644 --- a/rag/app/email.py +++ b/rag/app/email.py @@ -51,9 +51,11 @@ def chunk( attachment_res = [] if binary: - msg = BytesParser(policy=policy.default).parse(io.BytesIO(binary)) + with io.BytesIO(binary) as buffer: + msg = BytesParser(policy=policy.default).parse(buffer) else: - msg = BytesParser(policy=policy.default).parse(open(filename, "rb")) + with open(filename, "rb") as buffer: + msg = BytesParser(policy=policy.default).parse(buffer) text_txt, html_txt = [], [] # get the email header info