Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): better reply subject prefix recognition (#5634)

Peter Chinman2d6a260be036
diff --git a/apps/web/src/features/block-email/util/subjectText.test.ts b/apps/web/src/features/block-email/util/subjectText.test.ts
index 017763cd06..d4774879f6 100644
--- a/apps/web/src/features/block-email/util/subjectText.test.ts
+++ b/apps/web/src/features/block-email/util/subjectText.test.ts
@@ -1,6 +1,6 @@
+import type { ApiMessage } from '@service-email/generated/schemas';
import { describe, expect, it } from 'vitest';
-
-import { displaySubject } from './subjectText';
+import { displaySubject, getSubjectText } from './subjectText';
describe('displaySubject', () => {
it('returns the subject as-is when there is nothing to strip', () => {
@@ -34,3 +34,23 @@ describe('displaySubject', () => {
expect(displaySubject('Re: ')).toBe('[No subject]');
});
});
+
+describe('getSubjectText', () => {
+ const messageWithSubject = (subject: string): ApiMessage =>
+ ({ subject }) as ApiMessage;
+
+ it('preserves an existing reply prefix regardless of case', () => {
+ expect(getSubjectText(messageWithSubject('Re: Q3 contract'), 'reply')).toBe(
+ 'Re: Q3 contract'
+ );
+ expect(getSubjectText(messageWithSubject('RE: Q3 contract'), 'reply')).toBe(
+ 'RE: Q3 contract'
+ );
+ });
+
+ it('prepends a reply prefix when Re: only appears later in the subject', () => {
+ expect(
+ getSubjectText(messageWithSubject('Project Re: timeline'), 'reply')
+ ).toBe('Re: Project Re: timeline');
+ });
+});
diff --git a/apps/web/src/features/block-email/util/subjectText.ts b/apps/web/src/features/block-email/util/subjectText.ts
index 090db97153..59c4b1148d 100644
--- a/apps/web/src/features/block-email/util/subjectText.ts
+++ b/apps/web/src/features/block-email/util/subjectText.ts
@@ -18,10 +18,11 @@ export const getSubjectText = (
) => {
if (!replyingTo) return '';
if (replyType === 'reply-all' || replyType === 'reply') {
- if (replyingTo.subject?.includes('Re: ')) {
- return replyingTo.subject;
+ const subject = replyingTo.subject;
+ if (subject && /^re:/i.test(subject)) {
+ return subject;
} else {
- return `Re: ${replyingTo.subject}`;
+ return `Re: ${subject}`;
}
} else if (replyType === 'forward') {
return `Fwd: ${replyingTo.subject}`;