ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 get all attachments of a specific user public More...
 
 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, checkReadWrite(), and initAttachmentMaxUploadSize().

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

Member Function Documentation

◆ __deleteAttachmentDirectory()

ilFileDataMail::__deleteAttachmentDirectory (   $a_rel_path)

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

References ilUtil\delDir().

Referenced by deassignAttachmentFromDirectory().

529  {
530  ilUtil::delDir($this->mail_path . "/" . $a_rel_path);
531 
532  return true;
533  }
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 580 of file class.ilFileDataMail.php.

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

Referenced by ilObjMailAccess\_lookupDiskUsageOfUser().

581  {
582  // XXX - This method is extremely slow. We should
583  // use a cache to speed it up, for example, we should
584  // store the disk space used in table mail_attachment.
585  global $DIC;
586 
587  $mail_data_dir = ilUtil::getDataDir('filesystem') . DIRECTORY_SEPARATOR . "mail";
588 
589  $q = "SELECT path " .
590  "FROM mail_attachment ma " .
591  "JOIN mail m ON ma.mail_id=m.mail_id " .
592  "WHERE m.user_id = " . $DIC->database()->quote($user_id);
593  $result_set = $DIC->database()->query($q);
594  $size = 0;
595  $count = 0;
596  while ($row = $result_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
597  $attachment_path = $mail_data_dir . DIRECTORY_SEPARATOR . $row['path'];
598  $attachment_size = ilUtil::dirsize($attachment_path);
599  if ($attachment_size != -1) {
600  $size += $attachment_size;
601  }
602  $count++;
603  }
604  return array('count' => $count, 'size' => $size);
605  }
$size
Definition: RandomTest.php:84
global $DIC
Definition: saml.php:7
$row
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 209 of file class.ilFileDataMail.php.

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

210  {
211  if (is_array($a_attachments)) {
212  foreach ($a_attachments as $file) {
213  $path = $this->getAttachmentPath($file, $a_mail_id);
214  if (!copy($path, $this->getMailPath() . '/' . $this->user_id . '_' . $file)) {
215  return "ERROR: $this->getMailPath().'/'.$this->user_id.'_'.$file cannot be created";
216  }
217  }
218  } else {
219  return "ARRAY REQUIRED";
220  }
221  return '';
222  }
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 472 of file class.ilFileDataMail.php.

References $ilDB, and $res.

473  {
474  global $ilDB;
475 
476  /* $query = "INSERT INTO mail_attachment ".
477  "SET mail_id = ".$ilDB->quote($a_mail_id).", ".
478  "path = ".$ilDB->quote($this->user_id."_".$a_sent_mail_id)." ";
479  $res = $this->ilias->db->query($query);
480  */
481 
482  $oStorage = self::getStorage($a_sent_mail_id, $this->user_id);
483  $res = $ilDB->manipulateF(
484  '
485  INSERT INTO mail_attachment
486  ( mail_id, path) VALUES (%s, %s)',
487  array('integer', 'text'),
488  array($a_mail_id, $oStorage->getRelativePathExMailDirectory())
489  );
490  }
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 453 of file class.ilFileDataMail.php.

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

◆ checkReadWrite()

ilFileDataMail::checkReadWrite ( )

check if directory is writable overwritten method from base class private

Returns
bool

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

Referenced by __construct().

231  {
232  if (is_writable($this->mail_path) && is_readable($this->mail_path)) {
233  return true;
234  } else {
235  $this->ilias->raiseError("Mail directory is not readable/writable by webserver: " . $this->mail_path, $this->ilias->error_obj->FATAL);
236  }
237  }
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 328 of file class.ilFileDataMail.php.

References getMailPath().

329  {
330  @copy($a_abs_path, $this->getMailPath() . "/" . $this->user_id . "_" . $a_new_name);
331 
332  return true;
333  }
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 497 of file class.ilFileDataMail.php.

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

498  {
499  global $ilDB;
500  // IF IT'S THE LAST MAIL CONTAINING THESE ATTACHMENTS => DELETE ATTACHMENTS
501  $res = $ilDB->query("SELECT path FROM mail_attachment
502  WHERE mail_id = " . $ilDB->quote($a_mail_id, 'integer'));
503 
504  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
505  $path = $row->path;
506  }
507  if ($path) {
508  $res = $ilDB->query("SELECT COUNT(mail_id) count_mail_id FROM mail_attachment
509  WHERE path = " . $ilDB->quote($path, 'text')) ;
510 
511  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
512  $cnt_mail_id = $row->count_mail_id;
513  }
514  if ($cnt_mail_id == 1) {
516  }
517  }
518 
519  $res = $ilDB->manipulateF(
520  "DELETE FROM mail_attachment
521  WHERE mail_id = %s",
522  array('integer'),
523  array($a_mail_id)
524  );
525  return true;
526  }
foreach($_POST as $key=> $value) $res
$row
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 698 of file class.ilFileDataMail.php.

