@@ -6,7 +6,7 @@ var util = require('crypto-lib').util;
66// Controller
77//
88
9- var WriteCtrl = function ( $scope , $window , $filter , $q , appConfig , auth , keychain , pgp , email , outbox , dialog , axe , status ) {
9+ var WriteCtrl = function ( $scope , $window , $filter , $q , appConfig , auth , keychain , pgp , email , outbox , dialog , axe , status , invitation ) {
1010
1111 var str = appConfig . string ;
1212 var cfg = appConfig . config ;
@@ -52,6 +52,8 @@ var WriteCtrl = function($scope, $window, $filter, $q, appConfig, auth, keychain
5252 $scope . body = '' ;
5353 $scope . attachments = [ ] ;
5454 $scope . addressBookCache = undefined ;
55+ $scope . showInvite = undefined ;
56+ $scope . invited = [ ] ;
5557 }
5658
5759 function reportBug ( ) {
@@ -248,6 +250,9 @@ var WriteCtrl = function($scope, $window, $filter, $q, appConfig, auth, keychain
248250 recipient . key = key ;
249251 recipient . secure = true ;
250252 }
253+ } else {
254+ // show invite dialog if no key found
255+ $scope . showInvite = true ;
251256 }
252257 $scope . checkSendStatus ( ) ;
253258
@@ -286,6 +291,7 @@ var WriteCtrl = function($scope, $window, $filter, $q, appConfig, auth, keychain
286291
287292 // only allow sending if receviers exist
288293 if ( numReceivers < 1 ) {
294+ $scope . showInvite = false ;
289295 return ;
290296 }
291297
@@ -299,6 +305,7 @@ var WriteCtrl = function($scope, $window, $filter, $q, appConfig, auth, keychain
299305 $scope . okToSend = true ;
300306 $scope . sendBtnText = str . sendBtnSecure ;
301307 $scope . sendBtnSecure = true ;
308+ $scope . showInvite = false ;
302309 } else {
303310 // send plaintext
304311 $scope . okToSend = true ;
@@ -315,6 +322,56 @@ var WriteCtrl = function($scope, $window, $filter, $q, appConfig, auth, keychain
315322 $scope . attachments . splice ( $scope . attachments . indexOf ( attachment ) , 1 ) ;
316323 } ;
317324
325+ /**
326+ * Invite all users without a public key
327+ */
328+ $scope . invite = function ( ) {
329+ var sender = auth . emailAddress ,
330+ sendJobs = [ ] ,
331+ invitees = [ ] ;
332+
333+ $scope . showInvite = false ;
334+
335+ // get recipients with no keys
336+ $scope . to . forEach ( check ) ;
337+ $scope . cc . forEach ( check ) ;
338+ $scope . bcc . forEach ( check ) ;
339+
340+ function check ( recipient ) {
341+ if ( util . validateEmailAddress ( recipient . address ) && ! recipient . secure && $scope . invited . indexOf ( recipient . address ) === - 1 ) {
342+ invitees . push ( recipient . address ) ;
343+ }
344+ }
345+
346+ return $q ( function ( resolve ) {
347+ resolve ( ) ;
348+
349+ } ) . then ( function ( ) {
350+ invitees . forEach ( function ( recipientAddress ) {
351+ var invitationMail = invitation . createMail ( {
352+ sender : sender ,
353+ recipient : recipientAddress
354+ } ) ;
355+ // send invitation mail
356+ var promise = outbox . put ( invitationMail ) . then ( function ( ) {
357+ return invitation . invite ( {
358+ recipient : recipientAddress ,
359+ sender : sender
360+ } ) ;
361+ } ) ;
362+ sendJobs . push ( promise ) ;
363+ // remember already invited users to prevent spamming
364+ $scope . invited . push ( recipientAddress ) ;
365+ } ) ;
366+
367+ return Promise . all ( sendJobs ) ;
368+
369+ } ) . catch ( function ( err ) {
370+ $scope . showInvite = true ;
371+ return dialog . error ( err ) ;
372+ } ) ;
373+ } ;
374+
318375 //
319376 // Editing email body
320377 //
0 commit comments