I've got a bunch of students that opt to use the svn of roundcube (after I make sure there
are not huge bugs) and was threatened with certain death if I didn't patch it to use LDAP
auto-completion. Since I've parked it in a pseudo-production environment and it has the
potential to annoy people, I've added an option on the user settings to enable/disable
this. I also discovered that it will not auto-complete unless you have at least one entry
in your address book so I changed that as well. I've included the diff that has the
original additions as well as my own as a rough and ready patch for anyone wanting to run
this.
-Ryan Rittenhouse
--
Network Administrator
Goshen College
(574) 535-7004
Index: program/localization/en_US/labels.inc
===================================================================
--- program/localization/en_US/labels.inc (revision 404)
+++ program/localization/en_US/labels.inc (working copy)
@@ -216,6 +216,7 @@
$labels['htmleditor'] = 'Compose HTML messages';
$labels['htmlsignature'] = 'HTML signature';
$labels['previewpane'] = 'Show preview pane';
+$labels['ldapcomplete'] = 'Auto-Complete Addresses from Ldap (directory)';
$labels['autosavedraft'] = 'Automatically save draft';
$labels['everynminutes'] = 'every $n minutes';
Index: program/steps/settings/func.inc
===================================================================
--- program/steps/settings/func.inc (revision 404)
+++ program/steps/settings/func.inc (working copy)
@@ -178,6 +178,14 @@
rep_specialchars_output(rcube_label('previewpane')),
$input_preview->show($CONFIG['preview_pane']?1:0));
}
+
+ //show config for ldap auto completion
+ $field_id = 'rcmfd_ldapcomplete';
+ $input_preview = new checkbox(array('name' => '_ldap_complete', 'id' => $field_id, 'value' => 1));
+ $out .= sprintf("<tr><td class="title"><label for="%s">%s</label></td><td>%s</td></tr>\n",
+ $field_id,
+ rep_specialchars_output(rcube_label('ldapcomplete')),
+ $input_preview->show($CONFIG['ldap_complete']?1:0));
if (!empty($CONFIG['drafts_mbox']) && !isset($no_override['preview_pane']))
{
Index: program/steps/settings/save_prefs.inc
===================================================================
--- program/steps/settings/save_prefs.inc (revision 404)
+++ program/steps/settings/save_prefs.inc (working copy)
@@ -27,6 +27,7 @@
'prefer_html' => isset($_POST['_prefer_html']) ? TRUE : FALSE,
'htmleditor' => isset($_POST['_htmleditor']) ? TRUE : FALSE,
'preview_pane' => isset($_POST['_preview_pane']) ? TRUE : FALSE,
+ 'ldap_complete' => isset($_POST['_ldap_complete']) ? TRUE : FALSE,
'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0
);
Index: program/steps/mail/compose.inc
===================================================================
--- program/steps/mail/compose.inc (revision 404)
+++ program/steps/mail/compose.inc (working copy)
@@ -20,6 +20,7 @@
*/
require_once('Mail/mimeDecode.php');
+require_once('include/rcube_ldap.inc');
require_once('lib/html2text.inc');
// define constants for message compose mode
@@ -887,16 +888,53 @@
FROM ".get_table_name('contacts')." WHERE user_id=?
AND del<>1",$_SESSION['user_id']);
-if ($DB->num_rows($sql_result))
+if ($DB->num_rows($sql_result) || $CONFIG['ldap_complete'])
{
$a_contacts = array();
while ($sql_arr = $DB->fetch_assoc($sql_result))
if ($sql_arr['email'])
$a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
-
- $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
+
+ /* LDAP autocompletion */
+ if($CONFIG['ldap_complete']) foreach ($CONFIG['ldap_public'] as $ldapserv_config)
+ {
+ /* we need fuzzy search enabled */
+ if ($ldapserv_config['fuzzy_search'] != 1)
+ continue;
+
+ $mail_field = $ldapserv_config['mail_field'];
+ $name_field = $ldapserv_config['name_field'];
+
+ $cLdap = new rcube_ldap();
+
+ $cLdap->connect ($ldapserv_config['hosts'],
+ $ldapserv_config['port'],
+ 3,
+ $ldapserv_config['dn'],
+ $ldapserv_config['password']);
+
+
+
+ $results = $cLdap->search ($ldapserv_config['base_dn'],
+ $name_field."=*",
+ array($mail_field, $name_field),
+ $ldapserv_config['scope']);
+
+ for ($i = 0 ; $i < $results['count'] ; $i++)
+ {
+ $mail = $results[$i][$mail_field];
+ $name = $results[$i][$name_field][0];
+
+ for ($j = 0 ; $j < $mail['count'] ; $j++)
+ $a_contacts[] = format_email_recipient($mail[$j],
+ $name);
+ }
+ $cLdap->close ();
}
+ $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
+}
+
parse_template('compose');
?>