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
{
20 * Store Mails into Spool table.
22 * @param string|array $recipient
23 * Either a comma-seperated list of recipients
24 * (RFC822 compliant), or an array of recipients,
25 * each RFC822 valid. This may contain recipients not
26 * specified in the headers, for Bcc:, resending
28 * @param array $headers
29 * The array of headers to send with the mail.
32 * The full text of the message body, including any mime parts, etc.
36 * @return bool|CRM_Core_Error
39 public function send($recipient, $headers, $body, $job_id = NULL) {
41 foreach ($headers as $name => $value) {
42 $headerStr[] = "$name: $value";
44 $headerStr = implode("\n", $headerStr);
46 if (is_null($job_id)) {
47 // This is not a bulk mailing. Create a dummy job for it.
49 $session = CRM_Core_Session
::singleton();
51 $params['created_id'] = $session->get('userID');
52 $params['created_date'] = date('YmdHis');
53 $params['scheduled_id'] = $params['created_id'];
54 $params['scheduled_date'] = $params['created_date'];
55 $params['is_completed'] = 1;
56 $params['is_archived'] = 1;
57 $params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
58 $params['subject'] = $headers['Subject'];
59 $params['name'] = $headers['Subject'];
60 $mailing = CRM_Mailing_BAO_Mailing
::create($params);
62 if (empty($mailing) ||
is_a($mailing, 'CRM_Core_Error')) {
63 return PEAR
::raiseError('Unable to create spooled mailing.');
66 $job = new CRM_Mailing_BAO_MailingJob();
67 // if set to 1 it doesn't show in the UI
69 $job->status
= 'Complete';
70 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
71 $job->start_date
= $job->scheduled_date
;
72 $job->end_date
= $job->scheduled_date
;
73 $job->mailing_id
= $mailing->id
;
75 // need this for parent_id below
78 $job = new CRM_Mailing_BAO_MailingJob();
80 $job->status
= 'Complete';
81 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
82 $job->start_date
= $job->scheduled_date
;
83 $job->end_date
= $job->scheduled_date
;
84 $job->mailing_id
= $mailing->id
;
85 $job->parent_id
= $job_id;
86 $job->job_type
= 'child';
88 // this is the one we want for the spool
91 if (is_array($recipient)) {
92 $recipient = implode(';', $recipient);
96 $session = CRM_Core_Session
::singleton();
100 'recipient_email' => $recipient,
101 'headers' => $headerStr,
103 'added_at' => date("YmdHis"),
104 'removed_at' => NULL,
107 $spoolMail = new CRM_Mailing_DAO_Spool();
108 $spoolMail->copyValues($params);