12 require_once(
"./Services/FileSystem/classes/class.ilFileData.php");
47 define(
'MAILPATH',
'mail');
51 $this->user_id = $a_user_id;
64 if(is_writable($this->
getPath()))
66 if(mkdir($this->
getPath().
'/'.MAILPATH))
68 if(chmod($this->
getPath().
'/'.MAILPATH,0755))
70 $this->mail_path = $this->
getPath().
'/'.MAILPATH;
91 $max_size = $this->ilias->getSetting(
'mail_maxsize_attach',
'');
92 if(!strlen($max_size))
97 return (
float)$this->ilias->getSetting(
'mail_maxsize_attach', 0) * 1024;
127 $query = $ilDB->query(
"SELECT path FROM mail_attachment
128 WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer').
"");
133 $rel_path =
$row->path;
139 foreach((array)$files as
$file)
141 if($file[
'type'] ==
'file' && md5($file[
'entry']) == $a_filename)
144 'path' => $this->
getMailPath().
'/'.$rel_path.
'/'.$file[
'entry'],
145 'filename' => $file[
'entry']
170 $query = $ilDB->query(
"SELECT path FROM mail_attachment ".
171 "WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer').
"");
178 if(file_exists(
$path))
180 if(is_readable(
$path))
197 if(is_array($a_attachments))
199 foreach($a_attachments as
$file)
204 return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
210 return "ARRAY REQUIRED";
223 if(is_writable($this->mail_path) && is_readable($this->mail_path))
229 $this->ilias->raiseError(
"Mail directory is not readable/writable by webserver: ".$this->mail_path,$this->ilias->error_obj->FATAL);
251 $dp = opendir($this->mail_path);
253 while(
$file = readdir($dp))
260 if($uid == $this->user_id)
262 if(!is_dir($this->mail_path.
'/'.
$file))
266 'size' => filesize($this->mail_path.
'/'.
$file),
267 'ctime' => filectime($this->mail_path.
'/'.
$file)
292 $abs_path = $this->
getMailPath().
'/'.$this->user_id.
'_'.$name;
294 if(!$fp = @fopen($abs_path,
'w+'))
298 if(@fwrite($fp,$a_content) ===
false)
319 $this->
getMailPath() .
'/' . $this->user_id .
'_' . $file[
'name']
331 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
347 if(file_exists($a_path))
350 return 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))
501 $res = $ilDB->manipulateF(
'
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
529 WHERE path = ".$ilDB->quote(
$path,
'text')) ;
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);
571 $umf_parts = preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
572 $pms_parts = preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
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
668 $res = $ilDB->queryF(
671 array($this->user_id)
673 while(
$row = $ilDB->fetchAssoc(
$res))
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)