References $files, ilFile\$path, $source, GuzzleHttp\Psr7\$stream, $target, ilMimeTypeUtil\APPLICATION__ZIP, ilFileDelivery\DISP_ATTACHMENT, getAbsoluteAttachmentPoolPathByFilename(), ilUtil\getASCIIFilename(), getAttachmentPathByMailId(), ilFileUtils\getValidFilename(), ilUtil\ilTempnam(), and ilUtil\zip().

699  {
700  $path = '';
701  if (!$isDraft) {
702  $path = $this->getAttachmentPathByMailId($mailId);
703  if (0 === strlen($path)) {
704  throw new \ilException('mail_download_zip_no_attachments');
705  }
706  }
707 
708  $downloadFilename = \ilUtil::getASCIIFilename($basename);
709  if (0 === strlen($downloadFilename)) {
710  $downloadFilename = 'attachments';
711  }
712 
713  $processingDirectory = \ilUtil::ilTempnam();
714  $relativeProcessingDirectory = basename($processingDirectory);
715 
716  $absoluteZipDirectory = $processingDirectory . '/' . $downloadFilename;
717  $relativeZipDirectory = $relativeProcessingDirectory . '/' . $downloadFilename;
718 
719  $this->tmpDirectory->createDir($relativeZipDirectory);
720 
721  foreach ($files as $fileName) {
722  if ($isDraft) {
723  $source = str_replace(
724  $this->mail_path,
725  MAILPATH,
727  );
728  } else {
729  $source = MAILPATH . '/' . $path . '/' . $fileName;
730  }
731 
732  $source = str_replace('//', '/', $source);
733  if (!$this->storageDirectory->has($source)) {
734  continue;
735  }
736 
737  $target = $relativeZipDirectory . '/' . $fileName;
738 
739  $stream = $this->storageDirectory->readStream($source);
740  $this->tmpDirectory->writeStream($target, $stream);
741  }
742 
743  $pathToZipFile = $processingDirectory . '/' . $downloadFilename . '.zip';
744  \ilUtil::zip($absoluteZipDirectory, $pathToZipFile);
745 
746  $this->tmpDirectory->deleteDir($relativeZipDirectory);
747 
748  $delivery = new \ilFileDelivery($processingDirectory . '/' . $downloadFilename . '.zip');
749  $delivery->setDisposition(\ilFileDelivery::DISP_ATTACHMENT);
750  $delivery->setMimeType(\ilMimeTypeUtil::APPLICATION__ZIP);
751  $delivery->setConvertFileNameToAsci(true);
752  $delivery->setDownloadFileName(\ilFileUtils::getValidFilename($downloadFilename . '.zip'));
753  $delivery->setDeleteFile(true);
754 
755  $delivery->deliver();
756  }
$files
Definition: metarefresh.php:49
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
$stream
PHP stream implementation.
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: linkback.php:22
$target
Definition: test.php:19
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 387 of file class.ilFileDataMail.php.

References getAbsoluteAttachmentPoolPathPrefix().

Referenced by deliverAttachmentsAsZip().

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

◆ getAbsoluteAttachmentPoolPathPrefix()

ilFileDataMail::getAbsoluteAttachmentPoolPathPrefix ( )
Returns
string

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

Referenced by getAbsoluteAttachmentPoolPathByFilename().

128  : string
129  {
130  return $this->mail_path . '/' . $this->user_id . '_';
131  }
+ 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 192 of file class.ilFileDataMail.php.

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

Referenced by adoptAttachments().

193  {
194  $path = $this->getMailPath() . '/' . $this->getAttachmentPathByMailId($a_mail_id) . '/' . $a_filename;
195 
196  if (file_exists($path) && is_readable($path)) {
197  return $path;
198  }
199 
200  return '';
201  }
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 139 of file class.ilFileDataMail.php.

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

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

◆ getAttachmentPathByMailId()

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

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

References $query, and $row.

Referenced by deliverAttachmentsAsZip(), and getAttachmentPath().

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

◆ getAttachmentsTotalSizeLimit()

ilFileDataMail::getAttachmentsTotalSizeLimit ( )
Returns
float|null

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

