Improve Android OpenPGP, drafts and release builds
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+42
-33
@@ -595,6 +595,7 @@ function setupDraftComposer() {
|
||||
contentBase64: btoa(binary)
|
||||
});
|
||||
}
|
||||
if (closed) return;
|
||||
attachments.push(...selected);
|
||||
renderAttachments();
|
||||
await persist();
|
||||
@@ -621,58 +622,66 @@ function setupDraftComposer() {
|
||||
modal.querySelector('.compose-footer').insertBefore(save, selectMailUi('#send'));
|
||||
let saveTimer;
|
||||
let closed = false;
|
||||
const persist = async () => {
|
||||
if (closed || !selectMailUi('#compose-to')) return;
|
||||
let pendingSave = Promise.resolve();
|
||||
const persist = () => {
|
||||
if (closed || !modal.isConnected) return Promise.resolve(false);
|
||||
const values = {
|
||||
id: modal.dataset.draftId || window.crypto.randomUUID(),
|
||||
to: selectMailUi('#compose-to').value,
|
||||
cc: selectMailUi('#compose-cc').value,
|
||||
subject: selectMailUi('#compose-subject').value,
|
||||
text: selectMailUi('#compose-body').value,
|
||||
attachments
|
||||
to: modal.querySelector('#compose-to').value,
|
||||
cc: modal.querySelector('#compose-cc').value,
|
||||
subject: modal.querySelector('#compose-subject').value,
|
||||
text: modal.querySelector('#compose-body').value,
|
||||
attachments: [...attachments]
|
||||
};
|
||||
if (!Object.values(values).some(value => typeof value === 'string' && value.trim()) && !attachments.length) return;
|
||||
if (!modal.dataset.draftId && ![values.to, values.cc, values.subject, values.text].some(value => value.trim()) && !values.attachments.length) return Promise.resolve(false);
|
||||
values.id = modal.dataset.draftId || window.crypto.randomUUID();
|
||||
modal.dataset.draftId = values.id;
|
||||
const result = await window.daybreakMail.saveDraft(values);
|
||||
modal.dataset.draftId = result.id;
|
||||
const operation = pendingSave.then(async () => {
|
||||
await window.daybreakMail.saveDraft(values);
|
||||
return true;
|
||||
});
|
||||
pendingSave = operation.then(() => {}, () => {});
|
||||
return operation;
|
||||
};
|
||||
save.onclick = async () => {
|
||||
try {
|
||||
await persist();
|
||||
toastMailUi('Draft saved on this device');
|
||||
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||
const saved = await persist();
|
||||
toastMailUi(saved ? 'Draft saved on this device' : 'Nothing to save in this draft');
|
||||
if (saved && rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||
} catch (error) { toastMailUi(error.message || 'Could not save draft'); }
|
||||
};
|
||||
modal.addEventListener('input', () => {
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = setTimeout(() => persist().catch(error => toastMailUi(error.message || 'Could not save draft')), 700);
|
||||
});
|
||||
modal.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
||||
if (!event.target.classList.contains('modal-overlay')) return;
|
||||
const saveAndClose = () => {
|
||||
if (closed) return;
|
||||
clearTimeout(saveTimer);
|
||||
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||
persist().then(saved => { if (saved && rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||
.catch(error => toastMailUi(error.message || 'Could not save draft'));
|
||||
closed = true;
|
||||
};
|
||||
root.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
||||
if (!event.target.classList.contains('modal-overlay')) return;
|
||||
saveAndClose();
|
||||
}, true);
|
||||
root.querySelector('.modal-close')?.addEventListener('click', () => {
|
||||
clearTimeout(saveTimer);
|
||||
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||
.catch(error => toastMailUi(error.message || 'Could not save draft'));
|
||||
closed = true;
|
||||
}, true);
|
||||
selectMailUi('#discard').onclick = async () => {
|
||||
root.querySelector('.modal-close')?.addEventListener('click', saveAndClose, true);
|
||||
modal.addEventListener('keydown', event => {
|
||||
if (event.key === 'Escape') saveAndClose();
|
||||
});
|
||||
const deleteSavedDraft = async () => {
|
||||
clearTimeout(saveTimer);
|
||||
closed = true;
|
||||
await pendingSave;
|
||||
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
||||
};
|
||||
modal._deleteSavedDraft = deleteSavedDraft;
|
||||
selectMailUi('#discard').onclick = async () => {
|
||||
try {
|
||||
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
||||
await deleteSavedDraft();
|
||||
root.innerHTML = '';
|
||||
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||
} catch (error) { toastMailUi(error.message || 'Could not delete draft'); }
|
||||
};
|
||||
selectMailUi('#send').addEventListener('click', () => {
|
||||
clearTimeout(saveTimer);
|
||||
closed = true;
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1053,15 +1062,15 @@ if (window.daybreakMail) {
|
||||
return;
|
||||
}
|
||||
if (result.queued) {
|
||||
const draftId = selectMailUi('#modal-root .compose-modal')?.dataset.draftId;
|
||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||
const modal = selectMailUi('#modal-root .compose-modal');
|
||||
if (modal?._deleteSavedDraft) await modal._deleteSavedDraft();
|
||||
selectMailUi('#modal-root').innerHTML = '';
|
||||
toastMailUi('Offline: message queued and will send when connected');
|
||||
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||
return;
|
||||
}
|
||||
const draftId = selectMailUi('#modal-root .compose-modal')?.dataset.draftId;
|
||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||
const modal = selectMailUi('#modal-root .compose-modal');
|
||||
if (modal?._deleteSavedDraft) await modal._deleteSavedDraft();
|
||||
selectMailUi('#modal-root').innerHTML = '';
|
||||
toastMailUi(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');
|
||||
if (rendererState.activeFolder === 'Sent') syncMailbox(false, { offset: 0 });
|
||||
|
||||
+2
-2
@@ -158,8 +158,8 @@ pgpMailUi.wrapOpenMessage(baseOpenMessage => function (id) {
|
||||
});
|
||||
|
||||
// Compose: encrypt/sign options.
|
||||
pgpMailUi.wrapShowCompose(baseShowCompose => function (reply, forward = false) {
|
||||
baseShowCompose(reply, forward);
|
||||
pgpMailUi.wrapShowCompose(baseShowCompose => function (reply, forward = false, draft = null) {
|
||||
baseShowCompose(reply, forward, draft);
|
||||
const footer = selectPgpMailUi('#modal-root .compose-footer');
|
||||
if (!footer || !pgpApi()) return;
|
||||
const box = document.createElement('div');
|
||||
|
||||
+7
-5
@@ -32,7 +32,7 @@ function openEncryptionKeys() {
|
||||
<label class="compose-line"><span>HTTPS base URL</span><input id="pgp-server-url" type="url" placeholder="https://keys.example.org"></label>
|
||||
<label class="compose-line"><span>Protocol</span><select id="pgp-server-protocol"><option value="hkp">HKP</option><option value="vks">VKS</option></select></label>
|
||||
<div class="pgp-actions"><button class="discard" id="pgp-add-server">Add custom server…</button></div>`;
|
||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal pgp-keys-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
||||
<p class="account-note">${androidPgp ? 'EXPERIMENTAL ANDROID TESTING — not independently security reviewed. Private keys remain passphrase-protected inside the encrypted Android vault. Optional biometric unlock stores the passphrase in a Keystore key requiring user authentication. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered.' : 'OpenPGP keys are protected by a passphrase and stored encrypted by your operating system. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered.'} Contact keys below are used to encrypt mail to your correspondents and to check signatures.</p>
|
||||
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
||||
<h3 class="pgp-heading">Change a key passphrase</h3>
|
||||
@@ -52,7 +52,7 @@ function openEncryptionKeys() {
|
||||
<label class="compose-line"><span>Name</span><input id="pgp-name" maxlength="100" value="${escapePgpKeyUi(account.displayName || '')}"></label>
|
||||
<label class="compose-line"><span>Email</span><input id="pgp-email" type="email" value="${escapePgpKeyUi(account.email || '')}"></label>
|
||||
<label class="compose-line"><span>Passphrase</span><input id="pgp-passphrase" type="password" autocomplete="new-password" placeholder="At least 8 characters"></label>
|
||||
<div class="pgp-actions"><button class="send-button" id="pgp-generate">Create key</button><button class="discard" id="pgp-import">Import private key…</button></div>
|
||||
<div class="pgp-actions"><button class="send-button" id="pgp-generate">Create key</button><button class="discard" id="pgp-import">${androidPgp ? 'Import private key from file…' : 'Import private key…'}</button>${androidPgp ? '<button class="discard" id="pgp-import-paste">Paste private key…</button>' : ''}</div>
|
||||
<p class="account-note" id="pgp-status" role="status"></p>
|
||||
</div></div></div>`;
|
||||
const close = () => { root.innerHTML = ''; };
|
||||
@@ -229,15 +229,17 @@ function openEncryptionKeys() {
|
||||
} catch (error) { status(error.message || 'Could not create the key.'); }
|
||||
button.disabled = false;
|
||||
};
|
||||
selectPgpKeyUi('#pgp-import').onclick = async () => {
|
||||
const importPrivateKey = async source => {
|
||||
const passphrase = needPassphrase();
|
||||
if (!passphrase) return;
|
||||
try {
|
||||
const result = await window.daybreakMail.pgp.importKey({ passphrase, accountId: account.id || null });
|
||||
const result = await window.daybreakMail.pgp.importKey({ passphrase, accountId: account.id || null, ...(androidPgp ? { source } : {}) });
|
||||
status(result.canceled ? '' : result.keyChangedFrom?.length ? 'Key imported. You already have a different key for this address; compare fingerprints before trusting either key.' : 'Key imported.');
|
||||
await render();
|
||||
if (!result.canceled) await render();
|
||||
} catch (error) { status(error.message || 'Could not import the key.'); }
|
||||
};
|
||||
selectPgpKeyUi('#pgp-import').onclick = () => importPrivateKey(androidPgp ? 'file' : undefined);
|
||||
if (androidPgp) selectPgpKeyUi('#pgp-import-paste').onclick = () => importPrivateKey('paste');
|
||||
async function renderContacts() {
|
||||
const list = selectPgpKeyUi('#pgp-contact-list');
|
||||
let contacts = [];
|
||||
|
||||
@@ -11039,8 +11039,15 @@ ${body}`);
|
||||
await persist(data);
|
||||
return { key: publicInfo(entry), revocationCertificate: generated.revocationCertificate };
|
||||
},
|
||||
async importKey({ armoredKey, passphrase, accountId = null }) {
|
||||
if (!armoredKey) armoredKey = prompt("Paste an ASCII-armored OpenPGP private key (up to 200 KB):") || "";
|
||||
async importKey({ armoredKey, passphrase, accountId = null, source = "paste" }) {
|
||||
if (!armoredKey && source === "file") {
|
||||
const selected = await EpMail2.pickPgpPrivateKey();
|
||||
if (selected.canceled) return { canceled: true };
|
||||
armoredKey = selected.armoredKey;
|
||||
if (typeof armoredKey !== "string" || !armoredKey.trim()) throw new Error("That key file is empty.");
|
||||
} else if (!armoredKey) {
|
||||
armoredKey = prompt("Paste an ASCII-armored OpenPGP private key (up to 200 KB):") || "";
|
||||
}
|
||||
const armored = String(armoredKey).trim();
|
||||
if (!armored || armored.length > MAX_KEY_LENGTH) throw new Error("That key file is empty or too large.");
|
||||
if (typeof passphrase !== "string" || passphrase.length < 8) throw new Error("Use a passphrase of at least 8 characters.");
|
||||
|
||||
+49
-39
@@ -65,43 +65,53 @@ document.addEventListener('keydown', event => {
|
||||
action.run();
|
||||
});
|
||||
|
||||
shortcutProductivityUi.wrapOpenPreferences(baseOpenPreferences => async function () {
|
||||
await baseOpenPreferences();
|
||||
const fields = selectShortcutUi('#modal-root .compose-fields');
|
||||
const save = selectShortcutUi('#save-appearance');
|
||||
if (!fields || !save) return;
|
||||
const shortcuts = loadShortcuts();
|
||||
const section = document.createElement('div');
|
||||
section.className = 'shortcut-settings';
|
||||
section.innerHTML = `<h3>Keyboard shortcuts</h3><p class="account-note">Type a key or combination such as <code>c</code>, <code>Ctrl+Enter</code> or <code>Alt+n</code>. Leave blank to disable. Shortcuts are inactive while typing or in dialogs.</p>${shortcutActions.map(action =>
|
||||
`<label class="compose-line"><span>${action.label}</span><input class="shortcut-input" data-action="${action.id}" maxlength="24" value="${escapeShortcutUi(shortcuts[action.id])}" placeholder="None"></label>`).join('')}<button type="button" class="discard" id="reset-shortcuts">Reset to defaults</button>`;
|
||||
fields.append(section);
|
||||
section.addEventListener('keydown', event => {
|
||||
const input = event.target.closest('.shortcut-input');
|
||||
if (!input || ['Tab', 'Escape'].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
if (['Backspace', 'Delete'].includes(event.key)) { input.value = ''; return; }
|
||||
const combo = eventShortcut(event);
|
||||
if (combo) input.value = combo;
|
||||
function openShortcutSettings() {
|
||||
const root = selectShortcutUi('#modal-root');
|
||||
const shortcuts = loadShortcuts();
|
||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal"><div class="modal-head"><span>Keyboard shortcuts</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields"><p class="account-note">Type a key or combination such as <code>c</code>, <code>Ctrl+Enter</code> or <code>Alt+n</code>. Leave blank to disable. Shortcuts are inactive while typing or in dialogs.</p>${shortcutActions.map(action =>
|
||||
`<label class="compose-line"><span>${action.label}</span><input class="shortcut-input" data-action="${action.id}" maxlength="24" value="${escapeShortcutUi(shortcuts[action.id])}" placeholder="None"></label>`).join('')}<button type="button" class="discard" id="reset-shortcuts">Reset to defaults</button></div><div class="compose-footer"><button class="discard modal-close">Cancel</button><button class="send-button" id="save-shortcuts">Save shortcuts</button></div></div></div>`;
|
||||
const close = () => { root.innerHTML = ''; };
|
||||
root.querySelectorAll('.modal-close').forEach(button => { button.onclick = close; });
|
||||
selectShortcutUi('.modal-overlay').onclick = event => { if (event.target.classList.contains('modal-overlay')) close(); };
|
||||
const fields = selectShortcutUi('#modal-root .compose-fields');
|
||||
fields.addEventListener('keydown', event => {
|
||||
const input = event.target.closest('.shortcut-input');
|
||||
if (!input || ['Tab', 'Escape'].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
if (['Backspace', 'Delete'].includes(event.key)) { input.value = ''; return; }
|
||||
const combo = eventShortcut(event);
|
||||
if (combo) input.value = combo;
|
||||
});
|
||||
selectShortcutUi('#reset-shortcuts').onclick = () => {
|
||||
fields.querySelectorAll('.shortcut-input').forEach(input => {
|
||||
input.value = shortcutActions.find(action => action.id === input.dataset.action).fallback;
|
||||
});
|
||||
selectShortcutUi('#reset-shortcuts').onclick = () => {
|
||||
section.querySelectorAll('.shortcut-input').forEach(input => {
|
||||
input.value = shortcutActions.find(action => action.id === input.dataset.action).fallback;
|
||||
});
|
||||
};
|
||||
const baseSave = save.onclick;
|
||||
save.onclick = event => {
|
||||
const values = {};
|
||||
const used = new Map();
|
||||
for (const input of section.querySelectorAll('.shortcut-input')) {
|
||||
const value = normalizeShortcut(input.value);
|
||||
const label = shortcutActions.find(action => action.id === input.dataset.action).label;
|
||||
if (value && used.has(value)) { toastShortcutUi(`“${value}” is used by both ${used.get(value)} and ${label}`); return; }
|
||||
if (value) used.set(value, label);
|
||||
values[input.dataset.action] = value;
|
||||
}
|
||||
localStorage.setItem(shortcutStorageKey, JSON.stringify(values));
|
||||
baseSave?.call(save, event);
|
||||
};
|
||||
});
|
||||
})();
|
||||
};
|
||||
selectShortcutUi('#save-shortcuts').onclick = () => {
|
||||
const values = {};
|
||||
const used = new Map();
|
||||
for (const input of fields.querySelectorAll('.shortcut-input')) {
|
||||
const value = normalizeShortcut(input.value);
|
||||
const label = shortcutActions.find(action => action.id === input.dataset.action).label;
|
||||
if (value && used.has(value)) { toastShortcutUi(`“${value}” is used by both ${used.get(value)} and ${label}`); return; }
|
||||
if (value) used.set(value, label);
|
||||
values[input.dataset.action] = value;
|
||||
}
|
||||
localStorage.setItem(shortcutStorageKey, JSON.stringify(values));
|
||||
close();
|
||||
toastShortcutUi('Keyboard shortcuts saved');
|
||||
};
|
||||
}
|
||||
|
||||
shortcutProductivityUi.wrapOpenPreferences(baseOpenPreferences => async function () {
|
||||
await baseOpenPreferences();
|
||||
const fields = selectShortcutUi('#modal-root .compose-fields');
|
||||
if (!fields || !selectShortcutUi('#save-appearance')) return;
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'discard';
|
||||
button.id = 'open-keyboard-shortcuts';
|
||||
button.textContent = 'Keyboard shortcuts…';
|
||||
button.onclick = openShortcutSettings;
|
||||
fields.append(button);
|
||||
});})();
|
||||
|
||||
+2
-1
@@ -126,9 +126,10 @@ body.ep-daylight .row-check:checked{accent-color:#526a2c}
|
||||
body.ep-daylight .mail-safety-warning{background:#fff6df;color:#5b3c17}body.ep-daylight .mail-link-risky{background:#fff8ea;border-color:#d69b43}
|
||||
|
||||
.folder-add{border:0;background:transparent;color:#929990;font-size:18px;cursor:pointer}.folder-add:hover{color:#487354}.section-label+.folder-nav:empty{display:none}.custom-folder span:last-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.shortcut-settings h3{margin:16px 0 4px;font-size:13px}.shortcut-settings code{font-family:monospace}.shortcut-input{text-transform:none}.shortcut-settings #reset-shortcuts{margin-top:8px}
|
||||
.compose-fields code{font-family:monospace}.shortcut-input{text-transform:none}#reset-shortcuts{margin-top:8px}
|
||||
.attachments-modal{width:min(720px,94vw)}.attachment-toolbar{display:flex;gap:8px;margin-bottom:10px}.attachment-toolbar input{flex:1}.attachment-list{max-height:60vh;overflow:auto;display:grid;gap:8px}.attachment-row{display:flex;flex-wrap:wrap;gap:8px;align-items:center;padding:8px;border:1px solid var(--line);border-radius:8px}.attachment-row-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}.attachment-row-info strong,.attachment-row-info small{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.attachment-preview{flex-basis:100%;max-height:320px;overflow:auto;padding:8px;font-size:12px}.attachment-preview-image{max-width:100%;max-height:300px;display:block}.attachment-preview-text{margin:0;white-space:pre-wrap;word-break:break-word}.preview-attachment{font-size:14px}
|
||||
.pgp-heading{margin:16px 0 4px;font-size:13px}.pgp-actions{display:flex;gap:8px;margin-top:8px}#open-encryption-keys{margin-top:12px}
|
||||
.pgp-keys-modal .attachment-list{grid-template-columns:minmax(0,1fr)}.pgp-keys-modal .attachment-row{min-width:0}.pgp-keys-modal .attachment-row-info{flex:1 0 100%}.pgp-keys-modal .attachment-row-info strong,.pgp-keys-modal .attachment-row-info small{overflow:visible;text-overflow:clip;white-space:normal;overflow-wrap:anywhere}.pgp-keys-modal .attachment-row>button{max-width:100%;padding:8px;font-size:12px}.pgp-keys-modal .attachment-row>.compose-line{flex:1 1 180px;min-width:0}.pgp-keys-modal .pgp-trust{margin-left:0;max-width:100%}.pgp-keys-modal .pgp-actions{flex-wrap:wrap}
|
||||
|
||||
.pgp-prompt{z-index:2000}.pgp-prompt-box{max-width:420px}
|
||||
.pgp-status,.pgp-banner{display:flex;flex-direction:column;gap:2px;margin:10px 0;padding:10px 12px;border-radius:8px;border:1px solid var(--line,#c9d1c8);font-size:13px}
|
||||
|
||||
Reference in New Issue
Block a user