--- scripts/importGmail.class.php	2008-01-12 01:20:01.000000000 +0100
+++ scripts/importGmail.class.new.php	2008-02-05 13:55:52.000000000 +0100
@@ -129,26 +129,44 @@ class GMailer extends baseFunction
        curl_setopt($ch2, CURLOPT_COOKIE, $cokkies1);
        curl_setopt($ch2, CURLOPT_FOLLOWLOCATION,1);
        $html2 = curl_exec($ch2);
-    
-       $html2 = str_replace("\n","",$html2);     
-       $tempname = split('<b>All&nbsp;Contacts</b>',$html2,2);
-       preg_match_all('/<b>([^\<]*)/s',$tempname[1],$name);
-       $tempemail = preg_replace('/<b>([^\<]*)/s','',$tempname[1]);
-       $emails = explode("&nbsp;",strip_tags($tempemail));
-       $tot_contacts = strip_tags($name[0][0]) + 2;
        
-       for($i=2,$j=4;$i<$tot_contacts;$i++,$j++)
-       {
-       	/*
-            $result['name'][]=trim(strip_tags($name[0][$i]));
-           $result['email'][]=trim($emails[$j]);
-	*/
-	   $result[trim(strip_tags($name[0][$i]))] = trim($emails[$j]);
-       }
-       return $result;
-    }
-
+      $html2 = strip_tags($html2);
+      $html2 = str_replace('&nbsp;', ' ', $html2);
 
-    
+      $ex = split('All Contacts', $html2);
+      if (count($ex) > 1) {
+        $html2 = $ex[1];
+        $regex = "/(\w[-.\w]+\@[-.\w]+\.\w{2,4})\W/";
+         
+        $ex = explode("\n", $html2);
+        $lines = array();
+        $html2 = '';
+        foreach($ex as $l) {
+          if (trim($l) != '') {
+            $html2 .= trim($l)."\n";
+            $lines[] = trim($l);
+          }
+        }      
+        $emails = array();  
+        if (preg_match_all($regex, $html2, $match)) {
+          foreach($match[0] as $email){
+            $email = trim($email);
+             
+            if (!array_search($email, $emails)) {
+              $name = $lines[array_search($email, $lines)-1];
+              if (substr($name, 0, 1) != '-') {
+                if ($name == '') {
+                  $name = $email;
+                }
+                 
+                $emails[$name] = $email;
+              }
+            }
+          } 
+        }
+        
+        return $emails;
+      }
+    }
 }
 ?>
