Browse Source

Add enable/disable passive mode and send the flag to the engine on load

1.1.101
Chris Fuertes 2 years ago
parent
commit
9e945ab915
4 changed files with 94 additions and 44 deletions
  1. +73
    -39
      chrome/content/modules/pEp.js
  2. +16
    -0
      chrome/content/modules/pEpAdapter.js
  3. +2
    -2
      chrome/content/pEpForThunderbird.js
  4. +3
    -3
      chrome/content/pepmsghdrview.js

+ 73
- 39
chrome/content/modules/pEp.js View File

@ -50,6 +50,21 @@ class pEp {
return this;
};
static cloneMessage(source) {
let clone = new pEp.Message(source.id,
source.shortmsg,
source.longmsg,
deepCopy(source.from),
deepCopy(source.to),
source.dir,
source.enc_format,
deepCopy(source.attachments),
deepCopy(source.opt_fields));
source.cc && clone.setCc(source.cc);
source.bcc && clone.setBcc(source.bcc);
return clone;
}
async getVersion() {
this.log.info("pEp: getVersion()");
return await this.adapter.serverVersion();
@ -88,7 +103,6 @@ class pEp {
/**
* Function called on open mail
*/
async decryptMailWithMessage(message) {
message.dir = DIR_INCOMING;
return await this.adapter.decrypt_message(message);
@ -123,11 +137,21 @@ class pEp {
return await this.identity_rating(email);
}
async identity_rating(email, id, name, fp) {
let identity = new pEp.Identity(email, id, name, fp);
return await this.adapter.identity_rating(identity).then( rating => {
identity.rating = rating;
return identity;
init(prefs) {
this.setPrefs(prefs);
//Setup passive mode at startup
let passiveMode;
if (this.prefs.getPassiveMode()) {
passiveMode = this.enablePassiveMode();
} else {
passiveMode = this.disablePassiveMode();
}
passiveMode.then(response => {
logger.debug("passive mode: " + this.prefs.getPassiveMode());
}).catch(err => {
logger.error("Problem setting up passive mode", err)
});
}
@ -175,24 +199,21 @@ class pEp {
return await this.adapter.myself(identity);
}
async get_trustwords(identity1, identity2, language="en") {
this.log.info("pEp: get_trustwords()", identity1, identity2);
let user1 = new pEp.Identity( identity1.address, identity1.user_id, identity1.username, identity1.fpr);
let user2 = new pEp.Identity( identity2.address, identity2.user_id, identity2.username, identity2.fpr);
// send to pEpAdapter
return await this.adapter.get_trustwords(user1, user2, language);
async identity_rating(email, id, name, fp) {
let identity = new pEp.Identity(email, id, name, fp);
return await this.adapter.identity_rating(identity).then(rating => {
identity.rating = rating;
return identity;
});
}
async is_pEp_user(address, id, name, fingerprint) {
this.log.info("pEp: is_pEp_user()");
async get_trustwords(identity1, identity2, language = "en") {
this.log.info("pEp: get_trustwords()", identity1, identity2);
let identity = new pEp.Identity(address, id, name, fingerprint);
let user1 = new pEp.Identity(identity1.address, identity1.user_id, identity1.username, identity1.fpr);
let user2 = new pEp.Identity(identity2.address, identity2.user_id, identity2.username, identity2.fpr);
// send to pEpAdapter
return await this.adapter.is_pEp_user(identity).then( is_pEp => {
identity.is_pEp = is_pEp;
return identity;
});
return await this.adapter.get_trustwords(user1, user2, language);
}
async update_identity(address, id, name, fingerprint) {
@ -227,33 +248,45 @@ class pEp {
return await this.adapter.key_mistrusted(identity);
}
static cloneMessage(source) {
let clone = new pEp.Message(source.id,
source.shortmsg,
source.longmsg,
deepCopy(source.from),
deepCopy(source.to),
source.dir,
source.enc_format,
deepCopy(source.attachments),
deepCopy(source.opt_fields));
source.cc && clone.setCc(source.cc);
source.bcc && clone.setBcc(source.bcc);
return clone;
async is_pEp_user(address, id, name, fingerprint) {
this.log.info("pEp: is_pEp_user()");
let identity = new pEp.Identity(address, id, name, fingerprint);
// send to pEpAdapter
return await this.adapter.is_pEp_user(identity).then(is_pEp => {
identity.is_pEp = is_pEp;
return identity;
});
}
async enablePassiveMode() {
this.log.info("pEp: enablePassiveMode()");
// send to pEpAdapter
return await this.adapter.passiveMode(true);
}
async disablePassiveMode() {
this.log.info("pEp: disablePassiveMode()");
// send to pEpAdapter
return await this.adapter.passiveMode(false);
}
setPrefs(prefs) {
this.prefs = prefs;
}
disclaimerStep(message) {
let mode = this.prefs.getDisclaimerMode();
let disclaimer = this.prefs.getDisclaimer();
function withDisclaimer(message) {
let modified = deepCopy(message);
modified.longmsg += "\r\n" + disclaimer;
return modified;
}
if (mode === "disclaimer-encrypted") {
return this
.getOngoingRating(
@ -268,7 +301,7 @@ class pEp {
return message;
}
})
.catch(() => message );
.catch(() => message);
} else if (mode === "disclaimer-all") {
return Promise.resolve(withDisclaimer(message));
} else {
@ -378,15 +411,15 @@ pEp.Message = class {
commonHeaders() {
let opt = [];
// add extra headers
if ('opt_fields' in this) {
opt = this.opt_fields.map(({ key, value }) => [key, value]);
if ('opt_fields' in this) {
opt = this.opt_fields.map(({key, value}) => [key, value]);
}
return [
["Message-ID", this.id || "No-message-ID"],
["Subject", this.shortmsg]
].concat(opt);
}
partsFromEncrypted(atob, boundary) {
let common = this.commonHeaders();
return [{
@ -430,6 +463,7 @@ pEp.Message = class {
body: atob(attachment.value)
}
}
let common = this.commonHeaders();
let hasAttachments = this.attachments && this.attachments.length > 0;
if (hasAttachments) {
@ -458,7 +492,7 @@ pEp.Message = class {
}];
}
}
toParts(atob, boundary) {
let met = (this.enc_format === 0) ? this.partsFromUnencrypted.bind(this) : this.partsFromEncrypted.bind(this);
return met(atob, boundary);


+ 16
- 0
chrome/content/modules/pEpAdapter.js View File

@ -11,6 +11,7 @@ const API_METHOD_GET_MYSELF = "myself";
const API_METHOD_GET_UPDATE_IDENTITY = "update_identity";
const API_METHOD_GET_IS_PEP_USER = "is_pEp_user";
const API_METHOD_GET_TRUSTWORDS = "get_trustwords";
const API_METHOD_CONFIG_PASSIVE_MODE = "config_passive_mode";
const API_METHOD_GET_key_mistrusted = "key_mistrusted";
const API_METHOD_GET_trust_personal_key = "trust_personal_key";
const API_METHOD_GET_key_reset_trust = "key_reset_trust";
@ -64,6 +65,21 @@ class pEpAdapter {
});
}
async passiveMode(enable) {
this.log.info("pEpAdapter.js: passiveMode()");
let params = [enable];
return await this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_CONFIG_PASSIVE_MODE,
params
).then((response) => {
return response.result.return;
}).catch((err) => {
this.log.error(err.message, err);
return err;
});
}
async getOngoingRating(message) {
this.log.info("pEpAdapter.js: getOngoingRating()");
let params = [message, "0"];


+ 2
- 2
chrome/content/pEpForThunderbird.js View File

@ -15,8 +15,8 @@ class pEpForThunderbird extends pEp {
this.emitter = new MimeEmitter(jsmime, atob, pEpUtils.generateRandomString(33));
}
init() {
console.log(pEp);
init(prefs) {
super.init(prefs);
let decryptionComponent = pEpMimeDecrypt.makeComponent(this);
this.factories = {
encryption: new pEpFactory(pEpMimeEncrypt.Handler, this, pEp),


+ 3
- 3
chrome/content/pepmsghdrview.js View File

@ -72,7 +72,7 @@ var dbObserver = {
throw new Error("Cannot add column handler");
}
}
}
};
var ColumnOverlay = {
init: function (win) {
@ -127,7 +127,7 @@ var pEpHdrView = {
init: function () {
console.debug("pEpHdrView: init()", this, window);
this.onLoadListener();
pEpController.init();
pEpController.init(Prefs);
},
destroy: function () {
@ -144,7 +144,7 @@ var pEpHdrView = {
console.debug("pepmsghdrview.js: onLoadListener()", this, window);
MessageView.init(window);
ColumnOverlay.init(window);
ColumnOverlay.init(window, gDBView);
window.gMessageListeners.push({
onStartHeaders: this.onLoadMsgPanelFrameListener.bind(this),


Loading…
Cancel
Save