From 5fa0e15a1df9c62a532f28e37ac5f0f478130ed6 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 27 Feb 2026 18:47:11 +0800 Subject: [PATCH] Enhance attachment filename handling in delivery events - Update the filename logic in convertAttachments to prefer the semantic title from the delivery agent over the raw storage filename. - Ensure the original file extension is preserved when using the human-readable title, improving clarity for email clients. - Adjust logging to reflect the updated filename handling for better observability during attachment processing. --- agent/robot/events/handlers.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/agent/robot/events/handlers.go b/agent/robot/events/handlers.go index fb219965..f11ef319 100644 --- a/agent/robot/events/handlers.go +++ b/agent/robot/events/handlers.go @@ -393,9 +393,34 @@ func convertAttachments(ctx context.Context, attachments []robottypes.DeliveryAt log.Warn("convertAttachments: failed to read file fileID=%q uploader=%q: %v", fileID, uploader, err) continue } - log.Info("convertAttachments: added attachment filename=%q contentType=%q size=%d", info.Filename, info.ContentType, len(content)) + + // Prefer the semantic title from the delivery agent over the raw storage filename. + // The storage filename may be an auto-generated zip name (e.g. output_xxx.zip), + // while att.Title is the human-readable name set by the delivery agent. + filename := info.Filename + if att.Title != "" { + // Keep the original file extension from storage so the email client + // knows how to open it, but use the human-readable title as the base name. + ext := "" + if idx := strings.LastIndex(info.Filename, "."); idx >= 0 { + ext = info.Filename[idx:] + } + titleExt := "" + if idx := strings.LastIndex(att.Title, "."); idx >= 0 { + titleExt = att.Title[idx:] + } + if titleExt != "" { + // Title already has an extension — use it as-is. + filename = att.Title + } else { + // Title has no extension — append the storage extension. + filename = att.Title + ext + } + } + + log.Info("convertAttachments: added attachment filename=%q contentType=%q size=%d", filename, info.ContentType, len(content)) result = append(result, messengerTypes.Attachment{ - Filename: info.Filename, + Filename: filename, ContentType: info.ContentType, Content: content, })