32 require_once(
"classes/class.ilFileData.php");
61 define(
'MAILPATH',
'mail');
65 $this->user_id = $a_user_id;
79 if(is_writable($this->
getPath()))
81 if(mkdir($this->
getPath().
'/'.MAILPATH))
83 if(chmod($this->
getPath().
'/'.MAILPATH,0755))
85 $this->mail_path = $this->
getPath().
'/'.MAILPATH;
94 return $this->mail_maxsize_attach_message;
118 $query =
"SELECT path FROM mail_attachment ".
119 "WHERE mail_id = ".$ilDB->quote($a_mail_id).
"";
127 if($file[
'type'] ==
'file' && md5($file[
'entry']) == $a_filename)
130 'path' => $this->
getMailPath().
'/'.$row->path.
'/'.$file[
'entry'],
131 'filename' => $file[
'entry']
150 $query =
"SELECT path FROM mail_attachment ".
151 "WHERE mail_id = ".$ilDB->quote($a_mail_id).
"";
156 if(file_exists(
$path))
158 if(is_readable(
$path))
175 if(is_array($a_attachments))
177 foreach($a_attachments as
$file)
182 return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
188 return "ARRAY REQUIRED";
201 if(is_writable($this->mail_path) && is_readable($this->mail_path))
207 $this->ilias->raiseError(
"Mail directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
230 $dp = opendir($this->mail_path);
232 while(
$file = readdir($dp))
239 if($uid == $this->user_id)
241 if(!is_dir($this->mail_path.
'/'.
$file))
245 'size' => filesize($this->mail_path.
'/'.
$file),
261 if($a_http_post_file[
"size"] >= $this->mail_maxsize_attach)
266 if(isset($a_http_post_file) && $a_http_post_file[
'size'])
274 $a_http_post_file[
'name'], $this->
getMailPath().
'/'.$this->user_id.
'_'.
275 $a_http_post_file[
'name']);
292 @copy($a_abs_path,$this->
getMailPath().
"/".$this->user_id.
"_".$a_new_name);
308 if(file_exists($a_path))
311 return rename($a_path,$a_path.
'.old');
323 if(is_array($a_filenames))
325 foreach($a_filenames as
$file)
343 if(file_exists($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename)))
345 return unlink($this->mail_path.
'/'.basename($this->user_id.
'_'.$a_filename));
356 return $this->mail_path.
'/'.$this->user_id.
'_'.$a_path;
370 return "INTERNAL HERE ERROR: No valid mail_id given";
372 if(is_array($a_attachments))
374 foreach($a_attachments as $attachment)
376 if(!$this->
saveFile($a_mail_id,$attachment))
384 return "ARRAY REQUIRED";
397 if(!is_dir($this->mail_path.
'/'.$this->user_id.
'_'.$a_mail_id))
399 if(mkdir($this->mail_path.
'/'.$this->user_id.
'_'.$a_mail_id))
401 chmod($this->mail_path.
'/'.$this->user_id.
'_'.$a_mail_id,0755);
408 return copy($this->mail_path.
'/'.$this->user_id.
'_'.$a_attachment,
409 $this->mail_path.
'/'.$this->user_id.
'_'.$a_mail_id.
'/'.$a_attachment);
421 foreach($a_files as
$file)
423 if(!file_exists($this->mail_path.
'/'.$this->user_id.
'_'.$file))
443 $query =
"INSERT INTO mail_attachment ".
444 "SET mail_id = ".$ilDB->quote($a_mail_id).
", ".
445 "path = ".$ilDB->quote($this->user_id.
"_".$a_sent_mail_id).
" ";
446 $res = $this->ilias->db->query($query);
458 $query =
"SELECT path FROM mail_attachment ".
459 "WHERE mail_id = ".$ilDB->quote($a_mail_id).
" ";
461 $res = $this->ilias->db->query($query);
468 $query =
"SELECT COUNT(mail_id) AS count_mail_id FROM mail_attachment ".
469 "WHERE path = ".$ilDB->quote(
$path).
" ";
471 $res = $this->ilias->db->query($query);
474 $cnt_mail_id = $row->count_mail_id;
476 if($cnt_mail_id == 1)
482 $query =
"DELETE FROM mail_attachment ".
483 "WHERE mail_id = ".$ilDB->quote($a_mail_id).
" ";
484 $res = $this->ilias->db->query($query);
490 if(!@$dp = opendir($this->mail_path.
"/".$a_rel_path))
495 while(
$file = @readdir($dp))
505 unlink($this->mail_path.
"/".$a_rel_path.
"/".
$file);
507 @rmdir($this->mail_path.
"/".$a_rel_path);
515 $this->mail_maxsize_attach = $this->ilias->getSetting(
"mail_maxsize_attach") ?
516 $this->ilias->getSetting(
"mail_maxsize_attach") * 1024 : 1024 * 1024 * 64;
518 $this->mail_maxsize_attach_message = $this->ilias->getSetting(
"mail_maxsize_attach") ?
519 $this->ilias->getSetting(
"mail_maxsize_attach") :
520 ini_get(
"upload_max_filesize");
539 "FROM mail_attachment AS ma ".
540 "JOIN mail AS m ON ma.mail_id=m.mail_id ".
541 "WHERE m.user_id = ".$ilDB->quote(
$user_id);
542 $result_set = $ilDB->query($q);
547 $attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row[
'path'];
549 if ($attachment_size != -1)
551 $size += $attachment_size;
555 include_once(
"Modules/File/classes/class.ilObjFileAccess.php");
556 return ($as_string) ?