From: Olivier Guerrier <olivier@guerrier.com>
Date: Sun, 15 Mar 2009 01:05:13 +0100
Subject: [PATCH] multiples email adresses per mantis account

---
 mantis-1.1.1/core/email_api.php |   85 ++++++++++++++++++-------------
 mantis-1.1.1/lost_pwd.php       |    2 +-
 2 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/mantis-1.1.1/core/email_api.php b/mantis-1.1.1/core/email_api.php
index ea0eafe..dbef9d2 100644
--- a/mantis-1.1.1/core/email_api.php
+++ b/mantis-1.1.1/core/email_api.php
@@ -123,46 +123,53 @@
 
 		# Use a regular expression to check to see if the email is in valid format
 		#  x-xx.xxx@yyy.zzz.abc etc.
-		if ( preg_match( email_get_rfc822_regex(), $p_email, $t_check ) ) {
-			$t_local = $t_check[1];
-			$t_domain = $t_check[2];
-
-			# see if we're limited to one domain
-			if ( ON == config_get( 'limit_email_domain' ) ) {
-				if ( 0 != strcasecmp( $t_limit_email_domain, $t_domain ) ) {
-					return false;
+		$t_split_emails = split (';', $p_email);
+		foreach($t_split_emails as $t_split_email) {
+			$t_split_email_ok = false;
+			if ( preg_match( email_get_rfc822_regex(), $t_split_email, $t_check ) ) {
+				$t_local = $t_check[1];
+				$t_domain = $t_check[2];
+
+				# see if we're limited to one domain
+				if ( ON == config_get( 'limit_email_domain' ) ) {
+					if ( 0 != strcasecmp( $t_limit_email_domain, $t_domain ) ) {
+						return false;
+					}
 				}
-			}
 
-			if ( preg_match( '/\\[(\d+)\.(\d+)\.(\d+)\.(\d+)\\]/', $t_domain, $t_check ) ) {
-				# Handle domain-literals of the form '[1.2.3.4]'
-				#  as long as each segment is less than 255, we're ok
-				if ( $t_check[1] <= 255 &&
-					 $t_check[2] <= 255 &&
-					 $t_check[3] <= 255 &&
-					 $t_check[4] <= 255 ) {
-					return true;
-				}
-			} else if ( ON == config_get( 'check_mx_record' ) ) {
-				# Check for valid mx records
-				if ( getmxrr( $t_domain, $temp ) ) {
-					return true;
-				} else {
-					$host = $t_domain . '.';
-
-					# for no mx record... try dns check
-					if ( checkdnsrr( $host, 'ANY' ) ) {
-						return true;
+				if ( preg_match( '/\\[(\d+)\.(\d+)\.(\d+)\.(\d+)\\]/', $t_domain, $t_check ) ) {
+					# Handle domain-literals of the form '[1.2.3.4]'
+					#  as long as each segment is less than 255, we're ok
+					if ( $t_check[1] <= 255 &&
+						 $t_check[2] <= 255 &&
+						 $t_check[3] <= 255 &&
+						 $t_check[4] <= 255 ) {
+						$t_split_email_ok = true;
+					}
+				} else if ( ON == config_get( 'check_mx_record' ) ) {
+					# Check for valid mx records
+					if ( getmxrr( $t_domain, $temp ) ) {
+						$t_split_email_ok = true;
+					} else {
+						$host = $t_domain . '.';
+
+						# for no mx record... try dns check
+						if ( checkdnsrr( $host, 'ANY' ) ) {
+							$t_split_email_ok = true;
+						}
 					}
+				} else {
+					# Email format was valid but did't check for valid mx records
+					$t_split_email_ok = true;
 				}
-			} else {
-				# Email format was valid but did't check for valid mx records
-				return true;
+			}
+			if ( $t_split_email_ok == false ) {
+				# Everything failed.  The email is invalid
+				return false;
 			}
 		}
-
-		# Everything failed.  The email is invalid
-		return false;
+		# all addresses are valid
+		return true;
 	}
 	# --------------------
 	# Check if the email address is valid
@@ -780,9 +787,15 @@
 
 		if ( OFF !== $t_debug_email ) {
 			$t_message = 'To: '. $t_recipient . "\n\n" . $t_message;
-			$mail->AddAddress( $t_debug_email, '' );
+			$t_split_recipients = split (';', $t_debug_email);
+			foreach($t_split_recipients as $t_split_recipient) {
+				$mail->AddAddress( $t_split_recipient, '' );
+			}
 		} else {
-			$mail->AddAddress( $t_recipient, '' );
+			$t_split_recipients = split (';', $t_recipient);
+			foreach($t_split_recipients as $t_split_recipient) {
+				$mail->AddAddress( $t_split_recipient, '' );
+			}
 		}
 
 		$mail->Subject = $t_subject;
diff --git a/mantis-1.1.1/lost_pwd.php b/mantis-1.1.1/lost_pwd.php
index 7672232..360ca34 100644
--- a/mantis-1.1.1/lost_pwd.php
+++ b/mantis-1.1.1/lost_pwd.php
@@ -51,7 +51,7 @@
 	$t_user_table = config_get( 'mantis_user_table' );
 
 	# @@@ Consider moving this query to user_api.php
-	$query = 'SELECT id FROM ' . $t_user_table . ' WHERE username = \'' . $c_username . '\' AND email = \'' . $c_email . '\' AND enabled=1';
+	$query = 'SELECT id FROM ' . $t_user_table . ' WHERE username = \'' . $c_username . '\' AND email LIKE \'%' . $c_email . '%\' AND enabled=1';
 	$result = db_query( $query );
 
 	if ( 0 == db_num_rows( $result ) ) {
-- 
1.6.2

