From 812e5a3b72b4c7aeaa6a5e6c0c2681a3706012c0 Mon Sep 17 00:00:00 2001 From: alsoft10 Date: Mon, 13 Dec 2021 16:02:27 +0530 Subject: [PATCH 1/3] Feature update : #19569 --- .../class/emailcollector.class.php | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index f4341109000..7e97cf9b110 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2067,6 +2067,14 @@ class EmailCollector extends CommonObject $errorforactions++; $this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error); $this->errors = $tickettocreate->errors; + } else { + if($attachments) { + $destdir = $conf->ticket->dir_output.'/'.$tickettocreate->ref; + if (!dol_is_dir($destdir)) { + dol_mkdir($destdir); + $this->getmsg($connection, $imapemail, $destdir); + } + } } } } @@ -2290,7 +2298,7 @@ class EmailCollector extends CommonObject * @param string $mid prefix * @return array Array with number and object */ - private function getmsg($mbox, $mid) + private function getmsg($mbox, $mid, $destdir='') { // input $mbox = IMAP stream, $mid = message id // output all the following: @@ -2311,7 +2319,7 @@ class EmailCollector extends CommonObject } else { // multipart: cycle through each part foreach ($s->parts as $partno0 => $p) { - $this->getpart($mbox, $mid, $p, $partno0 + 1); + $this->getpart($mbox, $mid, $p, $partno0 + 1, $destdir); } } } @@ -2340,7 +2348,7 @@ class EmailCollector extends CommonObject * @param string $partno Partno * @return void */ - private function getpart($mbox, $mid, $p, $partno) + private function getpart($mbox, $mid, $p, $partno, $destdir='') { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg, $plainmsg, $charset, $attachments; @@ -2378,6 +2386,39 @@ class EmailCollector extends CommonObject $filename = ($params['filename']) ? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() $attachments[$filename] = $data; // this is a problem if two files have same name + + // Get file name (with extension) + $file_name_complete = $params['filename']; + + + $destination = $destdir.'/'.$file_name_complete; + + // Extract file extension + $extension = pathinfo($file_name_complete, PATHINFO_EXTENSION); + + // Extract file name without extension + $file_name = pathinfo($file_name_complete, PATHINFO_FILENAME); + + // Save an original file name variable to track while renaming if file already exists + $file_name_original = $file_name; + + // Increment file name by 1 + $num = 1; + + /** + * Check if the same file name already exists in the upload folder, + * append increment number to the original filename + */ + while (file_exists($destdir."/" . $file_name . "." . $extension)) { + $file_name = (string) $file_name_original . ' (' . $num . ')'; + $file_name_complete = $file_name . "." . $extension; + $destination = $destdir.'/'.$file_name_complete; + $num++; + } + + + file_put_contents($destination, $data); + } // TEXT From 5dd0aa05495a500582ca7153c90c360948cc197c Mon Sep 17 00:00:00 2001 From: alsoft10 Date: Thu, 23 Dec 2021 18:14:12 +0530 Subject: [PATCH 2/3] Feature Update #19678 --- htdocs/main.inc.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 9753f4b3d83..be964015f75 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1744,6 +1744,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } } + + //If you want to load custom javascript file from your selected theme directory + if (!empty($conf->global->ALLOW_THEME_JS)) { + $theme_js = dol_buildpath('/theme/'.$conf->theme.'/'.$conf->theme.'.js', 0); + if (file_exists($theme_js)) { + print ''."\n"; + } + } if (!empty($head)) { print $head."\n"; From a2cb020394be4a2d2d955359f07ac8170cfd88ff Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 23 Dec 2021 12:45:26 +0000 Subject: [PATCH 3/3] Fixing style errors. --- .../emailcollector/class/emailcollector.class.php | 13 ++++++------- htdocs/main.inc.php | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 7e97cf9b110..243b93a55c3 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2068,7 +2068,7 @@ class EmailCollector extends CommonObject $this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error); $this->errors = $tickettocreate->errors; } else { - if($attachments) { + if ($attachments) { $destdir = $conf->ticket->dir_output.'/'.$tickettocreate->ref; if (!dol_is_dir($destdir)) { dol_mkdir($destdir); @@ -2298,7 +2298,7 @@ class EmailCollector extends CommonObject * @param string $mid prefix * @return array Array with number and object */ - private function getmsg($mbox, $mid, $destdir='') + private function getmsg($mbox, $mid, $destdir = '') { // input $mbox = IMAP stream, $mid = message id // output all the following: @@ -2348,7 +2348,7 @@ class EmailCollector extends CommonObject * @param string $partno Partno * @return void */ - private function getpart($mbox, $mid, $p, $partno, $destdir='') + private function getpart($mbox, $mid, $p, $partno, $destdir = '') { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg, $plainmsg, $charset, $attachments; @@ -2386,11 +2386,11 @@ class EmailCollector extends CommonObject $filename = ($params['filename']) ? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() $attachments[$filename] = $data; // this is a problem if two files have same name - + // Get file name (with extension) $file_name_complete = $params['filename']; - + $destination = $destdir.'/'.$file_name_complete; // Extract file extension @@ -2407,7 +2407,7 @@ class EmailCollector extends CommonObject /** * Check if the same file name already exists in the upload folder, - * append increment number to the original filename + * append increment number to the original filename */ while (file_exists($destdir."/" . $file_name . "." . $extension)) { $file_name = (string) $file_name_original . ' (' . $num . ')'; @@ -2418,7 +2418,6 @@ class EmailCollector extends CommonObject file_put_contents($destination, $data); - } // TEXT diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index be964015f75..345ef7b496e 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1744,9 +1744,9 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } } - + //If you want to load custom javascript file from your selected theme directory - if (!empty($conf->global->ALLOW_THEME_JS)) { + if (!empty($conf->global->ALLOW_THEME_JS)) { $theme_js = dol_buildpath('/theme/'.$conf->theme.'/'.$conf->theme.'.js', 0); if (file_exists($theme_js)) { print ''."\n";