Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2763)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2764)
@@ -2088,53 +2088,6 @@
         }
 
-////////////////////////////////////////////////////////////////////////////////////////////////////
-		//	Build CID for embedded Images!!!
-		$pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';
-		$cid_imgs = '';
-		$name_cid_files = array();
-		preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);
-		$cid_array = array();
-		foreach($cid_imgs[6] as $j => $val){
-				if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) )
-      			{
-                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36);
-		        }
-		        $cid = $cid_array[$cid_imgs[4][$j].$val];
-        		$mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);
-
-				if (!$forwarding_attachments[$cid_imgs[6][$j]-2]) // The image isn't in the same mail?
-				{
-					$fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64');
-					$fileName = "image_".($j).".jpg";
-					$fileCode = "base64";
-					$fileType = "image/jpg";
-				}
-				else
-				{
-					$attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2];
-					$file_description = unserialize(rawurldecode($attach_img));
-
-					foreach($file_description as $i => $descriptor){
-						$file_description[$i]  = eregi_replace('\'*\'','',$descriptor);
-					}
-					$fileContent = $this->get_forwarding_attachment($file_description[0], $cid_imgs[4][$j], $file_description[3], 'base64');
-					$fileName = $file_description[2];
-					$fileCode = $file_description[4];
-					$fileType = $this->get_file_type($file_description[2]);
-					unset($forwarding_attachments[$cid_imgs[6][$j]-2]);
-				}
-				$tempDir = ini_get("session.save_path");
-				$file = "cidimage_".$this->session_id.$cid_imgs[6][$j].".dat";
-				$f = fopen($tempDir.'/'.$file,"w");
-				fputs($f,$fileContent);
-				fclose($f);
-				if ($fileContent)
-					$mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);
-				//else
-				//	return "Error loading image attachment content";
-
-		}
-////////////////////////////////////////////////////////////////////////////////////////////////////
-		//	Build Uploading Attachments!!!
+	  $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); 
+	//	Build Uploading Attachments!!!
 		if ((count($attachments)) && ($params['is_local_forward']!="1")) //Caso seja forward normal...
 		{
@@ -2233,4 +2186,69 @@
 	}
 
+	function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments)
+	{
+		//	Build CID for embedded Images!!!
+		$pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';
+		$cid_imgs = '';
+		$name_cid_files = array();
+		preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);
+		$cid_array = array();
+		foreach($cid_imgs[6] as $j => $val){
+			if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) )
+			{
+				$cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36);
+			}
+			$cid = $cid_array[$cid_imgs[4][$j].$val]; 
+			$mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);
+
+			if ($msg_uid != $cid_imgs[4][$j]) // The image is not in the same mail?
+			{
+				$fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64');
+				//prototype: get_forwarding_attachment ( folder, msg number, part, encoding)
+				$fileName = "image_".($j).".jpg";
+				$fileCode = "base64";
+				$fileType = "image/jpg";
+				$file_attached[0] = $cid_imgs[2][$j];
+				$file_attached[1] = $cid_imgs[4][$j];
+				$file_attached[2] = $fileName;
+				$file_attached[3] = $cid_imgs[6][$j];
+				$file_attached[4] = 'base64';
+				$file_attached[5] = strlen($fileContent); //Size of file
+				$return_forward[] = $file_attached;
+
+				unset($forwarding_attachments[$cid_imgs[6][$j]-2]);
+			}
+			else
+			{
+				$attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2];
+				$file_description = unserialize(rawurldecode($attach_img));
+				if (is_array($file_description))
+					foreach($file_description as $i => $descriptor){				
+						$file_description[$i]  = eregi_replace('\'*\'','',$descriptor);
+					}
+				$fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64');
+				$fileName = $file_description[2];
+				$fileCode = $file_description[4];
+				$fileType = $this->get_file_type($file_description[2]);
+				unset($forwarding_attachments[$cid_imgs[6][$j]-2]);
+				if (!empty($file_description))
+				{
+					$file_description[5] = strlen($fileContent); //Size of file
+					$return_forward[] = $file_description;
+				}
+			}
+			$tempDir = ini_get("session.save_path");
+			$file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat";					
+			$f = fopen($tempDir.'/'.$file,"w");
+			fputs($f,$fileContent);
+			fclose($f);
+			if ($fileContent)
+				$mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);
+			//else
+			//	return "Error loading image attachment content";						
+
+		}
+		return $return_forward;
+	}
     function add_recipients_cert($full_address)
 	{
@@ -2614,62 +2632,5 @@
 		$mail->Body = $body;
 
-		//	Build CID for embedded Images!!!
-		$pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU';
-		$cid_imgs = '';
-		$name_cid_files = array();
-		preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER);
-		$cid_array = array();
-		foreach($cid_imgs[6] as $j => $val){
-				if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) )
-      			{
-                $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36);
-		        }
-		        $cid = $cid_array[$cid_imgs[4][$j].$val];
-        		$mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body);
-
-				if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail?
-				{
-					$fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64');
-					//prototype: get_forwarding_attachment ( folder, msg number, part, encoding)
-					$fileName = "image_".($j).".jpg";
-					$fileCode = "base64";
-					$fileType = "image/jpg";
-					$file_attached[0] = $cid_imgs[2][$j];
-					$file_attached[1] = $cid_imgs[4][$j];
-					$file_attached[2] = $fileName;
-					$file_attached[3] = $cid_imgs[6][$j];
-					$file_attached[4] = 'base64';
-					$file_attached[5] = strlen($fileContent); //Size of file
-					$return_forward[] = $file_attached;
-				}
-				else
-				{
-					$attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2];
-					$file_description = unserialize(rawurldecode($attach_img));
-					foreach($file_description as $i => $descriptor){
-						$file_description[$i]  = eregi_replace('\'*\'','',$descriptor);
-					}
-					$fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64');
-					$fileName = $file_description[2];
-					$fileCode = $file_description[4];
-					$fileType = $this->get_file_type($file_description[2]);
-					unset($forwarding_attachments[$cid_imgs[6][$j]-2]);
-					if (!empty($file_description))
-					{
-						$file_description[5] = strlen($fileContent); //Size of file
-						$return_forward[] = $file_description;
-					}
-				}
-				$tempDir = ini_get("session.save_path");
-				$file = "cidimage_".$session_id.$cid_imgs[6][$j].".dat";
-				$f = fopen($tempDir.'/'.$file,"w");
-				fputs($f,$fileContent);
-				fclose($f);
-				if ($fileContent)
-					$mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType);
-				//else
-				//	return "Error loading image attachment content";
-
-		}
+		 $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); 
 
 	//	Build Forwarding Attachments!!!
