--- ldapprov.admin.inc.orig	2009-08-02 13:09:59.000000000 +0000
+++ ldapprov.admin.inc	2010-02-15 11:58:25.000000000 +0000
@@ -260,6 +260,11 @@
     '#collapsed' => TRUE,
     '#description' => t('Customize request validate messages sent to new members upon registering.') .' '. t('Available variables are:') .' !site, !validate_url, !validate_uri, !mailto, !first_name, !last_name, !date, !code.',
   );
+  $form['mail']['code']['ldapprov_mail_code_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send validate e-mail'),
+    '#default_value' => variable_get('ldapprov_mail_code_enable', TRUE),
+  );
   $form['mail']['code']['ldapprov_mail_code_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of validate e-mail'),
@@ -279,6 +284,11 @@
     '#collapsed' => TRUE,
     '#description' => t('Customize account manager notification messages.') .' '. t('Available variables are:') .' !site, !mailto, !first_name, !last_name, !date, !create_url.',
   );
+  $form['mail']['notify']['ldapprov_mail_notify_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send notify e-mail'),
+    '#default_value' => variable_get('ldapprov_mail_notify_enable', TRUE),
+  );
   $form['mail']['notify']['ldapprov_mail_notify_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of notify e-mail'),
@@ -298,6 +308,11 @@
     '#collapsed' => TRUE,
     '#description' => t('Customize request reject messages.') .' '. t('Available variables are:') .' !site, !mailto, !first_name, !last_name, !date, !message.',
   );
+  $form['mail']['reject']['ldapprov_mail_reject_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send reject e-mail'),
+    '#default_value' => variable_get('ldapprov_mail_reject_enable', TRUE),
+  );
   $form['mail']['reject']['ldapprov_mail_reject_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of reject e-mail'),
@@ -317,6 +332,11 @@
     '#collapsed' => TRUE,
     '#description' => t('Customize account creation notification messages.') .' '. t('Available variables are:') .' !site, !login_uri, !login_url, !mailto, !first_name, !last_name, !date, !username, !password, !message.',
   );
+  $form['mail']['create']['ldapprov_mail_create_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send account creation e-mail'),
+    '#default_value' => variable_get('ldapprov_mail_create_enable', TRUE),
+  );
   $form['mail']['create']['ldapprov_mail_create_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of creation e-mail'),
@@ -336,6 +356,11 @@
     '#collapsed' => TRUE,
     '#description' => t('Customize account deletion notification messages.') .' '. t('Available variables are:') .' !site, !mailto, !first_name, !last_name, !date, !username.',
   );
+  $form['mail']['delete']['ldapprov_mail_delete_enable'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send account deletion e-mail'),
+    '#default_value' => variable_get('ldapprov_mail_delete_enable', TRUE),
+  );
   $form['mail']['delete']['ldapprov_mail_delete_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of deletion e-mail'),
@@ -541,14 +566,19 @@
       variable_set('ldapprov_user_entry', $values['ldapprov_user_entry']);
 
       // E-mail notification.
+      variable_set('ldapprov_mail_code_enable', $values['ldapprov_mail_code_enable']);
       variable_set('ldapprov_mail_code_subject', $values['ldapprov_mail_code_subject']);
       variable_set('ldapprov_mail_code_body', $values['ldapprov_mail_code_body']);
+      variable_set('ldapprov_mail_notify_enable', $values['ldapprov_mail_notify_enable']);
       variable_set('ldapprov_mail_notify_subject', $values['ldapprov_mail_notify_subject']);
       variable_set('ldapprov_mail_notify_body', $values['ldapprov_mail_notify_body']);
+      variable_set('ldapprov_mail_reject_enable', $values['ldapprov_mail_reject_enable']);
       variable_set('ldapprov_mail_reject_subject', $values['ldapprov_mail_reject_subject']);
       variable_set('ldapprov_mail_reject_body', $values['ldapprov_mail_reject_body']);
+      variable_set('ldapprov_mail_create_enable', $values['ldapprov_mail_create_enable']);
       variable_set('ldapprov_mail_create_subject', $values['ldapprov_mail_create_subject']);
       variable_set('ldapprov_mail_create_body', $values['ldapprov_mail_create_body']);
+      variable_set('ldapprov_mail_delete_enable', $values['ldapprov_mail_delete_enable']);
       variable_set('ldapprov_mail_delete_subject', $values['ldapprov_mail_delete_subject']);
       variable_set('ldapprov_mail_delete_body', $values['ldapprov_mail_delete_body']);
 
