12 require_once(
"./Services/FileSystem/classes/class.ilFileData.php");
41 define(
'MAILPATH',
'mail');
45 $this->user_id = $a_user_id;
59 if(is_writable($this->
getPath()))
61 if(mkdir($this->
getPath().
'/'.MAILPATH))
63 if(chmod($this->
getPath().
'/'.MAILPATH,0755))
65 $this->mail_path = $this->
getPath().
'/'.MAILPATH;
104 $query = $ilDB->query(
"SELECT path FROM mail_attachment
105 WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer').
"");
110 $rel_path =
$row->path;
116 foreach((array)$files as
$file)
118 if($file[
'type'] ==
'file' && md5($file[
'entry']) == $a_filename)
121 'path' => $this->
getMailPath().
'/'.$rel_path.
'/'.$file[
'entry'],
122 'filename' => $file[
'entry']
147 $query = $ilDB->query(
"SELECT path FROM mail_attachment ".
148 "WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer').
"");
155 if(file_exists(
$path))
157 if(is_readable(
$path))
174 if(is_array($a_attachments))
176 foreach($a_attachments as
$file)
181 return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
187 return "ARRAY REQUIRED";
200 if(is_writable($this->mail_path) && is_readable($this->mail_path))
206 $this->ilias->raiseError(
"Mail directory is not readable/writable by webserver: ".$this->mail_path,$this->ilias->error_obj->FATAL);
228 $dp = opendir($this->mail_path);
230 while(
$file = readdir($dp))
237 if($uid == $this->user_id)
239 if(!is_dir($this->mail_path.
'/'.
$file))
243 'size' => filesize($this->mail_path.
'/'.
$file),
244 'ctime' => filectime($this->mail_path.
'/'.
$file)
261 if(strlen($a_content) >= $this->mail_maxsize_attach)
268 $abs_path = $this->
getMailPath().
'/'.$this->user_id.
'_'.$name;
270 if(!$fp = @fopen($abs_path,
'w+'))
274 if(@fwrite($fp,$a_content) ===
false)
292 if($a_http_post_file[
"size"] >= $this->mail_maxsize_attach)
297 if(isset($a_http_post_file) && $a_http_post_file[
'size'])
304 $a_http_post_file[
'tmp_name'],
305 $a_http_post_file[
'name'],
306 $this->
getMailPath().
'/'.$this->user_id.
'_'.$a_http_post_file[
'name']
322 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
338 if(file_exists($a_path))
341 return rename($a_path,$a_path.
'.old');
353 if(is_array($a_filenames))
355 foreach($a_filenames as
$file)
373 if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
375 return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
386 return $this->mail_path.
'/'.$this->user_id.
'_'.$a_path;
400 return "INTERNAL HERE ERROR: No valid mail_id given";
402 if(is_array($a_attachments))
404 foreach($a_attachments as $attachment)
406 if(!$this->
saveFile($a_mail_id,$attachment))
414 return "ARRAY REQUIRED";
421 static $fsstorage_cache = array();
423 if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
425 include_once
'Services/Mail/classes/class.ilFSStorageMail.php';
426 $fsstorage_cache[$a_mail_id][$a_usr_id] =
new ilFSStorageMail($a_mail_id, $a_usr_id);
429 return $fsstorage_cache[$a_mail_id][$a_usr_id];
443 $storage_directory = $oStorage->getAbsolutePath();
445 if(@!is_dir($storage_directory))
450 return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
451 $storage_directory.
'/'.$a_attachment);
463 foreach($a_files as
$file)
465 if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.$file))
492 $res = $ilDB->manipulateF(
'
493 INSERT INTO mail_attachment
494 ( mail_id, path) VALUES (%s, %s)',
495 array(
'integer',
'text'),
496 array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
510 $res = $ilDB->query(
"SELECT path FROM mail_attachment
511 WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer'));
519 $res = $ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
520 WHERE path = ".$ilDB->quote(
$path,
'text')) ;
524 $cnt_mail_id =
$row->count_mail_id;
526 if($cnt_mail_id == 1)
532 $res = $ilDB->manipulateF(
"DELETE FROM mail_attachment
551 $umf = ini_get(
"upload_max_filesize");
553 $pms = ini_get(
"post_max_size");
556 $multiplier_a=array(
"K"=>1024,
"M"=>1024*1024,
"G"=>1024*1024*1024);
558 $umf_parts=preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
559 $pms_parts=preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
561 if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
562 if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
565 $max_filesize = min($umf, $pms);
567 if (!$max_filesize) $max_filesize = max($umf, $pms);
570 $mail_system_limitation_in_byte = (float)$this->ilias->getSetting(
'mail_maxsize_attach', 0) * 1024;
571 if(!$mail_system_limitation_in_byte)
573 $mail_system_limitation_in_byte = $max_filesize;
576 $mail_system_limitation_in_byte = min($mail_system_limitation_in_byte, $max_filesize);
578 $this->mail_maxsize_attach = $mail_system_limitation_in_byte;
599 "FROM mail_attachment ma ".
600 "JOIN mail m ON ma.mail_id=m.mail_id ".
601 "WHERE m.user_id = ".$ilDB->quote(
$user_id);
602 $result_set = $ilDB->query($q);
607 $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
609 if ($attachment_size != -1)
611 $size += $attachment_size;
615 return array(
'count'=>$count,
'size'=>
$size);
621 public function onUserDelete()
631 $iter =
new RegexIterator(
634 foreach($iter as
$file)
642 @unlink($file->getPathname());
650 SELECT DISTINCT(ma1.path)
651 FROM mail_attachment ma1
653 ON mail.mail_id = ma1.mail_id
654 WHERE mail.user_id = %s
655 AND (SELECT COUNT(tmp.path) FROM mail_attachment tmp WHERE tmp.path = ma1.path) = 1
657 $res = $ilDB->queryF(
660 array($this->user_id)
662 while(
$row = $ilDB->fetchAssoc(
$res))
667 $iter =
new RecursiveIteratorIterator(
668 new RecursiveDirectoryIterator(
$path), RecursiveIteratorIterator::CHILD_FIRST
670 foreach($iter as $file)
678 @rmdir($file->getPathname());
682 @unlink($file->getPathname());
691 if($ilDB->getDBType() ==
'mysql' || $ilDB->getDBType() ==
'innodb')
695 FROM mail_attachment m1
697 SELECT mail_attachment.mail_id
699 INNER JOIN mail_attachment
700 ON mail_attachment.mail_id = mail.mail_id
703 ON m2.mail_id = m1.mail_id
706 array($this->user_id)
713 DELETE FROM mail_attachment
714 WHERE mail_attachment.mail_id IN (
715 SELECT mail_attachment.mail_id
717 INNER JOIN mail_attachment
718 ON mail_attachment.mail_id = mail.mail_id
723 array($this->user_id)