Public Member Functions | Data Fields

ilFileDataMail Class Reference

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
 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 ()

Data Fields

 $user_id
 $mail_path
 $mail_maxsize_attach

Detailed Description

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


Member Function Documentation

ilFileDataMail::__deleteAttachmentDirectory ( a_rel_path  ) 

Definition at line 450 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))
                        {
                                $this->__deleteAttachmentDirectory($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 474 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::adoptAttachments ( a_attachments,
a_mail_id 
)

adopt attachments (in case of forwarding a mail)

Parameters:
array attachments
integer mail_id public
Returns:
string error message

Definition at line 140 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:
integer mail_id
integer key for directory assignment public
Returns:
bool

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

References $query, and $res.

        {
                $query = "INSERT INTO mail_attachment ".
                        "SET mail_id = '".$a_mail_id."', ".
                        "path = '".$this->user_id."_".$a_sent_mail_id."'";
                $res = $this->ilias->db->query($query);
        }

ilFileDataMail::checkFilesExist ( a_files  ) 

check if files exist

Parameters:
array filenames to check public
Returns:
bool

Definition at line 382 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 166 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:
array Array with files. Absolute path required public
Returns:

Definition at line 255 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:
integer mail_id public
Returns:
bool

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

References ilFile::$path, $query, $res, $row, and __deleteAttachmentDirectory().

        {
                // IF IT'S THE LAST MAIL CONTAINING THESE ATTACHMENTS => DELETE ATTACHMENTS
                $query = "SELECT path FROM mail_attachment ".
                        "WHERE mail_id = '".$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 = '".$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)
                        {
                                $this->__deleteAttachmentDirectory($path);
                        }
                }

                $query = "DELETE FROM mail_attachment ".
                        "WHERE mail_id = '".$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:
string relative path public
Returns:
string absolute path

Definition at line 319 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:
string filename
integer mail_id public
Returns:
string path

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

References ilFile::$path, $query, $row, and getMailPath().

Referenced by adoptAttachments().

        {
                $query = "SELECT path FROM mail_attachment ".
                        "WHERE mail_id = '".$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::getMailPath (  ) 

get mail path public

Returns:
string path

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

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

        {
                return $this->mail_path;
        }

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

References $file, $files, 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 93 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 182 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:
integereger user_id public

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

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

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


                $this->__initAttachmentMaxSize();
        }

Here is the call graph for this function:

ilFileDataMail::initDirectory (  ) 

init directory overwritten method public

Returns:
string path

Definition at line 78 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:
string filename private
Returns:
bool

Definition at line 271 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:
integer mail id of mail in sent box
array filenames to save public
Returns:
bool

Definition at line 360 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:
integer mail id of mail in sent box
array filenames to save public
Returns:
string error message

Definition at line 331 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:
array HTTP_POST_FILES public
Returns:
integer 0 on success

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

References 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'])
                {
                        // 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:
string filename to delete public
Returns:
bool

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

Referenced by unlinkFiles().

        {
                if(file_exists($this->mail_path.'/'.$this->user_id.'_'.$a_filename))
                {
                        return unlink($this->mail_path.'/'.$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:
array filenames to delete public
Returns:
string error message with filename that couldn't be deleted

Definition at line 286 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 51 of file class.ilFileDataMail.php.

ilFileDataMail::$mail_path

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

ilFileDataMail::$user_id

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


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