ILIAS  Release_4_0_x_branch Revision 61816
 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/<calculated_path>/mail_<mail_id>_<user_id>/...
 saveFile ($a_mail_id, $a_attachment)
 save attachment file in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_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 ()
 _lookupDiskUsageOfUser ($user_id)
 Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified user id.
- 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 getStorage ($a_mail_id, $a_usr_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 21183 2009-08-20 09:29:54Z akill

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

Member Function Documentation

ilFileDataMail::__deleteAttachmentDirectory (   $a_rel_path)

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

References ilUtil\delDir().

Referenced by deassignAttachmentFromDirectory().

{
ilUtil::delDir($this->mail_path."/".$a_rel_path);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataMail::__initAttachmentMaxSize ( )

Definition at line 514 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:

ilFileDataMail::_lookupDiskUsageOfUser (   $user_id)

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

Parameters
intuser id.
Returns
array{'count'=>integer,'size'=>integer} // an associative array with the disk // usage in bytes and the count of attachments.

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

References $ilDB, $lng, $q, $row, $size, $user_id, 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 ma ".
"JOIN mail 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++;
}
return array('count'=>$count, 'size'=>$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 172 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 450 of file class.ilFileDataMail.php.

References $ilDB, $res, and getStorage().

{
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);
*/
$oStorage = self::getStorage($a_sent_mail_id, $this->user_id);
$res = $ilDB->manipulateF('
INSERT INTO mail_attachment
( mail_id, path) VALUES (%s, %s)',
array('integer', 'text'),
array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
);
}

+ Here is the call graph for this function:

ilFileDataMail::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

Definition at line 428 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 198 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->mail_path,$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 289 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 475 of file class.ilFileDataMail.php.

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

{
global $ilDB;
// IF IT'S THE LAST MAIL CONTAINING THESE ATTACHMENTS => DELETE ATTACHMENTS
$res = $ilDB->query("SELECT path FROM mail_attachment
WHERE mail_id = ".$ilDB->quote($a_mail_id,'integer'));
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$path = $row->path;
}
if($path)
{
$res = $ilDB->query("SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
WHERE path = ".$ilDB->quote($path,'text')) ;
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$cnt_mail_id = $row->count_mail_id;
}
if($cnt_mail_id == 1)
{
}
}
$res = $ilDB->manipulateF("DELETE FROM mail_attachment
WHERE mail_id = %s",
array('integer'),
array($a_mail_id));
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 353 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 137 of file class.ilFileDataMail.php.

References $ilDB, ilFile\$path, $query, $row, 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;
*/
$query = $ilDB->query("SELECT path FROM mail_attachment ".
"WHERE mail_id = ".$ilDB->quote($a_mail_id, 'integer')."");
while($row = $ilDB->fetchObject($query))
{
$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 94 of file class.ilFileDataMail.php.

References $file, $files, $ilDB, ilFile\$path, $query, $row, 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;
*/
$query = $ilDB->query("SELECT path FROM mail_attachment
WHERE mail_id = ".$ilDB->quote($a_mail_id,'integer')."");
$rel_path = "";
while($row = $ilDB->fetchObject($query))
{
$rel_path = $row->path;
$path = $this->getMailPath().'/'.$row->path;
}
foreach((array)$files as $file)
{
if($file['type'] == 'file' && md5($file['entry']) == $a_filename)
{
return array(
'path' => $this->getMailPath().'/'.$rel_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 82 of file class.ilFileDataMail.php.

References $mail_path.

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

{
}

+ Here is the caller graph for this function:

static ilFileDataMail::getStorage (   $a_mail_id,
  $a_usr_id 
)
static

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

Referenced by assignAttachmentsToDirectory(), and saveFile().

{
static $fsstorage_cache = array();
if(!is_object($fsstorage_cache[$a_mail_id][$a_usr_id]))
{
include_once 'Services/Mail/classes/class.ilFSStorageMail.php';
$fsstorage_cache[$a_mail_id][$a_usr_id] = new ilFSStorageMail($a_mail_id, $a_usr_id);
}
return $fsstorage_cache[$a_mail_id][$a_usr_id];
}

+ 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 226 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 72 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 214 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 39 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 57 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 305 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/<calculated_path>/mail_<mail_id>_<user_id>/...

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

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

References getStorage().

Referenced by saveFiles().

{
$oStorage = self::getStorage($a_mail_id, $this->user_id);
$oStorage->create();
$storage_directory = $oStorage->getAbsolutePath();
if(@!is_dir($storage_directory))
{
return false;
}
return copy($this->mail_path.'/'.$this->user_id.'_'.$a_attachment,
$storage_directory.'/'.$a_attachment);
}

+ Here is the call graph for this function:

+ 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/<calculated_path>/mail_<mail_id>_<user_id>/...

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

Definition at line 365 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 258 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 340 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 320 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 30 of file class.ilFileDataMail.php.

ilFileDataMail::$mail_path

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

Referenced by getMailPath().

ilFileDataMail::$user_id

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

Referenced by _lookupDiskUsageOfUser().


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