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;
74 return $this->mail_maxsize_attach_message;
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);
229 $dp = opendir($this->mail_path);
231 while(
$file = readdir($dp))
238 if($uid == $this->user_id)
240 if(!is_dir($this->mail_path.
'/'.
$file))
244 'size' => filesize($this->mail_path.
'/'.
$file),
260 if($a_http_post_file[
"size"] >= $this->mail_maxsize_attach)
265 if(isset($a_http_post_file) && $a_http_post_file[
'size'])
273 $a_http_post_file[
'name'], $this->
getMailPath().
'/'.$this->user_id.
'_'.
274 $a_http_post_file[
'name']);
291 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
307 if(file_exists($a_path))
310 return rename($a_path,$a_path.
'.old');
322 if(is_array($a_filenames))
324 foreach($a_filenames as
$file)
342 if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
344 return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
355 return $this->mail_path.
'/'.$this->user_id.
'_'.$a_path;
369 return "INTERNAL HERE ERROR: No valid mail_id given";
371 if(is_array($a_attachments))
373 foreach($a_attachments as $attachment)
375 if(!$this->
saveFile($a_mail_id,$attachment))
383 return "ARRAY REQUIRED";
390 static $fsstorage_cache = array();
392 if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
394 include_once
'Services/Mail/classes/class.ilFSStorageMail.php';
395 $fsstorage_cache[$a_mail_id][$a_usr_id] =
new ilFSStorageMail($a_mail_id, $a_usr_id);
398 return $fsstorage_cache[$a_mail_id][$a_usr_id];
412 $storage_directory = $oStorage->getAbsolutePath();
414 if(@!is_dir($storage_directory))
419 return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
420 $storage_directory.
'/'.$a_attachment);
432 foreach($a_files as
$file)
434 if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.$file))
461 $res = $ilDB->manipulateF(
'
462 INSERT INTO mail_attachment
463 ( mail_id, path) VALUES (%s, %s)',
464 array(
'integer',
'text'),
465 array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
479 $res = $ilDB->query(
"SELECT path FROM mail_attachment
480 WHERE mail_id = ".$ilDB->quote($a_mail_id,
'integer'));
488 $res = $ilDB->query(
"SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
489 WHERE path = ".$ilDB->quote(
$path,
'text')) ;
493 $cnt_mail_id =
$row->count_mail_id;
495 if($cnt_mail_id == 1)
501 $res = $ilDB->manipulateF(
"DELETE FROM mail_attachment
517 $this->mail_maxsize_attach = $this->ilias->getSetting(
"mail_maxsize_attach") ?
518 $this->ilias->getSetting(
"mail_maxsize_attach") * 1024 : 1024 * 1024 * 64;
520 $this->mail_maxsize_attach_message = $this->ilias->getSetting(
"mail_maxsize_attach") ?
521 $this->ilias->getSetting(
"mail_maxsize_attach") :
522 ini_get(
"upload_max_filesize");
543 "FROM mail_attachment ma ".
544 "JOIN mail m ON ma.mail_id=m.mail_id ".
545 "WHERE m.user_id = ".$ilDB->quote(
$user_id);
546 $result_set = $ilDB->query(
$q);
551 $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
553 if ($attachment_size != -1)
555 $size += $attachment_size;
559 return array(
'count'=>$count,
'size'=>
$size);