forked from civicrm/civicrm-core
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CATL-1613: Add new field to the mail account form - Skip emails which…
… do not have a Case ID or Case token
- Loading branch information
Showing
11 changed files
with
301 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
|
||
/** | ||
* Class CRM_Utils_Mail_CaseMail. | ||
*/ | ||
class CRM_Utils_Mail_CaseMail { | ||
|
||
/** | ||
* A word that is used for cases by default (in email subject). | ||
* | ||
* @var string | ||
*/ | ||
private $caseLabel = 'case'; | ||
|
||
/** | ||
* Default cases related email subject regexp patterns. | ||
* | ||
* All emails related to cases have case hash/id in the subject, e.g: | ||
* [case #ab12efg] Magic moment | ||
* [case #1234] Magic is here | ||
* This variable is defined in constructor. | ||
* | ||
* @var array|string[] | ||
*/ | ||
private $subjectPatterns = []; | ||
|
||
/** | ||
* Cases related email subject regexp patterns extended by hooks. | ||
* | ||
* @var array|string[] | ||
*/ | ||
private $subjectPatternsHooked = []; | ||
|
||
/** | ||
* CRM_Utils_Mail_CaseMail constructor. | ||
*/ | ||
public function __construct() { | ||
$this->subjectPatterns = [ | ||
'/\[' . $this->caseLabel . ' #([0-9a-f]{7})\]/i', | ||
'/\[' . $this->caseLabel . ' #(\d+)\]/i', | ||
]; | ||
} | ||
|
||
/** | ||
* Checks if email is related to cases. | ||
* | ||
* @param string $subject | ||
* Email subject. | ||
* | ||
* @return bool | ||
* TRUE if email subject contains case ID or case hash, FALSE otherwise. | ||
*/ | ||
public function isCaseEmail ($subject) { | ||
$subject = trim($subject); | ||
$patterns = $this->getSubjectPatterns(); | ||
$res = FALSE; | ||
|
||
for ($i = 0; !$res && $i < count($patterns); $i++) { | ||
$res = preg_match($patterns[$i], $subject) === 1; | ||
} | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* Returns cases related email subject patterns. | ||
* | ||
* These patterns could be used to check if email is related to cases. | ||
* | ||
* @return array|string[] | ||
*/ | ||
public function getSubjectPatterns() { | ||
// Allow others to change patterns using hook. | ||
if (empty($this->subjectPatternsHooked)) { | ||
$patterns = $this->subjectPatterns; | ||
CRM_Utils_Hook::caseEmailSubjectPatterns($patterns); | ||
$this->subjectPatternsHooked = $patterns; | ||
} | ||
|
||
return !empty($this->subjectPatternsHooked) | ||
? $this->subjectPatternsHooked | ||
: $this->subjectPatterns; | ||
} | ||
|
||
/** | ||
* Returns value of some class property. | ||
* | ||
* @param string $name | ||
* Property name. | ||
* | ||
* @return mixed|null | ||
* Property value or null if property does not exist. | ||
*/ | ||
public function get($name) { | ||
return $this->{$name} ?? NULL; | ||
} | ||
|
||
/** | ||
* Sets value of some class property. | ||
* | ||
* @param string $name | ||
* Property name. | ||
* @param mixed $value | ||
* New property value. | ||
*/ | ||
public function set($name, $value) { | ||
if (isset($this->{$name})) { | ||
$this->{$name} = $value; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*} | ||
|
||
{htxt id="is_non_case_email_skipped-title"} | ||
{ts}Skip emails which do not have a Case ID or Case hash{/ts} | ||
{/htxt} | ||
|
||
{htxt id="is_non_case_email_skipped"} | ||
<p>{ts}CiviCRM has functionality to file emails which contain the Case ID or Case Hash in the subject line in the format [case #1234] against a case record.{/ts}</p> | ||
<p>{ts}Where the Case ID or Case Hash is not included CiviCRM will file the email against the contact record, by matching the email addresses on the email with any email addresses of Contact records in CiviCRM.{/ts}</p> | ||
<p>{ts}Enabling this option will have CiviCRM skip any emails that do not have the Case ID or Case Hash so that the system will only process emails that can be placed on case records.{/ts}</p> | ||
<p>{ts}Any emails that are not processed will be moved to the ignored folder.{/ts}</p> | ||
<p>{ts}If email is skipped, no activities or contacts ("from"/"to"/"cc"/"bcc") will be created.{/ts}</p> | ||
{/htxt} | ||
|
||
{htxt id="is_contact_creation_disabled_if_no_match-title"} | ||
{ts}Do not create new contacts when filing emails{/ts} | ||
{/htxt} | ||
|
||
{htxt id="is_contact_creation_disabled_if_no_match"} | ||
<p>{ts}If this option is enabled, CiviCRM will not create new contacts ("from"/"to"/"cc"/"bcc") when filing emails.{/ts}</p> | ||
<p>{ts}If the email subject contains a valid Case ID or Case hash, the email will be filed against the case.{/ts}</p> | ||
{/htxt} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/phpunit/CRM/Utils/Mail/data/inbound/test_cases_email.eml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Delivered-To: [email protected] | ||
Received: by 10.2.13.84 with SMTP id 1234567890; | ||
Wed, 19 Dec 2018 10:01:11 +0100 (CET) | ||
Return-Path: <> | ||
Message-ID: <[email protected]> | ||
Date: Wed, 19 Dec 2018 10:01:07 +0100 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset="utf-8" | ||
Content-Transfer-Encoding: 8bit | ||
Content-Disposition: inline | ||
From: [email protected] | ||
To: [email protected] | ||
Subject: [case #214bf6d] Magic is here | ||
|
||
This test case is full of fun. |
15 changes: 15 additions & 0 deletions
15
tests/phpunit/CRM/Utils/Mail/data/inbound/test_non_cases_email.eml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Delivered-To: [email protected] | ||
Received: by 10.2.13.84 with SMTP id 1234567890; | ||
Wed, 19 Dec 2018 10:01:11 +0100 (CET) | ||
Return-Path: <> | ||
Message-ID: <[email protected]> | ||
Date: Wed, 19 Dec 2018 10:01:07 +0100 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset="utf-8" | ||
Content-Transfer-Encoding: 8bit | ||
Content-Disposition: inline | ||
From: [email protected] | ||
To: [email protected] | ||
Subject: Love letter | ||
|
||
I love you unit test, because you are not related to cases. |
Oops, something went wrong.