private function readAttachmentsFromFileSystem(MailContent $mail, &$att_version) { $att_version = 2; if ($mail->getHasAttachments() && FileRepository::isInRepository($mail->getContentFileId())) { $attachments = array(); $content = FileRepository::getFileContent($mail->getContentFileId()); if (str_starts_with($content, "--")) { $att_version = 1; } else { if (str_starts_with($content, "#att_ver")) { $att_version = trim(str_replace("#att_ver", "", substr($content, 0, strpos($content, "\n")))); } } if ($att_version < 2) { $i = 0; $offset = 0; while ($offset < strlen($content)) { $delim = "--000000000000000000000000000{$i}"; if (strpos($content, $delim, $offset) !== FALSE) { $offset = strpos($content, $delim) + strlen($delim); $endline = strpos($content, ";", $offset); $name = substr($content, $offset + 1, $endline - $offset - 1); $pos = strpos($name, ":"); $name = trim(substr($name, $pos + 1, strlen($name) - $pos - 1)); $offset = $endline + 1; $endline = strpos($content, ";", $offset); $type = substr($content, $offset + 1, $endline - $offset - 1); $pos = strpos($type, ":"); $type = trim(substr($type, $pos + 1, strlen($type) - $pos - 1)); $offset = $endline + 1; $endline = strpos($content, "{$delim}--"); $attachments[] = array('name' => $name, 'type' => $type, 'data' => base64_decode(trim(substr($content, $offset, $endline - $offset - 1)))); $offset = strpos($content, "{$delim}--") + strlen("{$delim}--") + 1; } else { break; } $i++; } } else { $lines = explode("\n", $content); foreach ($lines as $line) { if (!str_starts_with($line, "#") && trim($line) !== "") { $data = explode(",", $line); if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) { $path = FileRepository::getBackend()->getFilePath($data[2]); } else { $path = ROOT . "/tmp/" . gen_id(); file_put_contents($path, FileRepository::getFileContent($data[2])); } $attachments[] = array('name' => $data[0], 'type' => $data[1], 'path' => $path, 'repo_id' => $data[2]); } } } } else { $attachments = null; } return $attachments; }