12require_once(
"./Services/FileSystem/classes/class.ilFileData.php");
13require_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()))
67 if(mkdir($this->
getPath().
'/'.MAILPATH))
69 if(chmod($this->
getPath().
'/'.MAILPATH,0755))
71 $this->mail_path = $this->
getPath().
'/'.MAILPATH;
92 $max_size = $this->
ilias->getSetting(
'mail_maxsize_attach',
'');
93 if(!strlen($max_size))
98 return (
float)$this->
ilias->getSetting(
'mail_maxsize_attach', 0) * 1024;
116 return $this->mail_path .
'/' . $this->user_id .
'_';
136 $query =
$ilDB->query(
"SELECT path FROM mail_attachment
137 WHERE mail_id = ".
$ilDB->quote($a_mail_id,
'integer').
"");
142 $rel_path =
$row->path;
150 if(
$file[
'type'] ==
'file' && md5(
$file[
'entry']) == $a_filename)
154 'filename' =>
$file[
'entry']
179 $query =
$ilDB->query(
"SELECT path FROM mail_attachment ".
180 "WHERE mail_id = ".
$ilDB->quote($a_mail_id,
'integer').
"");
187 if(file_exists(
$path))
189 if(is_readable(
$path))
206 if(is_array($a_attachments))
208 foreach($a_attachments as
$file)
213 return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
219 return "ARRAY REQUIRED";
232 if(is_writable($this->mail_path) && is_readable($this->mail_path))
238 $this->
ilias->raiseError(
"Mail directory is not readable/writable by webserver: ".$this->mail_path,$this->
ilias->error_obj->FATAL);
248 return $this->getUnsentFiles();
257 private function getUnsentFiles()
261 $iter =
new DirectoryIterator($this->mail_path);
262 foreach($iter as
$file)
269 list($uid,
$rest) = explode(
'_',
$file->getFilename(), 2);
270 if($uid == $this->user_id)
274 'size' =>
$file->getSize(),
275 'ctime' =>
$file->getCTime()
300 $abs_path = $this->
getMailPath().
'/'.$this->user_id.
'_'.$name;
302 if(!$fp = @fopen($abs_path,
'w+'))
339 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
355 if(file_exists($a_path))
358 return \ilFileUtils::rename($a_path, $a_path .
'.old');
370 if(is_array($a_filenames))
372 foreach($a_filenames as
$file)
390 if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
392 return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
411 public function saveFiles($a_mail_id, array $a_attachments)
413 if(!is_numeric($a_mail_id) || $a_mail_id < 1)
415 throw new InvalidArgumentException(
'The passed mail_id must be a valid integer!');
418 foreach($a_attachments as $attachment)
420 $this->
saveFile($a_mail_id, $attachment);
426 static $fsstorage_cache = array();
428 if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
430 include_once
'Services/Mail/classes/class.ilFSStorageMail.php';
431 $fsstorage_cache[$a_mail_id][$a_usr_id] =
new ilFSStorageMail($a_mail_id, $a_usr_id);
434 return $fsstorage_cache[$a_mail_id][$a_usr_id];
448 $storage_directory = $oStorage->getAbsolutePath();
450 if(@!is_dir($storage_directory))
455 return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
456 $storage_directory.
'/'.$a_attachment);
468 foreach($a_files as
$file)
470 if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.
$file))
498 INSERT INTO mail_attachment
499 ( mail_id, path) VALUES (%s, %s)',
500 array(
'integer',
'text'),
501 array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
515 $res =
$ilDB->query(
"SELECT path FROM mail_attachment
516 WHERE mail_id = ".
$ilDB->quote($a_mail_id,
'integer'));
524 $res =
$ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
529 $cnt_mail_id =
$row->count_mail_id;
531 if($cnt_mail_id == 1)
537 $res = $ilDB->manipulateF(
"DELETE FROM mail_attachment
560 $umf = ini_get(
"upload_max_filesize");
562 $pms = ini_get(
"post_max_size");
565 $multiplier_a = array(
"K" => 1024,
"M" => 1024 * 1024,
"G" => 1024 * 1024 * 1024);
570 if(count($umf_parts) == 2)
572 $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
574 if(count($pms_parts) == 2)
576 $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
580 $max_filesize = min($umf, $pms);
582 if(!$max_filesize) $max_filesize = max($umf, $pms);
585 $this->mail_max_upload_file_size = $max_filesize;
606 "FROM mail_attachment ma ".
607 "JOIN mail m ON ma.mail_id=m.mail_id ".
608 "WHERE m.user_id = ".$ilDB->quote(
$user_id);
609 $result_set =
$ilDB->query($q);
614 $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
616 if ($attachment_size != -1)
618 $size += $attachment_size;
622 return array(
'count'=>$count,
'size'=>
$size);
628 public function onUserDelete()
638 $iter =
new RegexIterator(
639 new DirectoryIterator($this->
getMailPath()),
'/^'.$this->user_id.
'_/'
641 foreach($iter as
$file)
649 @unlink(
$file->getPathname());
653 catch(Exception $e) { }
657 SELECT DISTINCT(ma1.path)
658 FROM mail_attachment ma1
660 ON mail.mail_id = ma1.mail_id
661 WHERE mail.user_id = %s
662 AND (SELECT COUNT(tmp.path) FROM mail_attachment tmp WHERE tmp.path = ma1.path) = 1
667 array($this->user_id)
675 new RecursiveDirectoryIterator(
$path), RecursiveIteratorIterator::CHILD_FIRST
677 foreach($iter as
$file)
685 @rmdir(
$file->getPathname());
689 @unlink(
$file->getPathname());
694 catch(Exception $e) { }
704 WHERE mail.user_id = %s AND mail.mail_id = mail_attachment.mail_id
708 array($this->user_id)
An exception for terminatinating execution or to throw for unit testing.
This class handles all operations on files (attachments) in directory ilias_data/mail.
copyAttachmentFile($a_abs_path, $a_new_name)
Copy files in mail directory.
getAbsoluteAttachmentPoolPathPrefix()
checkReadWrite()
check if directory is writable overwritten method from base class @access private
saveFile($a_mail_id, $a_attachment)
save attachment file in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>...
getAbsolutePath($fileName)
get absolute path of filename
getAttachmentPath($a_filename, $a_mail_id)
get the path of a specific attachment
unlinkFiles($a_filenames)
unlink files: expects an array of filenames e.g.
assignAttachmentsToDirectory($a_mail_id, $a_sent_mail_id)
assign attachments to mail directory
static getStorage($a_mail_id, $a_usr_id)
static _lookupDiskUsageOfUser($user_id)
Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified...
initDirectory()
init directory overwritten method @access public
adoptAttachments($a_attachments, $a_mail_id)
adopt attachments (in case of forwarding a mail)
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.
getAttachmentPathByMD5Filename($a_filename, $a_mail_id)
get the path of a specific attachment
storeAsAttachment($a_filename, $a_content)
Store content as attachment.
rotateFiles($a_path)
rotate files with same name recursive method
getMailPath()
get mail path @access public
$mail_max_upload_file_size
initAttachmentMaxUploadSize()
getUserFilesData()
get all attachments of a specific user @access public
getAttachmentsTotalSizeLimit()
checkFilesExist($a_files)
check if files exist
deassignAttachmentFromDirectory($a_mail_id)
dassign attachments from mail directory
saveFiles($a_mail_id, array $a_attachments)
Saves all attachment files in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<us...
__deleteAttachmentDirectory($a_rel_path)
This class handles all operations on files in directory /ilias_data/.
getPath()
get Path @access public
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static _sanitizeFilemame($a_filename)
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static dirsize($directory)
get size of a directory or a file.
redirection script todo: (a better solution should control the processing via a xml file)
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
echo;exit;}function LogoutNotification($SessionID) { global $ilDB; $q="SELECT session_id, data FROM usr_session WHERE expires > (\w+)\|/" PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE