Skip to content

Commit

Permalink
Merge branch 'Combodo:master' into dectect_auto_mails
Browse files Browse the repository at this point in the history
  • Loading branch information
larhip authored May 4, 2022
2 parents af5fc9e + 9cc2234 commit ce48694
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 99 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ We would like to give a special thank you to the people from the community who c

### Names

- Lars Kaltefleiter (aka @larhip)
- Bostoen, Jeffrey (a.k.a @jbostoen)
- Lars Kaltefleiter (a.k.a @larhip)

### Companies

Expand Down
6 changes: 5 additions & 1 deletion ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ function FindMessageIDFromUIDL($aMessages, $sUIDL, EmailSource $oSource)
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(); // Check user rights and prompt if needed

$oPage = new ajax_page("");
if (version_compare(ITOP_DESIGN_LATEST_VERSION , '3.0') < 0) {
$oPage = new ajax_page('');
} else {
$oPage = new AjaxPage('');
}

$sOperation = utils::ReadParam('operation', '');
$iMailInboxId = utils::ReadParam('id', 0, false, 'raw_data');
Expand Down
3 changes: 2 additions & 1 deletion classes/emailbackgroundprocess.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ public function Process($iTimeLimit)
// By doing so we lose the ability to set the CMDBChange date
CMDBObject::SetCurrentChange(null);
CMDBObject::SetTrackInfo('Mail to ticket automation (background process)');
CMDBObject::SetTrackOrigin('custom-extension');
// Important: Don't use the \Combodo\iTop\Core\CMDBChange\CMDBChangeOrigin::EMAIL_PROCESSING yet, as it is only available in iTop 3.0+
CMDBObject::SetTrackOrigin('email-processing');

