Index: ldap_authentication/LdapAuthenticationConf.class.php
===================================================================
--- ldap_authentication/LdapAuthenticationConf.class.php	(revision 1406)
+++ ldap_authentication/LdapAuthenticationConf.class.php	(working copy)
@@ -23,6 +23,7 @@
   public $acctCreation = LDAP_AUTHENTICATION_ACCT_CREATION_DEFAULT;
   public $emailOption = LDAP_AUTHENTICATION_EMAIL_FIELD_DEFAULT;
   public $emailUpdate = LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DEFAULT;
+  public $emailEmpty = LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_IF_NONE_ON_ACCOUNT;
   public $ssoEnabled = FALSE;
   public $ssoRemoteUserStripDomainName = FALSE;
   public $seamlessLogin = FALSE;
@@ -57,6 +58,7 @@
     'ldapUserHelpLinkText',
     'emailOption',
     'emailUpdate',
+    'emailEmpty',
     'allowOnlyIfTextInDn',
     'excludeIfTextInDn',
     'allowTestPhp',
Index: ldap_authentication/LdapAuthenticationConfAdmin.class.php
===================================================================
--- ldap_authentication/LdapAuthenticationConfAdmin.class.php	(revision 1406)
+++ ldap_authentication/LdapAuthenticationConfAdmin.class.php	(working copy)
@@ -103,6 +103,11 @@
       LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DISABLE => t('Don\'t update stored email if LDAP email differs at login.'),
       );
 
+    $values['emailEmptyOptions'] = array(
+      LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_IF_NONE_ON_ACCOUNT => t('Generate a fake email address if the user account is being created or has none.'),
+      LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_ALWAYS => t('Always update the user with a generated fake email.'),
+      LDAP_AUTHENTICATION_EMAIL_EMPTY_DO_NOTHING => t('Do nothing and leave it empty (will make Drupal generate a lot of PHP warnings and notices).'),
+    );
 
     /**
      * 5. Single Sign-On / Seamless Sign-On
@@ -195,6 +200,8 @@
   public $emailUpdateDefault = LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE_NOTIFY;
   public $emailUpdateOptions;
 
+  public $emailEmptyDefault = LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_IF_NONE_ON_ACCOUNT;
+  public $emailEmptyOptions;
 
    /**
    * 5. Single Sign-On / Seamless Sign-On
@@ -429,6 +436,14 @@
       '#options' => $this->emailUpdateOptions,
       );
 
+    $form['email']['emailEmpty'] = array(
+      '#type' => 'radios',
+      '#title' => t('When LDAP mail attribute is empty'),
+      '#required' => 1,
+      '#default_value' => $this->emailEmpty,
+      '#options' => $this->emailEmptyOptions,
+    );
+
 
     /**
      * Begin single sign-on settings
Index: ldap_authentication/ldap_authentication.inc
===================================================================
--- ldap_authentication/ldap_authentication.inc	(revision 1406)
+++ ldap_authentication/ldap_authentication.inc	(working copy)
@@ -414,6 +414,30 @@
   }
 
   /**
+   * Ensures that in any case we won't save an empty mail attribute on the
+   * user account, and avoid Drupal core errors.
+   */
+  if (empty($ldap_user['mail'])) {
+    $search_user_by_email = FALSE; // Avoid a useless mail based user lookup.
+    switch ($auth_conf->emailEmpty) {
+      case LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_IF_NONE_ON_ACCOUNT:
+        if (!$account_exists || empty($account->mail)) {
+          // Generate email (predictable behavior so it won't change over time).
+          $ldap_user['mail'] = sprintf("%s-nonexisting@localhost.localdomain", md5($account->name));
+        }
+        break;
+      case LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_ALWAYS:
+        // Generate email (predictable behavior so it won't change over time).
+        $ldap_user['mail'] = sprintf("%s-nonexisting@localhost.localdomain", md5($account->name));
+        break;
+      // Other case is do nothing and leave an empty mail field.
+    }
+  }
+  else {
+    $search_user_by_email = TRUE;
+  }
+
+  /**
    * case 1: previously drupal authenticated user authenticated successfully on ldap
    *
    */
@@ -422,7 +446,8 @@
    	$account_exists = TRUE;
   }
   if (!$account_exists) {
-    if ($account_with_same_email = user_load_by_mail($ldap_user['mail'])) {
+    // Skip by email search if empty or generated.
+    if ($search_user_by_email && ($account_with_same_email = user_load_by_mail($ldap_user['mail']))) {
       /**
        * username does not exist but email does.  Since user_external_login_register does not deal with
        * mail attribute and the email conflict error needs to be caught beforehand, need to throw error here
Index: ldap_authentication/ldap_authentication.module
===================================================================
--- ldap_authentication/ldap_authentication.module	(revision 1406)
+++ ldap_authentication/ldap_authentication.module	(working copy)
@@ -26,6 +26,10 @@
 define('LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DISABLE',        3);
 define('LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DEFAULT',        1);
 
+define('LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_IF_NONE_ON_ACCOUNT', 1);
+define('LDAP_AUTHENTICATION_EMAIL_EMPTY_GENERATE_ALWAYS',             2);
+define('LDAP_AUTHENTICATION_EMAIL_EMPTY_DO_NOTHING',                  3);
+
 define('LDAP_AUTHENTICATION_EMAIL_ALLOW_DRUPAL_EMAIL', 1);
 define('LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE',       2);
 define('LDAP_AUTHENTICATION_EMAIL_FIELD_DISABLE',      3);
