1 import type { Message } from '../../interfaces/mail/Message';
2 import type { SendPreferences } from '../../interfaces/mail/crypto';
3 import type { EncryptionPreferences } from '../encryptionPreferences';
4 import { isEO, isSign } from '../messages';
5 import { getPGPSchemeAndMimeType } from './sendPreferences';
8 * Get the send preferences for sending a message based on the encryption preferences
9 * for sending to an email address, and the message preferences.
11 const getSendPreferences = (
12 encryptionPreferences: EncryptionPreferences,
13 message?: Partial<Message>
14 ): SendPreferences => {
25 isInternalWithDisabledE2EEForMail,
26 } = encryptionPreferences;
27 const isEncryptedToOutside = isEO(message);
28 // override encrypt if necessary
29 const newEncrypt = isInternalWithDisabledE2EEForMail ? false : encrypt || isEncryptedToOutside;
30 // override sign if necessary
31 // (i.e. when the contact sign preference is false and the user toggles "Sign" on the composer)
32 const newSign = isEncryptedToOutside || isInternalWithDisabledE2EEForMail ? false : sign || isSign(message);
33 // cast PGP scheme into what API expects. Override if necessary
34 const { pgpScheme, mimeType } = getPGPSchemeAndMimeType({ ...encryptionPreferences, sign: newSign }, message);
41 publicKeys: sendKey ? [sendKey] : undefined,
42 isPublicKeyPinned: isSendKeyPinned,
48 encryptionDisabled: isInternalWithDisabledE2EEForMail,
52 export default getSendPreferences;