+17

Add only the last document in ticket notification

Eric Staraj il y a 5 ans mis à jour il y a 4 ans 4

The prevent the notification to be rejected by the mail server, add only the last document added in the follow-up of the ticket to the notification. In the overway, the size of the mail may grow to much and could be rejected

Hi,

I upvote you, since it is exactly what I submitted as a bug and was told to report here.

The link : https://github.com/glpi-project/glpi/issues/6229

The forum reporting this : https://forum.glpi-project.org/viewtopic.php?pid=366204#p366204

+1

Hi,

To prevent this behavior, we made a modification in /inc/notificationeventmailing.class.php 

We fixed a max size at 5Mo for the notification and we look for the doc to attach in chronological order and add them to the notification one after the other until we reach the size 5Mo at each add.

Once we reach the size, we stop adding document and send the notification.

If the document added is too big we send the notification without docs even the oldest, to prevent mistake.

I would like to propose this feature to be added in GLPI.

This could be great to select this as an option like a check box for example.

Let me know if you are interested.

regards

Hi Eric, thanks for the answer.

Your modification is interesting, can you please share it anywhere ?

Hello,

The modification was made on /inc/notificationeventmailing.class.php in GLPI 9.3.3 we didn't test it with other version. Of course don't try this on you production instance

The easyest way is to comment from line 147 to 186 

/*
// manage item attached documents
$document_items = $DB->request('glpi_documents_items', [
'items_id' => $current->fields['items_id'],
'itemtype' => $current->fields['itemtype'],
]);
$inline_docs = [];
$doc = new Document();
if (count($document_items)) {
foreach ($document_items as $doc_i_data) {
$doc->getFromDB($doc_i_data['documents_id']);
// Add embeded image if tag present in ticket content
if (preg_match_all('/'.Document::getImageTag($doc->fields['tag']).'/',
$current->fields['body_html'], $matches, PREG_PATTERN_ORDER)) {
$image_path = Document::getImage(
GLPI_DOC_DIR."/".$doc->fields['filepath'],
'mail'
);
if ($mmail->AddEmbeddedImage($image_path,
$doc->fields['tag'],
$doc->fields['filename'],
'base64',
$doc->fields['mime'])) {
$inline_docs[$doc_i_data['documents_id']] = $doc->fields['tag'];
}
} else if ($CFG_GLPI['attach_ticket_documents_to_mail']) {
// Add all other attachments, according to configuration
$path = GLPI_DOC_DIR."/".$doc->fields['filepath'];
if (Document::isImage($path)) {
$path = Document::getImage(
$path,
'mail'
);
}
$mmail->addAttachment(
$path,
$doc->fields['filename']
);
}
}
}
*/

And then past the code below

/**
* DEBUT MODIFICATIONS DSI UCA
* Ajoute en pj du mail de notification les docs du plus récent au plus ancien jusqu'à ce que la taille maximum spécifiée soit atteinte
*/

// Modif
$query = "SELECT * FROM glpi_documents_items WHERE items_id='{$current->fields['items_id']}' AND itemtype='{$current->fields['itemtype']}' ORDER BY date_mod DESC";
$document_items = $DB->request($query);
//

$inline_docs = [];
$doc = new Document();

if (count($document_items)) {
// Modif
$files_size = 0;
$file_size_allowed = 5000000;
//

foreach ($document_items as $doc_i_data) {
$doc->getFromDB($doc_i_data['documents_id']);
// Add embeded image if tag present in ticket content
if (preg_match_all('/'.Document::getImageTag($doc->fields['tag']).'/',
$current->fields['body_html'], $matches, PREG_PATTERN_ORDER)) {
$image_path = Document::getImage(
GLPI_DOC_DIR."/".$doc->fields['filepath'],
'mail'
);
if ($mmail->AddEmbeddedImage($image_path,
$doc->fields['tag'],
$doc->fields['filename'],
'base64',
$doc->fields['mime'])) {
$inline_docs[$doc_i_data['documents_id']] = $doc->fields['tag'];
}
} else if ($CFG_GLPI['attach_ticket_documents_to_mail']) {
// Add all other attachments, according to configuration
$path = GLPI_DOC_DIR."/".$doc->fields['filepath'];

// Modif
$file_size = filesize($path);
if($file_size + $files_size > $file_size_allowed)
{
//$break = true;
break;
}
//

if (Document::isImage($path)) {
$path = Document::getImage(
$path,
'mail'
);
}
$mmail->addAttachment(
$path,
$doc->fields['filename']
);

// Modif
$files_size+= $file_size;
//
}

}
}
// Fin de modification

Let me know if it works fine for you. 

Regards