[imp] Cacheing the result of the from address hook

Richard Gilbert R.Gilbert at sheffield.ac.uk
Thu Oct 30 09:45:33 PST 2003


With reference to horde-2.2.4/imp-3.2.2...

I had configured the from address hook ($conf['hooks']['from']) to look
up the mail attribute in an LDAP directory.  I noticed that the from
address is looked up on almost every IMP operation so I have modified the
code to cache the result in the $_SESSION array.  It seems to have the
desired effect in that the LDAP directory is only queried once at login
time but I wanted to check with the experts that my use of the $_SESSION
array in this way is OK.  I made changes to imp/lib/IMP.php and
imp/lib/Identity/IMP.php as follows:

*** lib/IMP.php.dist    Thu Aug 21 02:54:07 2003
--- lib/IMP.php Wed Oct 29 18:27:22 2003
***************
*** 140,145 ****
--- 140,151 ----
              $_SESSION['imp']['mailbox'] = $prefs->getValue('mailbox');
              IMP::setLabel($_SESSION['imp']);

+             /* Cache the default from address corresponding to the username */
+             if (!empty($conf['hooks']['from']) &&
+                 function_exists($conf['hooks']['from'])) {
+                 $_SESSION['imp']['default_from'] = call_user_func($conf['hooks']['from'], $_SESSION['imp']);
+             }
+
              $GLOBALS['imp'] = &$_SESSION['imp'];

              return true;

*** lib/Identity/IMP.php.dist   Thu May 15 23:41:42 2003
--- lib/Identity/IMP.php        Tue Oct 28 18:25:42 2003
***************
*** 146,151 ****
--- 146,156 ----
          }

          $val = $this->getValue('from_addr', $ident);
+
+         if (empty($val)) {
+             $val = $imp['default_from'];
+         }
+
          if (empty($val) &&
              !empty($conf['hooks']['from']) &&
              function_exists($conf['hooks']['from'])) {

Thank you in anticipation for any feedback.

Richard
--
Richard Gilbert
Corporate Information and Computing Services
University of Sheffield, Sheffield, S10 2TN, UK
Phone: +44 114 222 3028   Fax: +44 114 222 3040


More information about the imp mailing list