diff --git a/modules/sendmail/batch/process_emails.php b/modules/sendmail/batch/process_emails.php
index 6af7a7033732c1ada094f3e9655460cffa34427c..5c3efa21f8da7bb90e9b28bef457a16795d20b97 100755
--- a/modules/sendmail/batch/process_emails.php
+++ b/modules/sendmail/batch/process_emails.php
@@ -12,290 +12,291 @@ while ($state <> 'END') {
         $GLOBALS['logger']->write('STATE:' . $state, 'INFO');
     }
     switch ($state) {
-		
-	/**********************************************************************/
+        
+    /**********************************************************************/
     /*                          LOAD_EMAILS 							  */
     /* List the records to proceed       								  */
     /**********************************************************************/
-    case 'LOAD_EMAILS' :
-		$query = "SELECT * FROM " . EMAILS_TABLE
-			. " WHERE email_status = 'W' and send_date is NULL";
-		$stmt = Bt_doQuery($GLOBALS['db'], $query);
-		$totalEmailsToProcess = $stmt->rowCount();
-		$currentEmail = 0;
-		if ($totalEmailsToProcess === 0) {
-			Bt_exitBatch(0, 'No e-mails to process');
+    case 'LOAD_EMAILS':
+        $query = "SELECT * FROM " . EMAILS_TABLE
+            . " WHERE email_status = 'W' and send_date is NULL";
+        $stmt = Bt_doQuery($GLOBALS['db'], $query);
+        $totalEmailsToProcess = $stmt->rowCount();
+        $currentEmail = 0;
+        if ($totalEmailsToProcess === 0) {
+            Bt_exitBatch(0, 'No e-mails to process');
+        }
+        $GLOBALS['logger']->write($totalEmailsToProcess . ' e-mails to proceed.', 'INFO');
+        $GLOBALS['emails'] = array();
+        while ($emailRecordset = $stmt->fetchObject()) {
+            $GLOBALS['emails'][] = $emailRecordset;
         }
-		$GLOBALS['logger']->write($totalEmailsToProcess . ' e-mails to proceed.', 'INFO');
-		$GLOBALS['emails'] = array();
-		while ($emailRecordset = $stmt->fetchObject()) {
-			$GLOBALS['emails'][] = $emailRecordset;
-		}
-		$state = 'SEND_AN_EMAIL';
-		$err = 0;
+        $state = 'SEND_AN_EMAIL';
+        $err = 0;
         $errTxt = '';
     break;
-		
-	/**********************************************************************/
+        
+    /**********************************************************************/
     /*                          SEND_AN_EMAIL	 		          	          */
     /* Load parameters and send an e-mail                                    */
     /**********************************************************************/
-    case 'SEND_AN_EMAIL' :
-		if($currentEmail < $totalEmailsToProcess) {
-			$email = $GLOBALS['emails'][$currentEmail];
-			//var_dump($email);exit;
-			$GLOBALS['mailer'] = new htmlMimeMail();
-			$GLOBALS['mailer']->setSMTPParams(
-				$host = (string)$mailerParams->smtp_host, 
-				$port = (string)$mailerParams->smtp_port,
-				$helo = (string)$mailerParams->domains,
-				$auth = filter_var($mailerParams->smtp_auth, FILTER_VALIDATE_BOOLEAN),
-				$user = (string)$mailerParams->smtp_user,
-				$pass = (string)$mailerParams->smtp_password
-				);
-			$mailfrom_generic = (string)$mailerParams->mailfrom;
-			
-			//Composing email	
-			//--> Set from
-			$userInfo = $users->get_user($email->user_id);
-			//var_dump($userInfo);
-			//echo 'userInfo : ' . $userInfo['mail'] . '==' . ' sender_email : ' . $email->sender_email . PHP_EOL;
-			if ($userInfo['mail'] == $email->sender_email) {
-				if (!empty($mailfrom_generic)) {
-
-					$GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$mailfrom_generic.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
-
-		            $GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
-						. $userInfo['lastname'].' <'.$mailfrom_generic.'> ');
-		            $emailFrom = $mailfrom_generic;
-		            $email->email_body = 'Courriel envoyé par : ' . $userInfo['firstname'].' '
-						. $userInfo['lastname'] . ' ' . $email->sender_email . ' ' .  '.<br/><br/>' . $email->email_body;
-				} else {
-
-					$GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$email->sender_email.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
-
-		            $GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
-						. $userInfo['lastname'].' <'.$email->sender_email.'> ');
-		            $emailFrom = $email->sender_email;
-				}
-				$GLOBALS['mailer']->setReplyTo($email->sender_email);
-				
-			} else {
-				if (!empty($mailfrom_generic)) {
-					$mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
-					$entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
-						
-		            $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $mailfrom_generic. '> ');
-		            $emailFrom = $mailfrom_generic;
-		            $email->email_body = 'Courriel envoyé par : ' . $entityShortLabel . ' ' . $sendmail_tools->explodeSenderEmail($email->sender_email) . ' ' .  '.<br/><br/>' . $email->email_body;
-				} else {
-					$mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
-					$entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
-
-		            $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $sendmail_tools->explodeSenderEmail($email->sender_email) . '> ');
-		            $emailFrom = $sendmail_tools->explodeSenderEmail($email->sender_email);
-				}
-				$GLOBALS['mailer']->setReplyTo($sendmail_tools->explodeSenderEmail($email->sender_email));
-			}
-
-			//echo $email->email_body . PHP_EOL;exit;
-
-			if (!empty($email->cc_list))$GLOBALS['logger']->write("Copy e-mail to : " . $email->cc_list, 'INFO');
-			if (!empty($email->cci_list))$GLOBALS['logger']->write("Copy invisible e-mail to : " . $email->cci_list, 'INFO');
-			
-			//--> Set the return path
-			if (!empty($mailfrom_generic)) {
-				$GLOBALS['mailer']->setReturnPath(
-					$userInfo['firstname'] . ' ' .  $userInfo['lastname'] . ' <' . $mailfrom_generic . '> '
-				);
-			} else {
-				$GLOBALS['mailer']->setReturnPath($userInfo['mail']);
-			}
-
-			//--> To
-			$to = array();
-			$to = explode(',', $email->to_list);
-			//--> Cc
-			if (!empty($email->cc_list)) {
-				$GLOBALS['mailer']->setCc($email->cc_list);
-			}
-			//--> Cci
-			if (!empty($email->cci_list)) {
-				$GLOBALS['mailer']->setBcc($email->cci_list);
-			}
-			//--> Set subject
-			$GLOBALS['mailer']->setSubject($email->email_object);
-			//--> Set body: Is Html/raw text ?
-			if ($email->is_html == 'Y') {
-				$body = str_replace('###', ';', $email->email_body);
-				$body = str_replace('___', '--', $body);
-				$body = $sendmail_tools->rawToHtml($body);
-				$GLOBALS['mailer']->setHtml($body);
-			} else {
-				$body = $sendmail_tools->htmlToRaw($email->email_body);
-				$GLOBALS['mailer']->setText($body);
-			}
-			//--> Set charset
-			$GLOBALS['mailer']->setTextCharset($GLOBALS['charset']);
-			$GLOBALS['mailer']->setHtmlCharset($GLOBALS['charset']);
-			$GLOBALS['mailer']->setHeadCharset($GLOBALS['charset']);
-			
-			//--> Set attachments
-
-			//zip M2M
-			if ($email->message_exchange_id) {
-				$GLOBALS['logger']->write("set zip on message: " . $email->message_exchange_id, 'INFO');
-
-				//Get uri zip
-				$query = "SELECT * FROM message_exchange WHERE message_id = ?";
-				$smtp = $stmt = Bt_doQuery($GLOBALS['db'], $query, array($email->message_exchange_id));
-				$messageExchange = $smtp->fetchObject();
-
-		        $docserver     = \Core\Models\DocserverModel::getById(['docserver_id' => $messageExchange->docserver_id]);
-		        $docserverType = \Core\Models\DocserverTypeModel::getById(['docserver_type_id' => $docserver[0]['docserver_type_id']]);
-
-		        $pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchange->path);
-		        $filePath      = $docserver[0]['path_template'] . $pathDirectory . $messageExchange->filename;
-		        $fingerprint   = \Core\Controllers\DocserverToolsController::doFingerprint([
-		            'path'            => $filePath,
-		            'fingerprintMode' => $docserverType[0]['fingerprint_mode'],
-		        ]);
-
-		        if($fingerprint['fingerprint'] != $messageExchange->fingerprint){
-		        	$GLOBALS['logger']->write(_PB_WITH_FINGERPRINT_OF_DOCUMENT.'. ResId master : ' . $email->res_id, 'ERROR');
-		        }
-
-				//Get file content
-				if(is_file($filePath)) {
-					//Filename
-					$resFilename = $sendmail_tools->createFilename($messageExchange->reference, 'zip');
-					$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
-
-					//File content
-					$file_content = $GLOBALS['mailer']->getFile($filePath);
-					//Add file
-					$GLOBALS['mailer']->addAttachment($file_content, $resFilename);
-				}
+    case 'SEND_AN_EMAIL':
+        if ($currentEmail < $totalEmailsToProcess) {
+            $email = $GLOBALS['emails'][$currentEmail];
+            //var_dump($email);exit;
+            $GLOBALS['mailer'] = new htmlMimeMail();
+            $GLOBALS['mailer']->setSMTPParams(
+                $host = (string)$mailerParams->smtp_host,
+                $port = (string)$mailerParams->smtp_port,
+                $helo = (string)$mailerParams->domains,
+                $auth = filter_var($mailerParams->smtp_auth, FILTER_VALIDATE_BOOLEAN),
+                $user = (string)$mailerParams->smtp_user,
+                $pass = (string)$mailerParams->smtp_password
+                );
+            $mailfrom_generic = (string)$mailerParams->mailfrom;
+            
+            //Composing email
+            //--> Set from
+            $userInfo = $users->get_user($email->user_id);
+            //var_dump($userInfo);
+            //echo 'userInfo : ' . $userInfo['mail'] . '==' . ' sender_email : ' . $email->sender_email . PHP_EOL;
+            if ($userInfo['mail'] == $email->sender_email) {
+                if (!empty($mailfrom_generic)) {
+                    $GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$mailfrom_generic.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
+
+                    $GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
+                        . $userInfo['lastname'].' <'.$mailfrom_generic.'> ');
+                    $emailFrom = $mailfrom_generic;
+                    $email->email_body = 'Courriel envoyé par : ' . $userInfo['firstname'].' '
+                        . $userInfo['lastname'] . ' ' . $email->sender_email . ' ' .  '.<br/><br/>' . $email->email_body;
+                } else {
+                    $GLOBALS['logger']->write('process e-mail '.($currentEmail+1)."/".$totalEmailsToProcess.' (FROM => '.$userInfo['firstname'].' '.$userInfo['lastname'].' <'.$email->sender_email.'>'.', TO => '.$email->to_list.', SUBJECT => '.$email->email_object.', CC =>'.$email->cc_list.', CCI => '.$email->cci_list.') ...', 'INFO');
+
+                    $GLOBALS['mailer']->setFrom($userInfo['firstname'].' '
+                        . $userInfo['lastname'].' <'.$email->sender_email.'> ');
+                    $emailFrom = $email->sender_email;
+                }
+                $GLOBALS['mailer']->setReplyTo($email->sender_email);
+            } else {
+                if (!empty($mailfrom_generic)) {
+                    $mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
+                    $entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
+                        
+                    $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $mailfrom_generic. '> ');
+                    $emailFrom = $mailfrom_generic;
+                    $email->email_body = 'Courriel envoyé par : ' . $entityShortLabel . ' ' . $sendmail_tools->explodeSenderEmail($email->sender_email) . ' ' .  '.<br/><br/>' . $email->email_body;
+                } else {
+                    $mailsEntities = $sendmail_tools->getAttachedEntitiesMails();
+                    $entityShortLabel = substr($mailsEntities[$email->sender_email], 0, strrpos($mailsEntities[$email->sender_email], "("));
+
+                    $GLOBALS['mailer']->setFrom($entityShortLabel . ' <' . $sendmail_tools->explodeSenderEmail($email->sender_email) . '> ');
+                    $emailFrom = $sendmail_tools->explodeSenderEmail($email->sender_email);
+                }
+                $GLOBALS['mailer']->setReplyTo($sendmail_tools->explodeSenderEmail($email->sender_email));
+            }
+
+            //echo $email->email_body . PHP_EOL;exit;
+
+            if (!empty($email->cc_list)) {
+                $GLOBALS['logger']->write("Copy e-mail to : " . $email->cc_list, 'INFO');
+            }
+            if (!empty($email->cci_list)) {
+                $GLOBALS['logger']->write("Copy invisible e-mail to : " . $email->cci_list, 'INFO');
+            }
+            
+            //--> Set the return path
+            if (!empty($mailfrom_generic)) {
+                $GLOBALS['mailer']->setReturnPath(
+                    $userInfo['firstname'] . ' ' .  $userInfo['lastname'] . ' <' . $mailfrom_generic . '> '
+                );
             } else {
-				//Res master
-				if ($email->is_res_master_attached == 'Y') {
-					$GLOBALS['logger']->write("set attachment on res master : " . $email->res_id, 'INFO');
-
-					//Get file from docserver
-					$resFile = $sendmail_tools->getResource($GLOBALS['collections'], $email->coll_id, $email->res_id);
-					//Get file content
-					if(is_file($resFile['file_path'])) {
-						//Filename
-						$resFilename = $sendmail_tools->createFilename($resFile['label'], $resFile['ext']);
-						$GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
-
-						//File content
-						$file_content = $GLOBALS['mailer']->getFile($resFile['file_path']);
-						//Add file
-						$GLOBALS['mailer']->addAttachment($file_content, $resFilename, $resFile['mime_type']); 
-					}
-				}
-				
-				//Other version of the document
-				if (!empty($email->res_version_id_list)) {
+                $GLOBALS['mailer']->setReturnPath($userInfo['mail']);
+            }
+
+            //--> To
+            $to = array();
+            $to = explode(',', $email->to_list);
+            //--> Cc
+            if (!empty($email->cc_list)) {
+                $GLOBALS['mailer']->setCc($email->cc_list);
+            }
+            //--> Cci
+            if (!empty($email->cci_list)) {
+                $GLOBALS['mailer']->setBcc($email->cci_list);
+            }
+            //--> Set subject
+            $GLOBALS['mailer']->setSubject($email->email_object);
+            //--> Set body: Is Html/raw text ?
+            if ($email->is_html == 'Y') {
+                $body = str_replace('###', ';', $email->email_body);
+                $body = str_replace('___', '--', $body);
+                $body = $sendmail_tools->rawToHtml($body);
+                $GLOBALS['mailer']->setHtml($body);
+            } else {
+                $body = $sendmail_tools->htmlToRaw($email->email_body);
+                $GLOBALS['mailer']->setText($body);
+            }
+            //--> Set charset
+            $GLOBALS['mailer']->setTextCharset($GLOBALS['charset']);
+            $GLOBALS['mailer']->setHtmlCharset($GLOBALS['charset']);
+            $GLOBALS['mailer']->setHeadCharset($GLOBALS['charset']);
+            
+            //--> Set attachments
+
+            //zip M2M
+            if ($email->message_exchange_id) {
+                $GLOBALS['logger']->write("set zip on message: " . $email->message_exchange_id, 'INFO');
+
+                //Get uri zip
+                $query = "SELECT * FROM message_exchange WHERE message_id = ?";
+                $smtp = $stmt = Bt_doQuery($GLOBALS['db'], $query, array($email->message_exchange_id));
+                $messageExchange = $smtp->fetchObject();
+
+                $docserver     = \Docserver\models\DocserverModel::getById(['id' => $messageExchange->docserver_id]);
+                $docserverType = \Docserver\models\DocserverTypeModel::getById(['id' => $docserver[0]['docserver_type_id']]);
+
+                $pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchange->path);
+                $filePath      = $docserver[0]['path_template'] . $pathDirectory . $messageExchange->filename;
+                $fingerprint   = \SrcCore\controllers\StoreController::getFingerPrint([
+                    'filePath' => $filePath,
+                    'mode'     => $docserverType[0]['fingerprint_mode'],
+                ]);
+
+                if ($fingerprint['fingerprint'] != $messageExchange->fingerprint) {
+                    $GLOBALS['logger']->write(_PB_WITH_FINGERPRINT_OF_DOCUMENT.'. ResId master : ' . $email->res_id, 'ERROR');
+                }
+
+                //Get file content
+                if (is_file($filePath)) {
+                    //Filename
+                    $resFilename = $sendmail_tools->createFilename($messageExchange->reference, 'zip');
+                    $GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
+
+                    //File content
+                    $file_content = $GLOBALS['mailer']->getFile($filePath);
+                    //Add file
+                    $GLOBALS['mailer']->addAttachment($file_content, $resFilename);
+                }
+            } else {
+                //Res master
+                if ($email->is_res_master_attached == 'Y') {
+                    $GLOBALS['logger']->write("set attachment on res master : " . $email->res_id, 'INFO');
+
+                    //Get file from docserver
+                    $resFile = $sendmail_tools->getResource($GLOBALS['collections'], $email->coll_id, $email->res_id);
+                    //Get file content
+                    if (is_file($resFile['file_path'])) {
+                        //Filename
+                        $resFilename = $sendmail_tools->createFilename($resFile['label'], $resFile['ext']);
+                        $GLOBALS['logger']->write("set attachment filename : " . $resFilename, 'INFO');
+
+                        //File content
+                        $file_content = $GLOBALS['mailer']->getFile($resFile['file_path']);
+                        //Add file
+                        $GLOBALS['mailer']->addAttachment($file_content, $resFilename, $resFile['mime_type']);
+                    }
+                }
+                
+                //Other version of the document
+                if (!empty($email->res_version_id_list)) {
                     $version = explode(',', $email->res_version_id_list);
-					foreach($version as $version_id) {
-						$GLOBALS['logger']->write("set attachment for version : " . $version_id, 'INFO');
-						$versionFile = $sendmail_tools->getVersion(
-								$GLOBALS['collections'],
-								$email->coll_id, 
-								$email->res_id,
-								$version_id
-							);
-						if(is_file($versionFile['file_path'])) {
-							//Filename
-							$versionFilename = $sendmail_tools->createFilename($versionFile['label'], $versionFile['ext']);
-							$GLOBALS['logger']->write("set attachment filename for version : " . $versionFilename, 'INFO');
-
-							//File content
-							$file_content = $GLOBALS['mailer']->getFile($versionFile['file_path']);
-							//Add file
-							$GLOBALS['mailer']->addAttachment($file_content, $versionFilename, $versionFile['mime_type']); 
-						}
-					}
-				}
-				
-				//Res attachment
-				if (!empty($email->res_attachment_id_list)) {
+                    foreach ($version as $version_id) {
+                        $GLOBALS['logger']->write("set attachment for version : " . $version_id, 'INFO');
+                        $versionFile = $sendmail_tools->getVersion(
+                                $GLOBALS['collections'],
+                                $email->coll_id,
+                                $email->res_id,
+                                $version_id
+                            );
+                        if (is_file($versionFile['file_path'])) {
+                            //Filename
+                            $versionFilename = $sendmail_tools->createFilename($versionFile['label'], $versionFile['ext']);
+                            $GLOBALS['logger']->write("set attachment filename for version : " . $versionFilename, 'INFO');
+
+                            //File content
+                            $file_content = $GLOBALS['mailer']->getFile($versionFile['file_path']);
+                            //Add file
+                            $GLOBALS['mailer']->addAttachment($file_content, $versionFilename, $versionFile['mime_type']);
+                        }
+                    }
+                }
+                
+                //Res attachment
+                if (!empty($email->res_attachment_id_list)) {
                     $attachments = explode(',', $email->res_attachment_id_list);
-					foreach($attachments as $attachment_id) {
-						$GLOBALS['logger']->write("set attachment on res attachment : " . $attachment_id, 'INFO');
-						$attachmentFile = $sendmail_tools->getAttachment(
-								$email->coll_id, 
-								$email->res_id,
-								$attachment_id
-							);
-						if(is_file($attachmentFile['file_path'])) {
-							//Filename
-							$attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
-							$GLOBALS['logger']->write("set attachment filename : " . $attachmentFilename, 'INFO');
-
-							//File content
-							$file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
-							//Add file
-							$GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']); 
-						}
-					}
+                    foreach ($attachments as $attachment_id) {
+                        $GLOBALS['logger']->write("set attachment on res attachment : " . $attachment_id, 'INFO');
+                        $attachmentFile = $sendmail_tools->getAttachment(
+                                $email->coll_id,
+                                $email->res_id,
+                                $attachment_id
+                            );
+                        if (is_file($attachmentFile['file_path'])) {
+                            //Filename
+                            $attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
+                            $GLOBALS['logger']->write("set attachment filename : " . $attachmentFilename, 'INFO');
+
+                            //File content
+                            $file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
+                            //Add file
+                            $GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']);
+                        }
+                    }
                 }
 
-				//Res version attachment
-				if (!empty($email->res_version_att_id_list)) {
+                //Res version attachment
+                if (!empty($email->res_version_att_id_list)) {
                     $attachments = explode(',', $email->res_version_att_id_list);
-					foreach($attachments as $attachment_id) {
-						$GLOBALS['logger']->write("set attachment version on res attachment : " . $attachment_id, 'INFO');
-						$attachmentFile = $sendmail_tools->getAttachment(
-								$email->coll_id, 
-								$email->res_id,
-								$attachment_id,
-								true
-							);
-						if(is_file($attachmentFile['file_path'])) {
-							//Filename
-							$attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
-							$GLOBALS['logger']->write("set attachment version filename : " . $attachmentFilename, 'INFO');
-
-							//File content
-							$file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
-							//Add file
-							$GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']); 
-						}
-					}
+                    foreach ($attachments as $attachment_id) {
+                        $GLOBALS['logger']->write("set attachment version on res attachment : " . $attachment_id, 'INFO');
+                        $attachmentFile = $sendmail_tools->getAttachment(
+                                $email->coll_id,
+                                $email->res_id,
+                                $attachment_id,
+                                true
+                            );
+                        if (is_file($attachmentFile['file_path'])) {
+                            //Filename
+                            $attachmentFilename = $sendmail_tools->createFilename($attachmentFile['label'], $attachmentFile['ext']);
+                            $GLOBALS['logger']->write("set attachment version filename : " . $attachmentFilename, 'INFO');
+
+                            //File content
+                            $file_content = $GLOBALS['mailer']->getFile($attachmentFile['file_path']);
+                            //Add file
+                            $GLOBALS['mailer']->addAttachment($file_content, $attachmentFilename, $attachmentFile['mime_type']);
+                        }
+                    }
+                }
+                
+                //Notes
+                if (!empty($email->note_id_list)) {
+                    $notes = explode(',', $email->note_id_list);
+                    $noteFile = $sendmail_tools->createNotesFile($email->coll_id, $email->res_id, $notes);
+                    if (is_file($noteFile['file_path'])) {
+                        //File content
+                        $file_content = $GLOBALS['mailer']->getFile($noteFile['file_path']);
+                        //Add file
+                        $GLOBALS['mailer']->addAttachment($file_content, $noteFile['filename'], $noteFile['mime_type']);
+                    }
                 }
-				
-				//Notes
-				if (!empty($email->note_id_list)) {
-					$notes = explode(',', $email->note_id_list);
-					$noteFile = $sendmail_tools->createNotesFile($email->coll_id, $email->res_id, $notes);
-					if(is_file($noteFile['file_path'])) {
-						//File content
-						$file_content = $GLOBALS['mailer']->getFile($noteFile['file_path']);
-						//Add file
-						$GLOBALS['mailer']->addAttachment($file_content, $noteFile['filename'], $noteFile['mime_type']); 
-					}
-				}
             }
 
-			//Now send the mail
-			$GLOBALS['logger']->write("sending e-mail ...", 'INFO');
-			$return = $GLOBALS['mailer']->send($to, (string)$mailerParams->type);
+            //Now send the mail
+            $GLOBALS['logger']->write("sending e-mail ...", 'INFO');
+            $return = $GLOBALS['mailer']->send($to, (string)$mailerParams->type);
 
-			if( ($return == 1 && ((string)$mailerParams->type == "smtp" || (string)$mailerParams->type == "mail" )) || ($return == 0 && (string)$mailerParams->type == "sendmail")) {
-				$exec_result = 'S';
-				$GLOBALS['logger']->write("e-mail sent.", 'INFO');
-			} else {
-				//$GLOBALS['logger']->write("Errors when sending message through SMTP :" . implode(', ', $GLOBALS['mailer']->errors), 'ERROR');
+            if (($return == 1 && ((string)$mailerParams->type == "smtp" || (string)$mailerParams->type == "mail")) || ($return == 0 && (string)$mailerParams->type == "sendmail")) {
+                $exec_result = 'S';
+                $GLOBALS['logger']->write("e-mail sent.", 'INFO');
+            } else {
+                //$GLOBALS['logger']->write("Errors when sending message through SMTP :" . implode(', ', $GLOBALS['mailer']->errors), 'ERROR');
                 $GLOBALS['logger']->write("SENDING EMAIL ERROR ! (" . $return[0].")", 'ERROR');
                 $GLOBALS['logger']->write("e-mail not sent !", 'ERROR');
-				$exec_result = 'E';
-				$err++;
-				$errTxt = ' (Last Error : '.$return[0].')';
+                $exec_result = 'E';
+                $err++;
+                $errTxt = ' (Last Error : '.$return[0].')';
 
-                $query = "INSERT INTO notif_email_stack (sender, recipient, subject, html_body, charset, module) VALUES (?, ?, ?, ?, ?, 'notifications')";  
+                $query = "INSERT INTO notif_email_stack (sender, recipient, subject, html_body, charset, module) VALUES (?, ?, ?, ?, ?, 'notifications')";
 
                 $html = "Message automatique : <br><br>
                 		Le courriel avec l'identifiant ".$email->email_id." dans la table 'sendmail' n'a pas été envoyé. <br>
@@ -303,41 +304,40 @@ while ($state <> 'END') {
                 		Répertoire d'installation de l'application : ".$GLOBALS['maarchDirectory']."<br>
                 		Fichier de configuration de sendmail : " . $GLOBALS['configFile'];
 
-        		$queryMlb = "SELECT alt_identifier FROM mlb_coll_ext WHERE res_id = ? ";
-				$stmt = Bt_doQuery($GLOBALS['db'], $queryMlb, array($email->res_id));
-				$mlbRecordSet = $stmt->fetchObject();
+                $queryMlb = "SELECT alt_identifier FROM mlb_coll_ext WHERE res_id = ? ";
+                $stmt = Bt_doQuery($GLOBALS['db'], $queryMlb, array($email->res_id));
+                $mlbRecordSet = $stmt->fetchObject();
 
-				$html .= '<br><br>Le courriel a été envoyé depuis le courrier dont le numéro chrono est : ' . $mlbRecordSet->alt_identifier;
+                $html .= '<br><br>Le courriel a été envoyé depuis le courrier dont le numéro chrono est : ' . $mlbRecordSet->alt_identifier;
 
                 $adminMails = explode(',', $GLOBALS['adminmail']);
-                if(!empty($adminMails)){
-		            foreach($adminMails as $recipient){
-	                	if(!empty($recipient)){
-		            		Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $recipient, $GLOBALS['subjectmail'], $html, $GLOBALS['charset']));
-		                }
-	                }                	
+                if (!empty($adminMails)) {
+                    foreach ($adminMails as $recipient) {
+                        if (!empty($recipient)) {
+                            Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $recipient, $GLOBALS['subjectmail'], $html, $GLOBALS['charset']));
+                        }
+                    }
                 }
 
-            	if(!empty($userInfo['mail'])){
-					if(strlen($email->email_object) >= 100) {
-						$objectToSend = mb_substr($email->email_object, 0, 100);
-						$objectToSend = substr($objectToSend, 0, strrpos($objectToSend, ' ')).'...';
-					} else {
-						$objectToSend = $email->email_object;
-					}					
+                if (!empty($userInfo['mail'])) {
+                    if (strlen($email->email_object) >= 100) {
+                        $objectToSend = mb_substr($email->email_object, 0, 100);
+                        $objectToSend = substr($objectToSend, 0, strrpos($objectToSend, ' ')).'...';
+                    } else {
+                        $objectToSend = $email->email_object;
+                    }
 
-            		$bodyMailError = "Message automatique : <br><br>
+                    $bodyMailError = "Message automatique : <br><br>
             						 Votre envoi de courriel dont l'objet est \"". $objectToSend . "\" avec le numéro chrono \"" . $mlbRecordSet->alt_identifier . "\" n'a pas été envoyé. Veuillez réessayer ou contacter votre administreur.";
-            		Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $userInfo['mail'], $GLOBALS['subjectmail'], $bodyMailError, $GLOBALS['charset']));
+                    Bt_doQuery($GLOBALS['db'], $query, array($emailFrom, $userInfo['mail'], $GLOBALS['subjectmail'], $bodyMailError, $GLOBALS['charset']));
                 }
