Android security implementation Phase 0-3 finalization part 1
This commit is contained in:
+33
-31
@@ -1,15 +1,17 @@
|
||||
import { Capacitor, registerPlugin } from '@capacitor/core';
|
||||
import { createAndroidPgp } from './android-pgp.js';
|
||||
import { Capacitor, registerPlugin } from '@capacitor/core';
|
||||
import { createAndroidPgp } from './android-pgp.js';
|
||||
|
||||
const EpMail = registerPlugin('EpMail');
|
||||
|
||||
if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {
|
||||
const daybreakMail = {
|
||||
if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {
|
||||
const daybreakMail = {
|
||||
getAppVersion: () => EpMail.getAppVersion().then(result => result.version),
|
||||
getNotificationPrivacy: () => EpMail.getNotificationPrivacy(),
|
||||
setNotificationDetails: enabled => EpMail.setNotificationDetails({ enabled }),
|
||||
getAppLockSettings: () => EpMail.getAppLockSettings(),
|
||||
setAppLockEnabled: enabled => EpMail.setAppLockEnabled({ enabled }),
|
||||
getNotificationPrivacy: () => EpMail.getNotificationPrivacy(),
|
||||
setNotificationDetails: enabled => EpMail.setNotificationDetails({ enabled }),
|
||||
getAppLockSettings: () => EpMail.getAppLockSettings(),
|
||||
setAppLockEnabled: enabled => EpMail.setAppLockEnabled({ enabled }),
|
||||
setAppLockDelay: seconds => EpMail.setAppLockDelay({ seconds }),
|
||||
deleteAllLocalData: () => EpMail.deleteAllLocalData(),
|
||||
getAccount: () => EpMail.getAccount(),
|
||||
listAccounts: () => EpMail.listAccounts(),
|
||||
selectAccount: id => EpMail.selectAccount({ id }),
|
||||
@@ -30,24 +32,24 @@ if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {
|
||||
previewAttachment: details => EpMail.previewAttachment(details),
|
||||
saveAttachment: details => EpMail.saveAttachment(details),
|
||||
openExternal: url => EpMail.openExternal({ url }),
|
||||
send: async message => {
|
||||
if (!message?.pgp || (!message.pgp.encrypt && !message.pgp.sign)) {
|
||||
if (message?.pgp?.plaintextFallback) {
|
||||
const { pgp: _options, ...plainMessage } = message;
|
||||
return EpMail.send({ ...plainMessage, pgpRequested: true });
|
||||
}
|
||||
return EpMail.send(message);
|
||||
}
|
||||
try {
|
||||
const { rawBase64, to, from } = await daybreakMail.pgp.buildOutgoing(message);
|
||||
const { pgp: _options, text: _text, attachments: _attachments, ...headers } = message;
|
||||
return await EpMail.send({ ...headers, rawBase64, envelope: { from, to }, text: '', attachments: [] });
|
||||
} catch (error) {
|
||||
return { failed: true, code: error.code || 'PGP_ERROR', message: error.message || 'Could not encrypt this message.' };
|
||||
}
|
||||
},
|
||||
pgpGetMessageSource: details => EpMail.pgpGetMessageSource(details),
|
||||
savePgpAttachment: details => EpMail.savePgpAttachment(details),
|
||||
send: async message => {
|
||||
if (!message?.pgp || (!message.pgp.encrypt && !message.pgp.sign)) {
|
||||
if (message?.pgp?.plaintextFallback) {
|
||||
const { pgp: _options, ...plainMessage } = message;
|
||||
return EpMail.send({ ...plainMessage, pgpRequested: true });
|
||||
}
|
||||
return EpMail.send(message);
|
||||
}
|
||||
try {
|
||||
const { rawBase64, to, from } = await daybreakMail.pgp.buildOutgoing(message);
|
||||
const { pgp: _options, text: _text, attachments: _attachments, ...headers } = message;
|
||||
return await EpMail.send({ ...headers, rawBase64, envelope: { from, to }, text: '', attachments: [] });
|
||||
} catch (error) {
|
||||
return { failed: true, code: error.code || 'PGP_ERROR', message: error.message || 'Could not encrypt this message.' };
|
||||
}
|
||||
},
|
||||
pgpGetMessageSource: details => EpMail.pgpGetMessageSource(details),
|
||||
savePgpAttachment: details => EpMail.savePgpAttachment(details),
|
||||
disconnect: id => EpMail.removeAccount({ id }),
|
||||
davList: () => EpMail.davList(),
|
||||
davConnect: config => EpMail.davConnect(config),
|
||||
@@ -57,8 +59,8 @@ if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {
|
||||
davSaveEvent: event => EpMail.davSaveEvent(event),
|
||||
davDeleteEvent: remote => EpMail.davDeleteEvent(remote),
|
||||
davSaveContact: contact => EpMail.davSaveContact(contact),
|
||||
davDeleteContact: remote => EpMail.davDeleteContact(remote)
|
||||
};
|
||||
daybreakMail.pgp = createAndroidPgp({ EpMail, getAccount: () => EpMail.getAccount() });
|
||||
window.daybreakMail = daybreakMail;
|
||||
}
|
||||
davDeleteContact: remote => EpMail.davDeleteContact(remote)
|
||||
};
|
||||
daybreakMail.pgp = createAndroidPgp({ EpMail, getAccount: () => EpMail.getAccount() });
|
||||
window.daybreakMail = daybreakMail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user