@@ -596,14 +626,19 @@
       variable_del('ldapprov_user_entry');
 
       // E-mail notification.
+      variable_del('ldapprov_mail_code_enable');
       variable_del('ldapprov_mail_code_subject');
       variable_del('ldapprov_mail_code_body');
+      variable_del('ldapprov_mail_notify_enable');
       variable_del('ldapprov_mail_notify_subject');
       variable_del('ldapprov_mail_notify_body');
+      variable_del('ldapprov_mail_reject_enable');
       variable_del('ldapprov_mail_reject_subject');
       variable_del('ldapprov_mail_reject_body');
+      variable_del('ldapprov_mail_create_enable');
       variable_del('ldapprov_mail_create_subject');
       variable_del('ldapprov_mail_create_body');
+      variable_del('ldapprov_mail_delete_enable');
       variable_del('ldapprov_mail_delete_subject');
       variable_del('ldapprov_mail_delete_body');
 
--- ldapprov.module.orig	2009-09-22 11:35:54.000000000 +0000
+++ ldapprov.module	2010-02-15 11:50:56.000000000 +0000
@@ -331,7 +331,7 @@
 function _ldapprov_mail_text($key, $language = NULL, $variables = array()) {
   $langcode = isset($language) ? $language->language : NULL;
 
-  if ($admin_setting = variable_get('ldapprov_mail_'. $key, FALSE)) {
+  if ($admin_setting = variable_get('ldapprov_mail_'. $key, '')) {
     // An admin setting overrides the default string.
     return t($admin_setting, $variables, $langcode);
   }
@@ -456,16 +456,17 @@
   }
 
   // Mail one time deletion notification.
-  $variables = array('!first_name' => isset($row->first_name) ? $row->first_name : NULL, '!last_name' => isset($row->last_name) ? $row->last_name : NULL);
-  $params = array('account' => $account, 'variables' => $variables);
-  $message = drupal_mail('ldapprov', 'delete', $account->mail, user_preferred_language($account), $params);
-  if ($message['result']) {
-    watchdog('ldapprov', 'Account deletion notification e-mail mailed to %name at %mail.', array('%name' => $account->name, '%mail' => $account->mail));
-  }
-  else {
-    watchdog('ldapprov', 'Error mailing account deletion notification to %name at %mail.', array('%name' => $account->name, '%mail' => $account->mail), WATCHDOG_ERROR);
+  if (variable_get('ldapprov_mail_delete_enable', TRUE)) {
+    $variables = array('!first_name' => isset($row->first_name) ? $row->first_name : NULL, '!last_name' => isset($row->last_name) ? $row->last_name : NULL);
+    $params = array('account' => $account, 'variables' => $variables);
+    $message = drupal_mail('ldapprov', 'delete', $account->mail, user_preferred_language($account), $params);
+    if ($message['result']) {
+      watchdog('ldapprov', 'Account deletion notification e-mail mailed to %name at %mail.', array('%name' => $account->name, '%mail' => $account->mail));
+    }
+    else {
+      watchdog('ldapprov', 'Error mailing account deletion notification to %name at %mail.', array('%name' => $account->name, '%mail' => $account->mail), WATCHDOG_ERROR);
+    }
   }
-
   // If this user has created other users, then capture his name in the db for the record.
   db_query("UPDATE {ldapprov} SET cname = '%s' WHERE cuid = %d", $account->name, $account->uid);
 }
@@ -833,7 +834,7 @@
     if (isset($first_name) && preg_match('/\s+$/', $first_name)) {
       $errors = ($messages) ? form_set_error('first_name', t('First Name cannot end with a space.')) : $errors + 1;
     }
-    if (isset($first_name) && preg_match('/[^a-zA-Z\'-\s]+/', $first_name)) {
+    if (isset($first_name) && preg_match('/[^\x80-\xF7a-zA-Z\'-\s]+/', $first_name)) {
       $errors = ($messages) ? form_set_error('first_name', t('First Name should contain only latin letters, apostrophe, dash or space.')) : $errors + 1;
     }
     /*
@@ -848,7 +849,7 @@
     if (isset($last_name) && preg_match('/\s+$/', $last_name)) {
       $errors = ($messages) ? form_set_error('last_name', t('Last Name cannot end with a space.')) : $errors + 1;
     }
-    if (isset($last_name) && preg_match('/[^a-zA-Z\'-\s]+/', $last_name)) {
+    if (isset($last_name) && preg_match('/[^\x80-\xF7a-zA-Z\'-\s]+/', $last_name)) {
       $errors = ($messages) ? form_set_error('last_name', t('Last Name should contain only latin letters, apostrophe, dash or space.')) : $errors + 1;
     }
     /*
@@ -937,17 +938,19 @@
 
     db_query("INSERT INTO {ldapprov} (name, mail, first_name, last_name, code, registered, data, status) VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '0')", isset($values['name']) ? $values['name'] : NULL, $values['mail'], $first_name, $last_name, $hash, $time, serialize($data));
 
-    // Mail one time login URL and instructions.
-    $variables = array('!validate_url' => url('user/validate/'. $hash, array('absolute' => TRUE)), '!validate_uri' => url('user/validate', array('absolute' => TRUE)), '!mailto' => $values['mail'], '!first_name' => $first_name, '!last_name' => $last_name, '!code' => $hash);
-    $params = array('variables' => $variables);
-    $message = drupal_mail('ldapprov', 'code', $values['mail'], $language, $params);
-    if ($message['result']) {
-      watchdog('ldapprov', 'E-mail validation request mailed to %first_name %last_name at %mail.', array('%first_name' => $first_name, '%last_name' => $last_name, '%mail' => $values['mail']));
-      drupal_set_message(t('An e-mail has been sent to the e-mail account %s to verify that you have entered a valid e-mail address.', array('%s' => $values['mail'])));
-    }
-    else {
-      watchdog('ldapprov', 'Error mailing e-mail validation request to %first_name %last_name at %mail.', array('%first_name' => $first_name, '%last_name' => $last_name, '%mail' => $values['mail']), WATCHDOG_ERROR);
-      drupal_set_message(t('Unable to send mail. Please contact the site admin.'), 'error');
+    // Mail one time login URL and instructions only if subject is not empty.
+    if (variable_get('ldapprov_mail_code_enable', TRUE)) {
+      $variables = array('!validate_url' => url('user/validate/'. $hash, array('absolute' => TRUE)), '!validate_uri' => url('user/validate', array('absolute' => TRUE)), '!mailto' => $values['mail'], '!first_name' => $first_name, '!last_name' => $last_name, '!code' => $hash);
+      $params = array('variables' => $variables);
+      $message = drupal_mail('ldapprov', 'code', $values['mail'], $language, $params);
+      if ($message['result']) {
+        watchdog('ldapprov', 'E-mail validation request mailed to %first_name %last_name at %mail.', array('%first_name' => $first_name, '%last_name' => $last_name, '%mail' => $values['mail']));
+        drupal_set_message(t('An e-mail has been sent to the e-mail account %s to verify that you have entered a valid e-mail address.', array('%s' => $values['mail'])));
+      }
+      else {
+        watchdog('ldapprov', 'Error mailing e-mail validation request to %first_name %last_name at %mail.', array('%first_name' => $first_name, '%last_name' => $last_name, '%mail' => $values['mail']), WATCHDOG_ERROR);
+        drupal_set_message(t('Unable to send mail. Please contact the site admin.'), 'error');
+      }
     }
     $form_state['redirect'] = 'user/validate';
   }
@@ -1080,13 +1083,15 @@
       while ($row2 = db_fetch_object($result)) {
         $account = user_load($row2->uid);
         $variables['!create_url'] = url('admin/user/accounts/pending/create/'. $row->rid, array('absolute' => TRUE, 'language' => user_preferred_language($account)));
-        $params = array('account' => $account, 'variables' => $variables);
-        $message = drupal_mail('ldapprov', 'notify', $account->mail, user_preferred_language($account), $params);
-        if ($message['result']) {
-          watchdog('ldapprov', 'E-mail notification message about %first_name %last_name account request mailed to %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $account->mail));
-        }
-        else {
-          watchdog('ldapprov', 'Error mailing notification e-mail about %first_name %last_name account request mailed to %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $account->mail), WATCHDOG_EROR);
+        if (variable_get('ldapprov_mail_notify_enable', TRUE)) {
+          $params = array('account' => $account, 'variables' => $variables);
+          $message = drupal_mail('ldapprov', 'notify', $account->mail, user_preferred_language($account), $params);
+          if ($message['result']) {
+            watchdog('ldapprov', 'E-mail notification message about %first_name %last_name account request mailed to %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $account->mail));
+          }
+          else {
+            watchdog('ldapprov', 'Error mailing notification e-mail about %first_name %last_name account request mailed to %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $account->mail), WATCHDOG_EROR);
+          }
         }
       }
 
@@ -1958,16 +1963,17 @@
     }
 
     // Mail one time login URL and instructions.
-    $variables = array('!mailto' => $data['mail'], '!first_name' => $first_name, '!last_name' => $last_name, '!username' => $name, '!password' => $pass, '!message' => isset($data['message']) ? $data['message'] : NULL);
-    $params = array('account' => $account, 'variables' => $variables);
-    $message = drupal_mail('ldapprov', 'create', $account->mail, user_preferred_language($account), $params);
-    if ($message['result']) {
-      watchdog('ldapprov', 'Account creation notification e-mail mailed to %name at %mail.', array('%name' => $name, '%mail' => $data['mail']));
-    }
-    else {
-      watchdog('ldapprov', 'Error mailing account creation notification to %name at %mail.', array('%name' => $name, '%mail' => $data['mail']), WATCHDOG_ERROR);
+    if (variable_get('ldapprov_mail_create_enable', TRUE)) {
+      $variables = array('!mailto' => $data['mail'], '!first_name' => $first_name, '!last_name' => $last_name, '!username' => $name, '!password' => $pass, '!message' => isset($data['message']) ? $data['message'] : NULL);
+      $params = array('account' => $account, 'variables' => $variables);
+      $message = drupal_mail('ldapprov', 'create', $account->mail, user_preferred_language($account), $params);
+      if ($message['result']) {
+        watchdog('ldapprov', 'Account creation notification e-mail mailed to %name at %mail.', array('%name' => $name, '%mail' => $data['mail']));
+      }
+      else {
+        watchdog('ldapprov', 'Error mailing account creation notification to %name at %mail.', array('%name' => $name, '%mail' => $data['mail']), WATCHDOG_ERROR);
+      }
     }
-
     // OG integration.
     if (module_exists('og')) {
       $og_register = isset($data['og_register']) ? array_filter($data['og_register']) : array();
@@ -2074,14 +2080,16 @@
   drupal_set_message(t('The account request for %first %last (%mail) has been rejected.', array('%first' => $row->first_name, '%last' => $row->last_name, '%mail' => $row->mail)));
 
   // Mail the user about rejection.
-  $variables = array('!mailto' => $row->mail, '!first_name' => $row->first_name, '!last_name' => $row->last_name, '!message' => isset($data['message']) ? $data['message'] : NULL);
-  $params = array('variables' => $variables);
-  $message = drupal_mail('ldapprov', 'reject', $row->mail, language_default(), $params);
-  if ($message['result']) {
-    watchdog('ldapprov', 'E-mail rejection message mailed to %first_name %last_name at %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $row->mail));
-  }
-  else {
-    watchdog('ldapprov', 'Error mailing rejection e-mail to %first_name %last_name at %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $row->mail), WATCHDOG_ERROR);
+  if (variable_get('ldapprov_mail_reject_enable', TRUE)) {
+    $variables = array('!mailto' => $row->mail, '!first_name' => $row->first_name, '!last_name' => $row->last_name, '!message' => isset($data['message']) ? $data['message'] : NULL);
+    $params = array('variables' => $variables);
+    $message = drupal_mail('ldapprov', 'reject', $row->mail, language_default(), $params);
+    if ($message['result']) {
+      watchdog('ldapprov', 'E-mail rejection message mailed to %first_name %last_name at %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $row->mail));
+    }
+    else {
+      watchdog('ldapprov', 'Error mailing rejection e-mail to %first_name %last_name at %mail.', array('%first_name' => $row->first_name, '%last_name' => $row->last_name, '%mail' => $row->mail), WATCHDOG_ERROR);
+    }
   }
 }
 
--- ldapprov.install.orig	2010-02-15 11:52:59.000000000 +0000
+++ ldapprov.install	2010-02-15 11:52:44.000000000 +0000
@@ -68,14 +68,19 @@
   variable_del('ldapprov_user_entry');
 
   // E-mail notification.
+  variable_del('ldapprov_mail_code_enable');
   variable_del('ldapprov_mail_code_subject');
   variable_del('ldapprov_mail_code_body');
+  variable_del('ldapprov_mail_notify_enable');
   variable_del('ldapprov_mail_notify_subject');
   variable_del('ldapprov_mail_notify_body');
+  variable_del('ldapprov_mail_reject_enable');
   variable_del('ldapprov_mail_reject_subject');
   variable_del('ldapprov_mail_reject_body');
+  variable_del('ldapprov_mail_create_enable');
   variable_del('ldapprov_mail_create_subject');
   variable_del('ldapprov_mail_create_body');
+  variable_del('ldapprov_mail_delete_enable');
   variable_del('ldapprov_mail_delete_subject');
   variable_del('ldapprov_mail_delete_body');
 
