|
|
@ -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); |
|
|
|