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'];
61 $mailing = CRM_Mailing_BAO_Mailing
::create($params, $ids);
63 if (empty($mailing) ||
is_a($mailing, 'CRM_Core_Error')) {
64 return PEAR
::raiseError('Unable to create spooled mailing.');
67 $job = new CRM_Mailing_BAO_MailingJob();
68 // if set to 1 it doesn't show in the UI
70 $job->status
= 'Complete';
71 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
72 $job->start_date
= $job->scheduled_date
;
73 $job->end_date
= $job->scheduled_date
;
74 $job->mailing_id
= $mailing->id
;
76 // need this for parent_id below
79 $job = new CRM_Mailing_BAO_MailingJob();
81 $job->status
= 'Complete';
82 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
83 $job->start_date
= $job->scheduled_date
;
84 $job->end_date
= $job->scheduled_date
;
85 $job->mailing_id
= $mailing->id
;
86 $job->parent_id
= $job_id;
87 $job->job_type
= 'child';
89 // this is the one we want for the spool
92 if (is_array($recipient)) {
93 $recipient = implode(';', $recipient);
97 $session = CRM_Core_Session
::singleton();
101 'recipient_email' => $recipient,
102 'headers' => $headerStr,
104 'added_at' => date("YmdHis"),
105 'removed_at' => NULL,
108 $spoolMail = new CRM_Mailing_DAO_Spool();
109 $spoolMail->copyValues($params);