Index: branches/2.2/mobile/inc/class.common_functions.inc.php
===================================================================
--- branches/2.2/mobile/inc/class.common_functions.inc.php	(revision 3573)
+++ branches/2.2/mobile/inc/class.common_functions.inc.php	(revision 3609)
@@ -63,4 +63,34 @@
 		}
 		
+		/**
+		 * Fixes the odd indexing of multiple file uploads from the format:
+		 *
+		 * $_FILES['field']['key']['index']
+		 *
+		 * To the more standard and appropriate:
+		 *
+		 * $_FILES['field']['index']['key']
+		 *
+		 * @param array $files
+		 * @author Corey Ballou
+		 * @link http://www.jqueryin.com
+		 */
+		function fixFilesArray(&$files)
+		{
+		    $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1);
+		
+		    foreach ($files as $key => $part) {
+		        // only deal with valid keys and multiple files
+		        $key = (string) $key;
+		        if (isset($names[$key]) && is_array($part)) {
+		            foreach ($part as $position => $value) {
+		                $files[$position][$key] = $value;
+		            }
+		            // remove old key reference
+		            unset($files[$key]);
+		        }
+		    }
+		}
+		
 	} //end common class
 	
Index: branches/2.2/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3605)
+++ branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3609)
@@ -322,4 +322,5 @@
 		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam'];
 		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'] = $current_config['expressoMail_Max_attachment_size'] ? $current_config['expressoMail_Max_attachment_size']."M" : ini_get('upload_max_filesize');
 
 			// echo '<script> var array_lang = new Array();var use_spam_filter = \''.$current_config['expressoMail_use_spam_filter'].'\' </script>';
