3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Mailing_BAO_Spool
extends CRM_Mailing_DAO_Spool
{
40 public function __construct() {
41 parent
::__construct();
45 * Store Mails into Spool table.
48 * @param array $headers
49 * The string of headers to send with the mail.
52 * The full text of the message body, including any.
57 * @internal param mixed $recipients Either a comma-seperated list of recipients
58 * (RFC822 compliant), or an array of recipients,
59 * each RFC822 valid. This may contain recipients not
60 * specified in the headers, for Bcc:, resending
63 * @return mixed Returns true on success, or a CRM_Eore_Error
64 * containing a descriptive error message on
67 public function send($recipient, $headers, $body, $job_id = NULL) {
69 foreach ($headers as $name => $value) {
70 $headerStr[] = "$name: $value";
72 $headerStr = implode("\n", $headerStr);
74 if (is_null($job_id)) {
75 // This is not a bulk mailing. Create a dummy job for it.
77 $session = CRM_Core_Session
::singleton();
79 $params['created_id'] = $session->get('userID');
80 $params['created_date'] = date('YmdHis');
81 $params['scheduled_id'] = $params['created_id'];
82 $params['scheduled_date'] = $params['created_date'];
83 $params['is_completed'] = 1;
84 $params['is_archived'] = 1;
85 $params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
86 $params['subject'] = $headers['Subject'];
87 $params['name'] = $headers['Subject'];
89 $mailing = CRM_Mailing_BAO_Mailing
::create($params, $ids);
91 if (empty($mailing) ||
is_a($mailing, 'CRM_Core_Error')) {
92 return PEAR
::raiseError('Unable to create spooled mailing.');
95 $job = new CRM_Mailing_BAO_MailingJob();
96 $job->is_test
= 0; // if set to 1 it doesn't show in the UI
97 $job->status
= 'Complete';
98 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
99 $job->start_date
= $job->scheduled_date
;
100 $job->end_date
= $job->scheduled_date
;
101 $job->mailing_id
= $mailing->id
;
103 $job_id = $job->id
; // need this for parent_id below
105 $job = new CRM_Mailing_BAO_MailingJob();
107 $job->status
= 'Complete';
108 $job->scheduled_date
= CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
109 $job->start_date
= $job->scheduled_date
;
110 $job->end_date
= $job->scheduled_date
;
111 $job->mailing_id
= $mailing->id
;
112 $job->parent_id
= $job_id;
113 $job->job_type
= 'child';
115 $job_id = $job->id
; // this is the one we want for the spool
117 if (is_array($recipient)) {
118 $recipient = implode(';', $recipient);
122 $session = CRM_Core_Session
::singleton();
126 'recipient_email' => $recipient,
127 'headers' => $headerStr,
129 'added_at' => date("YmdHis"),
130 'removed_at' => NULL,
133 $spoolMail = new CRM_Mailing_DAO_Spool();
134 $spoolMail->copyValues($params);