Index: branches/2.5/prototype/services/iCal.php
===================================================================
--- branches/2.5/prototype/services/iCal.php	(revision 8232)
+++ branches/2.5/prototype/services/iCal.php	(revision 8257)
@@ -495,7 +495,10 @@
 	    $isResponseDelegated = false;
 	    if ((isset($pv['delegatedFrom']) && $pv['delegatedFrom'] == 0) || !isset($pv['delegatedFrom']))  {
-		if ($pv['isOrganizer'] == 1)
-		    $vevent->setProperty('organizer', $pv['user']['mail'], array('CN' => $pv['user']['name']));
-		else {
+                if ($pv['isOrganizer'] == 1){ 
+                        if($pv['user']['id'] == Config::me('uidNumber')) 
+                                $pv['user']['mail'] = $pv['user']['mailSenderAddress']; 
+                         
+                        $vevent->setProperty('organizer', $pv['user']['mail'], array('CN' => $pv['user']['name'])); 
+                }else { 
 		    $pParams = array();
 		    $pParams['CN'] = $pv['user']['name'];
@@ -618,4 +621,5 @@
                         if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']){ //Organizador esta requisitando que você atualize o evento
 
+ 
                             $params['calendar'] = $params['calendar'] == 'true' ? $calendar : $params['calendar'];
                             $interation = self::_makeVEVENT($schedulable, $component, $params);
@@ -642,5 +646,5 @@
                     $interation = self::_makeVEVENT(array(), $component, $params);
 
-                    if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora
+                       if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora
 
                         /* Data de Inicio */
@@ -693,4 +697,5 @@
 
 
+ 
                         if ($uid = $component->getProperty('uid', false, false))
                         ;
@@ -710,4 +715,6 @@
 
 
+ 
+ 
                         if ($property = $component->getProperty('organizer', FALSE, TRUE)) {
                         $participant = array();
@@ -733,4 +740,5 @@
                         $sc['participants'][] = $participant;
                         }
+ 
 
 
@@ -749,4 +757,5 @@
                         $sc['participants'][] = $participant;
                         $sc['type'] = EVENT_ID;
+ 
 
 
@@ -801,4 +810,5 @@
                             break;
                         }
+ 
                         require_once ROOTPATH . '/api/parseTPL.php';
 
@@ -1228,4 +1238,5 @@
                     foreach ($schedulable['participants'] as $value){
 
+ 
                         if ($value['user']['id'] == $params['owner']) {
                             $isParticipant = true;
@@ -1429,4 +1440,5 @@
 
 
+ 
 	return $offset;
     }
@@ -1457,4 +1469,5 @@
     }
 
+ 
     private function _getStatusTodo($id) {
         $a = array(
@@ -1467,4 +1480,5 @@
     return isset($a[$id]) ? $a[$id] : 'NEED_ACTION';
     }
+ 
 
     private static function _checkParticipantByPermissions($schedulable) {
@@ -1583,4 +1597,6 @@
 
     static private function _makeVEVENT($schedulable, $component, $params) {
+ 
+ 
     	$interation = array();
     	$eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)';
@@ -1641,4 +1657,5 @@
 
 
+ 
     	$schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1');
 
@@ -1650,4 +1667,5 @@
     	if ($location = $component->getProperty('location', false, false))
     	    $schedulable['location'] = mb_convert_encoding($location, 'ISO-8859-1', 'UTF-8,ISO-8859-1');
+ 
 
 
@@ -1694,9 +1712,8 @@
     	    $participant['schedulable'] = $eventID;
 
-    	    if (isset($params['status']) && $mailUser == Config::me('mail'))
+    	    if (isset($params['status']) &&  ltrim( substr( $mailUser, 0 , strpos( $mailUser, '@' ) ), '@' )  ==  ltrim( substr( Config::me('mail'), 0, strpos( Config::me('mail'), '@' ) ), '@' ))
     		$participant['status'] = $params['status'];
     	    else
     		$participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED;
-
 
     	    $participant['isOrganizer'] = '0';
@@ -1731,4 +1748,5 @@
 
 
+ 
             if($participant = self::_getParticipantByMail($mailUser, $schedulable['participants'], true)){
 
@@ -1748,6 +1766,7 @@
     	    /* Verifica se este usuario é um usuario interno do ldap */
     	    $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser))));
-    	    $user = null;
-    	    if ($intUser && count($intUser) > 0) {
+ 
+            $user = null; 
+            if ($intUser && count($intUser) > 0 && $intUser[0]['id']) { 
                 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0;
                 $participant['user'] = $intUser[0]['id'];
@@ -1942,4 +1961,5 @@
 	$schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1');
 
+ 
 	/* Definindo Description */
 	if ($desc = $component->getProperty('description', false, false))
@@ -2144,4 +2164,6 @@
 	$interation['schedulable://' . $todoID] = $schedulable;
 
+ 
+ 
     return $interation;
     }
@@ -2163,4 +2185,5 @@
 		foreach ($sig2 as $val)
 		    $calendars[] = $val['calendar'];
+ 
 
 
