From: Michael M Slusarz Date: Tue, 4 May 2010 22:35:55 +0000 (-0600) Subject: Identity sanity checking in IMP. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=13dcd129fdefe97244f49da9b291c8c410f21b96;p=horde.git Identity sanity checking in IMP. Check for incorrect identity on compose if a single recipient address is tied to a different identity than the sending identity. --- diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 4c46ca5bb..e43ad440d 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -268,9 +268,10 @@ case _("Send"): } $options = array( + 'identity' => $identity, + 'readreceipt' => ($conf['compose']['allow_receipts'] && ($prefs->getValue('disposition_request_read') == 'always')), 'save_sent' => $save_sent_mail, - 'sent_folder' => $sent_mail_folder, - 'readreceipt' => ($conf['compose']['allow_receipts'] && ($prefs->getValue('disposition_request_read') == 'always')) + 'sent_folder' => $sent_mail_folder ); try { @@ -283,6 +284,12 @@ case _("Send"): } } catch (IMP_Compose_Exception $e) { $notification->push($e); + + /* Switch to tied identity. */ + if (!is_null($e->tied_identity)) { + $identity->setDefault($e->tied_identity); + $notification->push(_("Your identity has been switched to the identity associated with the current recipient address. The identity will not be checked again during this compose action.")); + } } break; } diff --git a/imp/compose.php b/imp/compose.php index 2db0da141..20ca6067f 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -418,11 +418,12 @@ case 'send_message': } $options = array( + 'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $vars->encrypt_options, + 'identity' => $identity, + 'priority' => $vars->priority, 'save_sent' => $save_sent_mail, 'sent_folder' => $sent_mail_folder, 'save_attachments' => $vars->save_attachments_select, - 'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $vars->encrypt_options, - 'priority' => $vars->priority, 'readreceipt' => $vars->request_read_receipt ); @@ -434,6 +435,12 @@ case 'send_message': $code = $e->getCode(); $notification->push($e->getMessage(), strpos($code, 'horde.') === 0 ? $code : 'horde.error'); + /* Switch to tied identity. */ + if (!is_null($e->tied_identity)) { + $identity->setDefault($e->tied_identity); + $notification->push(_("Your identity has been switched to the identity associated with the current recipient address. The identity will not be checked again during this compose action.")); + } + // TODO switch ($e->encrypt) { case 'pgp_symmetric_passphrase_dialog': @@ -717,14 +724,14 @@ if ($redirect) { $hidden = array( 'actionID' => '', - 'user' => Horde_Auth::getAuth(), - 'compose_requestToken' => Horde::getRequestToken('imp.compose'), + 'attachmentAction' => '', 'compose_formToken' => Horde_Token::generateId('compose'), + 'compose_requestToken' => Horde::getRequestToken('imp.compose'), 'composeCache' => $composeCacheID, 'mailbox' => htmlspecialchars(IMP::$mailbox), - 'attachmentAction' => '', 'oldrtemode' => $rtemode, - 'rtemode' => $rtemode + 'rtemode' => $rtemode, + 'user' => Horde_Auth::getAuth() ); if ($_SESSION['imp']['file_upload']) { diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 5032f904c..dd8d0770e 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Check for incorrect identity on compose if a single recipient address + is tied to a different identity than the sending identity. [mms] Use CATENATE (RFC 4469), if available, to strip MIME parts (Request #8092). [mms] Add preference to show flags created by other MUAs (Request #8882). diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 4740fd448..e1576056e 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -10,8 +10,8 @@ var DimpCompose = { // Variables defaulting to empty/false: // auto_save_interval, compose_cursor, disabled, drafts_mbox, - // editor_wait, is_popup, knl_p, knl_sm, last_msg, loaded, rte, - // skip_spellcheck, spellcheck, sc_submit, uploading + // editor_wait, is_popup, knl_p, knl_sm, last_msg, loaded, old_identity, + // rte, skip_spellcheck, spellcheck, sc_submit, uploading confirmCancel: function() { @@ -289,6 +289,11 @@ var DimpCompose = { this.resizeMsgArea(); break; } + } else if (!Object.isUndefined(d.identity)) { + this.old_identity = $F('identity'); + $('identity').setValue(d.identity); + this.changeIdentity(); + $('noticerow', 'identitychecknotice').invoke('show'); } this.setDisabled(false); @@ -486,15 +491,7 @@ var DimpCompose = { switch (opts.auto) { case 'forward_attach': $('noticerow', 'fwdattachnotice').invoke('show'); - $('composeMessage').stopObserving('keydown').observe('keydown', function() { - $('fwdattachnotice').fade({ - afterFinish: function() { - $('fwdattachnotice').up('TR').hide(); - this.resizeMsgArea(); - }.bind(this), - duration: 0.4 - }); - }.bind(this)); + $('composeMessage').stopObserving('keydown').observe('keydown', this.fadeNotice.bind(this, 'fwdattachnotice')); break case 'forward_body': @@ -523,6 +520,21 @@ var DimpCompose = { } }, + fadeNotice: function(elt) + { + elt = $(elt); + + elt.fade({ + afterFinish: function() { + if (!elt.siblings().any(Element.visible)) { + elt.up('TR').hide(); + this.resizeMsgArea(); + } + }.bind(this), + duration: 0.4 + }); + }, + setBodyText: function(msg) { if (IMP_Compose_Base.editor_on) { @@ -776,24 +788,22 @@ var DimpCompose = { this.setSaveSentMail($F(elt)); break; - case 'replyallnotice': - case 'replylistnotice': case 'fwdattachnotice': case 'fwdbodynotice': - elt.fade({ - afterFinish: function() { - elt.up('TR').hide(); - this.resizeMsgArea(); - }.bind(this), - duration: 0.4 - }); + case 'identitychecknotice': + case 'replyallnotice': + case 'replylistnotice': + this.fadeNotice(elt); if (!orig.match('SPAN.closeImg')) { if (id.startsWith('reply')) { $('to_loading_img').show(); DimpCore.doAction('getReplyData', { headeronly: 1, imp_compose: $F('composeCache'), type: 'reply' }, { callback: this.swapToAddressCallback.bind(this) }); - } else { + } else if (id.startsWith('fwd')) { DimpCore.doAction('GetForwardData', { dataonly: 1, imp_compose: $F('composeCache'), type: (id == 'fwdattachnotice' ? 'forward_body' : 'forward_attach') }, { callback: this.forwardAddCallback.bind(this) }); $('composeMessage').stopObserving('keydown'); + } else if (id == 'identitychecknotice') { + $('identity').setValue(this.old_identity); + this.changeIdentity(); } } e.stop(); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 49d371f84..c91c2c11a 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1337,6 +1337,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base *
      * 'action' - (string) The AJAX action string
      * 'draft_delete' - (integer) TODO
+     * 'identity' - (integer) If set, this is the identity that is tied to
+     *              the current recipient address.
      * 'log' - (array) TODO
      * 'mailbox' - (array) TODO
      * 'reply_folder' - (string) TODO
@@ -1370,6 +1372,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         $imptree->eltDiffStart();
 
         $options = array(
+            'identity' => $identity,
             'priority' => $this->_vars->priority,
             'readreceipt' => $this->_vars->request_read_receipt,
             'save_attachments' => $this->_vars->save_attachments_select,
@@ -1387,6 +1390,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         } catch (IMP_Compose_Exception $e) {
             $result->success = 0;
             $GLOBALS['notification']->push($e);
+
+            if (!is_null($e->tied_identity)) {
+                $result->identity = $e->tied_identity;
+            }
+
             return $result;
         }
 
diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php
index 00c335022..8777b8e86 100644
--- a/imp/lib/Compose.php
+++ b/imp/lib/Compose.php
@@ -427,13 +427,15 @@ class IMP_Compose
      * @param boolean $html    Whether this is an HTML message.
      * @param array $opts      An array of options w/the following keys:
      * 
-     * 'save_sent' = (bool) Save sent mail?
-     * 'sent_folder' = (string) The sent-mail folder (UTF7-IMAP).
-     * 'save_attachments' = (bool) Save attachments with the message?
      * 'encrypt' => (integer) A flag whether to encrypt or sign the message.
      *              One of IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC,
      *              IMP::SMIME_ENCRYPT, or IMP::SMIME_SIGNENC.
