Changeset 5989
- Timestamp:
- 04/20/12 18:14:09 (12 years ago)
- Location:
- trunk/prototype
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/config/followupflagged.ini
r5972 r5989 12 12 doImapDelete = modules/mail/interceptors/Helpers.php 13 13 14 [Imap.before.delete] 15 getReferenceToImapDelete = modules/mail/interceptors/Helpers.php 16 14 17 [PostgreSQL.before.find] 15 18 reFilterFind = modules/mail/interceptors/Helpers.php 16 17 [PostgreSQL.after.find]18 doImapFind = modules/mail/interceptors/Helpers.php19 19 20 20 [after.find] 21 21 deepnessFollowupflaggeds = modules/mail/interceptors/Helpers.php 22 22 23 [PostgreSQL.after.find] 24 doImapFind = modules/mail/interceptors/Helpers.php 23 25 24 26 -
trunk/prototype/modules/mail/interceptors/Helpers.php
r5983 r5989 133 133 134 134 if($imap_result) { 135 $params['messageId'] = $imap_result[ 'messageId'];135 $params['messageId'] = $imap_result[0]['messageId']; 136 136 } 137 137 } 138 138 139 139 $filter = array('=', 'messageId', $params['messageId']); 140 Controller::delete(array('concept' => 'followupflagged', 'service' => 'PostgreSQL'), null, $filter);140 Controller::delete(array('concept' => 'followupflagged', 'service' => 'PostgreSQL'), null, array('filter' => $filter)); 141 141 142 142 } … … 159 159 if(isset($uri['id'])) { 160 160 Controller::deleteALL(array('concept' => 'followupflagged'), null , array('filter' => array('=' , 'followupflagId' , $uri['id']))); 161 162 161 } 163 162 } … … 165 164 //followupflagged:PostgreSQL.before.delete 166 165 public function doImapDelete( &$uri , &$params , &$criteria , $original ) { 167 166 168 167 $imap_uri = $uri; 169 168 $imap_uri['service'] = 'Imap'; 170 list($messageId, $uri['id']) = explode('#', $uri['id']); 171 172 $result = Controller::delete($imap_uri, $params, $imap_criteria); 173 174 if (!$result) 175 return false; 169 170 $result = Controller::delete($imap_uri, $params, $criteria); 171 172 return $result; 173 174 } 175 176 //followupflagged:Imap.before.delete 177 public function getReferenceToImapDelete( &$uri , &$params , &$criteria , $original ) { 178 179 if ($uri['id'] && !$criteria) { 180 $db_uri = $uri; 181 $db_uri['service'] = 'PostgreSQL'; 182 $flagged = Controller::read($db_uri, false, false); 183 184 if ($flagged) { 185 if (!$criteria) 186 $criteria = array(); 187 $criteria['filter'] = array('=', 'messageId', $flagged['messageId']); 188 } else { 189 return false; 190 } 191 } 176 192 } 177 193 … … 190 206 //followupflagged:PostgreSQL.after.read 191 207 public function doImapRead( &$uri , &$result , &$criteria , $original ) { 192 208 /** 209 * Se a busca for apenas no banco de dados, pula-se todas as verificações 210 * deste interceptor. 211 */ 212 if ($original['URI']['service'] == 'PostgreSQL') return $result; 213 193 214 if ($result) { 194 $imap_result = Controller::read( 195 array('concept' => 'followupflagged', 'service' => 'Imap'), 215 $imap_uri = $uri; 216 $imap_uri['service'] = 'Imap'; 217 $imap_result = Controller::find( 218 $imap_uri, 196 219 false, 197 220 array('filter' => array('=', 'messageId', $result['messageId'])) … … 202 225 * Faz a consistência do banco com o imap 203 226 */ 204 if ( !$imap_result) {205 $r = Controller::delete ALL(array('concept' => 'followupflagged'), null, $criteria);227 if (count($imap_result) < 1) { 228 $r = Controller::delete($uri, null, $criteria); 206 229 return false; 230 } else { 231 $imap_result = $imap_result[0]; 207 232 } 208 233 … … 210 235 * Faz a consistência do banco com o imap 211 236 */ 212 if ($imap_result['messageId'] !== $ imap_result['messageId']) {237 if ($imap_result['messageId'] !== $result['messageId']) { 213 238 $n = $imap_result; 214 239 $n['followupflagId'] = 1; … … 236 261 237 262 if (self::in_arrayr('alarmDeadline', $original['criteria']) || self::in_arrayr('doneDeadline', $original['criteria'])) { 238 if (empty($result)) return $re ult;263 if (empty($result)) return $result; 239 264 240 265 $idList = array(); -
trunk/prototype/services/ImapServiceAdapter.php
r5960 r5989 676 676 case 'followupflagged': 677 677 { 678 679 /**680 * identifica se o formato de ID é "folder/subfolder/subsubfolder/<messageNumber>" ou "<message-id>"681 */682 $folderName = $messageNumber = false;683 if(!($messageHasId = preg_match('/<.*>/', $URI['id']))) {684 $folderName = dirname($URI['id']);685 $messageNumber = basename($URI['id']);686 }687 688 /**689 * TODO - efetuar o parsing do $criteria e obter a pasta passada690 */691 678 $map = array( 692 679 'folderName' => array(), … … 694 681 'messageId' => array() 695 682 ); 696 697 if ($folderName && $messageNumber) { 698 699 $this->mbox = $this->open_mbox($folderName); 700 $s = imap_clearflag_full($this->mbox, $messageNumber, '$Followupflagged', ST_UID); 701 702 imap_close($this->mbox, CL_EXPUNGE); 683 684 self::parseFilter($criteria["filter"], &$map); 685 686 if (!$map['folderName']) { 687 $folders = array (); 688 689 $folder_list = $this->get_folders_list(); 690 foreach ($folder_list as $folder) 691 if (isset($folder['folder_id'])) 692 $folders[] = $folder['folder_id']; 693 $map['folderName'] = $folders; 694 } 695 696 $messagesIds = $map['messageId']; 697 698 foreach ($map['folderName'] as $folder) { 699 $messages = array(); 700 701 $this->mbox = $this->open_mbox($folder); 702 703 /** 704 * Se é uma busca por messageId 705 */ 706 if (!empty($map['messageId'])) { 707 708 foreach ($messagesIds as $k => $v) { 709 $r = imap_search($this->mbox, 'UNDELETED KEYWORD "$Followupflagged" TEXT "'.$v.'"', SE_UID); 710 711 if ($r) { 712 $messages = $messages + $r; 713 unset($messagesIds[$k]); 714 } 715 } 716 717 /** 718 * Se é uma busca por messageNumber. 719 * Lembrando que, neste caso, só deve ser suportada uma única pasta no filtro. 720 */ 721 } else { 722 $messages = imap_search($this->mbox, 'UNDELETED KEYWORD "$Followupflagged"', SE_UID); 723 } 724 725 /** 726 * Se é uma busca por messageId, deve ser comparado com os messageNumbers 727 * passados no filtro, se houverem. 728 */ 729 if (!empty($map['messageNumber'])) { 730 foreach ($messages as $k => $m) 731 if (!in_array($m, $map['messageNumber'])) 732 unset($messages[$k]); 733 } 734 735 $s = true; 736 foreach ($messages as $k => $m) { 737 $s = imap_clearflag_full($this->mbox, $m, '$Followupflagged', ST_UID) && $s; 738 } 739 740 imap_close($this->mbox); 703 741 $this->mbox = false; 704 742 705 return $s; 706 } else { 707 /** 708 * Busca pela mensagem com o messageId dado. Se uma pasta foi passada, busca nela, 709 * senão busca em todas. 710 */ 711 712 $folders = array (); 713 if (isset($map['folderName'])) { 714 $folders = $map['folderName']; 715 } else { 716 $folder_list = $this->get_folders_list(); 717 foreach ($folder_list as $folder) 718 if (isset($folder['folder_id'])) 719 $folders[] = $folder['folder_id']; 720 } 721 722 foreach ($folders as $folder) { 723 724 $this->mbox = $this->open_mbox($folder); 725 if ($messages = imap_search($this->mbox, 'TEXT "'.$URI['id'].'"', SE_UID)) { 726 727 $s = imap_clearflag_full($this->mbox, $messages[0], '$Followupflagged', ST_UID); 728 729 imap_close($this->mbox, CL_EXPUNGE); 730 $this->mbox = false; 731 732 /** 733 * Stop searching in all folders 734 */ 735 return $s; 736 } 737 738 imap_close($this->mbox); 739 $this->mbox = false; 740 } 741 } 742 743 return false; 743 /** 744 * Se é uma busca por messageId e todos os messageIds foram econstrados: 745 * Stop searching in all folders 746 */ 747 if (!empty($map['messageId']) && empty($messagesIds)) 748 break; 749 } 750 751 return $s; 744 752 } 745 753 } … … 748 756 } 749 757 750 public function deleteAll( $URI, $justthese = false, $criteria = false ) // avaliar 751 {} 758 public function deleteAll( $URI, $justthese = false, $criteria = false ) 759 { 760 /** 761 * TODO - implementar a deleção de todos os followupflaggeds conforme filtro 762 */ 763 } 752 764 753 765 public function update( $URI, $data, $criteria = false )
Note: See TracChangeset
for help on using the changeset viewer.