Skip to content

Commit

Permalink
Fixed returned value in $parm->input that must be false and not []
Browse files Browse the repository at this point in the history
set version to 1.6.5
  • Loading branch information
tomolimo committed Feb 5, 2021
1 parent 4931e23 commit 58e091e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
22 changes: 13 additions & 9 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static function getAdditionnalHeaders($marubox, $mid) {
return $head;
}


/**
* Search for current email in order to get its msg num, that will be stored in $mailgate->{$mailgate->pluginmailanalyzer_mid_field}.
* The only way to find the right email in the current mailbox is to look for "message-id" property
Expand All @@ -139,6 +140,7 @@ static function getHeaderAndMsgNum($mailgate, $message_id) {
return []; // returns an empty array if not found, in this case, $mailgate->{$mailgate->pluginmailanalyzer_mid_field} is not changed
}


/**
* Create default mailgate
* @param int $mailgate_id is the id of the mail collector in GLPI DB
Expand Down Expand Up @@ -178,6 +180,7 @@ public static function plugin_pre_item_add_mailanalyzer_followup($parm) {
}
}


/**
* Summary of getTextFromHtml
* gets bare text content from HTML
Expand All @@ -194,6 +197,7 @@ public static function getTextFromHtml($str) {
return $ret;
}


/**
* Summary of getUserOnBehalfOf
* search for ##From if it exists, then try to find users_id from DB
Expand All @@ -215,20 +219,20 @@ public static function getUserOnBehalfOf($str) {
// else we try with name and firstname in this order
$matches = $matches[0];
if (isset($matches['email'])) {
$where2 = ['glpi_useremails.email' => $matches['email']];
$where = ['glpi_useremails.email' => $matches['email']];
} else {
$where2 = ['AND' => ['glpi_users.realname' => $DB->escape(trim( $matches['last'] )),
$where = ['AND' => ['glpi_users.realname' => $DB->escape(trim( $matches['last'] )),
'glpi_users.firstname' => $DB->escape(trim( $matches['first'] )),
'glpi_useremails.is_default' => 1
]];
}
$where2['AND']['glpi_users.is_active'] = 1;
$where2['AND']['glpi_users.is_deleted'] = 0;
$where['AND']['glpi_users.is_active'] = 1;
$where['AND']['glpi_users.is_deleted'] = 0;
$res = $DB->request([
'SELECT' => 'glpi_users.id',
'FROM' => 'glpi_users',
'RIGHT JOIN'=> ['glpi_useremails' => ['FKEY' => ['glpi_useremails' => 'users_id', 'glpi_users' => 'id']]],
'WHERE' => $where2,
'WHERE' => $where,
'LIMIT' => 1
]);

Expand Down Expand Up @@ -306,7 +310,7 @@ public static function plugin_pre_item_add_mailanalyzer($parm) {
if ($row = $res->next()) {
// email already received
// must prevent ticket creation
$parm->input = [ ];
$parm->input = false; //[ ];

// as Ticket creation is cancelled, then email is not deleted from mailbox
// then we need to set deletion flag to true to this email from mailbox folder
Expand Down Expand Up @@ -382,7 +386,7 @@ public static function plugin_pre_item_add_mailanalyzer($parm) {
]);

// prevent Ticket creation. Unfortunately it will return an error to receiver when started manually from web page
$parm->input = []; // empty array...
$parm->input = false; // []; // empty array...

// as Ticket creation is cancelled, then email is not deleted from mailbox
// then we need to set deletion flag to true to this email from mailbox folder
Expand All @@ -394,6 +398,7 @@ public static function plugin_pre_item_add_mailanalyzer($parm) {
}

return;

} else {
// ticket creation, but linked to the closed one...
$parm->input['_link'] = ['link' => '1', 'tickets_id_1' => '0', 'tickets_id_2' => $row['ticket_id']];
Expand All @@ -411,8 +416,7 @@ public static function plugin_pre_item_add_mailanalyzer($parm) {
if (count($res) <= 0) {
$DB->insert('glpi_plugin_mailanalyzer_message_id', ['message_id' => $ref]);
}
//$query = "INSERT IGNORE INTO glpi_plugin_mailanalyzer_message_id (message_id, ticket_id) VALUES ('".$ref."', 0);";
//$DB->query($query);

}

}
Expand Down
8 changes: 5 additions & 3 deletions mailanalyzer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<logo>https://raw.githubusercontent.com/tomolimo/mailanalyzer/master/plugin.png</logo>
<description>
<short>
<cs><![CDATA[Zásuvný modul Analyzátor e-mailů může být použit pro automatické zkombinování e-mailů ve skryté kopii do jednoho požadavku]]></cs>
<cs><![CDATA[Zásuvný modul Analyzátor e-mailů může být použit pro automatické zkombinování e-mailů ve skryté kopii do jednoho požadavku]]></cs>
<en><![CDATA[Mail Analyzer GLPI Plugin may be used to automatically combine CC mails into one Ticket]]></en>
</short>
<long>
<cs><![CDATA[Toto řeší problém s požadavky duplikovanými když je e-mail poslán nejen do GLPI, ale také ve skryté kopii ostatním a tito příjemci použijí „Odpovědět všem“ a GLPI ve výchozím stavu vytvoří nový požadavek. Viz: http://glpi.userecho.com/topic/1090667-new-rule-criteria-for-mail-receivers/.
V případě ping pong e-mailů přidá odpovědi jako následnou komunikaci k požadavku, vytvořenému prvním e-mailem.]]></cs>
<en><![CDATA[This solves the problem of duplicated Tickets when an email is sent to GLPI and CC to others, and when those CC recipees use 'Reply to All', GLPI by default will create a new ticket. See: http://glpi.userecho.com/topic/1090667-new-rule-criteria-for-mail-receivers/.
In case of ping pong emails it will add the replies as followups to the Ticket initially created by the first email.]]></en>
<cs><![CDATA[Toto řeší problém s požadavky duplikovanými když je e-mail poslán nejen do GLPI, ale také ve skryté kopii ostatním a tito příjemci použijí „Odpovědět všem“ a GLPI ve výchozím stavu vytvoří nový požadavek. Viz: http://glpi.userecho.com/topic/1090667-new-rule-criteria-for-mail-receivers/.
V případě ping pong e-mailů přidá odpovědi jako následnou komunikaci k požadavku, vytvořenému prvním e-mailem.]]></cs>
</long>
</description>
<homepage>https://github.com/tomolimo/mailanalyzer</homepage>
Expand All @@ -29,11 +31,11 @@
<compatibility>9.4</compatibility>
</version>
<version>
<num>1.5.1</num>
<num>1.5.2</num>
<compatibility>9.3</compatibility>
</version>
<version>
<num>1.4.2</num>
<num>1.4.3</num>
<compatibility>9.2</compatibility>
</version>
<version>
Expand Down
32 changes: 16 additions & 16 deletions setup.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?php

define ("PLUGIN_MAILANALYSER_VERSION", "1.6.4");
define ("PLUGIN_MAILANALYSER_VERSION", "1.6.5");

// Init the hooks of the plugins -Needed
function plugin_init_mailanalyzer() {

global $PLUGIN_HOOKS;
global $PLUGIN_HOOKS;

Plugin::registerClass('PluginMailAnalyzer', ['classname' => 'PluginMailAnalyzer']);
Plugin::registerClass('PluginMailAnalyzer', ['classname' => 'PluginMailAnalyzer']);

$PLUGIN_HOOKS['csrf_compliant']['mailanalyzer'] = true;
$PLUGIN_HOOKS['csrf_compliant']['mailanalyzer'] = true;

$PLUGIN_HOOKS['pre_item_add']['mailanalyzer'] = [
'Ticket' => ['PluginMailAnalyzer', 'plugin_pre_item_add_mailanalyzer'],
'ITILFollowup' => ['PluginMailAnalyzer', 'plugin_pre_item_add_mailanalyzer_followup']
];
$PLUGIN_HOOKS['pre_item_add']['mailanalyzer'] = [
'Ticket' => ['PluginMailAnalyzer', 'plugin_pre_item_add_mailanalyzer'],
'ITILFollowup' => ['PluginMailAnalyzer', 'plugin_pre_item_add_mailanalyzer_followup']
];

$PLUGIN_HOOKS['item_add']['mailanalyzer'] = [
'Ticket' => ['PluginMailAnalyzer', 'plugin_item_add_mailanalyzer']
];
$PLUGIN_HOOKS['item_add']['mailanalyzer'] = [
'Ticket' => ['PluginMailAnalyzer', 'plugin_item_add_mailanalyzer']
];

}

// Get the name and the version of the plugin - Needed
function plugin_version_mailanalyzer() {
global $LANG;
global $LANG;

return ['name' => 'Mail Analyzer',
'version' => PLUGIN_MAILANALYSER_VERSION,
Expand All @@ -37,14 +37,14 @@ function plugin_version_mailanalyzer() {
// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_mailanalyzer_check_prerequisites() {
if (version_compare(GLPI_VERSION, '9.4', 'lt')) {
echo "This plugin requires GLPI >= 9.4";
return false;
echo "This plugin requires GLPI >= 9.4";
return false;
} else {
return true;
return true;
}
}

function plugin_mailanalyzer_check_config() {
return true;
return true;
}

0 comments on commit 58e091e

Please sign in to comment.