12 require_once(
"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;
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'])
305 $a_http_post_file[
'name'], $this->
getMailPath().
'/'.$this->user_id.
'_'.
306 $a_http_post_file[
'name']);
323 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
339 if(file_exists($a_path))
342 return rename($a_path,$a_path.
'.old');
354 if(is_array($a_filenames))
356 foreach($a_filenames as
$file)
374 if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
376 return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
387 return $this->mail_path.
'/'.$this->user_id.
'_'.$a_path;
401 return "INTERNAL HERE ERROR: No valid mail_id given";
403 if(is_array($a_attachments))
405 foreach($a_attachments as $attachment)
407 if(!$this->
saveFile($a_mail_id,$attachment))
415 return "ARRAY REQUIRED";
422 static $fsstorage_cache = array();
424 if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
426 include_once
'Services/Mail/classes/class.ilFSStorageMail.php';
427 $fsstorage_cache[$a_mail_id][$a_usr_id] =
new ilFSStorageMail($a_mail_id, $a_usr_id);
430 return $fsstorage_cache[$a_mail_id][$a_usr_id];
444 $storage_directory = $oStorage->getAbsolutePath();
446 if(@!is_dir($storage_directory))
451 return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
452 $storage_directory.
'/'.$a_attachment);
464 foreach($a_files as
$file)
466 if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.$file))
493 $res = $ilDB->manipulateF(
'
494 INSERT INTO mail_attachment
495 ( mail_id, path) VALUES (%s, %s)',
496 array(
'integer',
'text'),
497 array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
511 $res = $ilDB->query(
"SELECT path FROM mail_attachment
512 WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer'));
520 $res = $ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
521 WHERE path = ".$ilDB->quote(
$path,
'text')) ;
525 $cnt_mail_id =
$row->count_mail_id;
527 if($cnt_mail_id == 1)
533 $res = $ilDB->manipulateF(
"DELETE FROM mail_attachment
552 $umf = ini_get(
"upload_max_filesize");
554 $pms = ini_get(
"post_max_size");
557 $multiplier_a=array(
"K"=>1024,
"M"=>1024*1024,
"G"=>1024*1024*1024);
559 $umf_parts=preg_split(
"/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
560 $pms_parts=preg_split(
"/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
562 if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
563 if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
566 $max_filesize = min($umf, $pms);
568 if (!$max_filesize) $max_filesize = max($umf, $pms);
571 $mail_system_limitation_in_byte = (float)$this->ilias->getSetting(
'mail_maxsize_attach', 0) * 1024;
572 if(!$mail_system_limitation_in_byte)
574 $mail_system_limitation_in_byte = $max_filesize;
577 $mail_system_limitation_in_byte = min($mail_system_limitation_in_byte, $max_filesize);
579 $this->mail_maxsize_attach = $mail_system_limitation_in_byte;
600 "FROM mail_attachment ma ".
601 "JOIN mail m ON ma.mail_id=m.mail_id ".
602 "WHERE m.user_id = ".$ilDB->quote(
$user_id);
603 $result_set = $ilDB->query($q);
608 $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
610 if ($attachment_size != -1)
612 $size += $attachment_size;
616 return array(
'count'=>$count,
'size'=>
$size);