Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1898)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1912)
@@ -24,4 +24,5 @@
 	var $functions;
 	var $foldersLimit;
+	var $imap_sentfolder;
 
 	function imap_functions (){
@@ -33,4 +34,5 @@
 		$this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'];
 		$this->functions	  = new functions();
+		$this->imap_sentfolder = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']   ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']   : str_replace("*","", $this->functions->getLang("Sent"));
 		$this->has_cid = false;
 
@@ -1760,4 +1762,13 @@
 	}
 
+	function folder_exists($folder){
+		$mbox =  $this->open_mbox();
+		$serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}";		
+		$list = imap_getmailboxes($mbox,$serverString, $folder);
+		$return = is_array($list);		
+		imap_close($mbox);
+		return $return;
+	}
+	
 	function send_mail($params)
 	{
@@ -1840,6 +1851,15 @@
 		$forwarding_attachments = $params['forwarding_attachments'];
 		$local_attachments = $params['local_attachments'];
-
-		$folder =$params['folder'];
+		
+		//Test if must be saved in shared folder and change if necessary
+		if( $fromaddress[2] == 'y' ){
+			//build shared folder path
+			$newfolder = "user".$this->imap_delimiter.$fromaddress[3].$this->imap_delimiter.$this->imap_sentfolder;
+			if( $this->folder_exists($newfolder) ) $folder = $newfolder;
+			else $folder =  $params['folder'];  			
+		} else	{
+			$folder = $params['folder'];			
+		}
+		
 		$folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");
 		$folder_name = $params['folder_name'];
Index: /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 1740)
+++ /trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 1912)
@@ -689,27 +689,44 @@
 	function getSharedUsersFrom($params){
 		$filter = '';
-		$i = 0;
+		$i = 0;		
+		//Added to save if must save sent messages in shared folder
+		$acl_save_sent_in_shared = array();
+		
 		if($params['uids']) {
 			$uids = explode(";",$params['uids']);
-			$this->imap = new imap_functions();
+			$this->imap = new imap_functions();			
 			foreach($uids as $index => $uid){
 				$params = array();
+				//Added to save if user has create permission 
+				$acl_create_message = array();
 				$acl = $this->imap->getacltouser($uid);
-				if(preg_match("/a/",$acl))
-					$filter .= "(uid=$uid)";
-			}
-		}
-
+				if ( preg_match("/a/",$acl )){				
+					$filter .= "(uid=$uid)";					
+					if ( preg_match("/p/",$acl )){				
+						$acl_save_sent_in_shared[ $i ] =$uid;
+						$i++;
+					}					
+				}							
+			}			
+		}
+		
 		$this->ldapRootConnect(false);
 		if ($this->ds) {
-			$justthese = array("cn","mail");
+			$justthese = array("cn","mail","uid");
 			if($filter) {
-				$filter="(&(phpgwAccountType=u)(|$filter))";
+				$filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))";
 				$sr		=	ldap_search($this->ds, $this->ldap_context, $filter, $justthese);
 				ldap_sort($this->ds,$sr,"cn");
 				$info 	= 	ldap_get_entries($this->ds, $sr);
-				for ($i = 0;$i < $info["count"]; $i++)
+				$var = print_r($acl_save_sent_in_shared, true);				
+				for ($i = 0;$i < $info["count"]; $i++){
 					$info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]);
-			}
+					//verify if user has permission to save sent messages in a shared folder
+					if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){						
+						$info[$i]['save_shared'][0] = 'y';
+					} else $info[$i]['save_shared'][0] = 'n';
+				}
+			}
+		
 			$info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
 
@@ -728,10 +745,12 @@
 				for ($j = 0;$j < $result["count"]; $j++){
 					$info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]);
-					$info[$i++]['mail'][0] = $result[$j]['mail'][0];
+					$info[$i]['mail'][0] = $result[$j]['mail'][0];
+					$info[$i]['save_shared'][0] = 'n';
+					$info[$i++]['uid'][0] = $result[$j]['uid'][0];					
 				}
 			}
 
 			$_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info;
-
+			
 			return $info;
 		}
Index: /trunk/expressoMail1_2/js/sharemailbox.js
===================================================================
--- /trunk/expressoMail1_2/js/sharemailbox.js	(revision 1495)
+++ /trunk/expressoMail1_2/js/sharemailbox.js	(revision 1912)
@@ -41,4 +41,6 @@
 			Element('em_input_writeAcl').checked = false;
 			Element('em_input_sendAcl').checked = false;