try {
$this->InitMessageTrace($oSource, $iMessage);
Expand Down
47 changes: 26 additions & 21 deletions classes/mailinboxesemailprocessor.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function Trace($sText)
/**
* Initializes the email sources: one source is created and associated with each MailInboxBase instance
*
* @return array An array of EmailSource objects
* @return MailInboxBase[] An array of EmailSource objects
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
Expand All @@ -73,6 +73,7 @@ public function ListEmailSources()
$oSearch = new DBObjectSearch('MailInboxBase');
$oSearch->AddCondition('active', 'yes');
$oSet = new DBObjectSet($oSearch);
/** @var \MailInboxBase $oInbox */
while($oInbox = $oSet->Fetch())
{
$this->aInboxes[$oInbox->GetKey()] = $oInbox;
Expand Down Expand Up @@ -118,33 +119,37 @@ protected function GetInboxFromSource(EmailSource $oSource)
protected function GetActionFromCode($iRetCode)
{
$sRetCode = 'Unknown Code '.$iRetCode;
switch($iRetCode)
{
switch ($iRetCode) {
case EmailProcessor::NO_ACTION:
$sRetCode = 'NO_ACTION';
break;
$sRetCode = 'NO_ACTION';
break;

case EmailProcessor::DELETE_MESSAGE;
$sRetCode = 'DELETE_MESSAGE';
break;
$sRetCode = 'DELETE_MESSAGE';
break;

case EmailProcessor::PROCESS_MESSAGE:
$sRetCode = 'PROCESS_MESSAGE';
break;
$sRetCode = 'PROCESS_MESSAGE';
break;

case EmailProcessor::PROCESS_ERROR:
$sRetCode = 'PROCESS_ERROR';
break;
$sRetCode = 'PROCESS_ERROR';
break;

case EmailProcessor::MARK_MESSAGE_AS_ERROR:
$sRetCode = 'MARK_MESSAGE_AS_ERROR';
break;
$sRetCode = 'MARK_MESSAGE_AS_ERROR';
break;

case EmailProcessor::MARK_MESSAGE_AS_UNDESIRED:
$sRetCode = 'MARK_MESSAGE_AS_UNDESIRED';
break;

case EmailProcessor::MARK_MESSAGE_AS_UNDESIRED:
$sRetCode = 'MARK_MESSAGE_AS_UNDESIRED';
break;
case EmailProcessor::MOVE_MESSAGE:
$sRetCode = 'MOVE_MESSAGE';
break;
}
return $sRetCode;

return $sRetCode;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/messagefrommailbox.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($sUIDL, $sRawHeaders, $sBody)
* @param string $sFilePath The path to the file to load
* @return RawEmailMessage The loaded message
*/
static public function FromFile($sFilePath)
public static function FromFile($sFilePath)
{
//TODO: improve error handling in case the file does not exist or is corrupted...
return new MessageFromMailbox(basename($sFilePath), file_get_contents($sFilePath), '');
Expand Down
40 changes: 1 addition & 39 deletions datamodel.combodo-email-synchro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @package combodo-email-synchro
*/</comment>
<category>grant_by_profile</category>
<category>grant_by_profile,application</category>
<abstract>true</abstract>
<key_type>autoincrement</key_type>
<db_table>mailinbox_base</db_table>
Expand Down Expand Up @@ -1262,43 +1262,5 @@ JS
<classes> <class id="EmailReplica"/></classes>
</group>
</groups>
<profiles>
<profile id="121" _delta="define">
<name>Mail Inbox Manager</name>
<description>Person in charge to create/modify Mail Inboxes</description>
<groups>
<group id="MailInbox">
<actions>
<action id="action:read">allow</action>
<action id="action:bulk read">allow</action>
<action id="action:write">allow</action>
<action id="action:bulk write">allow</action>
<action id="action:delete">allow</action>
</actions>
</group>
</groups>
</profile>
<profile id="122" _delta="define">
<name>Mail Messages Manager</name>
<description>Person in charge to manage Mail Messages</description>
<groups>
<group id="MailMessage">
<actions>
<action id="action:read">allow</action>
<action id="action:bulk read">allow</action>
<action id="action:write">allow</action>
<action id="action:bulk write">allow</action>
<action id="action:delete">allow</action>
<action id="action:bulk delete">allow</action>
</actions>
</group>
<group id="MailInbox">
<actions>
<action id="action:read">allow</action>
</actions>
</group>
</groups>
</profile>
</profiles>
</user_rights>
</itop_design>
2 changes: 1 addition & 1 deletion de.dict.combodo-email-synchro.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'Class:MailInboxBase/Attribute:active/Value:no' => 'Nein',

'MailInbox:MailboxContent' => 'Mailbox Inhalt',
'MailInbox:MailboxContent:ConfirmMessage' => 'Are you sure ?~~',
'MailInbox:MailboxContent:ConfirmMessage' => 'Sind Sie sicher?',
'MailInbox:EmptyMailbox' => 'Die Mailbox ist leer',
'MailInbox:Z_DisplayedThereAre_X_Msg_Y_NewInTheMailbox' => '%1$d Mails angezeigt. Es sind %2$d EMail(s) in der Mailbox (%3$d neu).',
'MailInbox:MaxAllowedPacketTooSmall' => 'Der MySQL-Parameter max_allowed_packet in "my.ini" ist zu klein: %1$s. Der empfohlene Wert ist mindestens: %2$s',
Expand Down
2 changes: 1 addition & 1 deletion es_cr.dict.combodo-email-synchro.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Dict::Add('ES CR', 'Spanish', 'Español, Castellaño', array(
Dict::Add('ES CR', 'Spanish', 'Español, Castellano', array(
// Dictionary entries go here
'Class:MailInboxBase' => 'Buzón de Correo',
'Class:MailInboxBase+' => 'Fuente de mensajes entrantes',
Expand Down
2 changes: 1 addition & 1 deletion module.combodo-email-synchro.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'combodo-email-synchro/3.5.1-dev',
'combodo-email-synchro/3.5.2',
array(
// Identification
'label' => 'Tickets synchronization via e-mail',
Expand Down
4 changes: 2 additions & 2 deletions test/HTMLDOMSanitizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
*/
class HTMLDOMSanitizerTest extends ItopTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

require_once(APPROOT . 'env-production/combodo-email-synchro/classes/rawemailmessage.class.inc.php');
require_once(APPROOT.'env-production/combodo-email-synchro/classes/rawemailmessage.class.inc.php');
}


Expand Down
2 changes: 1 addition & 1 deletion test/TestEmlFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class TestEmlFiles extends ItopTestCase
{

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/classes/RawEmailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class RawEmailMessageTest extends ItopTestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
57 changes: 29 additions & 28 deletions utils/decoding-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function Usage()
$endTime = microtime(true);

echo "====== Decoded eMail: =========\n";

echo "\n\n\n\n\n\n";
echo "========================================================================================================================\n";
echo "------ HEADER\n";
echo "Subject: {$oEmail->sSubject}\n";
echo "MessageID: {$oEmail->sMessageId}\n";
echo "Date: {$oEmail->sDate}\n";
Expand All @@ -64,70 +68,67 @@ function Usage()
echo "Attachments:".count($oEmail->aAttachments)."\n";
$idx = 1;
$aCIDToImage = array();
foreach($oEmail->aAttachments as $aAttachment)
{
foreach ($oEmail->aAttachments as $aAttachment) {
$sInline = $aAttachment['inline'] ? 'yes' : 'no';
echo "\t$idx {$aAttachment['filename']} - {$aAttachment['mimeType']}, ".strlen($aAttachment['content'])." bytes, CID: ".$aAttachment['content-id'].", Inline ?: $sInline\n";
// Uncomment the line below to dump the attachments as separate files
//file_put_contents('/tmp/'.$aAttachment['filename'], $aAttachment['content']);
if ($aAttachment['content-id'] != '')
{
if ($aAttachment['content-id'] != '') {
$aCIDToImage[$aAttachment['content-id']] = $aAttachment;
}
$idx++;
}

echo "\n\n\n\n\n\n";
echo "========================================================================================================================\n";
echo "------ BODY\n";
echo "Body Format: {$oEmail->sBodyFormat}\n\n";
echo "Body Text:\n{$oEmail->sBodyText}\n\n";
if ($oEmail->sBodyFormat == 'text/html')
{
if(preg_match_all('/<img[^>]+src=(?:"cid:([^"]+)"|cid:([^ >]+))[^>]*>/i', $oEmail->sBodyText, $aMatches, PREG_OFFSET_CAPTURE))
{
if ($oEmail->sBodyFormat == 'text/html') {
if (preg_match_all('/<img[^>]+src=(?:"cid:([^"]+)"|cid:([^ >]+))[^>]*>/i', $oEmail->sBodyText, $aMatches, PREG_OFFSET_CAPTURE)) {
//print_r($aMatches);
$aInlineImages = array();
foreach($aMatches[0] as $idx => $aInfo)
{
foreach ($aMatches[0] as $idx => $aInfo) {
$aInlineImages[$idx] = array('position' => $aInfo[1]);
}
foreach($aMatches[1] as $idx => $aInfo)
{
foreach ($aMatches[1] as $idx => $aInfo) {
$sCID = $aInfo[0];
if (!array_key_exists($sCID, $aCIDToImage))
{
if (!array_key_exists($sCID, $aCIDToImage)) {
echo "ERROR: inline image: $sCID NOT FOUND !!!\n";
}
else
{
} else {
$aInlineImages[$idx]['cid'] = $sCID;
echo "Ok, inline image {$aCIDToImage[$sCID]['filename']} as cid:$sCID\n";
}
}
$sWholeText = $oEmail->sBodyText;
$sWholeText = $oEmail->sBodyText;
$idx = count($aInlineImages);
while($idx > 0)
{
while ($idx > 0) {
$idx--;
$sBefore = substr($sWholeText, 0, $aInlineImages[$idx]['position']);
$sAfter = substr($sWholeText, $aInlineImages[$idx]['position']);
$sWholeText = $sBefore." [itop attachment: {$aInlineImages[$idx]['cid']}] ".$sAfter;
}
echo "=================\n";
echo "$sWholeText\n";
echo "=================\n";
echo "=================\n";
echo "$sWholeText\n";
echo "=================\n";

$sBodyText = $oEmail->StripTags($sWholeText);
}
else
{
} else {
echo "Inline Images: no inline-image found\n";
$sBodyText = $oEmail->StripTags();
}
echo "------ BODY Text version\n";
echo "Plain Text Version:\n$sBodyText\n";
}
echo "===============================\n";

echo "\n\n\n\n\n\n";
echo "========================================================================================================================\n";
echo "GetNewPartHTML() returned:\n";
echo "===============================\n";
echo $oEmail->GetNewPartHTML($oEmail->sBodyText);
echo "===============================\n";


echo "Decoding duration: ".sprintf('%.1f', 1000*($endTime - $startTime))." ms\n";
echo "\n\n\n\n\n\n";
echo "========================================================================================================================\n";
echo "Decoding duration: ".sprintf('%.1f', 1000 * ($endTime - $startTime))." ms\n";
Loading

0 comments on commit ce48694

Please sign in to comment.