Class AttachmentsHandler
Class AttachmentsHandler
This class will handle the email attachments organization. Every email must have
its own attachments directory so that we can avoid file issues between emails.
-
AttachmentsHandler
implements
AttachmentsHandlerInterface
Methods summary
public
__construct( string $p_uploadsDirPath )
Class Constructor
Parameters
$p_uploadsDirPath
Path to the server's "uploads" directory. The uploads directory
must already contain a "tmp" and an "attachments" directory created
by an FTP client (resolves permission problems).
Throws
InvalidArgumentException
If the provided argument is not valid.
public
uploadAttachment( EmailAttachmentInterface $attachment )
: EmailAttachment
Upload an attachment to "uploads/tmp" directory.
Upload an attachment to "uploads/tmp" directory.
This method takes the uploaded file information and places it in the "uploads/tmp" directory
as a temporary place, until the "uploadEmailCollection" moves it to the final destination.
Parameters
$attachment
- Contains the file information (path is required).
Returns
EmailAttachmentReturns an EmailAttachment instance with the new attachment path.
Throws
Exception
If method cannot copy the file from the PHP temp dir to the destination path.
Implementation of
public
uploadEmailCollection( EmailCollectionInterface $collection )
Process attachments for each email in collection.
Process attachments for each email in collection.
Important! Use this method after you save the emails into the database. The reason is that
this property separates each attachment file by its email ID, a value that is only accessible
after the email is already saved.
Deprecated
Since v2.3.3.0 this method is marked as deprecated and will be removed from the class.
Parameters
$collection
Passed by reference, contains emails of which the
attachments must be processed.
Codecoverageignore
Implementation of
public
deleteEmailCollection( EmailCollectionInterface $collection )
Delete attachments for each email in collection.
Delete attachments for each email in collection.
Every email has its own attachments directory. When emails are deleted we need
to remove their respective attachments.
Deprecated
Since v2.3.3.0 this method is marked as deprecated and will be removed from the class.
Parameters
$collection
- Contains email records to be deleted.
Codecoverageignore
Implementation of
public
getAttachmentsSize( void )
: integer
Get attachments directory file size in bytes.
Get attachments directory file size in bytes.
Returns
integer
Returns the size in bytes.
Link
Implementation of
public
deleteOldAttachments( DateTime $removalDate )
: array
Delete old attachments prior to removal date.
Delete old attachments prior to removal date.
This method will remove all the files and directories that are prior to the given date.
It will return removal information so that user can see how much disc spaces was set free.
Parameters
$removalDate
- From this date and before the attachment files will be removed.
Returns
array
Returns an array which contains the "count" and "size" values or the operation.
Implementation of
public
backupEmailAttachments( EmailInterface & $email )
Process email attachments.
Process email attachments.
This method will move all the email attachments to the "uploads/attachments" directory
and store them there for future reference and history navigation purposes. The email needs
to be saved first because the email ID will be used to distinguish the emails.
Parameters
$email
- Passed by reference, contains the email data.
Implementation of
public
deleteEmailAttachments( EmailInterface $email )
Deletes email attachments.
Deletes email attachments.
This method will remove all the email attachments from the server.
Parameters
$email
- Contains the email information.
Implementation of
public
emptyTempDirectory( void )
Removes all files within the "uploads/tmp" directory.
Removes all files within the "uploads/tmp" directory.
There might be cases where old unused files are left within the "tmp" directory and they
need to be deleted. This function will remove all these files.
Implementation of
Properties summary
protected
$uploadsDirPath
: string
Full server path to "uploads" directory.
Full server path to "uploads" directory.