-
-			}
-			//Update emails table
-			$query = "UPDATE " . EMAILS_TABLE 
-				. " SET send_date = CURRENT_TIMESTAMP "
-				. ", email_status = ? "
-				. " WHERE email_id = ? ";
-			$stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->email_id));
+            }
+            //Update emails table
+            $query = "UPDATE " . EMAILS_TABLE
+                . " SET send_date = CURRENT_TIMESTAMP "
+                . ", email_status = ? "
+                . " WHERE email_id = ? ";
+            $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->email_id));
 
             if ($email->message_exchange_id) {
                 //Update message table
@@ -346,13 +346,13 @@ while ($state <> 'END') {
                     . " WHERE message_id = ? ";
                 $stmt = Bt_doQuery($GLOBALS['db'], $query, array($exec_result, $email->message_exchange_id));
             }
-			$currentEmail++;
-			$state = 'SEND_AN_EMAIL';
-		} else {
-			$state = 'END';
-		}
+            $currentEmail++;
+            $state = 'SEND_AN_EMAIL';
+        } else {
+            $state = 'END';
+        }
         break;
-	}
+    }
 }
 
 $emailSent = $totalEmailsToProcess - $err;
@@ -371,4 +371,3 @@ array_map('unlink', glob($_SESSION['config']['tmppath']."/*"));
 
 //unlink($GLOBALS['lckFile']);
 exit($GLOBALS['exitCode']);