@@ -418,5 +419,5 @@
 		{	
 				
-			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p = $this->template;
 			$p->set_file(
 				Array(
@@ -475,6 +476,6 @@
 		{
 			
-			$functions = CreateObject('mobile.common_functions');
-			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$functions = $this->common;
+			$p = $this->template;
 					$p->set_file(
 						Array(
@@ -542,71 +543,5 @@
 			}
 			return $p->fp('out','rows_mails');
-/*
-			// Cria a lista de e-mails
-			$mail_rows = '';
-      $unread_msg_count = 0;
-      
-			if ($this->number_of_messages != 0)
-			{
-				$unread_msg_count = 0;
-				foreach ($messages as $index => $msg)
-				{
-				  $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-					$p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
-					$p->set_block('mobilemail_t', 'mail_row');
-					$p->set_block('mobilemail_t', 'end_strong');
-					$p->set_block('mobilemail_t', 'begin_strong');
-					$p->set_var('unseen_bkg', "seen_bkg");
-					$p->set_var('itememail_access_key', "0");
-					$p->set_var('str_new_message', "");
-
-					if (is_numeric($index))
-					{
-						!empty($msg['from']['name']) ? $from = $msg['from']['name'] : $from = $msg['from']['email'];
-						!empty($msg['subject']) ? $subject = $msg['subject'] : $subject = lang('[empty subject]');
-						if ($msg['Unseen'] == 'U')
-						{ //Setando as mensagens nao lidas
-							$p->set_var('strong_unseen_begin', trim($p->fp('mobilemail_t', 'begin_strong')));
-							$p->set_var('strong_unseen_end', trim($p->fp('mobilemail_t', 'end_strong')));
-							$p->set_var('unseen_bkg', "unseen_bkg");
-							$p->set_var('itememail_access_key', "9");
-							$unread_msg_count = $unread_msg_count + 1;
-							$p->set_var('str_new_message', lang("New message"));
-						}
-						$p->set_var('from', $from);
-						$p->set_var('subject', $subject);
-						$p->set_var('msg_number', $msg['msg_number']);
-						$p->set_var('date', $msg['smalldate']);
-						$p->set_var('msg_folder', $this->folders[$this->current_folder]['folder_id']);
-						$p->set_var('from_label', lang('From'));
-						$mail_rows .= $p->fp('mobilemail_t', 'mail_row');
-					}
-				}
-    
-				// Imprime a lista de e-mails
-				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-				$p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
-				$p->set_block('mobilemail_t', 'mail_list');
-				$p->set_var('mail_rows', $mail_rows);
-				$p->set_var('messages_total', $this->number_of_messages);
-				$p->set_var('unread_messages_total', $unread_msg_count);
-				if ($unread_msg_count)
-				{
-					$p->set_var('(unread_messages_total)', '('.$unread_msg_count.')');
-				}
-				
-				//$p->pfp('out', 'mail_list');
-				$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_list'));
-			}
-			else
-			{
-				// Lista de e-mails vazia
-				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-				$p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
-				$p->set_block('mobilemail_t', 'empty_list');
-				$p->set_var('empty_message', lang('Empty folder'));				
-				//$p->pfp('out', 'empty_list');
-				$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'empty_list'));
-			}*/
+
 		}
 
@@ -753,4 +688,5 @@
 			$this->template->set_var('lang_read_confirmation', lang("read confirmation"));
 			$this->template->set_var('lang_add_history', lang("add history"));
+			$this->template->set_var("show_forward_attachment","none");
 			
 			if(isset($params["error_message"])) {
@@ -772,4 +708,5 @@
 				if (isset($params['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $params['msg_number'], 'msg_folder' => $params['msg_folder'] ) );
 				
+				
 				if($params['type']=="clk")
 				{
@@ -830,5 +767,21 @@
 					
 					$this->template->set_var('msg_number', $_GET['msg_number']);
-					$this->template->set_var('msg_folder', $_GET['msg_folder']);		
+					$this->template->set_var('msg_folder', $_GET['msg_folder']);	
+					if(count($msg['attachments'])>0) {
+						$this->template->set_var("lang_forward_attachment",lang("forward attachments"));
+						$this->template->set_var("show_forward_attachment","block");
+						$this->template->set_block("new_msg_t","forward_attach_block");
+						foreach($msg['attachments'] as $forward_attach) {
+							$value = rawurlencode(serialize(array(0=>$msg['msg_folder'],
+										   1=>$msg['msg_number'],
+										   3=>$forward_attach['pid'],
+										   2=>$forward_attach['name'],
+										   4=>$forward_attach['encoding'])));
+							$this->template->set_var("value_forward_attach",$value);
+							$this->template->set_var("label_forward_attach",$forward_attach['name']);
+							$this->template->fp("forwarding_attachments","forward_attach_block",true);
+						}
+					}
+						
 				}
 				else if($params['type']=="use_draft"){
@@ -838,5 +791,5 @@
 					$this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar
 					$this->template->set_var('msg_number', $_GET['msg_number']);
-					$this->template->set_var('msg_folder', $_GET['msg_folder']);		
+					$this->template->set_var('msg_folder', $_GET['msg_folder']);
 				}
 				else{
@@ -867,4 +820,7 @@
 		{
 			$params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
+			$params["FILES"] = $_FILES["FILES"];
+			$this->common->fixFilesArray($params["FILES"]);
+			$params['forwarding_attachments'] = $params["forward_attachments"];
 			$return = $this->imap_functions->save_msg($params);
 			if($return["has_error"]) {
@@ -885,14 +841,19 @@
 			//Chamada da classe phpmailer
 			include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php");
-
+			include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.imap_functions.inc.php");
+			
 			//Recebe os dados do form (passados pelo POST)
 			$toaddress = $_POST['input_to'];
 			$ccaddress = $_POST['input_cc'];
 			$subject = $_POST['input_subject']; //"Mail Subject";
-			$body = $_POST['body']; //"Mail body. Any text.";
+			$body = nl2br($_POST['body']); //"Mail body. Any text.";
 			$isImportant = $_POST['check_important'];
 			$addHistory = $_POST['check_add_history'];
 			$readConfirmation = $_POST['check_read_confirmation'];
 			$msgNumber = $_POST['reply_msg_number'];
+			$attachments = $_FILES['FILES'];
+			$this->common->fixFilesArray($attachments);
+			$forwarding_attachments = $_POST["forward_attachments"];
+			
 
 			//Cria objeto
@@ -940,4 +901,36 @@
 			if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email'];
 
+			$imap_functions = new imap_functions();
+			if (count($attachments)>0) //Attachment
+			{
+				
+				$total_uploaded_size = 0;
+				$upload_max_filesize = str_replace("M","",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024;
+				
+				foreach ($attachments as $attach)
+				{
+					$mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $imap_functions->get_file_type($attach['name']));  // optional name					
+					$total_uploaded_size = $total_uploaded_size + $attach['size'];
+				}
+				if( $total_uploaded_size > $upload_max_filesize){
+
+					return $imap_functions->parse_error("message file too big");
+				}
+			}
+			if (count($forwarding_attachments) > 0) { //forward attachment
+				foreach($forwarding_attachments as $forwarding_attachment)
+				{
+					$file_description = unserialize(rawurldecode($forwarding_attachment));
+					$fileContent = $imap_functions->get_forwarding_attachment(
+											$file_description[0],
+											$file_description[1],
+											$file_description[3],
+											$file_description[4]);
+					$fileName = $file_description[2];
+					$mail->AddStringAttachment($fileContent,html_entity_decode(rawurldecode($fileName)), $file_description[4], $imap_functions->get_file_type($file_description[2]));
+
+				}
+			}
+			
 			//Se o e-mail nao for enviado por qualquer motivo...
 			if(!$mail->Send()) {
