[imp] Trouble making my own Hook.

Otto Stolz Otto.Stolz at uni-konstanz.de
Tue Oct 16 14:19:50 UTC 2007


Hello Manuel Mely,

sorry for not having answered earlier. Too much work to do, you know.

You wrote:
> I'm looking to you hooks.conf. I modified _imp_hook_vinfo, it seem to 
> be ok for $IMAP_Server variable, but i have other problem now. My 
> $servers array in servers.php is indexed, and what i get now is the 
> index instead of the value.

What sort of value do you expect? Of course, you'll get the index, as this
is most suitable for programming.

Look at the pertinent select tag in the HTML source of the Imp login screen:
one of the values given there will be selected by the user. This is the
reason why I have provided static strings as the server keys; rather, you
have numbers, but that should not pose a problem, in itself.

However, your numbers are dynamically generated, so I am not sure what will
happen, when your "directorio" database should ever be updated, while Imp
sessions are active.

>      function _imp_hook_vinfo($type = 'username')
>      { global $servers;
>         $Imp_user    = Util::getFormData('imapuser');
>         $IMAP_Server = Util::getFormData('server');

Here, you fetch the value from the select tag the user has selected.

...
>          $vdomain = String::lower($IMAP_Server);

Here, you probably want to say:
            $vdomain = String::lower($IMAP_Server['maildomain']);

You also wrote:
> Can somebody explain me which of this functions i 
> should use in order to change my auth to pop3 server as user at domain:

I have never tried to use Imp with a POP3 connection, as POP3 severely
restricts the access, so Imp will not be able to provide many of the
features you would wish to use.

> - _username_hook_frombackend
> - _username_hook_tobackend

These convert the username between the form used internally by Imp
and the username expected by your IMAP (or POP) server.

Note that your Imp-internal username should be unique over all
mail-servers, so Imp can tell the preferences of the users apart.
Example:
- Jon Doe has user-id "imap007" on the Imap server "mail.example.com",
- Elvira Eboli has user-id "imap007" on the Imap server "staff.example.com".
Now, you could use "imap007 at mail.example.com", and
"Jon.Doe at staff.example.com", respectively, as your Imp-internal user-ids;
or perhaps "imap007 at mail.example.com", and "Elvira.Eboli at staff.example.com",
respectively. You just have to be consistent.

> - _horde_hook_preauthenticate

I have never looked into this one. I guess, you can do almost anything,
before authentication is attempted. Beware, however, what Horde variables,
and classes, are already operable, in this early state of the session.

> - _imp_hook_vinfo

This has two, entirely unrelated, purposes:

- It is meant to convert the user-id typed into the login screen to
   its value used internally. Note that the user input will be delivered
   either via GET or via POST, depending on the previous action, as dis-
   cussed in the hooks.php I have sent you; hence you will have to use
   Util::getFormData to access the user's input.

- It provides a domain string that will be placed next to the user-id
   field, in the login screen. This design is broken, as _imp_hook_vinfo
   is a server-side function, hence will deliver it's value only after
   the user has clicked a button (usually the login button, so the login
   screen will no more be displayed when _imp_hook_vinfo's result is
   eventually available).

I use this to convert the user's alias address (e. g. "Jon.Doe") to the
IMAP server's user-id (e. g. "imap007"). Also, I get all necessary info
about the user from an LDAP server, and cache it in the session data for
later reference by the other hook functions.

My recommendations:

- Either use IMAP, or be prepared to bear with unpleasant restrictions.

- Develop a scheme of user-ids, and use them consistently:
   · a mnemonic e-mail address for the user, e. g. <Jon.Doe at example.com>
     (this is for the convenience of your users only, so you could live
     without it),
   · a mnemonic user-id for the user to login to all of your e-mail
     services, e. g. "Jon.Doe" (also for the convenience of your users),
   · a site-specific, unique IMP-internal user-id (you could use the mnemonic
     e-mail address, or a combination of the server-specific user-id and the
     server name, for that purpose),
   · a server-specific user-id to access the user's mailbox on some
     particular server.
   Note that the language in Horde's hook.php version is a bit sloppy,
   in this respect, so you may have problems to know, whether "user-id"
   is meant as the IMP-internal, or the server-specific user-id.
   Actually, deciphering this has taken weeks of my time.

  Good luck,
   Otto Stolz



More information about the imp mailing list