1 import type { CONTACT_MIME_TYPES } from '../../constants';
2 import { MIME_TYPES, PGP_SCHEMES } from '../../constants';
3 import type { ContactPublicKeyModel, MailSettings } from '../../interfaces';
4 import { PACKAGE_TYPE, SIGN } from '../../mail/mailSettings';
7 * Extract sign flag from the contact public key model and mail settings
9 export const extractSign = (model: ContactPublicKeyModel, mailSettings: MailSettings): boolean => {
10 const { sign } = model;
11 return sign !== undefined ? sign : mailSettings.Sign === SIGN.ENABLED;
15 * Extract PGP scheme from the contact public key model and mail settings
17 export const extractScheme = (model: ContactPublicKeyModel, mailSettings: MailSettings): PGP_SCHEMES => {
18 const { scheme } = model;
19 if (scheme === PGP_SCHEMES.PGP_INLINE || scheme === PGP_SCHEMES.PGP_MIME) {
22 if (mailSettings.PGPScheme === PACKAGE_TYPE.SEND_PGP_INLINE) {
23 return PGP_SCHEMES.PGP_INLINE;
25 return PGP_SCHEMES.PGP_MIME;
29 * Extract MIME type (for the composer) from the contact public key model and mail settings
31 export const extractDraftMIMEType = (model: ContactPublicKeyModel, mailSettings: MailSettings): CONTACT_MIME_TYPES => {
32 const { mimeType } = model;
33 const sign = extractSign(model, mailSettings);
34 const scheme = extractScheme(model, mailSettings);
36 if (sign && scheme === PGP_SCHEMES.PGP_INLINE) {
37 return MIME_TYPES.PLAINTEXT;