Skip to content

Commit

Permalink
fix: the mail editor is ignoring the mail text format setting
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavaldodiya committed Nov 6, 2023
1 parent 3402e54 commit 3c13005
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/store/zustand/editor/editor-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { getUserAccount, t } from '@zextras/carbonio-shell-ui';
import { getUserAccount, getUserSettings, t } from '@zextras/carbonio-shell-ui';
import { v4 as uuid } from 'uuid';

import { buildSavedAttachments, replaceCidUrlWithServiceUrl } from './editor-transformations';
Expand Down Expand Up @@ -69,14 +69,15 @@ export const generateNewMessageEditor = (messagesStoreDispatch: AppDispatch): Ma
};
const defaultIdentity = getDefaultIdentity();
const textWithSignature = getMailBodyWithSignature(text, defaultIdentity.defaultSignatureId);
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';

const editor = {
action: EditViewActions.NEW,
identityId: getDefaultIdentity().id,
id: editorId,
unsavedAttachments: [],
savedAttachments: [],
isRichText: true,
isRichText,
isUrgent: false,
recipients: {
to: [],
Expand Down Expand Up @@ -155,6 +156,7 @@ export const generateIntegratedNewEditor = (
plainText,
richText
};
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';
const defaultIdentity = getDefaultIdentity();
const textWithSignature = getMailBodyWithSignature(text, defaultIdentity.defaultSignatureId);
const unsavedAttachments: Array<UnsavedAttachment> = !compositionData?.aid
Expand All @@ -175,7 +177,7 @@ export const generateIntegratedNewEditor = (
id: editorId,
unsavedAttachments,
savedAttachments: [],
isRichText: true,
isRichText,
isUrgent: false,
recipients: {
to: recipients ?? [],
Expand Down Expand Up @@ -223,6 +225,7 @@ export const generateReplyAndReplyAllMsgEditor = (
};
const folderRoots = getRootsMap();
const from = getRecipientReplyIdentity(folderRoots, originalMessage);
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';
const toParticipants =
action === EditViewActions.REPLY
? retrieveReplyTo(originalMessage)
Expand All @@ -235,7 +238,7 @@ export const generateReplyAndReplyAllMsgEditor = (
id: editorId,
unsavedAttachments: [],
savedAttachments: savedInlineAttachments,
isRichText: true,
isRichText,
isUrgent: originalMessage.urgent,
recipients: {
to: toParticipants,
Expand Down Expand Up @@ -280,6 +283,7 @@ export const generateForwardMsgEditor = (
savedAttachments
)
};
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';
const folderRoots = getRootsMap();
const from = getRecipientReplyIdentity(folderRoots, originalMessage);
const editor = {
Expand All @@ -288,7 +292,7 @@ export const generateForwardMsgEditor = (
id: editorId,
unsavedAttachments: [],
savedAttachments,
isRichText: true,
isRichText,
isUrgent: originalMessage.urgent,
recipients: {
to: [],
Expand Down Expand Up @@ -321,6 +325,7 @@ export const generateEditAsDraftEditor = (
plainText: `${extractBody(originalMessage)[0]}`,
richText: replaceCidUrlWithServiceUrl(`${extractBody(originalMessage)[1]}`, savedAttachments)
};
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';
const fromParticipant = getFromParticipantFromMessage(originalMessage);
const fromIdentity = fromParticipant && getIdentityFromParticipant(fromParticipant);
const editor = {
Expand All @@ -329,7 +334,7 @@ export const generateEditAsDraftEditor = (
id: editorId,
unsavedAttachments: [],
savedAttachments: buildSavedAttachments(originalMessage),
isRichText: true,
isRichText,
isUrgent: originalMessage.urgent,
recipients: {
to: retrieveTO(originalMessage),
Expand Down Expand Up @@ -360,6 +365,7 @@ export const generateEditAsNewEditor = (
plainText: `${extractBody(originalMessage)[0]}`,
richText: replaceCidUrlWithServiceUrl(`${extractBody(originalMessage)[1]}`, savedAttachments)
};
const isRichText = getUserSettings().prefs?.zimbraPrefComposeFormat === 'html';
const fromParticipant = getFromParticipantFromMessage(originalMessage);
const fromIdentity = fromParticipant && getIdentityFromParticipant(fromParticipant);
const editor = {
Expand All @@ -368,7 +374,7 @@ export const generateEditAsNewEditor = (
id: editorId,
unsavedAttachments: [],
savedAttachments: buildSavedAttachments(originalMessage),
isRichText: true,
isRichText,
isUrgent: originalMessage.urgent,
recipients: {
to: retrieveTO(originalMessage),
Expand Down
13 changes: 13 additions & 0 deletions src/views/app/detail-panel/edit/tests/edit-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ describe('Edit view', () => {
// await screen.findByText('label.error_try_again', {}, { timeout: 4000 });
expect(getSoapMailBodyContent(msg, CT_PLAIN)).toBe(body);
}, 200000);

/**
* Test the creation of a new email
*/
test('create a new email and text format should be as per setting', async () => {
setupEditorStore({ editors: [] });
const reduxStore = generateStore();
const editor = generateNewMessageEditor(reduxStore.dispatch);
addEditor({ id: editor.id, editor });

// Text format should be plain as per the settings done
expect(editor.isRichText).toBe(false);
}, 20000);
});

/**
Expand Down

0 comments on commit 3c13005

Please sign in to comment.