+			Element('em_input_saveAcl').checked = false;
+			Element('em_input_saveAcl').disabled = true;
 			
 			if (data[user].indexOf('lrs',0) >= 0)
@@ -54,7 +56,11 @@
 				Element('em_input_deleteAcl').checked = true;
 			}
-			if (data[user].indexOf('wip',0) >= 0)
+			if (data[user].indexOf('wi',0) >= 0)
 			{
 				Element('em_input_writeAcl').checked = true;
+			}
+			if (data[user].indexOf('p',0) >= 0)
+			{
+				Element('em_input_saveAcl').checked = true;
 			}
 			if (data[user] != "false" && data[user].indexOf('a',0) >= 0)
@@ -63,4 +69,12 @@
 				Element('em_input_sendAcl').checked = true;
 			}
+			if (data[user] != "false" && data[user].indexOf('p',0) >= 0)
+			{
+				Element('em_input_saveAcl').disabled = false;
+				Element('em_input_saveAcl').checked = true;
+			} 
+			if( data[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
+				Element('em_input_saveAcl').disabled = false;
+			} else Element('em_input_saveAcl').disabled = true;
 		}
 		cExecute ("$this.imap_functions.getaclfromuser&user="+user, handler_getaclfromuser);
@@ -90,9 +104,24 @@
 			acl += 'd';
 
-		if (Element('em_input_writeAcl').checked)
-			acl += 'wip';
-
-		if (Element('em_input_sendAcl').checked)
-			acl += 'a';
+		if (Element('em_input_writeAcl').checked) {
+			acl += 'wi';			
+		}
+		
+		if (Element('em_input_sendAcl').checked){
+			acl += 'a';			
+		} else { 
+			Element('em_input_saveAcl').disabled = true;
+			Element('em_input_saveAcl').checked = false;
+		}
+		
+		if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
+			Element('em_input_saveAcl').disabled = false;				
+		} else {
+			Element('em_input_saveAcl').disabled = true;
+			Element('em_input_saveAcl').checked = false;
+		}
+		
+		if (Element('em_input_saveAcl').checked)
+			acl += 'p';
 		
 		var handler_setaclfromuser = function(data) {
@@ -128,4 +157,5 @@
 			Element('em_input_writeAcl').checked = false;
 			Element('em_input_sendAcl').checked = false;
+			Element('em_input_saveAcl').checked = false;
 		}
 		else
@@ -168,5 +198,6 @@
 								'<tr><td>'+get_lang('Exclusion')+':</td><td><input id=\'em_input_deleteAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_delmov_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
 								'<tr><td>'+get_lang('Write')+':</td><td><input id=\'em_input_writeAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_addcreate_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
-								'<tr><td>'+get_lang('Send')+':</td><td><input id=\'em_input_sendAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_sendlike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr></tbody></table>'+
+								'<tr><td>'+get_lang('Send')+':</td><td><input id=\'em_input_sendAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_sendlike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
+								'<tr><td>'+get_lang('Save')+':</td><td><input id=\'em_input_saveAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_savelike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr></tbody></table>'+
 							'</td></tr>'+
 			"</tbody></table>";
@@ -241,5 +272,5 @@
 		if(! this.arrayWin[div.id])
 		{
-			div.style.height = "460px";
+			div.style.height = "480px";
 			div.style.width = "540px";
 			var title = ":: "+get_lang("Mailbox Sharing")+" ::";
@@ -267,4 +298,5 @@
 		}
 		Element('em_input_sendAcl').disabled = true;
+		Element('em_input_saveAcl').disabled = true;
 		win.open();
 	}
@@ -361,4 +393,5 @@
 		Element('em_input_writeAcl').checked = false;
 		Element('em_input_sendAcl').checked = false;
+		Element('em_input_saveAcl').checked = false;
 	}
 	
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 1852)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 1912)
@@ -2535,5 +2535,5 @@
 				var _option = document.createElement("OPTION");
 				_option.text = '"'+data[x].cn[0] + '" <'+data[x].mail[0]+'>';
-				_option.value = data[x].cn[0] + ';'+data[x].mail[0];
+				_option.value = data[x].cn[0] + ';'+data[x].mail[0]+';'+data[x].save_shared[0]+';'+data[x].uid[0];
 				sel_from.options[sel_from.options.length] = _option	;
 			}
