diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 1ebe5c9ca5e..4ec19e70f5f 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -429,6 +429,14 @@ if (!$error && $massaction == 'confirm_presend') { $filepath = $fileparams['fullname']; } + if (getDolGlobalInt('MAIL_MASS_ACTION_SEARCH_MOST_RECENT_FILE_IF_NOT_FOUND') && isset($filepath) && !dol_is_file($filepath)) { + $fileparams = dol_most_recent_file($filedir, preg_quote($objectobj->ref, '/') . '([^\-])+' . (getDolGlobalInt('MAIN_ODT_AS_PDF') ? '\.pdf$' : '')); + if (isset($fileparams)) { + $filepath = $fileparams['fullname']; + $filename = $fileparams['name']; + } + } + // try to find other files generated for this object (last_main_doc) $filename_found = ''; $filepath_found = '';