ILIAS  Release_4_2_x_branch Revision 61807
 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
 storeAsAttachment ($a_filename, $a_content)
 Store content as attachment.
 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 meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id:
class.ilFileDataMail.php 34249 2012-04-17 13:13:09Z mjansen

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

Member Function Documentation

ilFileDataMail::__deleteAttachmentDirectory (   $a_rel_path)

Definition at line 540 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 ( )
Todo:
mjansen: Unfortunately we cannot reuse the implementation of ilFileInputGUI

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

Referenced by ilFileDataMail().

{
// Copy of ilFileInputGUI: begin
// get the value for the maximal uploadable filesize from the php.ini (if available)
$umf = ini_get("upload_max_filesize");
// get the value for the maximal post data from the php.ini (if available)
$pms = ini_get("post_max_size");
//convert from short-string representation to "real" bytes
$multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
$umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
// use the smaller one as limit
$max_filesize = min($umf, $pms);
if (!$max_filesize) $max_filesize = max($umf, $pms);
// Copy of ilFileInputGUI: end
$mail_system_limitation_in_byte = (float)$this->ilias->getSetting('mail_maxsize_attach', 0) * 1024;
if(!$mail_system_limitation_in_byte)
{
$mail_system_limitation_in_byte = $max_filesize;
}
$mail_system_limitation_in_byte = min($mail_system_limitation_in_byte, $max_filesize);
$this->mail_maxsize_attach = $mail_system_limitation_in_byte;
}

+ 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 590 of file class.ilFileDataMail.php.

References $ilDB, $lng, $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 482 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 460 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 321 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 507 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 385 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(), storeAsAttachment(), and storeUploadedFile().

{
}

+ Here is the caller graph for this function:

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

Definition at line 420 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
array

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

References $file, $files, and $rest.

Referenced by getUserFilesData().

{
$files = array();
$dp = opendir($this->mail_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($uid,$rest) = explode('_',$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' => filectime($this->mail_path.'/'.$file)
);
}
}
}
closedir($dp);
return $files;
}

+ Here is the caller graph for this function:

ilFileDataMail::getUploadLimit ( )

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

References $mail_maxsize_attach.

ilFileDataMail::getUserFilesData ( )

get all attachments of a specific user public

Returns
array

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

References $files, and getUnsentFiles().

{
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 337 of file class.ilFileDataMail.php.

Referenced by storeAsAttachment(), and 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 440 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 397 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::storeAsAttachment (   $a_filename,
  $a_content 
)

Store content as attachment.

Parameters
object$a_filename
object$a_content
Returns

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

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

{
if(strlen($a_content) >= $this->mail_maxsize_attach)
{
return 1;
}
$name = ilUtil::_sanitizeFilemame($a_filename);
$this->rotateFiles($this->getMailPath().'/'.$this->user_id.'_'.$name);
$abs_path = $this->getMailPath().'/'.$this->user_id.'_'.$name;
if(!$fp = @fopen($abs_path,'w+'))
{
return false;
}
if(@fwrite($fp,$a_content) === false)
{
@fclose($fp);
return false;
}
@fclose($fp);
return true;
}

+ 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 290 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 372 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 352 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.

Referenced by getUploadLimit().

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: