From 57d515bfc605bdf82e52f2574d9e21d338e27be5 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 21 Aug 2017 10:59:02 +0200 Subject: [PATCH] W.I.P. of S/MIME: - Offer to add sender's certificate into addressbook --- mail/inc/class.mail_ui.inc.php | 15 +++++++++++++-- mail/js/app.js | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 888c43ef2e..a35d61f630 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -486,7 +486,7 @@ class mail_ui $content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = "mail_DisplayNone"; $content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "mail_DisplayNone"; } - + //$zstarttime = microtime (true); $sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); //$zendtime = microtime(true) - $zstarttime; @@ -2233,6 +2233,17 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $response->data(true); } + /** + * Adds certificate to relevant contact + * @param array $_metadata data of sender's certificate + */ + function ajax_smimeAddCertToContact ($_metadata) + { + $response = Api\Json\Response::get(); + $ab = new addressbook_bo(); + $response->data($ab->set_smime_keys(array($_metadata['email'] => $_metadata['cert']))); + } + /** * Build actions for display toolbar */ @@ -3065,9 +3076,9 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $structure = $this->mail_bo->getStructure($uid, $partID, $mailbox, false); if (($smime = $structure->getMetadata('X-EGroupware-Smime'))) { - $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, $structure,true,false,true, $mailbox); $push = new Api\Json\Push(); + if (!empty($smime['addtocontact'])) $push->call('app.mail.smime_certAddToContact', $smime); if (is_array($attachments)) { $push->call('app.mail.set_smimeAttachments', $this->createAttachmentBlock($attachments, $_GET['_messageID'], $uid, $mailbox)); diff --git a/mail/js/app.js b/mail/js/app.js index 1663c71f22..babcd7d1e9 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -5853,6 +5853,26 @@ app.classes.mail = AppJS.extend( var smime_classes = 'smime_cert_verified smime_cert_notverified smime_cert_notvalid'; _nodes[i].removeClass(smime_classes); } + }, + /** + * Inform user about sender's certificate and offers to add it into + * relevant contact in addressbook. + * + * @param {type} _metadata + */ + smime_certAddToContact: function (_metadata) + { + if (!_metadata || _metadata.length < 1) return; + var self = this; + et2_dialog.show_dialog(function(_button){ + if (_button == 2) + { + self.egw.json('mail.mail_ui.ajax_smimeAddCertToContact', + _metadata,null,function(_message){egw.message(_message);}).sendRequest(true); + } + }, + this.egw.lang("There's a new certificate information for email %1. Would you like to update/add this certificate?\n %2",_metadata.email,_metadata.certHtml), + this.egw.lang('Update cert for user %1', _metadata.email),{},et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw); } });