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;
 
  128                $query = 
$ilDB->query(
"SELECT path FROM mail_attachment  
  129                                  WHERE mail_id = ".
$ilDB->quote($a_mail_id,
'integer').
"");
 
  134                        $rel_path = 
$row->path;
 
  140                foreach((array)$files as 
$file)
 
  142                        if(
$file[
'type'] == 
'file' && md5(
$file[
'entry']) == $a_filename)
 
  146                                        'filename' => 
$file[
'entry']
 
  171                $query = 
$ilDB->query(
"SELECT path FROM mail_attachment ".
 
  172                        "WHERE mail_id = ".
$ilDB->quote($a_mail_id, 
'integer').
"");
 
  179                if(file_exists(
$path))
 
  181                        if(is_readable(
$path))
 
  198                if(is_array($a_attachments))
 
  200                        foreach($a_attachments as 
$file)
 
  205                                        return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
 
  211                        return "ARRAY REQUIRED";
 
  224                if(is_writable($this->mail_path) && is_readable($this->mail_path))
 
  230                        $this->
ilias->raiseError(
"Mail directory is not readable/writable by webserver: ".$this->mail_path,$this->
ilias->error_obj->FATAL);
 
  240                return $this->getUnsentFiles();
 
  249        private function getUnsentFiles()
 
  254                foreach($iter as 
$file)
 
  261                                list($uid, 
$rest) = explode(
'_', 
$file->getFilename(), 2);
 
  262                                if($uid == $this->user_id)
 
  266                                                'size'     => 
$file->getSize(),
 
  267                                                'ctime'    => 
$file->getCTime()
 
  292                $abs_path = $this->
getMailPath().
'/'.$this->user_id.
'_'.$name;
 
  294                if(!$fp = @fopen($abs_path,
'w+'))
 
  298                if(@fwrite($fp,$a_content) === 
false)
 
  331                @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
 
  347                if(file_exists($a_path))
 
  350                        return \ilFileUtils::rename($a_path, $a_path . 
'.old');
 
  362                if(is_array($a_filenames))
 
  364                        foreach($a_filenames as 
$file)
 
  382                if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
 
  384                        return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
 
  395                return $this->mail_path.
'/'.$this->user_id.
'_'.$a_path;
 
  409                        return "INTERNAL HERE ERROR: No valid mail_id given";
 
  411                if(is_array($a_attachments))
 
  413                        foreach($a_attachments as $attachment)
 
  415                                if(!$this->
saveFile($a_mail_id,$attachment))
 
  423                        return "ARRAY REQUIRED";
 
  430                static $fsstorage_cache = array();
 
  432                if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
 
  434                        include_once 
'Services/Mail/classes/class.ilFSStorageMail.php';
 
  435                        $fsstorage_cache[$a_mail_id][$a_usr_id] = 
new ilFSStorageMail($a_mail_id, $a_usr_id);
 
  438                return $fsstorage_cache[$a_mail_id][$a_usr_id];
 
  452                $storage_directory = $oStorage->getAbsolutePath();
 
  454                if(@!is_dir($storage_directory))
 
  459                return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
 
  460                                        $storage_directory.
'/'.$a_attachment);
 
  472                        foreach($a_files as 
$file)
 
  474                                if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.
$file))
 
  502                        INSERT INTO mail_attachment  
  503                        ( mail_id, path) VALUES (%s, %s)',
 
  504                        array(
'integer', 
'text'),
 
  505                        array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
 
  519                $res = 
$ilDB->query(
"SELECT path FROM mail_attachment 
  520                                WHERE mail_id = ".
$ilDB->quote($a_mail_id,
'integer'));
 
  528                        $res = 
$ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment  
  533                                $cnt_mail_id = 
$row->count_mail_id;
 
  535                        if($cnt_mail_id == 1)
 
  541                $res = $ilDB->manipulateF(
"DELETE FROM mail_attachment  
  564                $umf = ini_get(
"upload_max_filesize");
 
  566                $pms = ini_get(
"post_max_size");
 
  569                $multiplier_a = array(
"K" => 1024, 
"M" => 1024 * 1024, 
"G" => 1024 * 1024 * 1024);
 
  574                if(count($umf_parts) == 2)
 
  576                        $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
 
  578                if(count($pms_parts) == 2)
 
  580                        $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
 
  584                $max_filesize = min($umf, $pms);
 
  586                if(!$max_filesize) $max_filesize = max($umf, $pms);
 
  589                $this->mail_max_upload_file_size = $max_filesize;
 
  610                        "FROM mail_attachment ma ".
 
  611                        "JOIN mail m ON ma.mail_id=m.mail_id ".
 
  612                        "WHERE m.user_id = ".$ilDB->quote(
$user_id);
 
  613                $result_set = 
$ilDB->query($q);
 
  618                        $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
 
  620                        if ($attachment_size != -1)
 
  622                                $size += $attachment_size;
 
  626                return array(
'count'=>$count, 
'size'=>
$size);
 
  632        public function onUserDelete()
 
  642                        $iter = 
new RegexIterator(
 
  645                        foreach($iter as 
$file)
 
  653                                        @unlink(
$file->getPathname());
 
  657                catch(Exception $e) { }
 
  661                        SELECT DISTINCT(ma1.path) 
  662                        FROM mail_attachment ma1 
  664                                ON mail.mail_id = ma1.mail_id 
  665                        WHERE mail.user_id = %s 
  666                        AND (SELECT COUNT(tmp.path) FROM mail_attachment tmp WHERE tmp.path = ma1.path) = 1 
  671                        array($this->user_id)
 
  678                                $iter = 
new RecursiveIteratorIterator(
 
  679                                        new RecursiveDirectoryIterator(
$path), RecursiveIteratorIterator::CHILD_FIRST
 
  681                                foreach($iter as 
$file)
 
  689                                                @rmdir(
$file->getPathname());
 
  693                                                @unlink(
$file->getPathname());
 
  698                        catch(Exception $e) { }
 
  702                if(
$ilDB->getDBType() == 
'mysql' || 
$ilDB->getDBType() == 
'innodb')
 
  706                                FROM mail_attachment m1 
  708                                        SELECT mail_attachment.mail_id 
  710                                        INNER JOIN mail_attachment 
  711                                                ON mail_attachment.mail_id = mail.mail_id 
  714                                ON m2.mail_id = m1.mail_id 
  717                                array($this->user_id)
 
  724                                DELETE FROM mail_attachment 
  725                                WHERE mail_attachment.mail_id IN ( 
  726                                        SELECT mail_attachment.mail_id 
  728                                        INNER JOIN mail_attachment 
  729                                                ON mail_attachment.mail_id = mail.mail_id 
  734                                array($this->user_id)
 
const DB_FETCHMODE_OBJECT
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.
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>...
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)
initDirectory()
init directory overwritten method @access public
saveFiles($a_mail_id, $a_attachments)
save all attachment files in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<use...
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.
_lookupDiskUsageOfUser($user_id)
Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified...
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
getAbsolutePath($a_path)
get absolute path of filename
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
__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)
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