Skip to content

Commit

Permalink
fix: stop adding RE and FWD if alrady in the msg title (#131)
Browse files Browse the repository at this point in the history
fix: stop adding RE and FWD if already in the msg title
  • Loading branch information
FrancescoGottardi authored Jul 21, 2022
1 parent a848b74 commit a43425b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/store/editor-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type CreateEditorPayload = {
};
};

// Regex reply msg title
const REPLY_REGEX = /(^(re:\s)+)/i;

// Regex forward msg title
const FORWARD_REGEX = /(^(fwd:\s)+)/i;

function createEditorReducer(
state: EditorsStateType,
{ payload }: { payload: CreateEditorPayload }
Expand Down Expand Up @@ -138,7 +144,7 @@ function createEditorReducer(
id: payload.id,
text: textWithSignatureRepliesForwards,
to: retrieveReplyTo(payload.original),
subject: `RE: ${payload.original.subject}`,
subject: `RE: ${payload.original.subject.replace(REPLY_REGEX, '')}`,
original: payload.original,
attach: { mp: retrieveAttachmentsType(payload.original, 'attachment') },
urgent: payload.original.urgent,
Expand All @@ -156,7 +162,7 @@ function createEditorReducer(
text: textWithSignatureRepliesForwards,
to: retrieveALL(payload.original, payload.accounts),
cc: retrieveCC(payload.original, payload.accounts),
subject: `RE: ${payload.original.subject}`,
subject: `RE: ${payload.original.subject.replace(REPLY_REGEX, '')}`,
original: payload.original,
attach: { mp: retrieveAttachmentsType(payload.original, 'attachment') },
urgent: payload.original.urgent,
Expand All @@ -172,7 +178,7 @@ function createEditorReducer(
state.editors[payload.editorId] = {
...empty,
text: textWithSignatureRepliesForwards,
subject: `Fwd: ${payload.original.subject}`,
subject: `FWD: ${payload.original.subject.replace(FORWARD_REGEX, '')}`,
original: payload.original,
attach: { mp: retrieveAttachmentsType(payload.original, 'attachment') },
urgent: payload.original.urgent,
Expand Down

0 comments on commit a43425b

Please sign in to comment.