12 require_once(
"./Services/FileSystem/classes/class.ilFileData.php");
13 require_once(
"./Services/Utilities/classes/class.ilFileUtils.php");
48 define(
'MAILPATH',
'mail');
49 parent::__construct();
50 $this->mail_path = parent::getPath() .
"/" . MAILPATH;
52 $this->user_id = $a_user_id;
65 if (is_writable($this->
getPath())) {
66 if (mkdir($this->
getPath() .
'/' . MAILPATH)) {
67 if (chmod($this->
getPath() .
'/' . MAILPATH, 0755)) {
68 $this->mail_path = $this->
getPath() .
'/' . MAILPATH;
89 $max_size = $this->
ilias->getSetting(
'mail_maxsize_attach',
'');
90 if (!strlen($max_size)) {
94 return (
float) $this->
ilias->getSetting(
'mail_maxsize_attach', 0) * 1024;
112 return $this->mail_path .
'/' . $this->user_id .
'_';
132 $query = $ilDB->query(
"SELECT path FROM mail_attachment 133 WHERE mail_id = " . $ilDB->quote($a_mail_id,
'integer') .
"");
137 $rel_path =
$row->path;
143 if ($file[
'type'] ==
'file' && md5($file[
'entry']) == $a_filename) {
145 'path' => $this->
getMailPath() .
'/' . $rel_path .
'/' . $file[
'entry'],
146 'filename' => $file[
'entry']
171 $query = $ilDB->query(
"SELECT path FROM mail_attachment " .
172 "WHERE mail_id = " . $ilDB->quote($a_mail_id,
'integer') .
"");
178 if (file_exists(
$path)) {
179 if (is_readable(
$path)) {
195 if (is_array($a_attachments)) {
196 foreach ($a_attachments as
$file) {
198 if (!copy(
$path, $this->
getMailPath() .
'/' . $this->user_id .
'_' . $file)) {
199 return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
203 return "ARRAY REQUIRED";
216 if (is_writable($this->mail_path) && is_readable($this->mail_path)) {
219 $this->
ilias->raiseError(
"Mail directory is not readable/writable by webserver: " . $this->mail_path, $this->
ilias->error_obj->FATAL);
229 return $this->getUnsentFiles();
238 private function getUnsentFiles()
243 foreach ($iter as
$file) {
247 if ($file->isFile()) {
248 list($uid,
$rest) = explode(
'_', $file->getFilename(), 2);
249 if ($uid == $this->user_id) {
252 'size' => $file->getSize(),
253 'ctime' => $file->getCTime()
279 if (!$fp = @fopen($abs_path,
'w+')) {
299 ilUtil::moveUploadedFile(
302 $this->
getMailPath() .
'/' . $this->user_id .
'_' . $file[
'name']
314 @copy($a_abs_path, $this->
getMailPath() .
"/" . $this->user_id .
"_" . $a_new_name);
330 if (file_exists($a_path)) {
332 return \ilFileUtils::rename($a_path, $a_path .
'.old');
344 if (is_array($a_filenames)) {
345 foreach ($a_filenames as
$file) {
361 if (file_exists($this->mail_path .
'/' . basename($this->user_id .
'_' . $a_filename))) {
362 return unlink($this->mail_path .
'/' . basename($this->user_id .
'_' . $a_filename));
383 if (!is_numeric($a_mail_id) || $a_mail_id < 1) {
387 foreach ($a_attachments as $attachment) {
388 $this->
saveFile($a_mail_id, $attachment);
394 static $fsstorage_cache =
array();
396 if (!is_object($fsstorage_cache[$a_mail_id][$a_usr_id])) {
397 include_once
'Services/Mail/classes/class.ilFSStorageMail.php';
398 $fsstorage_cache[$a_mail_id][$a_usr_id] =
new ilFSStorageMail($a_mail_id, $a_usr_id);
401 return $fsstorage_cache[$a_mail_id][$a_usr_id];
411 public function saveFile($a_mail_id, $a_attachment)
413 $oStorage = self::getStorage($a_mail_id, $this->user_id);
415 $storage_directory = $oStorage->getAbsolutePath();
417 if (@!is_dir($storage_directory)) {
422 $this->mail_path .
'/' . $this->user_id .
'_' . $a_attachment,
423 $storage_directory .
'/' . $a_attachment
435 foreach ($a_files as
$file) {
436 if (!file_exists($this->mail_path .
'/' . $this->user_id .
'_' . $file)) {
461 $oStorage = self::getStorage($a_sent_mail_id, $this->user_id);
462 $res = $ilDB->manipulateF(
464 INSERT INTO mail_attachment 465 ( mail_id, path) VALUES (%s, %s)',
466 array(
'integer',
'text'),
467 array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
480 $res = $ilDB->query(
"SELECT path FROM mail_attachment 481 WHERE mail_id = " . $ilDB->quote($a_mail_id,
'integer'));
487 $res = $ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment 488 WHERE path = " . $ilDB->quote(
$path,
'text')) ;
491 $cnt_mail_id =
$row->count_mail_id;
493 if ($cnt_mail_id == 1) {
498 $res = $ilDB->manipulateF(
499 "DELETE FROM mail_attachment 523 $umf = ini_get(
"upload_max_filesize");
525 $pms = ini_get(
"post_max_size");
528 $multiplier_a =
array(
"K" => 1024,
"M" => 1024 * 1024,
"G" => 1024 * 1024 * 1024);
530 $umf_parts = preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
531 $pms_parts = preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
533 if (count($umf_parts) == 2) {
534 $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
536 if (count($pms_parts) == 2) {
537 $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
541 $max_filesize = min($umf, $pms);
543 if (!$max_filesize) {
544 $max_filesize = max($umf, $pms);
548 $this->mail_max_upload_file_size = $max_filesize;
568 $q =
"SELECT path " .
569 "FROM mail_attachment ma " .
570 "JOIN mail m ON ma.mail_id=m.mail_id " .
571 "WHERE m.user_id = " . $DIC->database()->quote(
$user_id);
572 $result_set = $DIC->database()->query($q);
576 $attachment_path = $mail_data_dir . DIRECTORY_SEPARATOR .
$row[
'path'];
578 if ($attachment_size != -1) {
579 $size += $attachment_size;
589 public function onUserDelete()
598 $iter =
new RegexIterator(
600 '/^' . $this->user_id .
'_/' 602 foreach ($iter as
$file) {
607 if ($file->isFile()) {
608 @unlink($file->getPathname());
616 SELECT DISTINCT(ma1.path) 617 FROM mail_attachment ma1 619 ON mail.mail_id = ma1.mail_id 620 WHERE mail.user_id = %s 621 AND (SELECT COUNT(tmp.path) FROM mail_attachment tmp WHERE tmp.path = ma1.path) = 1 623 $res = $ilDB->queryF(
626 array($this->user_id)
628 while (
$row = $ilDB->fetchAssoc(
$res)) {
633 RecursiveIteratorIterator::CHILD_FIRST
635 foreach ($iter as
$file) {
640 if ($file->isDir()) {
641 @rmdir($file->getPathname());
643 @unlink($file->getPathname());
659 WHERE mail.user_id = %s AND mail.mail_id = mail_attachment.mail_id 663 array($this->user_id)
getAttachmentsTotalSizeLimit()
checkReadWrite()
check if directory is writable overwritten method from base class private
getAttachmentPath($a_filename, $a_mail_id)
get the path of a specific attachment
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'
__construct($a_user_id=0)
Constructor call base constructors checks if directory is writable and sets the optional user_id...
getMailPath()
get mail path public
This class handles all operations on files (attachments) in directory ilias_data/mail.
getAttachmentPathByMD5Filename($a_filename, $a_mail_id)
get the path of a specific attachment
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
saveFile($a_mail_id, $a_attachment)
save attachment file in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>...
unlinkFiles($a_filenames)
unlink files: expects an array of filenames e.g.
adoptAttachments($a_attachments, $a_mail_id)
adopt attachments (in case of forwarding a mail)
storeAsAttachment($a_filename, $a_content)
Store content as attachment.
checkFilesExist($a_files)
check if files exist
initDirectory()
init directory overwritten method public
static _sanitizeFilemame($a_filename)
getUserFilesData()
get all attachments of a specific user public
foreach($_POST as $key=> $value) $res
This class handles all operations on files in directory /ilias_data/.
assignAttachmentsToDirectory($a_mail_id, $a_sent_mail_id)
assign attachments to mail directory
redirection script todo: (a better solution should control the processing via a xml file) ...
getAbsoluteAttachmentPoolPathPrefix()
Create styles array
The data for the language used.
static _lookupDiskUsageOfUser($user_id)
Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified...
$mail_max_upload_file_size
static dirsize($directory)
get size of a directory or a file.
saveFiles($a_mail_id, array $a_attachments)
Saves all attachment files in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<us...
copyAttachmentFile($a_abs_path, $a_new_name)
Copy files in mail directory.
static getDataDir()
get data directory (outside webspace)
getAbsolutePath($fileName)
get absolute path of filename
deassignAttachmentFromDirectory($a_mail_id)
dassign attachments from mail directory
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
__deleteAttachmentDirectory($a_rel_path)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
initAttachmentMaxUploadSize()
static getStorage($a_mail_id, $a_usr_id)
rotateFiles($a_path)
rotate files with same name recursive method