Skip to content

Commit 3ab4450

Browse files
committed
recovery email validation when composer recipient != mailbox recipient
1 parent 5ea6e87 commit 3ab4450

File tree

20 files changed

+169
-55
lines changed

20 files changed

+169
-55
lines changed

electron_app/electron-starter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ async function initApp() {
105105
composerWindowManager.sendEventToMailbox('send-recovery-email', undefined)
106106
})
107107

108-
ipcMain.on('open-recovery-email-mailbox', () => {
109-
composerWindowManager.sendEventToMailbox('open-recovery-email-mailbox', undefined)
108+
ipcMain.on('open-recovery-email-mailbox', (ev,params) => {
109+
composerWindowManager.sendEventToMailbox('open-recovery-email-mailbox', params)
110110
})
111111

112112
// Socket

electron_app/src/ipc/client.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ ipc.answerRenderer('client-can-login', ({ username, domain }) =>
1515
clientManager.canLogin({ username, domain })
1616
);
1717

18-
ipc.answerRenderer('client-can-send', () => {
19-
const data = { recipientId: myAccount.recipientId };
18+
ipc.answerRenderer('client-can-send', params => {
19+
const recipientId =
20+
params && params.recipientId ? params.recipientId : myAccount.recipientId;
21+
const data = { recipientId };
2022
return clientManager.canSend(data);
2123
});
2224

@@ -183,8 +185,10 @@ ipc.answerRenderer('client-report-phishing', params => {
183185
return clientManager.reportPhishing(data);
184186
});
185187

186-
ipc.answerRenderer('client-resend-confirmation-email', () => {
187-
return clientManager.resendConfirmationEmail(myAccount.recipientId);
188+
ipc.answerRenderer('client-resend-confirmation-email', params => {
189+
const recipientId =
190+
params && params.recipientId ? params.recipientId : myAccount.recipientId;
191+
return clientManager.resendConfirmationEmail(recipientId);
188192
});
189193

190194
ipc.answerRenderer('client-reset-password', params =>

electron_app/src/ipc/composer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ ipc.answerRenderer(
1414
}
1515
);
1616

17-
ipc.answerRenderer('close-with-draft', composerId => {
18-
composerWindowManager.closeWithDraft(composerId);
19-
});
20-
2117
ipc.answerRenderer('open-empty-composer', () => {
2218
composerWindowManager.openNewComposer();
2319
});

electron_app/src/ipc/mailbox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ ipc.answerRenderer('maximize-mailbox', () => {
3838
mailboxWindow.toggleMaximize();
3939
});
4040

41+
ipc.answerRenderer('focus-mailbox', () => {
42+
mailboxWindow.focus();
43+
});
44+
4145
ipc.answerRenderer('minimize-mailbox', () => {
4246
mailboxWindow.minimize();
4347
});

electron_app/src/windows/composer.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,6 @@ const editDraft = async emailToEdit => {
143143
});
144144
};
145145

146-
const closeWithDraft = async composerId => {
147-
const window = BrowserWindow.fromId(composerId);
148-
try {
149-
if (globalManager.forcequit.get() && window.saved) return;
150-
if (
151-
globalManager.forcequit.get() ||
152-
(!window.saved && !isDraftEmpty(window.id))
153-
) {
154-
const dataDraft = globalManager.composerData.get(window.id);
155-
await saveDraftToDatabase(window.id, dataDraft);
156-
window.saved = true;
157-
globalManager.composerData.delete(window.id);
158-
sendEventToMailbox('save-draft-success');
159-
window.close();
160-
} else {
161-
globalManager.composerData.delete(window.id);
162-
}
163-
} catch (error) {
164-
sendEventToMailbox('save-draft-failed');
165-
}
166-
};
167-
168146
const destroy = async ({
169147
composerId,
170148
discard,
@@ -283,7 +261,6 @@ const saveDraftToDatabase = async (composerId, data) => {
283261

284262
module.exports = {
285263
destroy,
286-
closeWithDraft,
287264
editDraft,
288265
saveDraftChanges,
289266
sendEventToMailbox,

electron_app/src/windows/mailbox.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ const show = async ({ firstOpenApp = false }) => {
129129
}
130130
};
131131

132+
const focus = () => {
133+
if (mailboxWindow && mailboxWindow.focus) {
134+
mailboxWindow.focus();
135+
}
136+
};
137+
132138
const hide = () => {
133139
if (mailboxWindow && mailboxWindow.hide) {
134140
mailboxWindow.hide();
@@ -200,6 +206,7 @@ function getWindow() {
200206
module.exports = {
201207
close,
202208
hide,
209+
focus,
203210
getShowPreview,
204211
getWindow,
205212
send,

email_composer/src/components/Composer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import { Status } from './Control';
99
import { mySettings } from '../utils/electronInterface';
1010
import PopupHOC from './PopupHOC';
1111
import NotVerifiedRecoveryEmailPopup from '../components/NotVerifiedRecoveryEmailPopup';
12+
import RecoveryEmailSentPopup from '../components/RecoveryEmailSentPopup';
1213
import './composer.scss';
1314

1415
const NotverifiedrecoveryemailPopup = PopupHOC(NotVerifiedRecoveryEmailPopup);
16+
const Recoveryemailsentpopup = PopupHOC(RecoveryEmailSentPopup);
1517

1618
const Composer = props => (
1719
<div className="wrapper" data-theme={mySettings.theme || 'light'}>
@@ -76,6 +78,13 @@ const Composer = props => (
7678
theme={'dark'}
7779
/>
7880
)}
81+
{props.displayRecoveryEmailSentPopup && (
82+
<Recoveryemailsentpopup
83+
popupPosition={{ left: '45%', top: '45%' }}
84+
onTogglePopup={props.onToggleRecoveryEmailSentPopup}
85+
theme={'dark'}
86+
/>
87+
)}
7988
{(props.status === Status.WAITING ||
8089
props.status === Status.INITIALIZING ||
8190
props.isLinkingDevices) && <div className="composer-disable" />}
@@ -92,6 +101,7 @@ Composer.propTypes = {
92101
disableSendButtonOnInvalidEmail: PropTypes.func,
93102
displayNonCriptextPopup: PropTypes.bool,
94103
displayNotVerifiedRecoveryEmailPopup: PropTypes.bool,
104+
displayRecoveryEmailSentPopup: PropTypes.bool,
95105
files: PropTypes.array,
96106
getAccount: PropTypes.func,
97107
getBccEmails: PropTypes.func,
@@ -119,6 +129,7 @@ Composer.propTypes = {
119129
onSetNonCriptextRecipientsPassword: PropTypes.func,
120130
onTogglePopupNotVerifiedRecoveryEmail: PropTypes.func,
121131
onToggleRecipient: PropTypes.func,
132+
onToggleRecoveryEmailSentPopup: PropTypes.func,
122133
status: PropTypes.number,
123134
tagBlured: PropTypes.func,
124135
tagChanged: PropTypes.func,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import string from './../lang';
4+
5+
const RecoveryEmailSentPopup = props => {
6+
return (
7+
<div id="cptx-popup-container" className="popup-content">
8+
<div className="popup-paragraph">
9+
<p>{string.popups.recoveryEmailSentPopup.description}</p>
10+
</div>
11+
<button
12+
className="button-a popup-confirm-button"
13+
onClick={props.onTogglePopup}
14+
>
15+
<span>{string.popups.recoveryEmailSentPopup.buttons.ok}</span>
16+
</button>
17+
</div>
18+
);
19+
};
20+
21+
RecoveryEmailSentPopup.propTypes = {
22+
onTogglePopup: PropTypes.func
23+
};
24+
25+
export default RecoveryEmailSentPopup;

email_composer/src/components/popuphoc.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
z-index: 11;
1515
transform: translate(-50%, -50%);
1616
width: 286px;
17-
height: 341px;
1817
padding: 30px;
1918

2019
.popup-content {

email_composer/src/containers/Composer.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import {
1414
canSend,
1515
closeComposerWindow,
16-
closeWindowWithDraft,
1716
createEmail,
1817
getAlias,
1918
isCriptextDomain,
@@ -125,6 +124,7 @@ class ComposerWrapper extends Component {
125124
displayNotVerifiedRecoveryEmailPopup={
126125
this.state.displayNotVerifiedRecoveryEmailPopup
127126
}
127+
displayRecoveryEmailSentPopup={this.state.displayRecoveryEmailSentPopup}
128128
files={this.state.files}
129129
getAccount={this.hangleGetAccount}
130130
getBccEmails={this.handleGetBccEmail}
@@ -152,6 +152,7 @@ class ComposerWrapper extends Component {
152152
this.handleTogglePopupNotVerifiedRecoveryEmail
153153
}
154154
onToggleRecipient={this.handleToggleRecipient}
155+
onToggleRecoveryEmailSentPopup={this.handleToggleRecoveryEmailSentPopup}
155156
status={this.state.status}
156157
onSetNonCriptextRecipientsPassword={
157158
this.handleSetNonCriptextRecipientsPassword
@@ -393,20 +394,25 @@ class ComposerWrapper extends Component {
393394

394395
handleConfirmVerifyRecoveryEmail = async () => {
395396
const recoveryEmail = this.state.recoveryEmail;
397+
this.saveTemporalDraft();
396398
if (recoveryEmail === '') {
397-
this.saveTemporalDraft();
398-
sendEventToMailbox('open-recovery-email-mailbox', undefined);
399+
const params = {
400+
recipientId: myAccount.recipientId,
401+
accountId: myAccount.id
402+
};
399403
this.setState({
400404
displayNotVerifiedRecoveryEmailPopup: false
401405
});
402-
closeWindowWithDraft();
406+
sendEventToMailbox('open-recovery-email-mailbox', params);
403407
return;
404408
}
405409
this.setState({
406410
displayNotVerifiedRecoveryEmailPopup: false
407411
});
408-
await resendConfirmationEmail();
409-
sendEventToMailbox('send-recovery-email', undefined);
412+
this.setState({
413+
displayRecoveryEmailSentPopup: true
414+
});
415+
await resendConfirmationEmail({ recipientId: myAccount.recipientId });
410416
};
411417

412418
handleTogglePopupNotVerifiedRecoveryEmail = () => {
@@ -415,6 +421,12 @@ class ComposerWrapper extends Component {
415421
});
416422
};
417423

424+
handleToggleRecoveryEmailSentPopup = () => {
425+
this.setState({
426+
displayRecoveryEmailSentPopup: false
427+
});
428+
};
429+
418430
handleDisableSendButtonOnInvalidEmail = () => {
419431
this.setState(prevState => {
420432
if (prevState.status !== Status.DISABLED) {
@@ -773,7 +785,9 @@ class ComposerWrapper extends Component {
773785
});
774786
} else {
775787
this.setState({ status: Status.WAITING });
776-
const { status, body } = await canSend();
788+
const { status, body } = await canSend({
789+
recipientId: myAccount.recipientId.split('@')[0]
790+
});
777791

778792
if (status === 405) {
779793
const recoveryEmail = body.data.recovery;

0 commit comments

Comments
 (0)