@ -2,6 +2,9 @@ console.log("pepmessengercompose.js");
var pEpController = ChromeUtils . import ( "chrome://p4t/content/p4tb.js" ) . pEpController ;
var Handshake = ChromeUtils . import ( "chrome://p4t/content/modules/handshake.js" ) . Handshake ;
//let Composer = ChromeUtils.import("chrome://p4t/content/modules/composer.js").Composer;
const helper = ChromeUtils . import ( "chrome://p4t/content/TbHelper.js" ) . TbHelper ;
const { compatFactory } = ChromeUtils . import ( "chrome://p4t/content/compatFactory.js" ) ;
const { prefsFactory } = ChromeUtils . import ( "chrome://p4t/content/prefsFactory.js" ) ;
// Abstract Thunderbird methods
var TbAbstraction = {
@ -84,11 +87,41 @@ var _parseAddress = (address) => {
} ;
var pEpComposer = {
init : function ( ) {
init : function ( window ) {
console . log ( "pEpComposer: init()" ) ;
const kEncryptionPolicy_Always = 2 ;
this . window = window ;
const compat = compatFactory ( this . window ) ;
this . prefs = prefsFactory ( compat ) ;
this . initPrivacyWarning ( ) ;
// 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
// sent. A race condition is unlikely yet possible.
TbAbstraction . getCurrentIdentity ( ) . setIntAttribute ( "encryptionpolicy" , 2 ) ;
} ,
initPrivacyWarning ( ) {
let id = this . window . arguments [ 0 ] . originalMsgURI ;
if ( typeof id == 'undefined' ) {
// these windows have no original, users are starting a
// new conversation
return Promise . reject ( ) ;
} else {
let originalMail = helper . readMailFromURI ( id ) ;
return pEpController
. messageFromMIME ( originalMail )
. then ( ( message ) => {
return pEpController
. getOngoingRating (
message . from ,
message . to ,
message . cc ,
message . bcc )
} )
. then ( ( rating ) => this . originalRating = rating ) ;
}
} ,
destroy : function ( ) {
@ -156,7 +189,52 @@ var pEpComposer = {
sendMessageListener : function ( event ) {
console . log ( "pepmessengercompose.js: compose-send-message()" ) ;
//TODO To be implemented
if ( this . prefs . isWarnUnencrypted ( ) && this . privacyLoss ( ) ) {
if ( this . unencryptedDialog ( ) ) {
//throw "Message not sent due to privacy concerns";
event . preventDefault ( ) ;
}
} else {
// the privacy warning is the only function for this
// handler at the moment
return ;
}
} ,
unencryptedDialog ( ) {
/ *
open dialog and ask user to send mail unencrypted .
initially copied from the code for the empty subject
warning , ` comm-central ` codebase , file
` MsgComposeCommand.js `
* /
let flags = Services . prompt . BUTTON_TITLE_IS_STRING *
Services . prompt . BUTTON_POS_0 +
Services . prompt . BUTTON_TITLE_IS_STRING *
Services . prompt . BUTTON_POS_1 ;
let confirm = Services . prompt . confirmEx (
window ,
"Privacy Reminder" ,
"Some recipients cannot decrypt our messages, do you want to send the message unencrypted?" ,
flags ,
"Cancel Sending" ,
"Send Unencrypted" ,
null ,
null ,
{ value : 0 } ) ;
return ( confirm === 0 ) ;
} ,
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 ;
}
} ,
pEp_onRecipientsChanged : function ( ) {
@ -196,4 +274,4 @@ window.addEventListener("compose-window-init", pEpComposer.initListener.bind(pEp
window . addEventListener ( "compose-from-changed" , pEpComposer . fromChangedListener . bind ( pEpComposer ) , true ) ;
window . addEventListener ( 'compose-send-message' , pEpComposer . sendMessageListener . bind ( pEpComposer ) , true ) ;
pEpComposer . init ( ) ;
pEpComposer . init ( window ) ;