ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilFileDataMail Class Reference

Class ilFileDataMail. More...

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

Public Member Functions

 __construct ($a_user_id=0)
 Constructor call base constructors checks if directory is writable and sets the optional user_id. More...
 
 initDirectory ()
 init directory overwritten method public More...
 
 getUploadLimit ()
 
 getAttachmentsTotalSizeLimit ()
 
 getMailPath ()
 get mail path public More...
 
 getAbsoluteAttachmentPoolPathPrefix ()
 
 getAttachmentPathAndFilenameByMd5Hash (string $md5FileHash, int $mailId)
 
 getAttachmentPath ($a_filename, $a_mail_id)
 get the path of a specific attachment More...
 
 adoptAttachments ($a_attachments, $a_mail_id)
 adopt attachments (in case of forwarding a mail) More...
 
 checkReadWrite ()
 check if directory is writable overwritten method from base class private More...
 
 getUserFilesData ()
 
 storeAsAttachment ($a_filename, $a_content)
 Store content as attachment. More...
 
 storeUploadedFile ($file)
 
 copyAttachmentFile ($a_abs_path, $a_new_name)
 Copy files in mail directory. More...
 
 rotateFiles ($a_path)
 rotate files with same name recursive method More...
 
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g. More...
 
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo' More...
 
 getAbsoluteAttachmentPoolPathByFilename (string $fileName)
 Resolves a path for a passed filename in regards of a user's mail attachment pool, meaning attachments not being sent. More...
 
 saveFiles ($a_mail_id, array $a_attachments)
 Saves all attachment files in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>/... More...
 
 saveFile ($a_mail_id, $a_attachment)
 save attachment file in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>/... More...
 
 checkFilesExist ($a_files)
 check if files exist More...
 
 assignAttachmentsToDirectory ($a_mail_id, $a_sent_mail_id)
 assign attachments to mail directory More...
 
 deassignAttachmentFromDirectory ($a_mail_id)
 dassign attachments from mail directory More...
 
 __deleteAttachmentDirectory ($a_rel_path)
 
 deliverAttachmentsAsZip (string $basename, int $mailId, $files=[], $isDraft=false)
 
- Public Member Functions inherited from ilFileData
 __construct ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public. More...
 
 checkPath ($a_path)
 check if path exists and is writable More...
 
 getPath ()
 get Path public More...
 
- Public Member Functions inherited from ilFile
 __construct ()
 Constructor get ilias object public. More...
 
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables More...
 

Static Public Member Functions

static getStorage ($a_mail_id, $a_usr_id)
 
static _lookupDiskUsageOfUser ($user_id)
 Returns the number of bytes used on the harddisk for mail attachments, by the user with the specified user id. More...
 

Data Fields

 $user_id
 
 $mail_path
 
- Data Fields inherited from ilFile
 $path
 
 $ilias
 

Protected Member Functions

 initAttachmentMaxUploadSize ()
 

Protected Attributes

 $mail_max_upload_file_size
 
 $tmpDirectory
 
 $storageDirectory
 
 $db
 

Private Member Functions

 getAttachmentPathByMailId (int $mailId)
 

Detailed Description

Class ilFileDataMail.

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

Constructor & Destructor Documentation

◆ __construct()

ilFileDataMail::__construct (   $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 58 of file class.ilFileDataMail.php.

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), checkReadWrite(), initAttachmentMaxUploadSize(), and MAILPATH.

59  {
60  global $DIC;
61 
62  if (!defined('MAILPATH')) {
63  define('MAILPATH', 'mail');
64  }
66  $this->mail_path = parent::getPath() . "/" . MAILPATH;
67  $this->checkReadWrite();
68  $this->user_id = $a_user_id;
69 
70  $this->db = $DIC->database();
71  $this->tmpDirectory = $DIC->filesystem()->temp();
72  $this->storageDirectory = $DIC->filesystem()->storage();
73 
75  }
checkReadWrite()
check if directory is writable overwritten method from base class private
const MAILPATH
Definition: constants.php:48
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ __deleteAttachmentDirectory()

ilFileDataMail::__deleteAttachmentDirectory (   $a_rel_path)

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

References ilUtil\delDir().

