[imp] [PATCH] Identity check hook

Peter Stamfest peter at stamfest.at
Sat May 8 13:34:09 PDT 2004


Hi, 

I have just hacked up another IMP hook that some people might find useful, 
this is why I thought I should share it.

The following patch adds another hook (identity_check) to IMP. It gets 
called (if it exists) before anything is done about saving an identity.
This comes in very handy in several cases:

Eg:

* require a full name to be specified
* Allow to choose the From: address from a list of allowed aliases
* ...

What I do not like about it is the requirement to directly access form 
data in the hook function. I did not see another way to access that data.

peter


So here goes the patch. It applies cleanly to 3.2.3:


diff -ur imp-3.2.3/config/conf.php.dist imp-ps/config/conf.php.dist
--- imp-3.2.3/config/conf.php.dist	Mon Sep 22 20:36:20 2003
+++ imp-ps/config/conf.php.dist	Sat May  8 22:12:00 2004
@@ -421,3 +421,27 @@
 //         return $quota_html;
 //     }
 // }
+
+// If this is set to a function name, that function will be used
+// to check information provided by the user when editing an identity.
+// See the 'imp_identity_check' function below for an example.
+$conf['hooks']['identity_check'] = '';
+
+/* here is an example imp_identity_check function. It assures that the 
+ * from address is within the example.com domain. Note that this function has
+ * to retrieve the data directly from the form used to manage identies.
+ *
+ * A more useful example would be to check if the from address is one of the
+ * aliases configured to deliver e-mail to the underlying account.
+ */
+// if (!function_exists('imp_identity_check')) {
+//     function imp_identity_check ($imp) {
+//         $from = Horde::getFormData('from_addr');
+//         $dom = substr($from, strpos($from, '@') + 1);
+//         if ($from == '' || $dom == 'example.com') {
+//             return TRUE;
+//         }
+//         return FALSE;
+//     }
+// }
+// 
diff -ur imp-3.2.3/identities.php imp-ps/identities.php
--- imp-3.2.3/identities.php	Tue Feb  4 12:59:17 2003
+++ imp-ps/identities.php	Sat May  8 22:04:52 2004
@@ -60,6 +60,16 @@
      break;
 
  case IDENT_SAVE:
+     $id_check_ok = TRUE;
+     if (!empty($conf['hooks']['identity_check']) &&
+         function_exists($conf['hooks']['identity_check'])) {
+         $id_check_ok = call_user_func($conf['hooks']['identity_check'], $imp);
+     }
+
+     if (!$id_check_ok) {
+	 break;
+     }
+
      $edit_identity = Horde::getFormData('edit_identity');
      if (!isset($edit_identity) || $edit_identity == '') {
          $edit_identity = $identity->add();



More information about the imp mailing list