106  {
107  $max_size = $this->ilias->getSetting('mail_maxsize_attach', '');
108  if (!strlen($max_size)) {
109  return null;
110  }
111 
112  return (float) $this->ilias->getSetting('mail_maxsize_attach', 0) * 1024;
113  }
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 120 of file class.ilFileDataMail.php.

References $mail_path.

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

121  {
122  return $this->mail_path;
123  }
+ 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 413 of file class.ilFileDataMail.php.

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

◆ getUploadLimit()

ilFileDataMail::getUploadLimit ( )
Returns
int

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

References $mail_max_upload_file_size.

Referenced by storeAsAttachment().

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

◆ getUserFilesData()

ilFileDataMail::getUserFilesData ( )

get all attachments of a specific user public

Returns
array

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

References $files, and $rest.

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

◆ initAttachmentMaxUploadSize()

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

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

Referenced by __construct().

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

◆ initDirectory()

ilFileDataMail::initDirectory ( )

init directory overwritten method public

Returns
string path

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

References ilFileData\getPath().

82  {
83  if (is_writable($this->getPath())) {
84  if (mkdir($this->getPath() . '/' . MAILPATH)) {
85  if (chmod($this->getPath() . '/' . MAILPATH, 0755)) {
86  $this->mail_path = $this->getPath() . '/' . MAILPATH;
87  return true;
88  }
89  }
90  }
91  return false;
92  }
getPath()
get Path public
+ 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 344 of file class.ilFileDataMail.php.

Referenced by storeAsAttachment(), and storeUploadedFile().

345  {
346  if (file_exists($a_path)) {
347  $this->rotateFiles($a_path . ".old");
348  return \ilFileUtils::rename($a_path, $a_path . '.old');
349  }
350  return true;
351  }
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 432 of file class.ilFileDataMail.php.

Referenced by saveFiles().

433  {
434  $oStorage = self::getStorage($a_mail_id, $this->user_id);
435  $oStorage->create();
436  $storage_directory = $oStorage->getAbsolutePath();
437 
438  if (@!is_dir($storage_directory)) {
439  return false;
440  }
441 
442  return copy(
443  $this->mail_path . '/' . $this->user_id . '_' . $a_attachment,
444  $storage_directory . '/' . $a_attachment
445  );
446  }
+ 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 397 of file class.ilFileDataMail.php.

References saveFile().

398  {
399  if (!is_numeric($a_mail_id) || $a_mail_id < 1) {
400  throw new InvalidArgumentException('The passed mail_id must be a valid integer!');
401  }
402 
403  foreach ($a_attachments as $attachment) {
404  $this->saveFile($a_mail_id, $attachment);
405  }
406  }
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 284 of file class.ilFileDataMail.php.

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

Referenced by ilSoapUtils\distributeMails().

285  {
286  if (strlen($a_content) >= $this->getUploadLimit()) {
287  return 1;
288  }
289 
290  $name = ilUtil::_sanitizeFilemame($a_filename);
291  $this->rotateFiles($this->getMailPath() . '/' . $this->user_id . '_' . $name);
292 
293  $abs_path = $this->getMailPath() . '/' . $this->user_id . '_' . $name;
294 
295  if (!$fp = @fopen($abs_path, 'w+')) {
296  return false;
297  }
298  if (@fwrite($fp, $a_content) === false) {
299  @fclose($fp);
300  return false;
301  }
302  @fclose($fp);
303  return true;
304  }
getMailPath()
get mail path public
static _sanitizeFilemame($a_filename)
$a_content
Definition: workflow.php:93
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 309 of file class.ilFileDataMail.php.

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

310  {
311  $file['name'] = ilUtil::_sanitizeFilemame($file['name']);
312 
313  $this->rotateFiles($this->getMailPath() . '/' . $this->user_id . '_' . $file['name']);
314 
315  ilUtil::moveUploadedFile(
316  $file['tmp_name'],
317  $file['name'],
318  $this->getMailPath() . '/' . $this->user_id . '_' . $file['name']
319  );
320  }
getMailPath()
get mail path public
static _sanitizeFilemame($a_filename)
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 375 of file class.ilFileDataMail.php.

Referenced by unlinkFiles().

376  {
377  if (file_exists($this->mail_path . '/' . basename($this->user_id . '_' . $a_filename))) {
378  return unlink($this->mail_path . '/' . basename($this->user_id . '_' . $a_filename));
379  }
380  }
+ 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 358 of file class.ilFileDataMail.php.

References unlinkFile().

359  {
360  if (is_array($a_filenames)) {
361  foreach ($a_filenames as $file) {
362  if (!$this->unlinkFile($file)) {
363  return $file;
364  }
365  }
366  }
367  return '';
368  }
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().


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