"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/controller/gmail.controller.js" between
mailvelope-4.2.0.tar.gz and mailvelope-4.2.1.tar.gz

About: Mailvelope is a browser extension offering email encryption with PGP (for Firefox and Chrome).

gmail.controller.js  (mailvelope-4.2.0):gmail.controller.js  (mailvelope-4.2.1)
skipping to change at line 19 skipping to change at line 19
import * as gmail from '../modules/gmail'; import * as gmail from '../modules/gmail';
import * as sub from './sub.controller'; import * as sub from './sub.controller';
import {getPreferredKeyringId} from '../modules/keyring'; import {getPreferredKeyringId} from '../modules/keyring';
import {setAppDataSlot} from '../controller/sub.controller'; import {setAppDataSlot} from '../controller/sub.controller';
export default class GmailController extends sub.SubController { export default class GmailController extends sub.SubController {
constructor(port) { constructor(port) {
super(port); super(port);
this.editorControl = null; this.editorControl = null;
this.keyringId = getPreferredKeyringId(); this.keyringId = getPreferredKeyringId();
this.currentAction = null; this.authorizationRequest = null;
this.authQueue = [];
this.settingsTab = null; this.settingsTab = null;
// register event handlers // register event handlers
this.on('open-editor', this.onOpenEditor); this.on('open-editor', this.onOpenEditor);
this.on('secure-button', this.onSecureBtn); this.on('secure-button', this.onSecureBtn);
} }
activateComponent() { activateComponent() {
mvelo.tabs.activate({id: this.tabId}); mvelo.tabs.activate({id: this.tabId});
} }
skipping to change at line 72 skipping to change at line 71
try { try {
options.recipientsTo = options.recipientsTo || []; options.recipientsTo = options.recipientsTo || [];
options.recipientsCc = options.recipientsCc || []; options.recipientsCc = options.recipientsCc || [];
const {armored, encFiles, subject, to, cc} = await this.openEditor(options ); const {armored, encFiles, subject, to, cc} = await this.openEditor(options );
// send email via GMAIL api // send email via GMAIL api
this.editorControl.ports.editor.emit('send-mail-in-progress'); this.editorControl.ports.editor.emit('send-mail-in-progress');
const userEmail = options.userEmail; const userEmail = options.userEmail;
const toFormatted = to.map(({name, email}) => `${name} <${email}>`); const toFormatted = to.map(({name, email}) => `${name} <${email}>`);
const ccFormatted = cc.map(({name, email}) => `${name} <${email}>`); const ccFormatted = cc.map(({name, email}) => `${name} <${email}>`);
const mail = gmail.buildMail({message: armored, attachments: encFiles, sub ject, sender: userEmail, to: toFormatted, cc: ccFormatted}); const mail = gmail.buildMail({message: armored, attachments: encFiles, sub ject, sender: userEmail, to: toFormatted, cc: ccFormatted});
const scopes = [gmail.GMAIL_SCOPE_READONLY, gmail.GMAIL_SCOPE_SEND]; const accessToken = await this.editorControl.getAccessToken();
const accessToken = await gmail.getAccessToken(userEmail, scopes); const sendOptions = {
if (!accessToken) { email: userEmail,
this.editorControl.authorize(scopes); message: mail,
} else { accessToken
const sendOptions = { };
email: userEmail, if (options.threadId) {
message: mail, sendOptions.threadId = options.threadId;
accessToken }
}; try {
if (options.threadId) { await gmail.sendMessageMeta(sendOptions);
sendOptions.threadId = options.threadId; this.editorControl.ports.editor.emit('show-notification', {
} message: l10n.get('gmail_integration_sent_success'),
try { type: 'success',
await gmail.sendMessageMeta(sendOptions); autoHide: true,
this.editorControl.ports.editor.emit('show-notification', { hideDelay: 2000,
message: l10n.get('gmail_integration_sent_success'), closeOnHide: true,
type: 'success', dismissable: false
autoHide: true, });
hideDelay: 2000, } catch (error) {
closeOnHide: true, this.editorControl.ports.editor.emit('error-message', {
dismissable: false error: Object.assign(mapError(error), {
}); autoHide: false,
} catch (error) { dismissable: true
this.editorControl.ports.editor.emit('error-message', { })
error: Object.assign(mapError(error), { });
autoHide: false,
dismissable: true
})
});
}
this.editorControl = null;
} }
this.editorControl = null;
} catch (error) { } catch (error) {
if (error.code == 'EDITOR_DIALOG_CANCEL') { if (error.code == 'EDITOR_DIALOG_CANCEL') {
this.editorControl = null; this.editorControl = null;
return; return;
} }
this.editorControl.ports.editor.emit('error-message', { this.editorControl.ports.editor.emit('error-message', {
error: Object.assign(mapError(error), { error: Object.assign(mapError(error), {
autoHide: false, autoHide: false,
dismissable: false dismissable: false
}) })
}); });
} }
} }
async onSecureBtn({type, msgId, all, userEmail}) { async onSecureBtn({type, msgId, all, userEmail}) {
const scopes = [gmail.GMAIL_SCOPE_READONLY, gmail.GMAIL_SCOPE_SEND];
const accessToken = await gmail.getAccessToken(userEmail, scopes);
if (!accessToken) {
if (!this.tabId) {
const {id} = await mvelo.tabs.getActive();
this.tabId = id;
}
this.currentAction = {type, msgId, all, userEmail};
this.openAuthorizeDialog({email: userEmail, scopes, ctrlId: this.id});
return;
}
try { try {
const accessToken = await this.getAccessToken({email: userEmail});
const {threadId, internalDate, payload} = await gmail.getMessage({msgId, e mail: userEmail, accessToken}); const {threadId, internalDate, payload} = await gmail.getMessage({msgId, e mail: userEmail, accessToken});
const messageText = await gmail.extractMailBody({payload, userEmail, msgId , accessToken}); const messageText = await gmail.extractMailBody({payload, userEmail, msgId , accessToken});
let subject = gmail.extractMailHeader(payload, 'Subject'); let subject = gmail.extractMailHeader(payload, 'Subject');
const {email: sender, name: senderName} = gmail.parseEmailAddress(gmail.ex tractMailHeader(payload, 'From')); const {email: sender, name: senderName} = gmail.parseEmailAddress(gmail.ex tractMailHeader(payload, 'From'));
const recipientsTo = []; const recipientsTo = [];
const recipientsCc = []; const recipientsCc = [];
const to = gmail.extractMailHeader(payload, 'To'); const to = gmail.extractMailHeader(payload, 'To');
const cc = gmail.extractMailHeader(payload, 'Cc'); const cc = gmail.extractMailHeader(payload, 'Cc');
let attachments = []; let attachments = [];
skipping to change at line 181 skipping to change at line 165
quotedMailIndent: type === 'reply', quotedMailIndent: type === 'reply',
attachments, attachments,
keepAttachments: type !== 'reply' keepAttachments: type !== 'reply'
}; };
this.onOpenEditor(options); this.onOpenEditor(options);
} catch (error) { } catch (error) {
console.log(`Gmail API error: ${error.message}`); console.log(`Gmail API error: ${error.message}`);
} }
} }
/**
* Get access token
* @param {String} email
* @param {Array} scopes
* @param {Function} beforeAuth - called before new authorization request is
started
* @param {Function} afterAuth - called after successful authorization reques
t
* @return {String}
*/
async getAccessToken({email, scopes = [gmail.GMAIL_SCOPE_READONLY, gmail.GMAIL
_SCOPE_SEND], beforeAuth, afterAuth} = {}) {
const accessToken = await this.checkAuthorization(email, scopes);
if (accessToken) {
return accessToken;
}
if (beforeAuth) {
beforeAuth();
}
this.openAuthorizeDialog({email, scopes});
return new Promise((resolve, reject) => this.authorizationRequest = {resolve
, reject, afterAuth});
}
async onAuthorize({email, scopes}) { async onAuthorize({email, scopes}) {
let accessToken;
let error;
try { try {
accessToken = await gmail.authorize(email, scopes); const accessToken = await gmail.authorize(email, scopes);
if (this.currentAction) { mvelo.tabs.close(this.settingsTab);
if (this.currentAction.type === 'reply') { this.settingsTab = null;
this.onSecureReply(this.currentAction); this.activateComponent();
} else if (this.currentAction.type === 'forward') { if (this.authorizationRequest.afterAuth) {
this.onSecureForward(this.currentAction); this.authorizationRequest.afterAuth();
}
this.currentAction = null;
} }
this.authorizationRequest.resolve(accessToken);
} catch (e) { } catch (e) {
if (e.code === 'ID_GSUITE_ERROR') { this.authorizationRequest.reject(e);
throw (e); throw e;
}
console.log(e);
error = e;
} }
if (this.authQueue.length) {
for (const ctrlId of this.authQueue) {
const ctrl = sub.getById(ctrlId);
if (ctrl) {
ctrl.onAuthorized({error, accessToken});
}
}
this.authQueue = [];
} else {
this.activateComponent();
}
mvelo.tabs.close(this.settingsTab);
this.settingsTab = null;
} }
checkAuthorization(email, scopes) { checkAuthorization(email, scopes = [gmail.GMAIL_SCOPE_READONLY, gmail.GMAIL_SC OPE_SEND]) {
return gmail.getAccessToken(email, scopes); return gmail.getAccessToken(email, scopes);
} }
async openAuthorizeDialog({email, scopes, ctrlId}) { async openAuthorizeDialog({email, scopes}) {
this.authQueue.push(ctrlId); const activeTab = await mvelo.tabs.getActive();
if (activeTab) {
this.tabId = activeTab.id;
}
const slotId = getHash(); const slotId = getHash();
setAppDataSlot(slotId, {email, scopes, gmailCtrlId: this.id, ctrlId}); setAppDataSlot(slotId, {email, scopes, gmailCtrlId: this.id});
this.settingsTab = await mvelo.tabs.loadAppTab(`?slotId=${slotId}#/settings/ provider/auth`); this.settingsTab = await mvelo.tabs.loadAppTab(`?slotId=${slotId}#/settings/ provider/auth`);
} }
} }
 End of changes. 14 change blocks. 
77 lines changed or deleted 69 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)