ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilFileDataMail Class Reference

This class handles all operations on files (attachments) in directory ilias_data/mail. More...

+ Inheritance diagram for ilFileDataMail:
+ Collaboration diagram for ilFileDataMail:

Public Member Functions

 ilFileDataMail ($a_user_id=0)
 Constructor call base constructors checks if directory is writable and sets the optional user_id.
 initDirectory ()
 init directory overwritten method public
 getUploadLimit ()
 getMailPath ()
 get mail path public
 getAttachmentPathByMD5Filename ($a_filename, $a_mail_id)
 get the path of a specific attachment
 getAttachmentPath ($a_filename, $a_mail_id)
 get the path of a specific attachment
 adoptAttachments ($a_attachments, $a_mail_id)
 adopt attachments (in case of forwarding a mail)
 checkReadWrite ()
 check if directory is writable overwritten method from base class private
 getUserFilesData ()
 get all attachments of a specific user public
 getUnsentFiles ()
 get all files which are not sent find them in directory data/mail/ private
 storeUploadedFile ($a_http_post_file)
 store uploaded file in filesystem
 copyAttachmentFile ($a_abs_path, $a_new_name)
 Copy files in mail directory.
 rotateFiles ($a_path)
 rotate files with same name recursive method
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g.
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo'
 getAbsolutePath ($a_path)
 get absolute path of filename
 saveFiles ($a_mail_id, $a_attachments)
 save all attachment files in a specific mail directory .../mail/<user_id>_<mail_id>/...
 saveFile ($a_mail_id, $a_attachment)
 save attachment file in a specific mail directory .../mail/<user_id>_<mail_id>/...
 checkFilesExist ($a_files)
 check if files exist
 assignAttachmentsToDirectory ($a_mail_id, $a_sent_mail_id)
 assign attachments to mail directory
 deassignAttachmentFromDirectory ($a_mail_id)
 dassign attachments from mail directory
 __deleteAttachmentDirectory ($a_rel_path)
 __initAttachmentMaxSize ()
- Public Member Functions inherited from ilFileData
 ilFileData ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public.
 checkPath ($a_path)
 check if path exists and is writable
 getPath ()
 get Path public
- Public Member Functions inherited from ilFile
 ilFile ()
 Constructor get ilias object public.
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables

Static Public Member Functions

static _getDiskSpaceUsedBy ($user_id, $as_string=false)
 Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified user id.

Data Fields

 $user_id
 $mail_path
 $mail_maxsize_attach

Detailed Description

This class handles all operations on files (attachments) in directory ilias_data/mail.

Author
Stefan Meyer smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
Id:
class.ilFileDataMail.php 20451 2009-07-07 10:30:26Z mjansen

Definition at line 34 of file class.ilFileDataMail.php.

Member Function Documentation

ilFileDataMail::__deleteAttachmentDirectory (   $a_rel_path)

Definition at line 488 of file class.ilFileDataMail.php.

References $file.

Referenced by deassignAttachmentFromDirectory().

{
if(!@$dp = opendir($this->mail_path."/".$a_rel_path))
{
return false;
}
while($file = @readdir($dp))
{
if($file == '.' or $file == '..')
{
continue;
}
if(is_dir($file))
{
}
unlink($this->mail_path."/".$a_rel_path."/".$file);
}
@rmdir($this->mail_path."/".$a_rel_path);
closedir($dp);
return true;
}

+ Here is the caller graph for this function:

ilFileDataMail::__initAttachmentMaxSize ( )

Definition at line 512 of file class.ilFileDataMail.php.

Referenced by ilFileDataMail().

{
$this->mail_maxsize_attach = $this->ilias->getSetting("mail_maxsize_attach") ?
$this->ilias->getSetting("mail_maxsize_attach") * 1024 : 1024 * 1024 * 64;
$this->mail_maxsize_attach_message = $this->ilias->getSetting("mail_maxsize_attach") ?
$this->ilias->getSetting("mail_maxsize_attach") :
ini_get("upload_max_filesize");
}

+ Here is the caller graph for this function:

static ilFileDataMail::_getDiskSpaceUsedBy (   $user_id,
  $as_string = false 
)
static

Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified user id.

Parameters
intuser id.

Definition at line 529 of file class.ilFileDataMail.php.

References $lng, $size, $user_id, ilObjFileAccess\_sizeToString(), DB_FETCHMODE_ASSOC, ilUtil\dirsize(), and ilUtil\getDataDir().