-?>
diff --git a/modules/sendmail/messageExchangeList.php b/modules/sendmail/messageExchangeList.php
index 61f32c4da566b091ebd79fd2bac3ba80d1b77dd4..b8d27963e8332ab1db07383068dd3cf9069f2028 100644
--- a/modules/sendmail/messageExchangeList.php
+++ b/modules/sendmail/messageExchangeList.php
@@ -21,18 +21,14 @@ $select["message_exchange"] = [];
     $orderstr = "order by date desc";
 
 //Request
-    $tab=$request->PDOselect($select, $where, [$identifier], $orderstr,$_SESSION['config']['databasetype']);
+    $tab=$request->PDOselect($select, $where, [$identifier], $orderstr, $_SESSION['config']['databasetype']);
 
-if(!empty($tab)){    
-//Result Array
-    for ($i=0;$i<count($tab);$i++)
-    {
-        for ($j=0;$j<count($tab[$i]);$j++)
-        {
-            foreach(array_keys($tab[$i][$j]) as $value)
-            {
-                if($tab[$i][$j][$value]=="message_id")
-                {
+if (!empty($tab)) {
+    //Result Array
+    for ($i=0;$i<count($tab);$i++) {
+        for ($j=0;$j<count($tab[$i]);$j++) {
+            foreach (array_keys($tab[$i][$j]) as $value) {
+                if ($tab[$i][$j][$value]=="message_id") {
                     $tab[$i][$j]["message_id"]  = $tab[$i][$j]['value'];
                     $tab[$i][$j]["label"]       = 'ID';
                     $tab[$i][$j]["size"]        = "1";
@@ -42,8 +38,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = false;
                     $tab[$i][$j]["order"]       = 'message_id';
                 }
-                if($tab[$i][$j][$value]=="date")
-                {
+                if ($tab[$i][$j][$value]=="date") {
                     $tab[$i][$j]["label"]       = _CREATION_DATE;
                     $tab[$i][$j]["size"]        = "9";
                     $tab[$i][$j]["label_align"] = "left";
@@ -52,8 +47,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'date';
                 }
-                if($tab[$i][$j][$value]=="reference")
-                {
+                if ($tab[$i][$j][$value]=="reference") {
                     $tab[$i][$j]["label"]       = _IDENTIFIER;
                     $tab[$i][$j]["size"]        = "9";
                     $tab[$i][$j]["label_align"] = "left";
@@ -62,8 +56,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = false;
                     $tab[$i][$j]["order"]       = 'reference';
                 }
-                if($tab[$i][$j][$value]=="type")
-                {
+                if ($tab[$i][$j][$value]=="type") {
                     $tab[$i][$j]["value"]       = constant('_M2M_'.strtoupper($tab[$i][$j]["value"]));
                     $tab[$i][$j]["label"]       = _TYPE;
                     $tab[$i][$j]["size"]        = "8";
@@ -73,8 +66,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'type';
                 }
-                if($tab[$i][$j][$value]=="operation_date")
-                {
+                if ($tab[$i][$j][$value]=="operation_date") {
                     $tab[$i][$j]["value"]       = $request->dateformat($tab[$i][$j]["value"]);
                     $tab[$i][$j]["label"]       = _OPERATION_DATE;
                     $tab[$i][$j]["size"]        = "9";
@@ -84,8 +76,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'operation_date';
                 }
-                if($tab[$i][$j][$value]=="reception_date")
-                {
+                if ($tab[$i][$j][$value]=="reception_date") {
                     $tab[$i][$j]["value"]       = $request->dateformat($tab[$i][$j]["value"]);
                     $tab[$i][$j]["label"]       = _RECEPTION_DATE;
                     $tab[$i][$j]["size"]        = "9";
@@ -95,8 +86,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'reception_date';
                 }
-                if($tab[$i][$j][$value]=="recipient_org_name")
-                {
+                if ($tab[$i][$j][$value]=="recipient_org_name") {
                     $tab[$i][$j]["value"]       = $tab[$i][$j]["value"] . " (" . $recipient_org_identifier . ")";
                     $tab[$i][$j]["label"]       = _RECIPIENT;
                     $tab[$i][$j]["size"]        = "20";
@@ -106,19 +96,16 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'recipient_org_name';
                 }
-                if($tab[$i][$j][$value]=="sender_org_name")
-                {
+                if ($tab[$i][$j][$value]=="sender_org_name") {
                     $sender_org_name = $tab[$i][$j]["value"];
                     $tab[$i][$j]["show"]        = false;
                 }
-                if($tab[$i][$j][$value]=="recipient_org_identifier")
-                {
+                if ($tab[$i][$j][$value]=="recipient_org_identifier") {
                     $recipient_org_identifier = $tab[$i][$j]["value"];
                     $tab[$i][$j]["show"]      = false;
                 }
-                if($tab[$i][$j][$value]=="account_id")
-                {
-                    $userInfo = \Core\Models\UserModel::getById(['userId' => $tab[$i][$j]["value"]]);
+                if ($tab[$i][$j][$value]=="account_id") {
+                    $userInfo = \User\models\UserModel::getById(['id' => $tab[$i][$j]["value"]]);
                     $tab[$i][$j]["value"]       = $userInfo['firstname'] . " " . $userInfo['lastname'] . " (".$sender_org_name.")";
                     $tab[$i][$j]["label"]       = _SENDER;
                     $tab[$i][$j]["size"]        = "20";
@@ -128,8 +115,7 @@ if(!empty($tab)){
                     $tab[$i][$j]["show"]        = true;
                     $tab[$i][$j]["order"]       = 'account_id';
                 }
-                if($tab[$i][$j][$value]=="status")
-                {
+                if ($tab[$i][$j][$value]=="status") {
                     $tab[$i][$j]["value"] = '<img src="'
                         .$_SESSION['config']['businessappurl'].'static.php?module=sendmail&filename='
                         .$_SESSION['sendmail']['status'][$tab[$i][$j]["value"]]['img'].'" title="'
@@ -152,12 +138,12 @@ if(!empty($tab)){
     $paramsTab['bool_sortColumn']   = false;                                              //Affichage Tri
     $paramsTab['pageTitle']         = '<br><br>'._NUMERIC_PACKAGE_SENT;                   //Titre de la page
     $paramsTab['bool_bigPageTitle'] = false;                                              //Affichage du titre en grand
-    $paramsTab['urlParameters']     = 'identifier='.$identifier."&origin=".$origin.'&display=true'.$parameters;            //Parametres d'url supplementaires   
+    $paramsTab['urlParameters']     = 'identifier='.$identifier."&origin=".$origin.'&display=true'.$parameters;            //Parametres d'url supplementaires
     $paramsTab['listHeight']        = '100%';                                             //Hauteur de la liste
     $paramsTab['listCss']           = $css;                                               //CSS
     
     //Action icons array
-    $paramsTab['actionIcons'] = array();      
+    $paramsTab['actionIcons'] = array();
     $read = array(
         "script"    => "showEmailForm('".$_SESSION['config']['businessappurl']
                                 ."index.php?display=true&module=sendmail&page=sendmail_ajax_content"
@@ -166,7 +152,7 @@ if(!empty($tab)){
         "icon"      =>  'eye',
         "tooltip"   =>  _READ
     );
-    array_push($paramsTab['actionIcons'], $read);  
+    array_push($paramsTab['actionIcons'], $read);
 
     $download = array(
         "script"    => "window.location = 'index.php?display=true&module=sendmail&page=sendmail_ajax_content"
@@ -176,7 +162,7 @@ if(!empty($tab)){
         "tooltip"   =>  _SIMPLE_DOWNLOAD,
         "disabledRules" => "empty(@@filename@@)"
     );
-    array_push($paramsTab['actionIcons'], $download);  
+    array_push($paramsTab['actionIcons'], $download);
 
     //Output
     $status = 0;
diff --git a/modules/sendmail/sendmail_ajax_content.php b/modules/sendmail/sendmail_ajax_content.php
index 8b25746489159f61de0ed0af259825f9e39d8e76..6807144d0d96806aec04b447bda8d1292dc745dd 100755
--- a/modules/sendmail/sendmail_ajax_content.php
+++ b/modules/sendmail/sendmail_ajax_content.php
@@ -43,10 +43,6 @@ require_once 'modules/notifications/notifications_tables_definition.php';
 require_once "modules" . DIRECTORY_SEPARATOR . "sendmail" . DIRECTORY_SEPARATOR
     . "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php";
 require_once 'modules/sendmail/Controllers/SendMessageExchangeController.php';
-require_once "core/Models/DocserverModel.php";
-require_once "core/Models/DocserverTypeModel.php";
-require_once "core/Controllers/DocserverToolsController.php";
-
 
 $core_tools                = new core_tools();
 $request                   = new request();
@@ -57,17 +53,16 @@ $users_tools               = new class_users();
 $sendmail_tools            = new sendmail();
 
 
-if($_SESSION['features']['send_to_contact_with_mandatory_attachment'] == true && !isset($_REQUEST['join_attachment']) && $_REQUEST['action'] == 'send_to_contact_with_mandatory_attachment'){
-
-    $error = $request->wash_html(_PLEASE_CHOOSE_AN_ATTACHMENT,'NONE');
+if ($_SESSION['features']['send_to_contact_with_mandatory_attachment'] == true && !isset($_REQUEST['join_attachment']) && $_REQUEST['action'] == 'send_to_contact_with_mandatory_attachment') {
+    $error = $request->wash_html(_PLEASE_CHOOSE_AN_ATTACHMENT, 'NONE');
     $status = 1;
     echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}";
-    exit ();
-
+    exit();
 }
 
 
-function _parse($text) {
+function _parse($text)
+{
     //...
     $text = str_replace("\r\n", PHP_EOL, $text);
     $text = str_replace("\r", PHP_EOL, $text);
@@ -76,7 +71,8 @@ function _parse($text) {
     $text = str_replace(PHP_EOL, "\\n ", $text);
     return $text;
 }
-function _parse_error($text) {
+function _parse_error($text)
+{
     //...
     $text = str_replace("###", "\\n ", $text);
     return $text;
@@ -117,14 +113,24 @@ if (isset($_REQUEST['coll_id']) && ! empty($_REQUEST['coll_id'])) {
 }
 
 //Keep some origin parameters
-if (isset($_REQUEST['size']) && !empty($_REQUEST['size'])) $parameters .= '&size='.$_REQUEST['size'];
+if (isset($_REQUEST['size']) && !empty($_REQUEST['size'])) {
+    $parameters .= '&size='.$_REQUEST['size'];
+}
 if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
     $parameters .= '&order='.$_REQUEST['order'];
-    if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) $parameters .= '&order_field='.$_REQUEST['order_field'];
+    if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) {
+        $parameters .= '&order_field='.$_REQUEST['order_field'];
+    }
+}
+if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) {
+    $parameters .= '&what='.$_REQUEST['what'];
+}
+if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
+    $parameters .= '&template='.$_REQUEST['template'];
+}
+if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) {
+    $parameters .= '&start='.$_REQUEST['start'];
 }
-if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) $parameters .= '&what='.$_REQUEST['what'];
-if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) $parameters .= '&template='.$_REQUEST['template'];
-if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&start='.$_REQUEST['start'];
 
 //Keep the origin to reload the origin list
 $list_origin = $origin = '';
@@ -160,18 +166,18 @@ switch ($mode) {
         if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) {
             $parameters .= '&id='.$_REQUEST['id'];
         } else {
-            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE');
+            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
             $status = 1;
              //Close the modal
-            $js =  "window.parent.destroyModal('form_email');"; 
+            $js =  "window.parent.destroyModal('form_email');";
             break;
         }
     case 'add':
         if (empty($identifier)) {
-            $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE');
+            $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
             $status = 1;
              //Close the modal
-            $js =  "window.parent.destroyModal('form_email');"; 
+            $js =  "window.parent.destroyModal('form_email');";
         } else {
             //Reset arry of adresses
             unset($_SESSION['adresses']);
@@ -186,9 +192,9 @@ switch ($mode) {
     break;
         
     case 'added':
-        if($formContent == 'messageExchange'){
+        if ($formContent == 'messageExchange') {
             $return = SendMessageExchangeController::createMessageExchange($_REQUEST);
-            if(!empty($return['errors'])){
+            if (!empty($return['errors'])) {
                 $error = implode(", ", $return['errors']);
                 $status = 1;
             }
@@ -200,13 +206,13 @@ switch ($mode) {
                 $userEntitiesMails = $sendmail_tools->checkAttachedEntitiesMails($_SESSION['user']['UserId']);
             }
             if (empty($identifier)) {
-                $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE');
+                $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
                 $status = 1;
-            } else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
-                $error = $request->wash_html(_INCORRECT_SENDER,'NONE');
+            } elseif (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
+                $error = $request->wash_html(_INCORRECT_SENDER, 'NONE');
                 $status = 1;
             } else {
-                if (isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0 ) {
+                if (isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) {
                     if (!empty($_REQUEST['object'])) {
                         
                         //Check adress for to
@@ -216,14 +222,14 @@ switch ($mode) {
                         if (empty($error)) {
                             
                             //Check adress for cc
-                            (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? 
+                            (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)?
                                 $cc =  join(',', $_SESSION['adresses']['cc']) : $cc = '';
                             $error = $sendmail_tools->CheckEmailAdress($cc);
                             
                             if (empty($error)) {
                             
                                 //Check adress for cci
-                                (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? 
+                                (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)?
                                     $cci =  join(',', $_SESSION['adresses']['cci']) : $cci = '';
                                 $error = $sendmail_tools->CheckEmailAdress($cci);
                                 
@@ -233,22 +239,22 @@ switch ($mode) {
                                     $collId = $_REQUEST['coll_id'];
                                     $object = $_REQUEST['object'];
                                     $senderEmail = $_REQUEST['sender_email'];
-                                    (isset($_REQUEST['join_file']) 
+                                    (isset($_REQUEST['join_file'])
                                         && count($_REQUEST['join_file']) > 0
                                     )? $res_master_attached = 'Y' : $res_master_attached = 'N';
                                     //attachment
                                     if (isset($_REQUEST['join_attachment']) && count($_REQUEST['join_attachment']) > 0) {
                                         $attachment_list = join(',', $_REQUEST['join_attachment']);
-                                    } 
+                                    }
                                     //Version attachment
                                     if (isset($_REQUEST['join_version_attachment']) && count($_REQUEST['join_version_attachment']) > 0) {
                                         $attachment_version_list = join(',', $_REQUEST['join_version_attachment']);
-                                    }   
-                                    //version document                              
+                                    }
+                                    //version document
                                     if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) {
                                         $version_list = join(',', $_REQUEST['join_version']);
                                     }
-    								//Notes
+                                    //Notes
                                     if (isset($_REQUEST['notes']) && count($_REQUEST['notes']) > 0) {
                                         $note_list = join(',', $_REQUEST['notes']);
                                     }
@@ -259,23 +265,23 @@ switch ($mode) {
                                     if ($isHtml == 'Y') {
                                         $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']);
                                     } else {
-                                         $body = $_REQUEST['body_from_raw'];
+                                        $body = $_REQUEST['body_from_raw'];
                                     }
                                     
                                     //Status
                                     if ($_REQUEST['for'] == 'save') {
                                         $email_status = 'D';
-                                    } else if ($_REQUEST['for'] == 'send'){
+                                    } elseif ($_REQUEST['for'] == 'send') {
                                         $email_status = 'W';
                                     }
                               
-                                    //Query                 
+                                    //Query
                                     $stmt = $db->query(
                                         "INSERT INTO " . EMAILS_TABLE . "(coll_id, res_id, user_id, to_list, cc_list,
                                         cci_list, email_object, email_body, is_res_master_attached, res_version_id_list, 
                                         res_attachment_id_list, res_version_att_id_list,note_id_list, is_html, email_status, creation_date, sender_email) 
                                         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)",
-                                        array($collId, $identifier, $userId, $to, $cc, $cci, $object, $body, $res_master_attached, 
+                                        array($collId, $identifier, $userId, $to, $cc, $cci, $object, $body, $res_master_attached,
                                         $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml, $email_status, $senderEmail)
                                     );
                                    
@@ -292,9 +298,9 @@ switch ($mode) {
                                                 . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                                                 $_SESSION['config']['databasetype'], 'sendmail'
                                             );
-                                        } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
+                                        } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
                                             $hist->add(
-                                                $view, $identifier, "UP", 'resup',  _EMAIL_ADDED . _ON_DOC_NUM
+                                                $view, $identifier, "UP", 'resup', _EMAIL_ADDED . _ON_DOC_NUM
                                                 . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                                                 $_SESSION['config']['databasetype'], 'sendmail'
                                             );
@@ -308,7 +314,6 @@ switch ($mode) {
                                     
                                     //Reload and show message
                                     $js =  $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_ADDED."';";
-                
                                 } else {
                                     $status = 1;
                                 }
@@ -319,11 +324,11 @@ switch ($mode) {
                             $status = 1;
                         }
                     } else {
-                        $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE');
+                        $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!', 'NONE');
                         $status = 1;
                     }
                 } else {
-                    $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE');
+                    $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!', 'NONE');
                     $status = 1;
                 }
             }
@@ -340,17 +345,17 @@ switch ($mode) {
             }
             //Res ID
             if (empty($identifier)) {
-                $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!','NONE');
+                $error = $request->wash_html(_IDENTIFIER.' '._IS_EMPTY.'!', 'NONE');
                 $status = 1;
-            } else if (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
-                $error = $request->wash_html(_INCORRECT_SENDER,'NONE');
+            } elseif (!in_array($_REQUEST['sender_email'], array_keys($userEntitiesMails)) && $core_tools->test_service('use_mail_services', 'sendmail', false)) {
+                $error = $request->wash_html(_INCORRECT_SENDER, 'NONE');
                 $status = 1;
             } else {
                 if ((isset($_SESSION['adresses']['to']) && count($_SESSION['adresses']['to']) > 0) || $_REQUEST['for'] == 'save') {
                     if (!empty($_REQUEST['object']) || $_REQUEST['for'] == 'save') {
                         
                         //Check adress for to
-                        if(!empty($_SESSION['adresses']['to'])){
+                        if (!empty($_SESSION['adresses']['to'])) {
                             $to =  join(',', $_SESSION['adresses']['to']);
                             $error = $sendmail_tools->CheckEmailAdress($to);
                         }
@@ -358,14 +363,14 @@ switch ($mode) {
                         if (empty($error)) {
                             
                             //Check adress for cc
-                            (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)? 
+                            (isset($_SESSION['adresses']['cc']) && count($_SESSION['adresses']['cc']) > 0)?
                                 $cc =  join(',', $_SESSION['adresses']['cc']) : $cc = '';
                             $error = $sendmail_tools->CheckEmailAdress($cc);
                             
                             if (empty($error)) {
                             
                                 //Check adress for cci
-                                (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)? 
+                                (isset($_SESSION['adresses']['cci']) && count($_SESSION['adresses']['cci']) > 0)?
                                     $cci =  join(',', $_SESSION['adresses']['cci']) : $cci = '';
                                 $error = $sendmail_tools->CheckEmailAdress($cci);
                                 
@@ -375,7 +380,7 @@ switch ($mode) {
                                     $collId = $_REQUEST['coll_id'];
                                     $object = $_REQUEST['object'];
                                     $senderEmail = $_REQUEST['sender_email'];
-                                    (isset($_REQUEST['join_file']) 
+                                    (isset($_REQUEST['join_file'])
                                         && count($_REQUEST['join_file']) > 0
                                     )? $res_master_attached = 'Y' : $res_master_attached = 'N';
                                     if (isset($_REQUEST['join_version']) && count($_REQUEST['join_version']) > 0) {
@@ -397,16 +402,16 @@ switch ($mode) {
                                     if ($isHtml == 'Y') {
                                         $body = $sendmail_tools->cleanHtml($_REQUEST['body_from_html']);
                                     } else {
-                                         $body = $_REQUEST['body_from_raw'];
+                                        $body = $_REQUEST['body_from_raw'];
                                     }
                                     //Status
                                     if ($_REQUEST['for'] == 'save') {
                                         $email_status = 'D';
-                                    } else if ($_REQUEST['for'] == 'send'){
+                                    } elseif ($_REQUEST['for'] == 'send') {
                                         $email_status = 'W';
                                     }
                                     
-                                    //Query                 
+                                    //Query
                                     $db->query(
                                         "UPDATE " . EMAILS_TABLE . " SET to_list = ?, cc_list = ?, cci_list = ?, email_object = ?, 
 												email_body = ?, is_res_master_attached = ?, res_version_id_list = ?, 
@@ -414,7 +419,7 @@ switch ($mode) {
 												is_html = ?, email_status = ?, sender_email = ?, send_date = ? where email_id = ? "
                                             ." and res_id =  ? and user_id = ?",
                                             array($to, $cc, $cci, $object, $body, $res_master_attached, $version_list, $attachment_list, $attachment_version_list, $note_list, $isHtml,
-												$email_status, $senderEmail, NULL, $id, $identifier, $userId )
+                                                $email_status, $senderEmail, null, $id, $identifier, $userId )
                                     );
                                     
                                     //History
@@ -426,9 +431,9 @@ switch ($mode) {
                                                 . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                                                 $_SESSION['config']['databasetype'], 'sendmail'
                                             );
-                                        } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
+                                        } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
                                             $hist->add(
-                                                $view, $identifier, "UP", 'resup',  _EMAIL_UPDATED . _ON_DOC_NUM
+                                                $view, $identifier, "UP", 'resup', _EMAIL_UPDATED . _ON_DOC_NUM
                                                 . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                                                 $_SESSION['config']['databasetype'], 'sendmail'
                                             );
@@ -441,7 +446,7 @@ switch ($mode) {
                                     }
                                     
                                     //Reload and show message
-                                    $js =  $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_UPDATED."';"; 
+                                    $js =  $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_UPDATED."';";
                                 } else {
                                     $status = 1;
                                 }
@@ -452,20 +457,19 @@ switch ($mode) {
                             $status = 1;
                         }
                     } else {
-                        $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!','NONE');
+                        $error = $request->wash_html(_EMAIL_OBJECT.' '._IS_EMPTY.'!', 'NONE');
                         $status = 1;
                     }
                 } else {
-                    $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!','NONE');
+                    $error = $request->wash_html(_SEND_TO.' '._IS_EMPTY.'!', 'NONE');
                     $status = 1;
                 }
             }
-            
         } else {
-            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE');
+            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
             $status = 1;
              //Close the modal
-            $js =  "window.parent.destroyModal('form_email');"; 
+            $js =  "window.parent.destroyModal('form_email');";
         }
     break;
     
@@ -480,7 +484,7 @@ switch ($mode) {
             $request->query("delete from " . EMAILS_TABLE . " where email_id = " . $id);
             
             //Delete email from stack too ???
-            $request->query("delete from " . _NOTIF_EVENT_STACK_TABLE_NAME 
+            $request->query("delete from " . _NOTIF_EVENT_STACK_TABLE_NAME
                 . " where table_name = '" . EMAILS_TABLE . "' and record_id = '" . $id . "'");
             
             //History
@@ -492,16 +496,16 @@ switch ($mode) {
                         . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                         $_SESSION['config']['databasetype'], 'sendmail'
                     );
-                } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
+                } elseif (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
                     $hist->add(
-                        $view, $identifier, "UP", 'resup',  _EMAIL_REMOVED . _ON_DOC_NUM
+                        $view, $identifier, "UP", 'resup', _EMAIL_REMOVED . _ON_DOC_NUM
                         . $identifier . ' (' . $id . ') : "' . $request->cut_string($object, 254) .'"',
                         $_SESSION['config']['databasetype'], 'sendmail'
                     );
                 }
 
                 $hist->add(
-                    EMAILS_TABLE, $id, "DEL", 'maildel', _EMAIL_REMOVED . ' (' . $id . ') : "' 
+                    EMAILS_TABLE, $id, "DEL", 'maildel', _EMAIL_REMOVED . ' (' . $id . ') : "'
                     . $request->cut_string($object, 254) .'"',
                     $_SESSION['config']['databasetype'], 'sendmail'
                 );
@@ -509,12 +513,11 @@ switch ($mode) {
             
             //Reload and show message
             $js =  $list_origin."window.parent.top.$('main_info').innerHTML = '"._EMAIL_REMOVED."';";
-            
         } else {
-            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!','NONE');
+            $error = $request->wash_html(_ID.' '._IS_EMPTY.'!', 'NONE');
             $status = 1;
             //Close the modal
-            $js =  "window.parent.destroyModal('form_email');"; 
+            $js =  "window.parent.destroyModal('form_email');";
         }
     break;
     case 'adress':
@@ -523,26 +526,29 @@ switch ($mode) {
                 //Clean up email
                 $email = trim($_REQUEST['email']);
                 //Reset session adresses if necessary
-                if (!isset($_SESSION['adresses'][$_REQUEST['field']])) $_SESSION['adresses'][$_REQUEST['field']] = array();
+                if (!isset($_SESSION['adresses'][$_REQUEST['field']])) {
+                    $_SESSION['adresses'][$_REQUEST['field']] = array();
+                }
                 //For ADD
                 if ($_REQUEST['for'] == 'add') {
                     array_push($_SESSION['adresses'][$_REQUEST['field']], $email);
                 //For DEL
-                } else  if ($_REQUEST['for'] == 'del') {
+                } elseif ($_REQUEST['for'] == 'del') {
                     //unset adress in array
                     unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]);
                     //If no adresse for field, unset the entire sub-array
-                    if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) 
+                    if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) {
                         unset($_SESSION['adresses'][$_REQUEST['field']]);
+                    }
                 }
                 //Get content
                 $content = $sendmail_tools->updateAdressInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']);
             } else {
-                $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!','NONE');
+                $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!', 'NONE');
                 $status = 1;
             }
         } else {
-            $error = $request->wash_html(_UNKNOW_ERROR.'!','NONE');
+            $error = $request->wash_html(_UNKNOW_ERROR.'!', 'NONE');
             $status = 1;
         }
     break;
@@ -550,28 +556,30 @@ switch ($mode) {
     if (isset($_REQUEST['for']) && isset($_REQUEST['field']) && isset($_REQUEST['contactAddress'])) {
         if (isset($_REQUEST['contactAddress']) && !empty($_REQUEST['contactAddress'])) {
             $contactAddress = trim($_REQUEST['contactAddress']);
-            if (!isset($_SESSION['adresses'][$_REQUEST['field']])) $_SESSION['adresses'][$_REQUEST['field']] = array();
+            if (!isset($_SESSION['adresses'][$_REQUEST['field']])) {
+                $_SESSION['adresses'][$_REQUEST['field']] = array();
+            }
 
             if ($_REQUEST['for'] == 'add') {
                 $contactLabel         = \Contact\models\ContactModel::getContactFullLabel(['addressId' => $contactAddress]);
                 $contactInfo          = \Contact\models\ContactModel::getFullAddressById(['addressId' => $contactAddress]);
                 $contactCommunication = \Contact\models\ContactModel::getContactCommunication(['contactId' => $contactInfo[0]['contact_id']]);
                 $_SESSION['adresses'][$_REQUEST['field']][$contactAddress] = $contactLabel.'. ('._COMMUNICATION_TYPE.' : '.$contactCommunication['value'].'))';
-
-            } else  if ($_REQUEST['for'] == 'del') {
+            } elseif ($_REQUEST['for'] == 'del') {
                 unset($_SESSION['adresses'][$_REQUEST['field']][$_REQUEST['index']]);
                 //If no adresse for field, unset the entire sub-array
-                if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) 
+                if (count($_SESSION['adresses'][$_REQUEST['field']]) == 0) {
                     unset($_SESSION['adresses'][$_REQUEST['field']]);
+                }
             }
 
             $content = $sendmail_tools->updateContactInputField($path_to_script, $_SESSION['adresses'], $_REQUEST['field']);
         } else {
-            $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!','NONE');
+            $error = $request->wash_html(_EMAIL.' '._IS_EMPTY.'!', 'NONE');
             $status = 1;
         }
     } else {
-        $error = $request->wash_html(_UNKNOW_ERROR.'!','NONE');
+        $error = $request->wash_html(_UNKNOW_ERROR.'!', 'NONE');
         $status = 1;
     }
     break;
@@ -580,21 +588,22 @@ switch ($mode) {
         $RequestSeda         = new RequestSeda();
         $messageExchangeData = $RequestSeda->getMessageByIdentifierAndResId(['message_id' => $_GET['id'], 'res_id_master' => $_GET['identifier']]);
 
-        $docserver     = \Core\Models\DocserverModel::getById(['docserver_id' => $messageExchangeData->docserver_id]);
-        $docserverType = \Core\Models\DocserverTypeModel::getById(['docserver_type_id' => $docserver[0]['docserver_type_id']]);
+        $docserver     = \Docserver\models\DocserverModel::getById(['id' => $messageExchangeData->docserver_id]);
+        $docserverType = \Docserver\models\DocserverTypeModel::getById(['id' => $docserver[0]['docserver_type_id']]);
 
         $pathDirectory = str_replace('#', DIRECTORY_SEPARATOR, $messageExchangeData->path);
         $filePath      = $docserver[0]['path_template'] . $pathDirectory . $messageExchangeData->filename;
-        $fingerprint   = \Core\Controllers\DocserverToolsController::doFingerprint([
-            'path'            => $filePath,
-            'fingerprintMode' => $docserverType[0]['fingerprint_mode'],
+        $fingerprint   = \SrcCore\controllers\StoreController::getFingerPrint([
+            'filePath' => $filePath,
+            'mode'     => $docserverType[0]['fingerprint_mode'],
         ]);
 
-        if($fingerprint['fingerprint'] != $messageExchangeData->fingerprint){
-            echo _PB_WITH_FINGERPRINT_OF_DOCUMENT;exit;
+        if ($fingerprint['fingerprint'] != $messageExchangeData->fingerprint) {
+            echo _PB_WITH_FINGERPRINT_OF_DOCUMENT;
+            exit;
         }
 
-        if(file_exists($filePath)){
+        if (file_exists($filePath)) {
             header('Pragma: public');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@@ -611,5 +620,4 @@ switch ($mode) {
         exit();
 }
 echo "{status : " . $status . ", content : '" . addslashes(_parse($content)) . "', error : '" . addslashes(_parse_error($error)) . "', exec_js : '".addslashes($js)."'}";
-exit ();
-?>
+exit();
diff --git a/phpunit.xml b/phpunit.xml
index c008de4e66c1813d24b45002ac148351fac02f26..281e809637d11d65b3a08fbb1b42bafa9a373f37 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -17,6 +17,7 @@
             <file>core/Test/ResControllerTest.php</file>
             <file>core/Test/StatusControllerTest.php</file>
             <file>core/Test/UserControllerTest.php</file>
+            <!-- <file>core/Test/GroupControllerTest.php</file> -->
             <file>modules/convert/Test/ProcessConvertTest.php</file>
             <file>modules/convert/Test/ProcessFulltextTest.php</file>
             <file>modules/convert/Test/ProcessManageConvertTest.php</file>