Identity sanity checking in IMP.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 4 May 2010 22:35:55 +0000 (16:35 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 4 May 2010 22:36:24 +0000 (16:36 -0600)
Check for incorrect identity on compose if a single recipient address
is tied to a different identity than the sending identity.

imp/compose-mimp.php
imp/compose.php
imp/docs/CHANGES
imp/js/compose-dimp.js
imp/lib/Ajax/Application.php
imp/lib/Compose.php
imp/lib/Compose/Exception.php
imp/lib/Prefs/Identity.php
imp/templates/dimp/chunks/compose.php

index 4c46ca5..e43ad44 100644 (file)
@@ -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;
     }
index 2db0da1..20ca606 100644 (file)
@@ -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']) {
index 5032f90..dd8d077 100644 (file)
@@ -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).
index 4740fd4..e157605 100644 (file)
@@ -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();
index 49d371f..c91c2c1 100644 (file)
@@ -1337,6 +1337,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      * <pre>
      * '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;
         }
 
index 00c3350..8777b8e 100644 (file)
@@ -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:
      * <pre>
-     * '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.
      * </pre>
@@ -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']);
index 1a7ca2e..87f83d3 100644 (file)
@@ -11,7 +11,7 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @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;
+
 }
index b497475..14cd245 100644 (file)
@@ -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];
             }
 
index 1366e70..0e63787 100644 (file)
@@ -130,6 +130,7 @@ $compose_disable = !IMP::canCompose();
       <li id="replylistnotice" style="display:none"><span class="iconImg closeImg"></span><?php echo _("You are currently replying to the mailing list. Click here to reply to the original sender instead.") ?></li>
       <li id="fwdattachnotice" style="display:none"><span class="iconImg closeImg"></span><?php echo _("Click here to add the original message text to the body.") ?></li>
       <li id="fwdbodynotice" style="display:none"><span class="iconImg closeImg"></span><?php echo _("Click here to add the original message as an attachment.") ?></li>
+      <li id="identitychecknotice" style="display:none"><span class="iconImg closeImg"></span><?php echo _("Your identity has been switched to the identity associated with the current recipient address. Click here to revert to the original identity. The identity will not be checked again during this compose action.") ?></li>
      </ul>
     </td>
    </tr>