{
// XXX - This method is extremely slow. We should
// use a cache to speed it up, for example, we should
// store the disk space used in table mail_attachment.
global $ilDB, $lng;
$mail_data_dir = ilUtil::getDataDir('filesystem').DIRECTORY_SEPARATOR."mail";
$q = "SELECT path ".
"FROM mail_attachment AS ma ".
"JOIN mail AS m ON ma.mail_id=m.mail_id ".
"WHERE m.user_id = ".$ilDB->quote($user_id);
$result_set = $ilDB->query($q);
$size = 0;
$count = 0;
while($row = $result_set->fetchRow(DB_FETCHMODE_ASSOC))
{
$attachment_path = $mail_data_dir.DIRECTORY_SEPARATOR.$row['path'];
$attachment_size = ilUtil::dirsize($attachment_path);
if ($attachment_size != -1)
{
$size += $attachment_size;
}
$count++;
}
include_once("Modules/File/classes/class.ilObjFileAccess.php");
return ($as_string) ?
$count.' '.$lng->txt('mail_attachments').', '.ilObjFileAccess::_sizeToString($size) :
}

+ Here is the call graph for this function:

ilFileDataMail::adoptAttachments (   $a_attachments,
  $a_mail_id 
)

adopt attachments (in case of forwarding a mail)

Parameters
arrayattachments
integermail_id public
Returns
string error message

Definition at line 173 of file class.ilFileDataMail.php.

References $file, ilFile\$path, getAttachmentPath(), and getMailPath().

{
if(is_array($a_attachments))
{
foreach($a_attachments as $file)
{
$path = $this->getAttachmentPath($file,$a_mail_id);
if(!copy($path,$this->getMailPath().'/'.$this->user_id.'_'.$file))
{
return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
}
}
}
else
{
return "ARRAY REQUIRED";
}
return '';
}

+ Here is the call graph for this function:

ilFileDataMail::assignAttachmentsToDirectory (   $a_mail_id,
  $a_sent_mail_id 
)

assign attachments to mail directory

Parameters
integermail_id
integerkey for directory assignment public
Returns
bool

Definition at line 439 of file class.ilFileDataMail.php.

References $res.

{
global $ilDB;
$query = "INSERT INTO mail_attachment ".
"SET mail_id = ".$ilDB->quote($a_mail_id).", ".
"path = ".$ilDB->quote($this->user_id."_".$a_sent_mail_id)." ";
$res = $this->ilias->db->query($query);
}
ilFileDataMail::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

Definition at line 417 of file class.ilFileDataMail.php.

References $file.

{
if($a_files)
{
foreach($a_files as $file)
{
if(!file_exists($this->mail_path.'/'.$this->user_id.'_'.$file))
{
return false;
}
}
return true;
}
return true;
}
ilFileDataMail::checkReadWrite ( )

check if directory is writable overwritten method from base class private

Returns
bool

Definition at line 199 of file class.ilFileDataMail.php.

Referenced by ilFileDataMail().

{
if(is_writable($this->mail_path) && is_readable($this->mail_path))
{
return true;
}
else
{
$this->ilias->raiseError("Mail directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
}
}

+ Here is the caller graph for this function:

ilFileDataMail::copyAttachmentFile (   $a_abs_path,
  $a_new_name 
)

Copy files in mail directory.

This is used for sending ILIAS generated mails with attachments

Parameters
arrayArray with files. Absolute path required public
Returns

Definition at line 290 of file class.ilFileDataMail.php.

References getMailPath().

{
@copy($a_abs_path,$this->getMailPath()."/".$this->user_id."_".$a_new_name);
return true;
}

+ Here is the call graph for this function:

ilFileDataMail::deassignAttachmentFromDirectory (   $a_mail_id)

dassign attachments from mail directory

Parameters
integermail_id public
Returns
bool

Definition at line 454 of file class.ilFileDataMail.php.

References ilFile\$path, $res, __deleteAttachmentDirectory(), and DB_FETCHMODE_OBJECT.

{
global $ilDB;
// IF IT'S THE LAST MAIL CONTAINING THESE ATTACHMENTS => DELETE ATTACHMENTS
$query = "SELECT path FROM mail_attachment ".
"WHERE mail_id = ".$ilDB->quote($a_mail_id)." ";
$res = $this->ilias->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$path = $row->path;
}
if($path)
{
$query = "SELECT COUNT(mail_id) AS count_mail_id FROM mail_attachment ".
"WHERE path = ".$ilDB->quote($path)." ";
$res = $this->ilias->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$cnt_mail_id = $row->count_mail_id;
}
if($cnt_mail_id == 1)
{
}
}
$query = "DELETE FROM mail_attachment ".
"WHERE mail_id = ".$ilDB->quote($a_mail_id)." ";
$res = $this->ilias->db->query($query);
return true;
}

