From f1bba2eff83ad94df414940ceb18cede40059dac Mon Sep 17 00:00:00 2001
From: Alexandr Kirienko <alex@kirienko.net>
Date: Tue, 14 Apr 2015 23:10:28 +0300
Subject: [PATCH] #2149661: Users with empty mail field.

---
 includes/fboauth.fboauth.inc | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/includes/fboauth.fboauth.inc b/includes/fboauth.fboauth.inc
index 0d41725..cb66c4a 100755
--- a/includes/fboauth.fboauth.inc
+++ b/includes/fboauth.fboauth.inc
@@ -95,7 +95,6 @@ function fboauth_action_connect($app_id, $access_token) {
     // No association between FB & this Drupal site, yet.
     // So lets check & see if the FB address matches a Drupal email address.
     else {
-      if (!empty($fbuser->email)) {
         $account = NULL;
 
         // Check and see if multiple_email module is in use.
@@ -193,14 +192,6 @@ function fboauth_action_connect($app_id, $access_token) {
             log in before you can connect your account to Facebook. 
             Creation of new accounts on this site is disabled.'));
         }
-      }
-      // Email not provided by Facebook.
-      else {
-        drupal_set_message(t("Facebook didn't provide an e-mail address " .
-          "to be associated with your account, so we can't compare it " .
-          "with the e-mail addresses in this system."));
-        return;
-      }
       // Done if no e-mail address provided by facebook.
     }
   }
@@ -270,16 +261,14 @@ function fboauth_create_user($fbuser, $options = array()) {
     $username = $username . $i;
   }
 
-  // get the facebook e-mail address in case the main e-mail address isn't available from facebook.
-  // this still will fail if the Facebook user hasn't set a Facebook username, since per 
-  // https://www.drupal.org/node/2149661#comment-9623017 #6  the fbid with @facebook.com isn't a valid email.
-  $facebook_mail = isset($fbuser->username) ? $fbuser->username . '@facebook.com' : '';
+  // Use fake email if user email not available.
+  $user_mail = empty($fbuser->email) ? $fbuser->id . '@facebook.com' : $fbuser->email;
 
   // Initialize basic properties that are unlikely to need changing.
   $edit = array(
     'name' => $username,
-    'mail' => !empty($fbuser->email) ? $fbuser->email : $facebook_mail,
-    'init' => !empty($fbuser->email) ? $fbuser->email : $facebook_mail,
+    'mail' => $user_mail,
+    'init' => $user_mail,
     // If user_register is "1", then no approval required.
     'status' => $options['status'],
     'timezone' => variable_get('date_default_timezone'),
-- 
1.9.1

