Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\extensions\core\IncomingEmail;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -37,7 +37,7 @@ class _Support
|
||||
/* Replying? */
|
||||
$request = $this->_emailIsReplyForRequest( $email );
|
||||
$department = $this->_getDepartment( $email );
|
||||
|
||||
|
||||
if ( $request )
|
||||
{
|
||||
/* IS this request locked? */
|
||||
@@ -73,6 +73,11 @@ class _Support
|
||||
$this->_processNewRequest( $email, $member, $department );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Track a property in the reply-to header for reference later
|
||||
*/
|
||||
protected $_lastMessageId = NULL;
|
||||
|
||||
/**
|
||||
* Is reply?
|
||||
@@ -98,6 +103,12 @@ class _Support
|
||||
preg_match( '/\=5BSR(\d+?)\.(.+?)(\.(\d+))?\=5D/', $email->raw, $matches )
|
||||
)
|
||||
{
|
||||
/* We have to store this now so we can inspect it later in _processReply() */
|
||||
if( isset( $matches[4] ) AND $matches[4] )
|
||||
{
|
||||
$this->_lastMessageId = $matches[4];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$request = \IPS\nexus\Support\Request::load( $matches[1] );
|
||||
@@ -109,12 +120,21 @@ class _Support
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
/* If the same email generated a new support request within the last 10 minutes, add this as a reply to that */
|
||||
/* If the same email generated a new support request within the last 10 minutes and the department is the same, add this as a reply to that */
|
||||
try
|
||||
{
|
||||
$recentRequest = \IPS\Db::i()->select( '*', 'nexus_support_requests', array( 'r_email=? AND r_started>?', $email->from, ( time() - 600 ) ) )->first();
|
||||
return \IPS\nexus\Support\Request::constructFromData( $recentRequest );
|
||||
$department = $this->_getDepartment( $email );
|
||||
$where = array();
|
||||
$where[] = array( 'r_email=?', $email->from );
|
||||
$where[] = array( 'r_started>?', time() - 600 );
|
||||
|
||||
if ( $department )
|
||||
{
|
||||
$where[] = array( 'r_department=?', $department->_id );
|
||||
}
|
||||
|
||||
$recentRequest = \IPS\Db::i()->select( '*', 'nexus_support_requests', $where )->first();
|
||||
return \IPS\nexus\Support\Request::constructFromData( $recentRequest );
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
|
||||
@@ -149,15 +169,15 @@ class _Support
|
||||
|
||||
$pending = FALSE;
|
||||
$newMessage = NULL;
|
||||
if ( $staff and isset( $matches[4] ) )
|
||||
if ( $staff and $this->_lastMessageId )
|
||||
{
|
||||
$newMessage = $request->comments( 1, 0, 'date', 'desc' );
|
||||
if ( $matches[4] != $newMessage->id )
|
||||
if ( $newMessage and $this->_lastMessageId != $newMessage->id )
|
||||
{
|
||||
$pending = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$request->status = \IPS\nexus\Support\Status::load( TRUE, $staff ? 'status_default_staff' : 'status_default_member' );
|
||||
$request->last_reply = time();
|
||||
$request->last_reply_by = (int) $member->member_id;
|
||||
@@ -175,6 +195,7 @@ class _Support
|
||||
$reply->raw = $email->raw;
|
||||
$reply->save();
|
||||
static::makeAndClaimAttachments( $email->attachments, $reply, $member );
|
||||
static::storeAttachmentMappings( $email->mappedAttachments, $reply, $member );
|
||||
|
||||
if ( $pending )
|
||||
{
|
||||
@@ -233,7 +254,7 @@ class _Support
|
||||
protected function _processNewRequest( \IPS\Email\Incoming\Email $email, \IPS\Member $member, \IPS\nexus\Support\Department $department, \IPS\nexus\Support\Request $previousRequest = NULL )
|
||||
{
|
||||
/* Make sure we're looking at the right department. */
|
||||
if ( !is_null( $previousRequest ) )
|
||||
if ( !\is_null( $previousRequest ) )
|
||||
{
|
||||
/* Use the existing requests department instead. */
|
||||
$department = $previousRequest->department;
|
||||
@@ -259,8 +280,8 @@ class _Support
|
||||
|
||||
if ( $previousRequest )
|
||||
{
|
||||
$request->log( 'previous_request', $previousRequest, NULL, $member );
|
||||
$previousRequest->log( 'previous_request', NULL, $request, $member );
|
||||
$request->log( 'previous_request', $previousRequest, NULL, ( $member->member_id ) ? $member : FALSE );
|
||||
$previousRequest->log( 'previous_request', NULL, $request, ( $member->member_id ) ? $member : FALSE );
|
||||
}
|
||||
|
||||
$request->sendNotifications();
|
||||
@@ -313,7 +334,7 @@ class _Support
|
||||
$reply = $this->_createReply( $email, $request, $member, $quoted, $originallyFromEmail );
|
||||
|
||||
/* Create a hidden note */
|
||||
if ( trim( $email->message ) or count( $email->attachments ) )
|
||||
if ( trim( $email->message ) or \count( $email->attachments ) )
|
||||
{
|
||||
$note = new \IPS\nexus\Support\Reply;
|
||||
$note->request = $request->id;
|
||||
@@ -325,6 +346,7 @@ class _Support
|
||||
$note->save();
|
||||
|
||||
static::makeAndClaimAttachments( $email->attachments, $note, $member );
|
||||
static::storeAttachmentMappings( $email->mappedAttachments, $note, $member );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
@@ -363,13 +385,6 @@ class _Support
|
||||
$notify[] = array( 'type' => 'e', 'value' => $cc );
|
||||
}
|
||||
}
|
||||
foreach( ( $email->bcc ?: array() ) as $cc )
|
||||
{
|
||||
if ( $cc !== $department->email )
|
||||
{
|
||||
$notify[] = array( 'type' => 'e', 'value' => $cc, 'bcc' => 1 );
|
||||
}
|
||||
}
|
||||
|
||||
$request->notify = $notify;
|
||||
$request->save();
|
||||
@@ -377,6 +392,7 @@ class _Support
|
||||
/* Create the reply */
|
||||
$reply = $this->_createReply( $email, $request, $member, $email->message . $email->quote, $email->from );
|
||||
static::makeAndClaimAttachments( $email->attachments, $reply, $member );
|
||||
static::storeAttachmentMappings( $email->mappedAttachments, $reply, $member );
|
||||
|
||||
/* Send confirmation email */
|
||||
if ( \IPS\Settings::i()->nexus_sout_autoreply )
|
||||
@@ -498,7 +514,7 @@ class _Support
|
||||
) );
|
||||
}
|
||||
|
||||
if ( count( $replacements ) )
|
||||
if ( \count( $replacements ) )
|
||||
{
|
||||
foreach ( $replacements as $find => $replace )
|
||||
{
|
||||
@@ -507,4 +523,25 @@ class _Support
|
||||
$reply->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store attachment mappings if a previous attachment was reused in this email
|
||||
*
|
||||
* @param array $attachments Attachment IDs
|
||||
* @param \IPS\nexus\Support\Reply $reply The support request reply
|
||||
* @param \IPS\Member $member The member it's from
|
||||
* @return void
|
||||
*/
|
||||
public static function storeAttachmentMappings( array $attachments, \IPS\nexus\Support\Reply $reply, \IPS\Member $member )
|
||||
{
|
||||
foreach ( $attachments as $id )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_attachments_map', array(
|
||||
'attachment_id' => $id,
|
||||
'location_key' => 'nexus_Support',
|
||||
'id1' => $reply->request,
|
||||
'id2' => $reply->id,
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user