From: <lei...@us...> - 2011-02-03 14:35:39
|
Author: leithoff Date: Thu Feb 3 15:35:30 2011 New Revision: 33717 URL: http://www.egroupware.org/viewvc/egroupware?rev=33717&view=rev Log: fix bug, while mail2tracker and using accounts stored in ldap; fix for tracker id found, but no data returned for ID (external ID); improved tracker id detection from subject (mail2tracker) Modified: trunk/tracker/inc/class.tracker_bo.inc.php Modified: trunk/tracker/inc/class.tracker_bo.inc.php URL: http://www.egroupware.org/viewvc/egroupware/trunk/tracker/inc/class.tracker_bo.inc.php?rev=33717&r1=33716&r2=33717&view=diff ============================================================================== --- trunk/tracker/inc/class.tracker_bo.inc.php (original) +++ trunk/tracker/inc/class.tracker_bo.inc.php Thu Feb 3 15:35:30 2011 @@ -1522,10 +1522,10 @@ /** * Try to extract a ticket number from a subject line * - * @param string the subjectline from the incoming message + * @param string the subjectline from the incoming message, may be modified when we find some id, but not matching available trackers * @return int ticket ID, or 0 of no ticket ID was recognized */ - function get_ticketId($subj='') + function get_ticketId(&$subj='') { if (empty($subj)) { @@ -1540,15 +1540,30 @@ { return 0; // } - + if (strpos($tr_data[1][0],'#') !== false) // there is more than one part of the subject, that could be a tracker ID + { + // try once more, and modify the tr_data as we go for comparsion with tracker subject + $buff = $tr_data; + unset($tr_data); + preg_match_all("/(.*)( #[0-9]+:? ?-? )(.*)$/",$buff[1][0], $tr_data); + $tr_data[0][0] = $buff[0][0]; + $tr_data[3][0] = $tr_data[3][0].$buff[2][0].$buff[3][0]; + } preg_match_all("/[0-9]+/",$tr_data[2][0], $tr_id); $tracker_id = $tr_id[0][0]; + if (!is_numeric($tracker_id)) return 0; // nothing found that looks like an ID //error_log(__METHOD__.array2string(array(0=>$tracker_id,1=>$subj))); $trackerData = $this->search(array('tr_id' => $tracker_id),'tr_summary'); - + if (is_numeric($tracker_id) && empty($trackerData)) // we have a numeric ID, but we could not find it in our database, is it external? + { + // we modify the subject as external tracker ids mess up our recognition of tracker ids + if ($tracker_id > 0) $subj = $tr_data[1][0].str_replace('#','ID:',$tr_data[2][0]).$tr_data[3][0]; + return 0; + } // Use strncmp() here, since a Fwd might add a sqr bracket. if (strncmp($trackerData[0]['tr_summary'], $tr_data[3][0], strlen($trackerData[0]['tr_summary']))) { + //_debug_array($trackerData); return 0; // Summary doesn't match. Should this be ok? } return $tracker_id; @@ -1581,6 +1596,8 @@ //$type = isset($this->enums['type']['email']) ? 'email' : 'note'; //$status = isset($this->status['defaults'][$type]) ? $this->status['defaults'][$type] : 'done'; $ticketId = $this->get_ticketId($_subject); + //_debug_array('TickedId found:'.$ticketId); + // we have to check if we know this ticket before proceeding if ($ticketId == 0) { $trackerentry = array( @@ -1604,7 +1621,7 @@ array( 'email' => $mailadr, 'email_home' => $mailadr - ),'contact_id,contact_email,contact_email_home,egw_accounts.account_id as account_id','','','',false,'OR',false,null,'',false)); + ),'contact_id,contact_email,contact_email_home,egw_addressbook.account_id as account_id','','','',false,'OR',false,null,'',false)); } if (!$contacts || !is_array($contacts) || !is_array($contacts[0])) { @@ -1654,11 +1671,14 @@ $this->read($ticketId); //echo "<p>data[tr_edit_mode]={$this->data['tr_edit_mode']}, this->htmledit=".array2string($this->htmledit)."</p>\n"; // Ascii Replies are converted to html, if htmledit is disabled (default), we allways convert, as this detection is weak - foreach ($this->data['replies'] as &$reply) - { - if (!$this->htmledit || stripos($reply['reply_message'], '<br') === false && stripos($reply['reply_message'], '<p>') === false) + if (is_array($this->data['replies'])) + { + foreach ($this->data['replies'] as &$reply) { - $reply['reply_message'] = nl2br(html::htmlspecialchars($reply['reply_message'])); + if (!$this->htmledit || stripos($reply['reply_message'], '<br') === false && stripos($reply['reply_message'], '<p>') === false) + { + $reply['reply_message'] = nl2br(html::htmlspecialchars($reply['reply_message'])); + } } } $trackerentry = $this->data; |