From 1f2c9e641afccbe34581e9cd161156d491f7d3de Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 26 Oct 2015 19:57:07 +0000 Subject: [PATCH] Handle multiple attachments with the same name when linking attachments from an email into an entry for another application --- mail/inc/class.mail_integration.inc.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mail/inc/class.mail_integration.inc.php b/mail/inc/class.mail_integration.inc.php index cd9196d244..35fbfd3952 100644 --- a/mail/inc/class.mail_integration.inc.php +++ b/mail/inc/class.mail_integration.inc.php @@ -76,6 +76,10 @@ class mail_integration { $time = time(); $_date = egw_time::server2user($time->now,'ts'); } + + // For dealing with multiple files of the same name + $dupe_count = $file_list = array(); + $GLOBALS['egw_info']['flags']['currentapp'] = $app; //error_log(__METHOD__.__LINE__.': RowID:'.$_GET['rowid'].': emailAddress:'. array2string($_to_emailAddress).' && '.$app); // Integrate not yet saved mail @@ -137,6 +141,13 @@ class mail_integration { { $attachment['file'] = $GLOBALS['egw_info']['server']['temp_dir'].SEP.basename($attachment['file']); } + if(in_array($attachment['name'], $file_list)) + { + $dupe_count[$attachment['name']]++; + $attachment['name'] = pathinfo($attachment['name'], PATHINFO_FILENAME) . + ' ('.($dupe_count[$attachment['name']] + 1).')' . '.' . + pathinfo($attachment['name'], PATHINFO_EXTENSION); + } $attachments[] = array( 'name' => $attachment['name'], 'mimeType' => $attachment['type'], @@ -144,6 +155,7 @@ class mail_integration { 'tmp_name' => $attachment['file'], 'size' => $attachment['size'], ); + $file_list[] = $attachment['name']; } } if ($messageFolder && $messageUid && $messagePartId && $mo->isDraftFolder($messageFolder) && !$mo->isTemplateFolder($messageFolder))