--- sharedemail.module
+++ (clipboard)
@@ -71,22 +71,41 @@
  */
 function sharedemail_user($type, & $edit, & $user, $category= NULL) {
   $mail = isset($edit['mail']) ? $edit['mail'] : '';
-
+  
+  //TODO change the 'if' structure to a 'switch case' structure to keep the code clean.
+  //TODO find a way to intercept the 'insert' or 'update' user operation,
+  //hook_user doesn't let us change the insert case. update case not checked.
+  
+  //On the validation pass, add 'sharedemail_' to the email address so it doesn't clash
   if ($type == 'validate' && !user_validate_mail($mail)) {
     // Only show warning message if more than 1 user with the same email
     $uid = db_result(db_query("SELECT uid FROM {users} WHERE uid <> %d AND LOWER(mail) = LOWER('%s')", $user->uid, $edit['mail']));
     if (!empty($uid)) {
       $edit['mail']= 'sharedemail_'. $mail;
-
       // Show warning text to those with the permission selected
       if (user_access('show warning text')) {
         drupal_set_message(variable_get('sharedemail_msg', ''));
       }
     }
-  } 
-  elseif (($type == 'submit' || $type == 'update') && strpos($mail, 'sharedemail_') == 0) {
+  }
+  
+  //try to remove the 'sharedemail_' string before the email address is entered into the database
+  //this now does not work for the user registration case. user update case not checked.
+  if (($type == 'submit' || $type == 'update') && strpos($mail, 'sharedemail_') == 0) {
     $edit['mail'] = str_replace('sharedemail_', '', $mail);
   }
+  
+  //If this is a user being loaded, check for the 'sharedemail_' string in the email address
+  //If so, make a direct change to the database, and also update the current user object
+  if ($type == 'load') {
+    $mail = $user->mail;
+    if (strpos($mail, 'sharedemail_') == 0) {
+      $uid = $user->uid;
+      $realmail = str_replace('sharedemail_', '', $mail);
+      db_query("UPDATE {users} SET {mail} = '%s' WHERE uid = '%d'", $realmail, $uid);
+      $user->mail = $realmail;
+    }
+  }
 }
 
 /**
