3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_BAO_Spool
extends CRM_Mailing_DAO_Spool
{
22 public function __construct() {
23 parent
::__construct();
27 * Store Mails into Spool table.
29 * @param string|array $recipient
30 * Either a comma-seperated list of recipients
31 * (RFC822 compliant), or an array of recipients,
32 * each RFC822 valid. This may contain recipients not
33 * specified in the headers, for Bcc:, resending
35 * @param array $headers
36 * The array of headers to send with the mail.
39 * The full text of the message body, including any mime parts, etc.
43 * @return bool|CRM_Core_Error
46 public function send($recipient, $headers, $body, $job_id = NULL) {
48 foreach ($headers as $name => $value) {
49 $headerStr[] = "$name: $value";
51 $headerStr = implode("\n", $headerStr);
53 if (is_null($job_id)) {
54 // This is not a bulk mailing. Create a dummy job for it.
56 $session = CRM_Core_Session
::singleton();
58 $params['created_id'] = $session->get('userID');
59 $params['created_date'] = date('YmdHis');
60 $params['scheduled_id'] = $params['created_id'];
61 $params['scheduled_date'] = $params['created_date'];
62 $params['is_completed'] = 1;
63 $params['is_archived'] = 1;
64 $params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
65 $params['subject'] = $headers['Subject'];
66 $params['name'] = $headers['Subject'];
68 $mailing = CRM_Mailing_BAO_Mailing
::create($params, $ids);
70 if (empty($mailing) ||
is_a($mailing, 'CRM_Core_Error')) {
71 return PEAR
::raiseError('Unable to create spooled mailing.');
74 $job = new CRM_Mailing_BAO_MailingJob();
75 // if set to 1 it doesn't show in the UI
77 $job->status
= 'Complete';
78 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
79 $job->start_date
= $job->scheduled_date
;
80 $job->end_date
= $job->scheduled_date
;
81 $job->mailing_id
= $mailing->id
;
83 // need this for parent_id below
86 $job = new CRM_Mailing_BAO_MailingJob();
88 $job->status
= 'Complete';
89 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
90 $job->start_date
= $job->scheduled_date
;
91 $job->end_date
= $job->scheduled_date
;
92 $job->mailing_id
= $mailing->id
;
93 $job->parent_id
= $job_id;
94 $job->job_type
= 'child';
96 // this is the one we want for the spool
99 if (is_array($recipient)) {
100 $recipient = implode(';', $recipient);
104 $session = CRM_Core_Session
::singleton();
108 'recipient_email' => $recipient,
109 'headers' => $headerStr,
111 'added_at' => date("YmdHis"),
112 'removed_at' => NULL,
115 $spoolMail = new CRM_Mailing_DAO_Spool();
116 $spoolMail->copyValues($params);