Feature update : #19569
This commit is contained in:
parent
964656c728
commit
812e5a3b72
@ -2067,6 +2067,14 @@ class EmailCollector extends CommonObject
|
|||||||
$errorforactions++;
|
$errorforactions++;
|
||||||
$this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error);
|
$this->error = 'Failed to create ticket: '.$langs->trans($tickettocreate->error);
|
||||||
$this->errors = $tickettocreate->errors;
|
$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
|
* @param string $mid prefix
|
||||||
* @return array Array with number and object
|
* @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
|
// input $mbox = IMAP stream, $mid = message id
|
||||||
// output all the following:
|
// output all the following:
|
||||||
@ -2311,7 +2319,7 @@ class EmailCollector extends CommonObject
|
|||||||
} else {
|
} else {
|
||||||
// multipart: cycle through each part
|
// multipart: cycle through each part
|
||||||
foreach ($s->parts as $partno0 => $p) {
|
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
|
* @param string $partno Partno
|
||||||
* @return void
|
* @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
|
// $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
|
||||||
global $htmlmsg, $plainmsg, $charset, $attachments;
|
global $htmlmsg, $plainmsg, $charset, $attachments;
|
||||||
@ -2378,6 +2386,39 @@ class EmailCollector extends CommonObject
|
|||||||
$filename = ($params['filename']) ? $params['filename'] : $params['name'];
|
$filename = ($params['filename']) ? $params['filename'] : $params['name'];
|
||||||
// filename may be encoded, so see imap_mime_header_decode()
|
// filename may be encoded, so see imap_mime_header_decode()
|
||||||
$attachments[$filename] = $data; // this is a problem if two files have same name
|
$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
|
// TEXT
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user