[imp] Hook - translate char /create username from full email.

Otto Stolz Otto.Stolz at uni-konstanz.de
Thu Dec 13 09:24:16 UTC 2007


Hi, Lauro Costa G. Borges,

you wrote:
>   The problem is Horde is set to use Imp as auth app, and Imp does not  
> use that hook, of course.

I guess, you mean _prefs_hook_fullname, and perhaps
_prefs_hook_from_addr.

These functions will be called 2 times at login time,
and 3 times at logout time, but only once (at login time), they
get a sensible argument and are supposed to yield a pertinent
result. Hence, if they see an empty argument, they should return
immediately, yielding an empty result.

The results of these functions are inserted in the From line
of outgoing e-letters.

This is my _prefs_hook_fullname declaration:
> if (!function_exists('_prefs_hook_fullname')) :
>   function _prefs_hook_fullname($user=NULL)
>   { $name = empty($user) ? '' : knu_user_data ('cn', $user);    
>     knu_debug(__LINE__, '_prefs_hook_fullname', array($user), NULL, $name);
>     return $name;
>   }
> endif;
where knu_user_data does the processing in earnest,
and knu_debug optionally logs some debug information.

Or perhaps, you mean _username_hook_frombackend and
_username_hook_tobackend? These translate the username between
a horde-internal, and an external, form. The internal form is
used, e. g. as an index in the preferences database.

Or perhaps, you mean _imp_hook_vinfo? This is called during
login to process the input from the Imp login form.
- It is activated via the HTML interface: Setup/Mail/CustomHooks.
- If it is invoked as _imp_hook_vinfo('vdomain'),
   it is supposed to yield a domain string to be placed in the
   input form next to the Username field.
- If it is invoked as _imp_hook_vinfo(), it is supposed to
   yield the (possibly modified) username.
- Note that, when this hook is called, both IMP::getCurrentServer()
   and $_SESSION['imp'] are still undefined, IMP::serverString()
   is still inoperable, and the data from the login form may have been
   either transmitted via GET, or via POST, so you should access
   them via the Util::getFormData method.

This is my declaration:
> if (!function_exists('_imp_hook_vinfo')) :
>   function _imp_hook_vinfo($type='username')
>   { global $servers; // cf. imp/config/servers.php
>     $Imp_user    = Util::getFormData('imapuser');
>     $IMAP_Server = Util::getFormData('server');
>     if (empty($IMAP_Server)) :      // if pristine Login form,
>       reset($servers);
>       $IMAP_Server = key($servers); // then use the the topmost server
>     endif;
> 
>     if ($type=='username') :
>       $vinfo = knu_user_data('uid', $Imp_user, $IMAP_Server);
>     elseif ($type=='vdomain') :
>       $vinfo = isset($servers[$IMAP_Server]) ? $servers[$IMAP_Server]['maildomain'] : '';
>     else :
>       $vinfo = '*?*';
>     endif;
> 
>     knu_debug( __LINE__
>              , '_imp_hook_vinfo'
>              , array($type)
>              , array( '$IMAP_Server'       => $IMAP_Server
>                     , '$Imp_user'          => $Imp_user
>                     , '$_GET'              => $_GET
>                     , '$_POST'             => $_POST
>                     , '$_SESSION[\'imp\']' => (isset($_SESSION['imp'])?$_SESSION['imp']:NULL)
>                     )
>              , $vinfo);
>     return $vinfo;
>   }
> endif;
where, again, knu_user_data does the processing in earnest, and
knu_debug optionally logs its arguments.

Good luck,
   Otto Stolz


More information about the imp mailing list