+ Here is the call graph for this function:

ilFileDataMail::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path public
Returns
string absolute path

Definition at line 354 of file class.ilFileDataMail.php.

{
return $this->mail_path.'/'.$this->user_id.'_'.$a_path;
}
ilFileDataMail::getAttachmentPath (   $a_filename,
  $a_mail_id 
)

get the path of a specific attachment

Parameters
stringfilename
integermail_id public
Returns
string path

Definition at line 146 of file class.ilFileDataMail.php.

References ilFile\$path, DB_FETCHMODE_OBJECT, and getMailPath().

Referenced by adoptAttachments().

{
global $ilDB;
$query = "SELECT path FROM mail_attachment ".
"WHERE mail_id = ".$ilDB->quote($a_mail_id)."";
$row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
$path = $this->getMailPath().'/'.$row->path.'/'.$a_filename;
if(file_exists($path))
{
if(is_readable($path))
{
return $path;
}
return '';
}
return '';
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataMail::getAttachmentPathByMD5Filename (   $a_filename,
  $a_mail_id 
)

get the path of a specific attachment

Parameters
stringmd5 encrypted filename
integermail_id public
Returns
string path

Definition at line 114 of file class.ilFileDataMail.php.

References $file, $files, ilFile\$path, DB_FETCHMODE_OBJECT, ilUtil\getDir(), and getMailPath().

{
global $ilDB;
$query = "SELECT path FROM mail_attachment ".
"WHERE mail_id = ".$ilDB->quote($a_mail_id)."";
$row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
$path = $this->getMailPath().'/'.$row->path;
foreach((array)$files as $file)
{
if($file['type'] == 'file' && md5($file['entry']) == $a_filename)
{
return array(
'path' => $this->getMailPath().'/'.$row->path.'/'.$file['entry'],
'filename' => $file['entry']
);
}
}
return '';
}

+ Here is the call graph for this function:

ilFileDataMail::getMailPath ( )

get mail path public

Returns
string path

Definition at line 102 of file class.ilFileDataMail.php.

References $mail_path.

Referenced by adoptAttachments(), copyAttachmentFile(), getAttachmentPath(), getAttachmentPathByMD5Filename(), and storeUploadedFile().

{
}

+ Here is the caller graph for this function:

ilFileDataMail::getUnsentFiles ( )

get all files which are not sent find them in directory data/mail/ private

Returns
bool

Definition at line 227 of file class.ilFileDataMail.php.

References $file, $files, $rest, and ilFormat\formatDate().

Referenced by getUserFilesData().

{
$files = array();
$dp = opendir($this->mail_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($uid,$rest) = split('_',$file,2);
if($uid == $this->user_id)
{
if(!is_dir($this->mail_path.'/'.$file))
{
$files[] = array(
'name' => $rest,
'size' => filesize($this->mail_path.'/'.$file),
'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->mail_path.'/'.$file))));
}
}
}
closedir($dp);
return $files;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataMail::getUploadLimit ( )

Definition at line 92 of file class.ilFileDataMail.php.

{
return $this->mail_maxsize_attach_message;
}
ilFileDataMail::getUserFilesData ( )

get all attachments of a specific user public

Returns
bool

Definition at line 215 of file class.ilFileDataMail.php.

References $files, and getUnsentFiles().

{
// FIRST GET FILES OF USER IN BASE DIRECTORY
return $files = $this->getUnsentFiles();
}

+ Here is the call graph for this function:

ilFileDataMail::ilFileDataMail (   $a_user_id = 0)

Constructor call base constructors checks if directory is writable and sets the optional user_id.

Parameters
integeregeruser_id public

Definition at line 59 of file class.ilFileDataMail.php.

References __initAttachmentMaxSize(), checkReadWrite(), ilFileData\getPath(), and ilFileData\ilFileData().

{
define('MAILPATH','mail');
$this->mail_path = parent::getPath()."/".MAILPATH;
$this->checkReadWrite();
$this->user_id = $a_user_id;
}

+ Here is the call graph for this function:

ilFileDataMail::initDirectory ( )

init directory overwritten method public

Returns
string path

Definition at line 77 of file class.ilFileDataMail.php.

References ilFileData\getPath().

{
if(is_writable($this->getPath()))
{
if(mkdir($this->getPath().'/'.MAILPATH))
{
if(chmod($this->getPath().'/'.MAILPATH,0755))
{
$this->mail_path = $this->getPath().'/'.MAILPATH;
return true;
}
}
}
return false;
}

+ Here is the call graph for this function:

ilFileDataMail::rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename private
Returns
bool

Definition at line 306 of file class.ilFileDataMail.php.

Referenced by storeUploadedFile().

{
if(file_exists($a_path))
{
$this->rotateFiles($a_path.".old");
return rename($a_path,$a_path.'.old');
}
return true;
}

+ Here is the caller graph for this function:

ilFileDataMail::saveFile (   $a_mail_id,
  $a_attachment 
)

save attachment file in a specific mail directory .../mail/<user_id>_<mail_id>/...

Parameters
integermail id of mail in sent box
arrayfilenames to save public
Returns
bool

Definition at line 395 of file class.ilFileDataMail.php.

Referenced by saveFiles().

{
if(!is_dir($this->mail_path.'/'.$this->user_id.'_'.$a_mail_id))
{
if(mkdir($this->mail_path.'/'.$this->user_id.'_'.$a_mail_id))
{
chmod($this->mail_path.'/'.$this->user_id.'_'.$a_mail_id,0755);
}
else
{
return false;
}
}
return copy($this->mail_path.'/'.$this->user_id.'_'.$a_attachment,
$this->mail_path.'/'.$this->user_id.'_'.$a_mail_id.'/'.$a_attachment);
}

+ Here is the caller graph for this function:

ilFileDataMail::saveFiles (   $a_mail_id,
  $a_attachments 
)

save all attachment files in a specific mail directory .../mail/<user_id>_<mail_id>/...

Parameters
integermail id of mail in sent box
arrayfilenames to save public
Returns
string error message

Definition at line 366 of file class.ilFileDataMail.php.

References saveFile().

{
if(!$a_mail_id)
{
return "INTERNAL HERE ERROR: No valid mail_id given";
}
if(is_array($a_attachments))
{
foreach($a_attachments as $attachment)
{
if(!$this->saveFile($a_mail_id,$attachment))
{
return $attachment;
}
}
}
else
{
return "ARRAY REQUIRED";
}
return '';
}

+ Here is the call graph for this function:

ilFileDataMail::storeUploadedFile (   $a_http_post_file)

store uploaded file in filesystem

Parameters
arrayHTTP_POST_FILES public
Returns
integer 0 on success

Definition at line 259 of file class.ilFileDataMail.php.

References ilUtil\_sanitizeFilemame(), getMailPath(), ilUtil\moveUploadedFile(), and rotateFiles().

{
if($a_http_post_file["size"] >= $this->mail_maxsize_attach)
{
return 1;
}
if(isset($a_http_post_file) && $a_http_post_file['size'])
{
$a_http_post_file['name'] = ilUtil::_sanitizeFilemame($a_http_post_file['name']);
// CHECK IF FILE WITH SAME NAME EXISTS
$this->rotateFiles($this->getMailPath().'/'.$this->user_id.'_'.$a_http_post_file['name']);
ilUtil::moveUploadedFile($a_http_post_file['tmp_name'],
$a_http_post_file['name'], $this->getMailPath().'/'.$this->user_id.'_'.
$a_http_post_file['name']);
//move_uploaded_file($a_http_post_file['tmp_name'],$this->getMailPath().'/'.$this->user_id.'_'.
// $a_http_post_file['name']);
return 0;
}
return 1;
}

+ Here is the call graph for this function:

ilFileDataMail::unlinkFile (   $a_filename)

unlink one uploaded file expects a filename e.g 'foo'

Parameters
stringfilename to delete public
Returns
bool

Definition at line 341 of file class.ilFileDataMail.php.

Referenced by unlinkFiles().

{
if(file_exists($this->mail_path.'/'.basename($this->user_id.'_'.$a_filename)))
{
return unlink($this->mail_path.'/'.basename($this->user_id.'_'.$a_filename));
}
}

+ Here is the caller graph for this function:

ilFileDataMail::unlinkFiles (   $a_filenames)

unlink files: expects an array of filenames e.g.

array('foo','bar')

Parameters
arrayfilenames to delete public
Returns
string error message with filename that couldn't be deleted

Definition at line 321 of file class.ilFileDataMail.php.

References $file, and unlinkFile().

{
if(is_array($a_filenames))
{
foreach($a_filenames as $file)
{
if(!$this->unlinkFile($file))
{
return $file;
}
}
}
return '';
}

+ Here is the call graph for this function:

Field Documentation

ilFileDataMail::$mail_maxsize_attach

Definition at line 50 of file class.ilFileDataMail.php.

ilFileDataMail::$mail_path

Definition at line 48 of file class.ilFileDataMail.php.

Referenced by getMailPath().

ilFileDataMail::$user_id

Definition at line 41 of file class.ilFileDataMail.php.

Referenced by _getDiskSpaceUsedBy().


The documentation for this class was generated from the following file: