@ -376,6 +376,8 @@ function rcube_webmail()
this . http _post ( postact , postdata ) ;
}
this . check _mailvelope ( this . env . action ) ;
// detect browser capabilities
if ( ! this . is _framed ( ) && ! this . env . extwin )
this . browser _capabilities _check ( ) ;
@ -3341,6 +3343,141 @@ function rcube_webmail()
$ ( 'input.rcpagejumper' ) . val ( this . env . current _page ) . prop ( 'disabled' , this . env . pagecount < 2 ) ;
} ;
// check for mailvelope API
this . check _mailvelope = function ( action )
{
if ( typeof window . mailvelope !== 'undefined' ) {
this . mailvelope _init ( action ) ;
}
else {
$ ( window ) . on ( 'mailvelope' , function ( ) {
ref . mailvelope _init ( action ) ;
} ) ;
}
} ;
//
this . mailvelope _init = function ( action )
{
if ( this . env . browser _capabilities )
this . env . browser _capabilities [ 'pgpmime' ] = 1 ;
var keyring = this . get _local _storage _prefix ( ) ;
mailvelope . getKeyring ( keyring ) . then ( function ( kr ) {
ref . mailvelope _keyring = kr ;
} , function ( err ) {
// attempt to create a new keyring for this app/user
mailvelope . createKeyring ( keyring ) . then ( function ( kr ) {
ref . mailvelope _keyring = kr ;
keyring = keyring . identifier ;
} , function ( err ) {
console . error ( err )
} ) ;
} ) ;
if ( action == 'show' || action == 'preview' ) {
// decrypt text body
if ( this . env . is _pgp _content && window . mailvelope ) {
var data = $ ( this . env . is _pgp _content ) . text ( ) ;
ref . mailvelope _display _container ( this . env . is _pgp _content , data , keyring ) ;
}
// load pgp/mime message and pass it to the mailvelope display container
else if ( this . env . pgp _mime _part && window . mailvelope ) {
var msgid = this . display _message ( this . get _label ( 'loadingdata' ) , 'loading' ) ,
selector = this . env . pgp _mime _container ;
$ . ajax ( {
type : 'GET' ,
url : this . url ( 'get' , { '_mbox' : this . env . mailbox , '_uid' : this . env . uid , '_part' : this . env . pgp _mime _part } ) ,
error : function ( o , status , err ) {
ref . hide _message ( msgkey ) ;
ref . http _error ( o , status , err , lock ) ;
} ,
success : function ( data ) {
ref . mailvelope _display _container ( selector , data , keyring , msgid ) ;
}
} ) ;
}
}
else if ( action == 'compose' && window . mailvelope ) {
this . enable _command ( 'compose-encrypted' , true ) ;
}
} ;
// handler for the 'compose-encrypt' command
this . compose _encrypted = function ( props )
{
var container = $ ( '#' + this . env . composebody ) . parent ( ) ;
mailvelope . createEditorContainer ( '#' + container . attr ( 'id' ) , keyring ) . then ( function ( editor ) {
ref . mailvelope _editor = editor ;
container . addClass ( 'mailvelope' ) ;
$ ( '#' + ref . env . composebody ) . hide ( ) ;
} ) ;
} ;
// callback to replace the message body with the full armored
this . mailvelope _submit _messageform = function ( draft , saveonly )
{
// get recipients
var recipients = [ ] ;
$ . each ( [ 'to' , 'cc' , 'bcc' ] , function ( i , field ) {
var pos , rcpt , val = $ . trim ( $ ( '[name="_' + field + '"]' ) . val ( ) ) ;
while ( val . length && rcube _check _email ( val , true ) ) {
rcpt = RegExp . $2
recipients . push ( rcpt ) ;
val = val . substr ( val . indexOf ( rcpt ) + rcpt . length + 1 ) . replace ( /^\s*,\s*/ , '' ) ;
console . log ( '*' , val )
}
} ) ;
// check if we have keys for all recipients
var isvalid = recipients . length > 0 ;
ref . mailvelope _keyring . validKeyForAddress ( recipients ) . then ( function ( status ) {
$ . each ( status , function ( k , v ) {
console . log ( 'validate' , k , v )
if ( ! v ) {
isvalid = false ;
alert ( "No key found for " + k )
}
} ) ;
if ( ! isvalid ) {
if ( ! recipients . length )
alert ( ref . get _label ( 'norecipientwarning' ) ) ;
return false ;
}
ref . mailvelope _editor . encrypt ( recipients ) . then ( function ( armored ) {
console . log ( 'encrypted message' , armored ) ;
var form = this . gui _objects . messageform ;
// all checks passed, send message
// var msgid = ref.set_busy(true, draft || saveonly ? 'savingmessage' : 'sendingmessage')
} , function ( err ) {
console . log ( err )
} ) ;
} ) ;
return false ;
} ;
// wrapper for the mailvelope.createDisplayContainer API call
this . mailvelope _display _container = function ( selector , data , keyring , msgid )
{
mailvelope . createDisplayContainer ( selector , data , keyring , { } ) . then ( function ( ) {
$ ( selector ) . addClass ( 'mailvelope' ) . find ( '.message-part, .part-notice' ) . hide ( ) ;
ref . hide _message ( msgid ) ;
setTimeout ( function ( ) { $ ( window ) . resize ( ) ; } , 10 ) ;
} , function ( err ) {
console . error ( err )
ref . hide _message ( msgid ) ;
ref . display _message ( 'Message decryption failed: ' + err . message , 'error' )
} ) ;
} ;
/*********************************************************/
/********* mailbox folders methods *********/
/*********************************************************/
@ -3612,6 +3749,10 @@ function rcube_webmail()
) ;
}
if ( this . mailvelope _editor ) {
return this . mailvelope _submit _messageform ( draft , saveonly ) ;
}
// all checks passed, send message
var msgid = this . set _busy ( true , draft || saveonly ? 'savingmessage' : 'sendingmessage' ) ,
lang = this . spellcheck _lang ( ) ,