Skip to content
Snippets Groups Projects
Commit b4ecec0e authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #1263 from greezybacon/issue/email-references-user


email: Improve user identification from headers

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 039f68e9 67782d9a
No related branches found
No related tags found
No related merge requests found
...@@ -357,14 +357,14 @@ Class ThreadEntry { ...@@ -357,14 +357,14 @@ Class ThreadEntry {
return $this->ht['@headers']; return $this->ht['@headers'];
} }
function getEmailReferences() { function getEmailReferences($include_mid=true) {
if (!isset($this->_references)) { $references = '';
$headers = self::getEmailHeaderArray(); $headers = self::getEmailHeaderArray();
if (isset($headers['References']) && $headers['References']) if (isset($headers['References']) && $headers['References'])
$this->_references = $headers['References']." "; $references = $headers['References']." ";
$this->_references .= $this->getEmailMessageId(); if ($include_mid)
} $references .= $this->getEmailMessageId();
return $this->_references; return $references;
} }
function getTaggedEmailReferences($prefix, $refId) { function getTaggedEmailReferences($prefix, $refId) {
...@@ -374,7 +374,7 @@ Class ThreadEntry { ...@@ -374,7 +374,7 @@ Class ThreadEntry {
$mid = substr_replace($this->getEmailMessageId(), $mid = substr_replace($this->getEmailMessageId(),
$ref, strpos($this->getEmailMessageId(), '@'), 0); $ref, strpos($this->getEmailMessageId(), '@'), 0);
return sprintf('%s %s', $this->getEmailReferences(), $mid); return sprintf('%s %s', $this->getEmailReferences(false), $mid);
} }
function getEmailReferencesForUser($user) { function getEmailReferencesForUser($user) {
...@@ -849,7 +849,7 @@ Class ThreadEntry { ...@@ -849,7 +849,7 @@ Class ThreadEntry {
return ThreadEntry::lookup($id); return ThreadEntry::lookup($id);
} }
foreach (array('mid', 'in-reply-to', 'references') as $header) { foreach (array('in-reply-to', 'references') as $header) {
$matches = array(); $matches = array();
if (!isset($mailinfo[$header]) || !$mailinfo[$header]) if (!isset($mailinfo[$header]) || !$mailinfo[$header])
continue; continue;
...@@ -863,6 +863,7 @@ Class ThreadEntry { ...@@ -863,6 +863,7 @@ Class ThreadEntry {
// (parent) on the far right. // (parent) on the far right.
// @see rfc 1036, section 2.2.5 // @see rfc 1036, section 2.2.5
// @see http://www.jwz.org/doc/threading.html // @see http://www.jwz.org/doc/threading.html
$thread = null;
foreach (array_reverse($matches[0]) as $mid) { foreach (array_reverse($matches[0]) as $mid) {
//Try to determine if it's a reply to a tagged email. //Try to determine if it's a reply to a tagged email.
$ref = null; $ref = null;
...@@ -873,20 +874,29 @@ Class ThreadEntry { ...@@ -873,20 +874,29 @@ Class ThreadEntry {
} }
$res = db_query(sprintf($search, db_input($mid))); $res = db_query(sprintf($search, db_input($mid)));
while (list($id) = db_fetch_row($res)) { while (list($id) = db_fetch_row($res)) {
if (!($t = ThreadEntry::lookup($id))) continue; if (!($t = ThreadEntry::lookup($id)))
continue;
//We found a match - see if we can ID the user. // Capture the first match thread item
if (!$thread)
$thread = $t;
// We found a match - see if we can ID the user.
// XXX: Check access of ref is enough? // XXX: Check access of ref is enough?
if ($ref && ($uid = $t->getUIDFromEmailReference($ref))) { if ($ref && ($uid = $t->getUIDFromEmailReference($ref))) {
if ($ref[0] =='s') //staff if ($ref[0] =='s') //staff
$mailinfo['staffId'] = $uid; $mailinfo['staffId'] = $uid;
else //user or collaborator. else // user or collaborator.
$mailinfo['userId'] = $uid; $mailinfo['userId'] = $uid;
}
return $t; // Best possible case — found the thread and the
// user
return $t;
}
} }
} }
// Second best case — found a thread but couldn't identify the
// user from the header. Return the first thread entry matched
if ($thread)
return $thread;
} }
// Search for ticket by the [#123456] in the subject line // Search for ticket by the [#123456] in the subject line
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment