17 require_once
'Mail/Queue/Container.php';
51 if (!is_array($options) || !isset($options[
'dir'])) {
52 return new Mail_Queue_Error(MAILQUEUE_ERROR_NO_OPTIONS,
53 $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__,
54 'No queue directory specified!');
56 $this->dir = $options[
'dir'];
69 $this->_last_item = 0;
70 $this->queue_data = array();
73 foreach ($queue_files as $index => $messageID) {
74 if ($this->limit && ($index + 1 > $this->limit))
break;
77 $mail_body =
new Mail_Queue_Body(
79 $mail_array[
'create_time'],
80 $mail_array[
'time_to_send'],
81 $mail_array[
'sent_time'],
82 $mail_array[
'id_user'],
84 $mail_array[
'sender'],
85 $mail_array[
'recipient'],
86 unserialize($mail_array[
'headers']),
87 unserialize($mail_array[
'body']),
88 $mail_array[
'delete_after_send'],
89 $mail_array[
'try_sent']
91 if (is_a($mail_body,
'Mail_Queue_Body')) {
92 $this->queue_data[$this->_last_item] = $mail_body;
112 if (!is_dir($dir))
return Array();
115 if ($handle = opendir($dir)) {
116 while (($file = readdir($handle)) !==
false) {
117 if ($file ==
'.' || $file ==
'..') {
119 }
else if (is_file($dir.
'/'.$file)) {
148 function put($time_to_send, $id_user, $ip, $sender,
149 $recipient, $headers, $body, $delete_after_send=
true)
153 if (method_exists($this,
'_isSerialized')) {
154 if ($this->_isSerialized($recipient)) {
155 $to = unserialize($recipient);
160 $header_array = unserialize($headers);
161 if (isset($header_array[
'custom_id'])) {
162 $custom_id = substr($header_array[
'custom_id'], 0, 113);
163 $id = md5(uniqid($custom_id));
164 unset($header_array[
'custom_id']);
165 $headers = serialize($header_array);
167 $id = md5(uniqid(
''));
172 'time_to_send' => $time_to_send,
173 'id_user' => $id_user,
177 'headers' => $headers,
179 'delete_after_send' => $delete_after_send,
181 'create_time' => date(
"Y-m-d G:i:s", time()),
199 if (is_file($this->dir.
'/'.$id)) {
200 require $this->dir.
'/'.$id;
202 return isset($mail_entry) ? $mail_entry : Array();
215 $output =
'<?php $mail_entry = '.var_export($contents,
true).
'; ?>';
216 $fp = fopen($this->dir.
'/'.$id,
'w');
217 $return_value = fwrite($fp, $output);
219 return $return_value;
232 if (!is_object($mail) || !is_a($mail,
'mail_queue_body')) {
233 return new Mail_Queue_Error(
'Expected: Mail_Queue_Body class',
236 $count = $mail->_try();
239 if (!empty($mail_array)) {
240 $mail_array[
'try_sent'] = $count;
257 if (!is_object($mail) || !is_a($mail,
'mail_queue_body')) {
258 return new Mail_Queue_Error(MAILQUEUE_ERROR_UNEXPECTED,
259 $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__,
260 'Expected: Mail_Queue_Body class');
264 if (!empty($mail_array)) {
265 $mail_array[
'sent_time'] = time();
284 $success = rename($this->dir.
'/'.$id, $this->dir.
'/sent/'.$id);
286 if ($success ===
false) {
287 return new Mail_Queue_Error(MAILQUEUE_ERROR_QUERY_FAILED,
288 $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__,
289 'Unable to delete mail from queue (MailID #'.$id.
')');