From 01fe2da368239a859d478ee0f3dc24758e12aeec Mon Sep 17 00:00:00 2001 From: Andrew McLeod Date: Sun, 23 Oct 2022 20:07:49 +0100 Subject: [PATCH] fix(email): generate random filename when attachment filenames are same upon inbound email (#18483) Fix issue when an email has multiple inline images with the same filename. Currently the cid_map is overwritten; instead, attach the files with different names. Emails where every inline image has the filename 'image.png', only one of the images ends up correctly linked. --- frappe/email/receive.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frappe/email/receive.py b/frappe/email/receive.py index 351c14481d..0cf01083f7 100644 --- a/frappe/email/receive.py +++ b/frappe/email/receive.py @@ -604,6 +604,9 @@ class Email: fname = get_random_filename(content_type=content_type) else: fname = get_random_filename(content_type=content_type) + # Don't clobber existing filename + while fname in self.cid_map: + fname = get_random_filename(content_type=content_type) self.attachments.append( {