Skip to content

Commit

Permalink
Relates to #6, needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Jul 5, 2018
1 parent 50a2c34 commit 2c5e3ba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
38 changes: 36 additions & 2 deletions class.RewriterPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RewriterPlugin extends Plugin {
*
* @var boolean
*/
const DUMPWHOLETHING = TRUE;
const DUMPWHOLETHING = FALSE;

/**
* Hook the bootstrap process, wait for tickets to be created. Run on every
Expand Down Expand Up @@ -95,7 +95,7 @@ function ($entry) {
$this->purgeAttachmentsByDepartment($entry);
});
}
}
}

/**
* Takes an array of variables and checks to see if it matches the normal
Expand Down Expand Up @@ -144,6 +144,10 @@ private function process_ticket(&$vars) {
$this->rewrite($vars, $sender);
}
}
// See if Zendesk Chat emails need to be rewritten:
if($this->getConfig()->get('zendesk') && $vars['email'] == 'noreply@zopim.com'){
$this->rewriteZendesk($vars);
}

// See if admin has added any email rewriting rules:
if ($rules = $this->getConfig()->get('email-rewrite')) {
Expand Down Expand Up @@ -357,6 +361,36 @@ private function deepSearchForSender($html) {
return $sender;
}

private function rewriteZendesk(&$vars){
$text = $vars['message']->getClean();
// Find the original sender
$emails = $this->findEmailAddresses($text);
// how many can there be?
// Let's assume the last one..
$senders_email = array_pop($emails);
// Find the original name:
// Delete any new lines and strip html:
$lineless = str_replace("\n",'', strip_tags($text));
// Name exists between NAME & EMAIL, like NAMEJames SmithEMAIL etc, so
// we just replace the whole piece of text with whatever is between those:
$senders_name = preg_replace("/.*NAME([a-z' ]+)EMAIL.*/i","\$1",$lineless);
if(!$senders_name){
$senders_name = $senders_email; // make do..
}

// Now we can rewrite the sender
$sender = array(
array(),
array(
trim($senders_name)
),
array(
trim($senders_email)
)
);
$this->rewrite($vars,$sender);
}

/**
* Finds any email addresses in a piece of text, Returns an array of those
* addresses.
Expand Down
10 changes: 8 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,20 @@ function getOptions() {
)),
'dr' => new SectionBreakField(
array(
'label' => 'Drupal Contact Parser'
'label' => 'Explicitly defined parsers'
)),
'drupal' => new BooleanField(
array(
'default' => TRUE,
'label' => $__('Rewrite Drupal Contact Form emails'),
'hint' => $__(
"Drupal sends specific email formats that we can look for.")
"Rewrite Drupal contact-form emails.")
)),
'zendesk' => new BooleanField(
array(
'default' => FALSE,
'label' => $__('Rewrite Zendesk contact emails'),
'hint' => $__('Rewrite Zendesk chat notification emails.')
)),
'dsf' => new SectionBreakField(
array(
Expand Down

0 comments on commit 2c5e3ba

Please sign in to comment.