Index: /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3248)
+++ /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3289)
@@ -203,5 +203,5 @@
 			$p->set_var('reply_all', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&reply_all=true");
 			$p->set_var('forward', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&forward=true");
-			if (!empty($msg['attachments']) && !empty($msg['attachments']['names']))
+			if (!empty($msg['attachments']))
 			{
 				$attachs = "<br>".lang("This message has the follow attachments:")."<br>";
Index: /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3271)
+++ /branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3289)
@@ -3560,5 +3560,5 @@
 	{
 		$array_parts_attachments = array();
-		$array_parts_attachments['names'] = '';
+		//$array_parts_attachments['names'] = '';
 		include_once("class.imap_attachment.inc.php");
 		$imap_attachment = new imap_attachment();
@@ -3573,10 +3573,10 @@
 				$array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin";
 				$array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index];
-				$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', ';
+				//$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', ';
 				$array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index];
 				$i++;
 			}
 		}
-		$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2));
+		//$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2));
 		return $array_parts_attachments;
 	}
Index: /branches/2.2/expressoMail1_2/inc/class.exporteml.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.exporteml.inc.php	(revision 3273)
+++ /branches/2.2/expressoMail1_2/inc/class.exporteml.inc.php	(revision 3289)
@@ -91,7 +91,24 @@
 	function createFileZip($files, $tempDir){		
 		$tmp_zip_filename = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".zip";
-		$command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " .  escapeshellcmd($files);
+		
+                if (!empty($files))
+                {
+                    if (is_array($files))
+                    {
+                        for ($i=0; $i < count($files); $i++)
+                        {
+                            $files[$i] = escapeshellarg($files[$i]);
+                        }
+                        $files = implode(' ', $files);
+                    }
+                    else
+                    {
+                        $files = escapeshellcmd($files);
+                    }
+                }
+                
+		$command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " .  $files;
 		if(!exec($command)) {
-			$command = "cd " .  escapeshellarg($tempDir) . " && rm ".escapeshellcmd($files)." ". escapeshellarg($tmp_zip_filename);
+			$command = "cd " .  escapeshellarg($tempDir) . " && rm ".$files." ". escapeshellarg($tmp_zip_filename);
 			exec($command);
 			return null;
@@ -464,17 +481,43 @@
 		$imap_attachment = new imap_attachment();
 		$attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
-		foreach($attachments as $i => $attachment){
-			if($i && $i == 'names')
-				continue;
-																		
+		
+		$fileNames = Array();
 			
-			$fileName = $this->remove_accents($attachment['name']);
+		for ($i = 0; $i < count($attachments); $i++)
+                {
+                   $attachments[$i]['name'] = $this->remove_accents($attachments[$i]['name']);
+                   $fileNames[$i] = $attachments[$i]['name'];
+                }
+
+                for ($i = 0; $i < count($attachments); $i++)
+                {
+                        $fileName = $attachments[$i]['name'];
+                        $result = array_keys($fileNames, $fileName);
+
+                        // Detecta duplicatas
+                        if (count($result) > 1)
+                        {
+                            for ($j = 1; $j < count($result); $j++)
+                            {
+                                $replacement = '('.$j.')$0';
+                                if (preg_match('/\.\w{2,4}$/', $fileName))
+                                {
+                                    $fileNames[$result[$j]] = preg_replace('/\.\w{2,4}$/', $replacement, $fileName);
+                                }
+                                else
+                                {
+                                    $fileNames[$result[$j]] .= "($j)";
+                                }
+                                $attachments[$result[$j]]['name'] = $fileNames[$result[$j]];
+                            }
+                        }
+                        // Fim detecta duplicatas
+
 			$f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
 			if(!$f)
 				return False;			
 						
-			$fileNames .= "'".$fileName."' ";
-			$fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
-			if($attachment['encoding'] == 'base64')
+			$fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachments[$i]['pid'], FT_UID);
+			if($attachments[$i]['encoding'] == 'base64')
 				fputs($f,imap_base64($fileContent));
 			else		
@@ -487,5 +530,5 @@
 		$nameFileZip = '';
 		
-		if($fileNames) {
+		if(!empty($fileNames)) {
 			$nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);						
 			if($nameFileZip)
Index: /branches/2.2/expressoMail1_2/inc/class.imap_attachment.inc.php
===================================================================
--- /branches/2.2/expressoMail1_2/inc/class.imap_attachment.inc.php	(revision 1059)
+++ /branches/2.2/expressoMail1_2/inc/class.imap_attachment.inc.php	(revision 3289)
@@ -53,5 +53,5 @@
 		$msg->fetch_structure($msgno);
 		$array_parts_attachments = array();		
-		$array_parts_attachments['names'] = '';
+		//$array_parts_attachments['names'] = '';
 		
 		//print_r($msg->fname[$msgno]);
@@ -67,10 +67,10 @@
 				$array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin";
 				$array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index];
-				$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', ';
+				//$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', ';
 				$array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index];
 				$i++;
 			}
 		}
-		$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2));
+		//$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2));
 		return $array_parts_attachments;
 	}
