Handle multiple attachments with the same name when linking attachments from an email into an entry for another application

This commit is contained in:
Ralf Becker 2015-10-27 10:29:57 +00:00
parent bfee0a1bce
commit 9cb46a4d79
2 changed files with 23 additions and 0 deletions

View File

@ -5763,6 +5763,9 @@ class emailadmin_imapbase
//_debug_array($attachments); //_debug_array($attachments);
if (is_array($attachments)) if (is_array($attachments))
{ {
// For dealing with multiple files of the same name
$dupe_count = $file_list = array();
foreach ($attachments as $num => $attachment) foreach ($attachments as $num => $attachment)
{ {
if ($attachment['mimeType'] == 'MESSAGE/RFC822') if ($attachment['mimeType'] == 'MESSAGE/RFC822')
@ -5809,11 +5812,19 @@ class emailadmin_imapbase
//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']); //if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']);
translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']); translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
} }
if(in_array($attachments[$num]['name'], $file_list))
{
$dupe_count[$attachments[$num]['name']]++;
$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
}
$attachments[$num]['type'] = $attachments[$num]['mimeType']; $attachments[$num]['type'] = $attachments[$num]['mimeType'];
$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
$tmpfile = fopen($attachments[$num]['tmp_name'],'w'); $tmpfile = fopen($attachments[$num]['tmp_name'],'w');
fwrite($tmpfile,$attachments[$num]['attachment']); fwrite($tmpfile,$attachments[$num]['attachment']);
fclose($tmpfile); fclose($tmpfile);
$file_list[] = $attachments[$num]['name'];
unset($attachments[$num]['attachment']); unset($attachments[$num]['attachment']);
} }
} }

View File

@ -76,6 +76,10 @@ class mail_integration {
$time = time(); $time = time();
$_date = egw_time::server2user($time->now,'ts'); $_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; $GLOBALS['egw_info']['flags']['currentapp'] = $app;
//error_log(__METHOD__.__LINE__.': RowID:'.$_GET['rowid'].': emailAddress:'. array2string($_to_emailAddress).' && '.$app); //error_log(__METHOD__.__LINE__.': RowID:'.$_GET['rowid'].': emailAddress:'. array2string($_to_emailAddress).' && '.$app);
// Integrate not yet saved mail // Integrate not yet saved mail
@ -137,6 +141,13 @@ class mail_integration {
{ {
$attachment['file'] = $GLOBALS['egw_info']['server']['temp_dir'].SEP.basename($attachment['file']); $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( $attachments[] = array(
'name' => $attachment['name'], 'name' => $attachment['name'],
'mimeType' => $attachment['type'], 'mimeType' => $attachment['type'],
@ -144,6 +155,7 @@ class mail_integration {
'tmp_name' => $attachment['file'], 'tmp_name' => $attachment['file'],
'size' => $attachment['size'], 'size' => $attachment['size'],
); );
$file_list[] = $attachment['name'];
} }
} }
if ($messageFolder && $messageUid && $messagePartId && $mo->isDraftFolder($messageFolder) && !$mo->isTemplateFolder($messageFolder)) if ($messageFolder && $messageUid && $messagePartId && $mo->isDraftFolder($messageFolder) && !$mo->isTemplateFolder($messageFolder))