diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f0130dd5f5758a126afad596d801b51266d2bf4..483ef4945b1f047d39ca178534788761c743eadf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,21 @@ Toutes les modifications apportées au projet seront documentées dans ce fichie
 Le format est basé sur le modèle [Keep a Changelog](http://keepachangelog.com/)
 et adhère aux principes du [Semantic Versioning](http://semver.org/).
 
+## [3.1.22] - 2024-07-01
+### Modifications
+- [OAUTH] Dans le cas de la scrutation de mails via Oauth2, les informations du mail (De, Répondre à, Date, Objet) n'étaient pas reprises dans le contenu du document généré
+- [OAUTH] Ajout du mail entre parenthèses après les informations From, To et ReplyTo de la scrutaiton de mails
+  [OAUTH] Si le contenu du mail n'est pas en HTML, on n'ajoute pas les informations From, ReplyTo et To au contenu du document affiché dans la visionneuse
+- [OAUTH] Si le sujet du mail possède des accents on les enlève pour ne pas "casser" l'affichage
+
+### Corrections
+- L'ID de la métadonnée "Date de clôture" avait été oublié dans le modèle Bancontenu.php au moment de la clôture
+- L'affichage des commentaires dans le flux d'origine provoque une erreur si aucun commentaire n'est disponible
+- Le tri sur la colonne "Date de réception" des bannettes de l'agent ne fonctionnait pas correctement, le tri se faisait sur le jour et non pas sur l'ensemble de la date
+- La recherche par nom d'organisme et nom de contact pose souci si le champ possède des quote ou simple quote (' ou ’)
+- Dans le cas de la scrutation de mails en OAUTH2, les champs De, A, Objet, Date n'étaient pas repris dans le document généré
+- Au moment de clore et répondre, il ne faut pas répercuter la date de clôture sinon cela pose soucis.
+
 ## [3.1.21] - 2024-05-06
 ### Ajouts
 - Ajout d'un champ "Complément d'adresse 2" pour les contacts et les organismes
diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php
index ee9d6d517cff7c919e3f17792029131eeb9e595f..6755644d9b1e11a17c0389b233d59e1a23f84471 100755
--- a/app/Config/bootstrap.php
+++ b/app/Config/bootstrap.php
@@ -569,6 +569,7 @@ function noaccents_upper($string) {
 function js_escape($value) {
     $value = str_replace('"', '\\"', $value);
     $value = str_replace(array("\r\n", "\r", "\n"), "\\n", $value);
+    $value = str_replace("’", "\’", $value);
     return $value;
 }
 
diff --git a/app/Config/version b/app/Config/version
index 5c5bdc27dfc8b77517c585036673f5686bd24c6e..be706e820457ae43065abc11f01a13b65eac0774 100755
--- a/app/Config/version
+++ b/app/Config/version
@@ -1 +1 @@
-3.1.21
+3.1.22
diff --git a/app/Config/webgfc.inc.default b/app/Config/webgfc.inc.default
index 8028005d7c7cbded4349c221b0c4601c4953845c..5023417230d755cbd56a53f5d81af7e1efd45525 100755
--- a/app/Config/webgfc.inc.default
+++ b/app/Config/webgfc.inc.default
@@ -549,8 +549,9 @@ Configure::write('Ldap.AddTargetDnBaseDn', false);
 Configure::write('AppPathFix', '/var/www/webgfc');
 
 // Paramètre pour utiliser iconv vers du utf8 si souci au moment de la scrutation de mails
-// @defautl: false
 // esterel: true
+// esterel: true
+// ollioules: true
 Configure::write('Wkhtmltopdf.EncodingIssue', false);
 
 // Paramètre pour déterminer si on recharge la page du flux une fois l'envoi en copie réalisé
diff --git a/app/Model/Bancontenu.php b/app/Model/Bancontenu.php
index b95be10a7082804b6c5bb2fc4dd3ad0f677f0edc..aa141328d564c0ae3ffb415152f3a0c2ee1c03a8 100755
--- a/app/Model/Bancontenu.php
+++ b/app/Model/Bancontenu.php
@@ -218,7 +218,7 @@ class Bancontenu extends AppModel {
 					'CourrierMetadonnee' => [
 						'valeur' => date('d/m/Y'),
 						'courrier_id' => $courrier_id,
-						'metadonnee_id' => Configure::read('Metadonnee.DateCloture')
+						'metadonnee_id' => '-1'
 					]
 				];
 				$retval = $this->Courrier->Metadonnee->CourrierMetadonnee->save($courrierMetadonnee);
diff --git a/app/Model/Courrier.php b/app/Model/Courrier.php
index 33040f8938eefea54378ada8118b16c4b095c509..a3cbf9f7fb3ef0ee11d66e3cad2670ba0c99bde2 100755
--- a/app/Model/Courrier.php
+++ b/app/Model/Courrier.php
@@ -735,15 +735,17 @@ class Courrier extends AppModel {
 		);
 		foreach($allmetas as $meta ) {
 			if( $meta['Metadonnee']['isrepercutable'] ) {
-				$newCourrierMetadonnee = array(
-					'CourrierMetadonnee' => array(
-						'courrier_id' => $this->id,
-						'metadonnee_id' => $meta['Metadonnee']['id'] ,
-						'valeur' => $meta['CourrierMetadonnee']['valeur']
-					)
-				);
-				$this->CourrierMetadonnee->create($newCourrierMetadonnee);
-				$this->CourrierMetadonnee->save();
+				if($meta['Metadonnee']['id'] != '-1') {
+					$newCourrierMetadonnee = array(
+						'CourrierMetadonnee' => array(
+							'courrier_id' => $this->id,
+							'metadonnee_id' => $meta['Metadonnee']['id'],
+							'valeur' => $meta['CourrierMetadonnee']['valeur']
+						)
+					);
+					$this->CourrierMetadonnee->create($newCourrierMetadonnee);
+					$this->CourrierMetadonnee->save();
+				}
 			}
 		}
 
@@ -3649,6 +3651,15 @@ class Courrier extends AppModel {
 				}
 			}
 
+			if( isset($filename->flags) ){
+				/** @var \Webklex\PHPIMAP\Message $filename */
+				$fromForFile = '<b>De: </b>' . $filename->getFrom()[0]->personal . ' ('. $filename->getFrom()[0]->mail . ')' . '</br>';
+				$replyToForFile = '<b>Répondre à: </b>' . $filename->getReplyTo()[0]->personal . ' ('. $filename->getReplyTo()[0]->mail . ')' . '</br>';
+				$toForFile = '<b>A: </b>' . $filename->getTo()[0]->personal . ' ('. $filename->getTo()[0]->mail . ')' .' </br>';
+				$objectForFile = '<b>Objet:</b> ' . replace_accents($filename->getSubject()) . '</br>';
+				$dateForFile = '<b>Date:</b> ' . date('d/m/Y à H:i:s', strtotime($filename->getDate())) . '</br>';
+			}
+
 			$bodyFrom = $from;
 			$bodyFrom .= $replyTo;
 			$bodyFrom .= $to;
@@ -3833,11 +3844,11 @@ class Courrier extends AppModel {
 				$pjContent = [];
 				$nbPjs = $filename->getAttachments()->count();
 				$bodyPj = "\n " . "Nombre de pjs: " . $nbPjs;
-				$bodyFrom = 'De: '.$filename->getFrom()[0]->full;
-				$bodyFrom .= 'Répondre à: '.$filename->getReplyTo()[0]->full;
-				$bodyFrom .= 'A: '.$filename->getTo()[0]->full;
-				$bodyFrom .= 'Objet: '.$filename->getSubject();
-				$bodyFrom .= 'Le: '.$filename->getDate();
+				$bodyFrom = 'De: '.$filename->getFrom()[0]->personal . ' ('. $filename->getFrom()[0]->mail . ')' . '<br />';
+				$bodyFrom .= 'Répondre à: '.$filename->getReplyTo()[0]->personal . ' ('. $filename->getReplyTo()[0]->mail . ')' . '<br />';
+				$bodyFrom .= 'A: '.$filename->getTo()[0]->personal . ' ('. $filename->getTo()[0]->mail . ')' . '<br />';
+				$bodyFrom .= 'Objet: '.$filename->getSubject() . '<br />';
+				$bodyFrom .= 'Le : ' . date('d/m/Y à H:i:s', strtotime($filename->getDate())) . '</br>';
 				foreach( $aAttachment as $i => $attachment ) {
 					/** @var \Webklex\PHPIMAP\Attachment $attachment */
 					$pjContent[$i] = $attachment->getAttributes();
@@ -3943,6 +3954,11 @@ class Courrier extends AppModel {
 					if (!empty(base64_decode($objet, true))) {
 						$objet = base64_decode($objet);
 					}
+
+					if ($objet !== $filename->getTextbody()) {
+						$objet = $bodyFromForFile . '<br />' . $objet;
+					}
+
 					$this->_genFileAssocMailWithoutpj($filename->subject, $objet, $courrierId, $conn, true, $pjContent, true);
 					if ($filename->getAttachments()->count() != 0) {
 						$this->_oauthGenFileAssocMail($pjContent, $courrierId, $conn);
diff --git a/app/Model/Recherche.php b/app/Model/Recherche.php
index 3f69b7781e9d0f4b02efea30bae26605e24484e1..8f7dc9f1a1237787044b6b24c5f523e54e4d3143 100755
--- a/app/Model/Recherche.php
+++ b/app/Model/Recherche.php
@@ -555,7 +555,7 @@ class Recherche extends AppModel {
 
 		//critères Organisme
 		if (!empty($params['Recherche']['organismename'])) {
-			$conditions[] = array('Organisme.name ILIKE' => $Courrier->Organisme->wildcard("*{$params['Recherche']['organismename']}*"));
+			$conditions[] = 'NOACCENTS_UPPER(Organisme.name) LIKE \'' . $this->wildcard('%' . noaccents_upper( $params['Recherche']['organismename'] ) . '%') . '\'';
 		} else if (!empty($params['Organisme']['Organisme'])) {
 			$organisme_conditions = array();
 			foreach ($params['Organisme']['Organisme'] as $organisme_id) {
@@ -572,7 +572,7 @@ class Recherche extends AppModel {
 
 		//critères Contact
 		if (!empty($params['Recherche']['contactname'])) {
-			$conditions[] = array('Contact.name ILIKE' => $Courrier->Contact->wildcard("*{$params['Recherche']['contactname']}*"));
+			$conditions[] = 'NOACCENTS_UPPER(Contact.name) ILIKE \'' . $this->wildcard('%' . str_replace("'", "'", $params['Recherche']['contactname'] ) . '%') . '\'';
 		} else if (!empty($params['Contact']['Contact'])) {
 			$contact_conditions = array();
 			foreach ($params['Contact']['Contact'] as $contact_id) {
diff --git a/app/Model/User.php b/app/Model/User.php
index a9217e61c18d67f120d88ec91a751adddfbe972b..4e188be69686a391ea8e22f994a4ebe6595a0bfc 100755
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -1683,6 +1683,7 @@ class User extends AppModel {
 				$this->create();
 				$username = $data['User']['username'];
 				$userDATA['User'] = $data['User'];
+				$userDATA['User']['mail'] = trim($data['User']['mail']);
 				$userDATA['User']['username'] = $username;
 				$userDATA['User']['password'] = Security::hash($username, 'sha256', true);
 				$userDATA['User']['desktop_id'] = $desktopId;
diff --git a/app/View/Courriers/get_parent.ctp b/app/View/Courriers/get_parent.ctp
index 51faf7b8dd1fd571d547bfd2bb3fa27f59c66c9e..520ab36c888ce4553a2d00362944ad68c759ecb6 100755
--- a/app/View/Courriers/get_parent.ctp
+++ b/app/View/Courriers/get_parent.ctp
@@ -96,7 +96,11 @@ $priority = array(
 </dl>
 <legend class="panel-title"><?php echo __d('courrier', 'Commentaires'); ?></legend>
 <dl>
-	<?php echo $this->GFCComment->drawComments($comments); ?>
+	<?php
+		if( isset($comments) && !empty($comments) ) {
+			echo $this->GFCComment->drawComments($comments);
+		}
+	?>
 </dl>
 <legend class="panel-title"><?php echo __d('document', 'Document.main_doc'); ?></legend>
 <?php
diff --git a/app/View/Courriers/historique_global.ctp b/app/View/Courriers/historique_global.ctp
index e69f4fd20996dab2afa17593cb559919296bd644..83f330dd9131beb5f2304200152795691b223a04 100755
--- a/app/View/Courriers/historique_global.ctp
+++ b/app/View/Courriers/historique_global.ctp
@@ -126,7 +126,7 @@ asort($civilite);
 											echo $this->Html->link($img, '/courriers/historiqueGlobal/' . $courrier['Courrier']['id'] . "/true", array('escape' => false, 'class' => 'print btn btn-info-webgfc btn-secondary'));
 											?>
 										<?php else:?>
-											<a href="#" title="<?php echo  __d('default', 'Button.send'); ?>"  alt="<?php echo  __d('default', 'Button.send'); ?>" class="sendcpy btn btn-info-webgfc btn-secondary"><i class="fa fa-paper-plane" aria-hidden="true"></i></a>
+											<a href="#" title="<?php echo  __d('default', 'Button.sendcpy'); ?>"  alt="<?php echo  __d('default', 'Button.sendcpy'); ?>" class="sendcpy btn btn-info-webgfc btn-secondary"><i class="fa fa-paste" aria-hidden="true"></i></a>
 										<?php endif;?>
 										<?php /*if( $connecteurgedIsActif ) :?>
 											<a href="#" title="<?php echo  __d('default', 'Button.export'); ?>"  alt="<?php echo  __d('default', 'Button.export'); ?>" class="sendtoged btn btn-info-webgfc btn-secondary"><i class="fa fa-share-square-o" aria-hidden="true"></i></a>
diff --git a/app/View/Helper/BannetteHelper.php b/app/View/Helper/BannetteHelper.php
index ed740574766c936ed717fe6f89a2e8430089d7d1..3bb3b4712bc60fc5192884d3cafcff103a204c42 100755
--- a/app/View/Helper/BannetteHelper.php
+++ b/app/View/Helper/BannetteHelper.php
@@ -865,7 +865,7 @@ class BannetteHelper extends Helper {
                     } else if ($key == "contact") {
                         $ths .= $this->Html->tag('th', $value, array('class' => 'thContact', 'data-sortable' => 'true', 'data-field' => 'contact', 'data-visible' => 'true'));
                     } else if ($key == "date") {
-                        $ths .= $this->Html->tag('th', $value, array('class' => 'thDate', 'data-order' => 'desc', 'data-sortable' => 'true', 'data-field' => 'date', 'data-visible' => 'true'));
+						$ths .= $this->Html->tag('th', $value, array('class' => 'thDate', 'data-sorter' => 'dateSort', 'data-order' => 'desc', 'data-sortable' => 'true', 'data-field' => 'date', 'data-visible' => 'true'));
                     } else if ($key == "typesoustype") {
                         $ths .= $this->Html->tag('th', $value, array('class' => 'thTypesoustype', 'data-field' => 'typesoustype', 'data-sortable' => 'true', 'data-switchable' => 'false'));
                     } else if ($key == "bureau") {
diff --git a/app/webroot/js/bannette.js b/app/webroot/js/bannette.js
index 237fe294869659eef4055a55cd3c86fff2e7bb0e..770c1233f7a2002b21cf9c663a696b04d819869e 100755
--- a/app/webroot/js/bannette.js
+++ b/app/webroot/js/bannette.js
@@ -234,4 +234,19 @@ function isButtonAiguillage(nbInCircuit) {
     }
 }
 
-
+function dateSort(a, b) {
+	a = a.split("/").reverse().join("/");
+	b = b.split("/").reverse().join("/");
+	a = new Date(a);
+	b = new Date(b);
+	console.log(a);
+	if(a < b) {
+		return 1;
+	}
+	else if( a > b) {
+		return -1;
+	}
+	else {
+		return 0;
+	}
+}