fix: attachment link on email sent

This commit is contained in:
mahdahar 2026-04-21 14:47:20 +07:00
parent 147765b31f
commit 47fe3598f4
3 changed files with 26 additions and 3 deletions

View File

@ -60,6 +60,8 @@ class Activities extends Controller {
$attachment = 'upload/' . substr($attachment, 5); $attachment = 'upload/' . substr($attachment, 5);
} }
$attachment = preg_replace('#^(?:upload/)+#', 'upload/', $attachment);
if (strpos($attachment, 'upload/legacy/file/') === 0 || strpos($attachment, 'upload/') === 0) { if (strpos($attachment, 'upload/legacy/file/') === 0 || strpos($attachment, 'upload/') === 0) {
return $attachment; return $attachment;
} }
@ -100,6 +102,25 @@ class Activities extends Controller {
return implode(',', array_unique(array_filter($normalized))); return implode(',', array_unique(array_filter($normalized)));
} }
protected function normalizeAttachmentListForExternalMailer(?string $attachments): string
{
$normalizedList = $this->normalizeAttachmentList($attachments);
if ($normalizedList === '') {
return '';
}
$items = array_filter(array_map('trim', explode(',', $normalizedList)), static function ($item) {
return $item !== '';
});
$externalList = [];
foreach ($items as $item) {
$externalList[] = preg_replace('#^(?:upload/)+#', '', $item);
}
return implode(',', array_unique(array_filter($externalList)));
}
protected function findFirstUploadedFile(array $files): ?UploadedFile protected function findFirstUploadedFile(array $files): ?UploadedFile
{ {
foreach ($files as $file) { foreach ($files as $file) {
@ -1458,7 +1479,7 @@ class Activities extends Controller {
$sql = "select subject, attachment,siteid from activities where actid='$actid'"; $sql = "select subject, attachment,siteid from activities where actid='$actid'";
$query = $db->query($sql); $query = $db->query($sql);
$result = $query->getResultArray(); $result = $query->getResultArray();
$data['attachment'] = $result[0]['attachment']; $data['attachment'] = $this->normalizeAttachmentList($result[0]['attachment']);
$data['subject'] = $result[0]['subject']; $data['subject'] = $result[0]['subject'];
$siteid = $result[0]['siteid']; $siteid = $result[0]['siteid'];
@ -1504,6 +1525,7 @@ class Activities extends Controller {
$subject = $this->request->getVar('subject'); $subject = $this->request->getVar('subject');
$message = $this->request->getVar('message'); $message = $this->request->getVar('message');
$attachment = $this->normalizeAttachmentList($this->request->getVar('attachment')); $attachment = $this->normalizeAttachmentList($this->request->getVar('attachment'));
$attachmentForMailer = $this->normalizeAttachmentListForExternalMailer($attachment);
// // $attachments = explode(',',$attachment); // // $attachments = explode(',',$attachment);
// /* // /*
@ -1552,7 +1574,7 @@ class Activities extends Controller {
'bcc' => $bccs, 'bcc' => $bccs,
'subject' => $subject, 'subject' => $subject,
'message' => $message, 'message' => $message,
'attachment' => $attachment, 'attachment' => $attachmentForMailer,
'certificates' => $certificates 'certificates' => $certificates
]; ];
$jsonData = json_encode($data); $jsonData = json_encode($data);

View File

@ -106,7 +106,7 @@ foreach ($emails as $data) {
<div class="row mb-2"> <div class="row mb-2">
<label for="attachment" class="col-sm-2 col-form-label">Attachment list</label> <label for="attachment" class="col-sm-2 col-form-label">Attachment list</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control form-control-sm" name="attachment" id="attachment" value="<?=$activities[0]['attachment']?>" > <input type="text" class="form-control form-control-sm" name="attachment" id="attachment" value="<?=$attachment?>" >
</div> </div>
</div> </div>
</div> </div>

View File

@ -13,6 +13,7 @@ function resolve_attachment_relative_path($filename) {
} }
$normalized = str_replace('\\', '/', ltrim($filename, '/')); $normalized = str_replace('\\', '/', ltrim($filename, '/'));
$normalized = preg_replace('#^(?:upload/)+#', 'upload/', $normalized);
if (strpos($normalized, 'upload/') === 0) { if (strpos($normalized, 'upload/') === 0) {
return $normalized; return $normalized;
} }