Generate unique magento email in case of duplicate

For a B2B customer we integrated Microsoft Dynamics Nav with Magento. One of the issues when synching customers from Dynamics Nav to Magento is the fact that Dynamics Nav can hold duplicate email adresses for customers and contacts.

We resolved this issue by creating a unique new email address when a duplicate email address was found.

\app\code\local\Mage\Customer\Model\Resource\customer.php

Original if statement to check if duplicate email address and throw exception

$result = $adapter->fetchOne($select, $bind);
if ($result) {
   throw Mage::exception('Mage_Customer', 
   Mage::helper('customer')->__('This customer email already exists'),
   Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
   );
}

Create unique email addresses with datetimestamp+original email address

$result = $adapter->fetchOne($select, $bind);
if ($result) {
   $msParts = explode(' ',str_replace('0.','',microtime()));
   $datetimestamp = date('YmdHis').'-'.$msParts[0];
   $duplicate_email = $customer->getEmail();
   $temp_email = $datetimestamp.'+'.$duplicate_email;
   $customer->setEmail($temp_email);
}

Note: You need the timestamp in ms since the API can process multiple customers in a second.


So, what do you think ?