class MailSenderQueue

Class to handle mailing queues

Constants

SORTORDER_ASC

SORTORDER_DESC

SORT_COUNT

SORT_DATE

SORT_TITLE

SORT_STATUS

SORT_VOLUME

STATUS_TOSEND

STATUS_SENT

STATUS_ERROR

Methods

__construct(string $directory)

Initialize queue with a root folder for all queues (each queue will have a subfolder)

string
createQueue(string $qtitle, int $qbatchcount = 50)

Create a new queue

object
getQueue(string $qid)

Get info about a queue.

object[]
getQueues(string $sort, string $sortorder = self::SORTORDER_ASC)

Get data about all queues

bool
push(string $qid, MailContent $mail, string $from, string $to, string $subject)

Push an email to the queue

renameQueue(string $qid, string $value)

Rename a queue

unlockQueue(string $qid)

Unlock a queue (a queue is locked when all email have been sent)

int
searchQueue(string $qid, string $mail)

Search an email recipient in the queue

string
emlFromQueue(string $qid, int $index)

Extract an email from the queue

closeQueue(string $qid)

Close a queue (all emails have been pushed in the queue)

bool|string
resendFromQueue(Mailer $mailer, string $qid, int $index, string|NULL $bcc = NULL, string|NULL $to = NULL)

Resend an email from the queue

string
newQueueFromErrors(string $qid, string $title)

Create a new queue with email whose status is error

bool|string
sendQueue(Mailer $mailer, string $qid, string $suppl_headers = "")

Send a batch of email through a Mailer instance, and optionnally add headers

object[]
recipientsFromQueue(string $qid)

Get recipients for a queue

recipientError(string $qid, int $index)

Set an email to error (after it has been sent)

clearLog(string $qid)

Erase log for a queue

purgeQueue(string $qid)

Erase a queue from disk

purgeAllQueues()

Erase all queues on disk

Details

at line 211
__construct(string $directory)

Initialize queue with a root folder for all queues (each queue will have a subfolder)

Parameters

string $directory Root folder for queues storage

at line 228
string createQueue(string $qtitle, int $qbatchcount = 50)

Create a new queue

Parameters

string $qtitle Name of queue to create
int $qbatchcount Number of emails to send at a time (batch sending)

Return Value

string The unique ID of the queue

at line 255
object getQueue(string $qid)

Get info about a queue.

The litteral object returned have the following properties :

  • count : number of emails in the queue
  • sendOffset : the index of the next email to send (used when batching sendings)
  • batchCount : the number of emails to send in one batch
  • date : the timestamp of queue creation
  • lastBatchDate : the timestamp of the last batch sending process
  • sendLog : an array of string for log
  • title : the queue title
  • locked : contains TRUE if queue has been sent completely, FALSE otherwise
  • volume : the size of the queue (in bytes)

Parameters

string $qid ID of the queue

Return Value

object Litteral object describing the queue

at line 269
object[] getQueues(string $sort, string $sortorder = self::SORTORDER_ASC)

Get data about all queues

Parameters

string $sort One of the SORT_xxx constant defined here
string $sortorder One of the SORTORDER_xxx constant defined here

Return Value

object[] Returns an indexed array of queues litteral objects (indexes are the queues ID)

See also

MailSenderQueue::getQueue

at line 317
bool push(string $qid, MailContent $mail, string $from, string $to, string $subject)

Push an email to the queue

Parameters

string $qid ID of the queue
MailContent $mail Email object
string $from Email address of the sender
string $to Email recipient
string $subject Email subject

Return Value

bool Always return FALSE (meaning no error)

at line 341
renameQueue(string $qid, string $value)

Rename a queue

Parameters

string $qid ID of the queue
string $value New name

at line 353
unlockQueue(string $qid)

Unlock a queue (a queue is locked when all email have been sent)

Parameters

string $qid ID of the queue

at line 367
int searchQueue(string $qid, string $mail)

Search an email recipient in the queue

Parameters

string $qid ID of the queue
string $mail Email of recipient

Return Value

int 0-index of email found in the queue

at line 396
string emlFromQueue(string $qid, int $index)

Extract an email from the queue

Parameters

string $qid ID of the queue
int $index 0-index of email in the queue

Return Value

string Email raw text (headers and content)

at line 425
closeQueue(string $qid)

Close a queue (all emails have been pushed in the queue)

Parameters

string $qid ID of the queue

at line 441
bool|string resendFromQueue(Mailer $mailer, string $qid, int $index, string|NULL $bcc = NULL, string|NULL $to = NULL)

Resend an email from the queue

Parameters

Mailer $mailer Mailer used for sending the email again
string $qid ID of the queue
int $index 0-index of the email to send in the queue
string|NULL $bcc Recipient in bcc, if necessary
string|NULL $to Recipient to send the email to, if we want to override the previous recipient

Return Value

bool|string Return FALSE if email was sent (meaning no error), or a string with an error message

at line 459
string newQueueFromErrors(string $qid, string $title)

Create a new queue with email whose status is error

Parameters

string $qid ID of the queue to extract emails in error from
string $title Name of the new queue

Return Value

string Returns the ID of the new queue created

at line 493
bool|string sendQueue(Mailer $mailer, string $qid, string $suppl_headers = "")

Send a batch of email through a Mailer instance, and optionnally add headers

Parameters

Mailer $mailer Mailer instance to send email through
string $qid ID of the queue to process
string $suppl_headers Optionnal supplementary headers

Return Value

bool|string Returns FALSE if the process was OK, an string with an error message otherwise

at line 553
object[] recipientsFromQueue(string $qid)

Get recipients for a queue

The litteral objects returned in the array have the following properties :

  • to : recipient
  • id : 0-index of the email in the source queue
  • status : one of the STATUS constants

Parameters

string $qid ID of the queue to extract recipients from

Return Value

object[] Return an array of litteral objects about recipients

at line 582
recipientError(string $qid, int $index)

Set an email to error (after it has been sent)

Useful when the email recipient is later reported to be wrong

Parameters

string $qid ID of the queue
int $index 0-index of the email to set to error status

at line 622
clearLog(string $qid)

Erase log for a queue

Parameters

string $qid ID of the queue

at line 642
purgeQueue(string $qid)

Erase a queue from disk

Parameters

string $qid ID of the queue

at line 662
purgeAllQueues()

Erase all queues on disk