+     * 'identity' => (IMP_Prefs_Identity) If set, checks for proper tie-to
+     *               addresses.
      * 'priority' => (string) The message priority ('high', 'normal', 'low').
+     * 'save_sent' = (bool) Save sent mail?
+     * 'sent_folder' = (string) The sent-mail folder (UTF7-IMAP).
+     * 'save_attachments' = (bool) Save attachments with the message?
      * 'readreceipt' => (bool) Add return receipt headers?
      * 'useragent' => (string) The User-Agent string to use.
      * 
@@ -454,6 +456,20 @@ class IMP_Compose $recip = $this->recipientList($header); $header = array_merge($header, $recip['header']); + /* Check for correct identity usage. */ + if (!$this->getMetadata('identity_check') && + (count($recip['list']) === 1) && + isset($opts['identity'])) { + $identity_search = $opts['identity']->getMatchingIdentity($recip['list']); + if (!is_null($identity_search) && + ($opts['identity']->getDefault() != $identity_search)) { + $this->_metadata['identity_check'] = true; + $e = new IMP_Compose_Exception(_("Recipient address does not match the currently selected identity.")); + $e->tied_identity = $identity_search; + throw $e; + } + } + $barefrom = Horde_Mime_Address::bareAddress($header['from'], $_SESSION['imp']['maildomain']); $encrypt = empty($opts['encrypt']) ? 0 : $opts['encrypt']; $recipients = implode(', ', $recip['list']); diff --git a/imp/lib/Compose/Exception.php b/imp/lib/Compose/Exception.php index 1a7ca2e08..87f83d342 100644 --- a/imp/lib/Compose/Exception.php +++ b/imp/lib/Compose/Exception.php @@ -11,7 +11,7 @@ * @author Michael Slusarz * @package IMP */ -class IMP_Compose_Exception extends Horde_Exception_Prior +class IMP_Compose_Exception extends IMP_Exception { /** * Stores information on whether an encryption dialog window needs @@ -21,4 +21,11 @@ class IMP_Compose_Exception extends Horde_Exception_Prior */ public $encrypt = null; + /** + * If set, indicates that this identity matches the given to address. + * + * @var integer + */ + public $tied_identity = null; + } diff --git a/imp/lib/Prefs/Identity.php b/imp/lib/Prefs/Identity.php index b497475e7..14cd24561 100644 --- a/imp/lib/Prefs/Identity.php +++ b/imp/lib/Prefs/Identity.php @@ -371,7 +371,8 @@ class Imp_Prefs_Identity extends Horde_Prefs_Identity /* Search 'tieto' addresses first. */ /* Check for this address explicitly. */ - if ($search_ties && isset($this->_cached['tie_addresses'][$find_address])) { + if ($search_ties && + isset($this->_cached['tie_addresses'][$find_address])) { return $this->_cached['tie_addresses'][$find_address]; } diff --git a/imp/templates/dimp/chunks/compose.php b/imp/templates/dimp/chunks/compose.php index 1366e7077..0e6378783 100644 --- a/imp/templates/dimp/chunks/compose.php +++ b/imp/templates/dimp/chunks/compose.php @@ -130,6 +130,7 @@ $compose_disable = !IMP::canCompose(); +