P4TB-73 use identity `protectionDisabled` for disabled accounts

1.1.101
francesco 3 years ago
parent ab6b45519f
commit afc3667fca

@ -297,11 +297,20 @@ var TbHelper = {
return accountOptions.forAccount(account).decrypt();
},
disabledForAccount (gCurrentIdentity) {
encryptForAccount (gCurrentIdentity, privateOriginal) {
let Helper = ChromeUtils.import("chrome://p4t/content/TbHelper.js").TbHelper;
let accountOptions = Helper.getAccountOptions();
let account = Helper.getAccountWithIdentity(gCurrentIdentity);
return accountOptions.forAccount(account).disabled();
let current = accountOptions.forAccount(account);
if (current.disabled() && current.decrypt()) {
// P4TB-75 a disabled account with permission to decrypt will
// use p≡p when replying to a private message
return privateOriginal; // encrypt if the original was private
} else {
// if users do not want us to decrypt their messages
// we cannot rely on rating to detect private ones
return !current.disabled();
}
}
};

@ -5,7 +5,6 @@
"use strict";
const jsmime = ChromeUtils.import("resource:///modules/jsmime.jsm").jsmime;
const helper = ChromeUtils.import("chrome://p4t/content/TbHelper.js").TbHelper;
const {classes: Cc, results: Cr, interfaces: Ci} = Components;
const maxBufferLen = 102400;
@ -162,7 +161,7 @@ PgpMimeEncrypt.prototype = {
// nsIMsgComposeSecure interface
requiresCryptoEncapsulation: function (identity) {
console.log('mimeEntcrypt.js: requiresCryptoEncapsusation');
return !helper.disabledForAccount(identity);
return true;
},
beginCryptoEncapsulation: function (outStream, recipientList, msgCompFields, msgIdentity, sendReport, isDraft) {

@ -85,6 +85,12 @@ var _parseAddress = (address) => {
})
};
function isPrivate (rating) {
// starting from `PEP_rating_reliable` in
// `_PEP_rating` in the engine `message_api.h`
return rating && rating > 5;
}
var pEpComposer = {
init: function (window) {
@ -93,7 +99,7 @@ var pEpComposer = {
this.window = window;
const compat = compatFactory(this.window);
this.prefs = prefsFactory(compat);
this.initPrivacyWarning();
this.originalRatingPromise = this.getOriginalRating();
// we do not wait for the promises above to be
// resolved. pEpComposer init is run when the compose window
// is open and privacy will be checked when the message is
@ -103,7 +109,7 @@ var pEpComposer = {
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", false);
},
initPrivacyWarning() {
getOriginalRating() {
let id = this.window.arguments[0].originalMsgURI;
if (id === '') {
// these windows have no original, users are starting a
@ -120,8 +126,7 @@ var pEpComposer = {
message.to,
message.cc,
message.bcc)
})
.then((rating) => this.originalRating = rating );
});
}
},
@ -146,22 +151,34 @@ var pEpComposer = {
let cc = (msgCompFields.cc) ? _parseAddress(msgCompFields.cc) : undefined;
let bcc = (msgCompFields.bcc) ? _parseAddress(msgCompFields.bcc) : undefined;
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
let protectionDisabled = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
console.log("ONGOING RATING: ", rating);
if (typeof rating === "undefined") rating = -2;
updateMsgIdentity(rating);
pEpController.getPrivacyColorFromRating(rating).then((color) => {
createPrivacyNode(color, protectionDisabled);
});
}).catch(() => {
pEpController.getPrivacyColorFromRating(-2).then((color) => {
createPrivacyNode(color);
this.originalRatingPromise
.then((originalRating) => {
if (helper.encryptForAccount(gCurrentIdentity, isPrivate(originalRating))) {
return pEpController.getOngoingRating(from, to, cc, bcc);
} else {
if (!protectionDisabled) {
this.toggleDisableProtectionButtonAction()
protectionDisabled = !protectionDisabled;
}
return Promise.resolve(-2);
}
})
.then((rating) => {
console.log("ONGOING RATING: ", rating);
if (typeof rating === "undefined") rating = -2;
updateMsgIdentity(rating);
pEpController.getPrivacyColorFromRating(rating).then((color) => {
createPrivacyNode(color, protectionDisabled);
});
})
.catch(() => {
pEpController.getPrivacyColorFromRating(-2).then((color) => {
createPrivacyNode(color);
});
});
});
},
initListener: function (event) {
@ -235,12 +252,7 @@ var pEpComposer = {
privacyLoss() {
let rating = getCurrentIdentity().getIntAttribute("pEpRating");
return private(this.originalRating) && !private(rating);
function private (rating) {
// starting from `PEP_rating_reliable` in
// `_PEP_rating` in the engine `message_api.h`
return rating > 5;
}
return isPrivate(this.originalRating) && !isPrivate(rating);
},
pEp_onRecipientsChanged: function () {
@ -276,8 +288,6 @@ var pEpComposer = {
},
toggleDisableProtectionButtonAction: function() {
//Placeholder
//TODO To be implemented
let previousValue = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", !previousValue);

@ -14,6 +14,27 @@ window
No bar will be shown
## Encryption disabled
Encryption can be disabled because of several reasons
### Disabled account
There is an option to disable p≡p for a specific account. If p≡p is
disabled for the current account, the privacy bar will show no color
#### Keep decrypting
When p≡p is disabled for an account and "keep decrypting" is set for
the same account, p≡p will encrypt anyway when replying to an
encrypted message
### Disable button
This button is in the composer toolbar. When the button is toggled,
green and yellow privacy status will be shown with a lighter shade and
the outgoing message will not be encrypted
# Options
You can access pEp options by clicking on the Thunderbird menu which

@ -17,14 +17,14 @@ let tests = [
return isObject(helper.getAccountWithIdentity(gCurrentIdentity));
},
() => {
return typeof helper.disabledForAccount(gCurrentIdentity, true) == 'boolean';
return typeof helper.encryptForAccount(gCurrentIdentity, true) == 'boolean';
},
() => {
return typeof helper.disabledForAccount(gCurrentIdentity, false) == 'boolean';
return typeof helper.encryptForAccount(gCurrentIdentity, false) == 'boolean';
}];
function test() {
function fail (test) { return !test(); }
return !tests.map(fail).some();
return !tests.some(fail);
}
test();

@ -21,6 +21,7 @@ let tests = [
try {
return typeof Helper.decryptForSelectedAccount(gFolderDisplay) == "boolean";
} catch (e) {
console.log("this test requires a message to be selected");
return false;
}
}
@ -29,7 +30,7 @@ let tests = [
function test() {
if (gFolderDisplay) {
function fail (test) { return !test(); }
return !tests.map(fail).some();
return !tests.some(fail);
} else {
console.log("it's still too early for the tests");
return false;

Loading…
Cancel
Save