Referenced by deassignAttachmentFromDirectory().

526  {
527  ilUtil::delDir($this->mail_path . "/" . $a_rel_path);
528 
529  return true;
530  }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupDiskUsageOfUser()

static ilFileDataMail::_lookupDiskUsageOfUser (   $user_id)
static

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

References $DIC, Vendor\Package\$e, $ilDB, ilFile\$path, $query, $res, $size, $user_id, ilUtil\dirsize(), ilDBConstants\FETCHMODE_ASSOC, ilUtil\getDataDir(), and getMailPath().

Referenced by ilObjMailAccess\_lookupDiskUsageOfUser().

578  {
579  // XXX - This method is extremely slow. We should
580  // use a cache to speed it up, for example, we should
581  // store the disk space used in table mail_attachment.
582  global $DIC;
583 
584  $mail_data_dir = ilUtil::getDataDir('filesystem') . DIRECTORY_SEPARATOR . "mail";
585 
586  $q = "SELECT path " .
587  "FROM mail_attachment ma " .
588  "JOIN mail m ON ma.mail_id=m.mail_id " .
589  "WHERE m.user_id = " . $DIC->database()->quote($user_id);
590  $result_set = $DIC->database()->query($q);
591  $size = 0;
592  $count = 0;
593  while ($row = $result_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
594  $attachment_path = $mail_data_dir . DIRECTORY_SEPARATOR . $row['path'];
595  $attachment_size = ilUtil::dirsize($attachment_path);
596  if ($attachment_size != -1) {
597  $size += $attachment_size;
598  }
599  $count++;
600  }
601  return array('count' => $count, 'size' => $size);
602  }
$size
Definition: RandomTest.php:84
global $DIC
Definition: goto.php:24
static dirsize($directory)
get size of a directory or a file.
static getDataDir()
get data directory (outside webspace)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ adoptAttachments()

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

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

212  {
213  if (is_array($a_attachments)) {
214  foreach ($a_attachments as $file) {
215  $path = $this->getAttachmentPath($file, $a_mail_id);
216  if (!copy($path, $this->getMailPath() . '/' . $this->user_id . '_' . $file)) {
217  return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
218  }
219  }
220  } else {
221  return "ARRAY REQUIRED";
222  }
223  return '';
224  }
getAttachmentPath($a_filename, $a_mail_id)
get the path of a specific attachment
getMailPath()
get mail path public
+ Here is the call graph for this function:

◆ assignAttachmentsToDirectory()

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

References $ilDB, and $res.

470  {
471  global $ilDB;
472 
473  /* $query = "INSERT INTO mail_attachment ".
474  "SET mail_id = ".$ilDB->quote($a_mail_id).", ".
475  "path = ".$ilDB->quote($this->user_id."_".$a_sent_mail_id)." ";
476  $res = $this->ilias->db->query($query);
477  */
478 
479  $oStorage = self::getStorage($a_sent_mail_id, $this->user_id);
480  $res = $ilDB->manipulateF(
481  '
482  INSERT INTO mail_attachment
483  ( mail_id, path) VALUES (%s, %s)',
484  array('integer', 'text'),
485  array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
486  );
487  }
foreach($_POST as $key=> $value) $res
global $ilDB

◆ checkFilesExist()

ilFileDataMail::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

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

451  {
452  if ($a_files) {
453  foreach ($a_files as $file) {
454  if (!file_exists($this->mail_path . '/' . $this->user_id . '_' . $file)) {
455  return false;
456  }
457  }
458  return true;
459  }
460  return true;
461  }

◆ checkReadWrite()

ilFileDataMail::checkReadWrite ( )

check if directory is writable overwritten method from base class private

Returns
bool

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

Referenced by __construct().

233  {
234  if (is_writable($this->mail_path) && is_readable($this->mail_path)) {
235  return true;
236  } else {
237  $this->ilias->raiseError("Mail directory is not readable/writable by webserver: " . $this->mail_path, $this->ilias->error_obj->FATAL);
238  }
239  }
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the caller graph for this function:

◆ copyAttachmentFile()

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

References getMailPath().

326  {
327  @copy($a_abs_path, $this->getMailPath() . "/" . $this->user_id . "_" . $a_new_name);
328 
329  return true;
330  }
getMailPath()
get mail path public
+ Here is the call graph for this function:

◆ deassignAttachmentFromDirectory()

ilFileDataMail::deassignAttachmentFromDirectory (   $a_mail_id)

dassign attachments from mail directory

Parameters
integermail_id public
Returns
bool

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

References $ilDB, ilFile\$path, $res, __deleteAttachmentDirectory(), and ilDBConstants\FETCHMODE_OBJECT.

495  {
496  global $ilDB;
497  // IF IT'S THE LAST MAIL CONTAINING THESE ATTACHMENTS => DELETE ATTACHMENTS
498  $res = $ilDB->query("SELECT path FROM mail_attachment
499  WHERE mail_id = " . $ilDB->quote($a_mail_id, 'integer'));
500 
501  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
502  $path = $row->path;
503  }
504  if ($path) {
505  $res = $ilDB->query("SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
506  WHERE path = " . $ilDB->quote($path, 'text')) ;
507 
508  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
509  $cnt_mail_id = $row->count_mail_id;
510  }
511  if ($cnt_mail_id == 1) {
513  }
514  }
515 
516  $res = $ilDB->manipulateF(
517  "DELETE FROM mail_attachment
518  WHERE mail_id = %s",
519  array('integer'),
520  array($a_mail_id)
521  );
522  return true;
523  }
foreach($_POST as $key=> $value) $res
global $ilDB
__deleteAttachmentDirectory($a_rel_path)
+ Here is the call graph for this function:

◆ deliverAttachmentsAsZip()

ilFileDataMail::deliverAttachmentsAsZip ( string  $basename,
int  $mailId,
  $files = [],
  $isDraft = false 
)
Parameters
string$basename
int$mailId
array$files
bool$isDraft
Exceptions

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

References ilFile\$path, $source, ilMimeTypeUtil\APPLICATION__ZIP, ilFileDelivery\DISP_ATTACHMENT, getAbsoluteAttachmentPoolPathByFilename(), ilUtil\getASCIIFilename(), getAttachmentPathByMailId(), ilFileUtils\getValidFilename(), ilUtil\ilTempnam(), MAILPATH, and ilUtil\zip().

696  {
697  $path = '';
698  if (!$isDraft) {
699  $path = $this->getAttachmentPathByMailId($mailId);
700  if (0 === strlen($path)) {
701  throw new \ilException('mail_download_zip_no_attachments');
702  }
703  }
704 
705  $downloadFilename = \ilUtil::getASCIIFilename($basename);
706  if (0 === strlen($downloadFilename)) {
707  $downloadFilename = 'attachments';
708  }
709 
710  $processingDirectory = \ilUtil::ilTempnam();
711  $relativeProcessingDirectory = basename($processingDirectory);
712 
713  $absoluteZipDirectory = $processingDirectory . '/' . $downloadFilename;
714  $relativeZipDirectory = $relativeProcessingDirectory . '/' . $downloadFilename;
715 
716  $this->tmpDirectory->createDir($relativeZipDirectory);
717 
718  foreach ($files as $fileName) {
719  if ($isDraft) {
720  $source = str_replace(
721  $this->mail_path,
722  MAILPATH,
724  );
725  } else {
726  $source = MAILPATH . '/' . $path . '/' . $fileName;
727  }
728 
729  $source = str_replace('//', '/', $source);
730  if (!$this->storageDirectory->has($source)) {
731  continue;
732  }
733 
734  $target = $relativeZipDirectory . '/' . $fileName;
735 
736  $stream = $this->storageDirectory->readStream($source);
737  $this->tmpDirectory->writeStream($target, $stream);
738  }
739 
740  $pathToZipFile = $processingDirectory . '/' . $downloadFilename . '.zip';
741  \ilUtil::zip($absoluteZipDirectory, $pathToZipFile);
742 
743  $this->tmpDirectory->deleteDir($relativeZipDirectory);
744 
745  $delivery = new \ilFileDelivery($processingDirectory . '/' . $downloadFilename . '.zip');
746  $delivery->setDisposition(\ilFileDelivery::DISP_ATTACHMENT);
747  $delivery->setMimeType(\ilMimeTypeUtil::APPLICATION__ZIP);
748  $delivery->setConvertFileNameToAsci(true);
749  $delivery->setDownloadFileName(\ilFileUtils::getValidFilename($downloadFilename . '.zip'));
750  $delivery->setDeleteFile(true);
751 
752  $delivery->deliver();
753  }
const MAILPATH
Definition: constants.php:48
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
getAttachmentPathByMailId(int $mailId)
getAbsoluteAttachmentPoolPathByFilename(string $fileName)
Resolves a path for a passed filename in regards of a user&#39;s mail attachment pool, meaning attachments not being sent.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
$source
Definition: metadata.php:76
static getValidFilename($a_filename)
Get valid filename.
+ Here is the call graph for this function:

◆ getAbsoluteAttachmentPoolPathByFilename()

ilFileDataMail::getAbsoluteAttachmentPoolPathByFilename ( string  $fileName)

Resolves a path for a passed filename in regards of a user's mail attachment pool, meaning attachments not being sent.

Parameters
string$fileName
Returns
string

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

References getAbsoluteAttachmentPoolPathPrefix().

Referenced by deliverAttachmentsAsZip().

384  : string
385  {
386  return $this->getAbsoluteAttachmentPoolPathPrefix() . $fileName;
387  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAbsoluteAttachmentPoolPathPrefix()

ilFileDataMail::getAbsoluteAttachmentPoolPathPrefix ( )
Returns
string

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

Referenced by getAbsoluteAttachmentPoolPathByFilename().

130  : string
131  {
132  return $this->mail_path . '/' . $this->user_id . '_';
133  }
+ Here is the caller graph for this function:

◆ getAttachmentPath()

ilFileDataMail::getAttachmentPath (   $a_filename,
  $a_mail_id 
)

get the path of a specific attachment

Parameters
stringfilename
integermail_id
Returns
string path

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

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

Referenced by adoptAttachments().

195  {
196  $path = $this->getMailPath() . '/' . $this->getAttachmentPathByMailId($a_mail_id) . '/' . $a_filename;
197 
198  if (file_exists($path) && is_readable($path)) {
199  return $path;
200  }
201 
202  return '';
203  }
getMailPath()
get mail path public
getAttachmentPathByMailId(int $mailId)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAttachmentPathAndFilenameByMd5Hash()

ilFileDataMail::getAttachmentPathAndFilenameByMd5Hash ( string  $md5FileHash,
int  $mailId 
)
Parameters
string$md5FileHash
int$mailId
Returns
array array An array containing the 'path' and the 'filename' for the passed MD5 hash
Exceptions

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

References ilFile\$path, $res, ilUtil\getDir(), and getMailPath().

Referenced by ilMailFolderGUI\deliverFile().

141  : array
142  {
143  $res = $this->db->queryF(
144  "SELECT path FROM mail_attachment WHERE mail_id = %s",
145  ['integer'],
146  [$mailId]
147  );
148 
149  if (1 !== (int) $this->db->numRows($res)) {
150  throw new \OutOfBoundsException();
151  }
152 
153  $row = $this->db->fetchAssoc($res);
154 
155  $relativePath = $row['path'];
156  $path = $this->getMailPath() . '/' . $row['path'];
157 
158  $files = ilUtil::getDir($path);
159  foreach ($files as $file) {
160  if ($file['type'] === 'file' && md5($file['entry']) === $md5FileHash) {
161  return [
162  'path' => $this->getMailPath() . '/' . $relativePath . '/' . $file['entry'],
163  'filename' => $file['entry']
164  ];
165  }
166  }
167 
168  throw new \OutOfBoundsException();
169  }
getMailPath()
get mail path public
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAttachmentPathByMailId()

ilFileDataMail::getAttachmentPathByMailId ( int  $mailId)
private
Parameters
int$mailId
Returns
string

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

References $query.

Referenced by deliverAttachmentsAsZip(), and getAttachmentPath().

175  : string
176  {
177  $query = $this->db->query(
178  "SELECT path FROM mail_attachment WHERE mail_id = " . $this->db->quote($mailId, 'integer')
179  );
180 
181  while ($row = $this->db->fetchObject($query)) {
182  return $row->path;
183  }
184 
185  return '';
186  }
$query
+ Here is the caller graph for this function:

◆ getAttachmentsTotalSizeLimit()

ilFileDataMail::getAttachmentsTotalSizeLimit ( )
Returns
float|null

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

108  {
109  $max_size = $this->ilias->getSetting('mail_maxsize_attach', '');
110  if (!strlen($max_size)) {
111  return null;
112  }
113 
114  return (float) $this->ilias->getSetting('mail_maxsize_attach', 0) * 1024;
115  }
redirection script todo: (a better solution should control the processing via a xml file) ...

◆ getMailPath()

ilFileDataMail::getMailPath ( )

get mail path public

Returns
string path

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

References $mail_path.

Referenced by _lookupDiskUsageOfUser(), adoptAttachments(), copyAttachmentFile(), getAttachmentPath(), getAttachmentPathAndFilenameByMd5Hash(), storeAsAttachment(), and storeUploadedFile().

123  {
124  return $this->mail_path;
125  }
+ Here is the caller graph for this function:

◆ getStorage()

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

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

411  {
412  static $fsstorage_cache = array();
413 
414  if (!is_object($fsstorage_cache[$a_mail_id][$a_usr_id])) {
415  include_once 'Services/Mail/classes/class.ilFSStorageMail.php';
416  $fsstorage_cache[$a_mail_id][$a_usr_id] = new ilFSStorageMail($a_mail_id, $a_usr_id);
417  }
418 
419  return $fsstorage_cache[$a_mail_id][$a_usr_id];
420  }

◆ getUploadLimit()

ilFileDataMail::getUploadLimit ( )
Returns
int

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

References $mail_max_upload_file_size.

Referenced by storeAsAttachment().

100  {
102  }
+ Here is the caller graph for this function:

◆ getUserFilesData()

ilFileDataMail::getUserFilesData ( )
Returns
list<array{name: string, size: int, ctime: int}>

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

References $rest, and $user_id.

243  : array
244  {
245  return $this->getUnsentFiles();
246  }

◆ initAttachmentMaxUploadSize()

ilFileDataMail::initAttachmentMaxUploadSize ( )
protected
Todo:
mjansen: Unfortunately we cannot reuse the implementation of ilFileInputGUI

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

Referenced by __construct().

536  {
539  // Copy of ilFileInputGUI: begin
540  // get the value for the maximal uploadable filesize from the php.ini (if available)
541  $umf = ini_get("upload_max_filesize");
542  // get the value for the maximal post data from the php.ini (if available)
543  $pms = ini_get("post_max_size");
544 
545  //convert from short-string representation to "real" bytes
546  $multiplier_a = array("K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024);
547 
548  $umf_parts = preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
549  $pms_parts = preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
550 
551  if (count($umf_parts) == 2) {
552  $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
553  }
554  if (count($pms_parts) == 2) {
555  $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
556  }
557 
558  // use the smaller one as limit
559  $max_filesize = min($umf, $pms);
560 
561  if (!$max_filesize) {
562  $max_filesize = max($umf, $pms);
563  }
564  // Copy of ilFileInputGUI: end
565 
566  $this->mail_max_upload_file_size = $max_filesize;
567  }
+ Here is the caller graph for this function:

◆ initDirectory()

ilFileDataMail::initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath(), and MAILPATH.

84  {
85  if (is_writable($this->getPath())) {
86  if (mkdir($this->getPath() . '/' . MAILPATH)) {
87  if (chmod($this->getPath() . '/' . MAILPATH, 0755)) {
88  $this->mail_path = $this->getPath() . '/' . MAILPATH;
89  return true;
90  }
91  }
92  }
93  return false;
94  }
getPath()
get Path public
const MAILPATH
Definition: constants.php:48
+ Here is the call graph for this function:

◆ rotateFiles()

ilFileDataMail::rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename private
Returns
bool

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

Referenced by storeAsAttachment(), and storeUploadedFile().

342  {
343  if (file_exists($a_path)) {
344  $this->rotateFiles($a_path . ".old");
345  return \ilFileUtils::rename($a_path, $a_path . '.old');
346  }
347  return true;
348  }
rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the caller graph for this function:

◆ saveFile()

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

Referenced by saveFiles().

430  {
431  $oStorage = self::getStorage($a_mail_id, $this->user_id);
432  $oStorage->create();
433  $storage_directory = $oStorage->getAbsolutePath();
434 
435  if (@!is_dir($storage_directory)) {
436  return false;
437  }
438 
439  return copy(
440  $this->mail_path . '/' . $this->user_id . '_' . $a_attachment,
441  $storage_directory . '/' . $a_attachment
442  );
443  }
+ Here is the caller graph for this function:

◆ saveFiles()

ilFileDataMail::saveFiles (   $a_mail_id,
array  $a_attachments 
)

Saves all attachment files in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>/...

Parameters
integer$a_mail_idid of mail in sent box
array$a_attachmentsto save

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

References saveFile().

395  {
396  if (!is_numeric($a_mail_id) || $a_mail_id < 1) {
397  throw new InvalidArgumentException('The passed mail_id must be a valid integer!');
398  }
399 
400  foreach ($a_attachments as $attachment) {
401  $this->saveFile($a_mail_id, $attachment);
402  }
403  }
saveFile($a_mail_id, $a_attachment)
save attachment file in a specific mail directory .../mail/<calculated_path>/mail_<mail_id>_<user_id>...
+ Here is the call graph for this function:

◆ storeAsAttachment()

ilFileDataMail::storeAsAttachment (   $a_filename,
  $a_content 
)

Store content as attachment.

Parameters
object$a_filename
object$a_content
Returns

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

References $name, ilUtil\_sanitizeFilemame(), getMailPath(), getUploadLimit(), and rotateFiles().

Referenced by ilSoapUtils\distributeMails().

282  {
283  if (strlen($a_content) >= $this->getUploadLimit()) {
284  return 1;
285  }
286 
287  $name = ilUtil::_sanitizeFilemame($a_filename);
288  $this->rotateFiles($this->getMailPath() . '/' . $this->user_id . '_' . $name);
289 
290  $abs_path = $this->getMailPath() . '/' . $this->user_id . '_' . $name;
291 
292  if (!$fp = @fopen($abs_path, 'w+')) {
293  return false;
294  }
295  if (@fwrite($fp, $a_content) === false) {
296  @fclose($fp);
297  return false;
298  }
299  @fclose($fp);
300  return true;
301  }
getMailPath()
get mail path public
if($format !==null) $name
Definition: metadata.php:230
static _sanitizeFilemame($a_filename)
rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storeUploadedFile()

ilFileDataMail::storeUploadedFile (   $file)
Parameters
array$file

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

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

307  {
308  $file['name'] = ilUtil::_sanitizeFilemame($file['name']);
309 
310  $this->rotateFiles($this->getMailPath() . '/' . $this->user_id . '_' . $file['name']);
311 
313  $file['tmp_name'],
314  $file['name'],
315  $this->getMailPath() . '/' . $this->user_id . '_' . $file['name']
316  );
317  }
getMailPath()
get mail path public
static _sanitizeFilemame($a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the call graph for this function:

◆ unlinkFile()

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

373  {
374  if (file_exists($this->mail_path . '/' . basename($this->user_id . '_' . $a_filename))) {
375  return unlink($this->mail_path . '/' . basename($this->user_id . '_' . $a_filename));
376  }
377  }
+ Here is the caller graph for this function:

◆ unlinkFiles()

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

References unlinkFile().

356  {
357  if (is_array($a_filenames)) {
358  foreach ($a_filenames as $file) {
359  if (!$this->unlinkFile($file)) {
360  return $file;
361  }
362  }
363  }
364  return '';
365  }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g &#39;foo&#39;
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilFileDataMail::$db
protected

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

◆ $mail_max_upload_file_size

ilFileDataMail::$mail_max_upload_file_size
protected

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

Referenced by getUploadLimit().

◆ $mail_path

ilFileDataMail::$mail_path

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

Referenced by getMailPath().

◆ $storageDirectory

ilFileDataMail::$storageDirectory
protected

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

◆ $tmpDirectory

ilFileDataMail::$tmpDirectory
protected

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

◆ $user_id

ilFileDataMail::$user_id

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

Referenced by _lookupDiskUsageOfUser(), and getUserFilesData().


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