17 require_once SQ_PACKAGES_PATH.
'/bulkmail/bulkmail_post_office/bulkmail_post_office.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
46 $this->_ser_attrs = TRUE;
47 parent::__construct($assetid);
61 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id,
'bulkmail_post_office', TRUE);
62 if (!empty($parents)) {
63 $array_keys = array_keys($parents);
64 $assetid = array_pop($array_keys);
66 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($assetid)) {
67 $post_office = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
72 if (is_null($post_office)) {
73 $post_office = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
93 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
94 $details_info = $bm->generateJobDetails($this, $post_office);
95 $errors = $bm->isValidJob($details_info, TRUE);
96 if (!empty($errors)) {
97 trigger_localised_error(
'BML0001', E_USER_WARNING, $errors[0]);
102 $server_details = $post_office->attr(
'server_details');
103 $driver = array_get_index($server_details,
'driver',
'');
105 $mail_object = $mf->factory($driver, $server_details);
108 $data_dir = $post_office->data_path.
'/.data/'.$this->id;
109 require_once SQ_PACKAGES_PATH.
'/bulkmail/bulk_mailer.inc';
111 $content = $bm->generateContent($details_info, $data_dir);
114 $use_post_office_header = $this->
attr(
'use_post_office_header');
115 if ($use_post_office_header) {
116 $from = $post_office->attr(
'from');
117 $subject = $post_office->attr(
'subject');
118 $header_details = $post_office->attr(
'header_details');
120 $from = $this->
attr(
'from');
121 $subject = $this->
attr(
'subject');
122 $header_details = $this->
attr(
'header_details');
124 $header_details[
'from'] = $from;
126 require_once SQ_FUDGE_PATH.
'/general/text.inc';
127 $keywords = retrieve_keywords_replacements($subject);
128 $replacements = Array();
129 $content_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($details_info[
'content_id']);
130 foreach ($keywords as $word) {
131 $replacements[$word] = $content_asset->getKeywordReplacement($word);
133 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($content_asset);
134 replace_keywords($subject, $replacements);
138 $header_details[
'subject'] = $subject;
139 $header_details[
'To'] = $recipient;
142 if (!empty($header_details[
'subject'])) {
143 $header_details[
'subject'] .=
' (Preview)';
146 $text_only_content = html_entity_decode(strip_tags($content));
149 $mime =
new Mail_mime(
"\n");
150 if (!$this->
attr(
'content_text_only')) {
151 $mime->setHTMLBody($content);
153 $mime->setTxtBody($text_only_content);
155 'head_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
156 'text_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
157 'html_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
159 $body = @$mime->get($param);
160 $headers = @$mime->headers($header_details);
161 $status = @$mail_object->send($recipient, $headers, $body);
162 if ($status instanceof PEAR_Error) {
164 trigger_localised_error(
'BML0002', E_USER_WARNING, $status->getMessage());
185 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
186 $queued_jobs = $bm->getQueuedJobs($this->
id);
189 if (!empty($queued_jobs))
return FALSE;
191 switch ($new_status) {
194 if (!$bm->addJob($this))
return FALSE;
196 case SQ_STATUS_UNDER_CONSTRUCTION:
197 $job_path = $bm->getJobDataPath($this->
id);
198 clear_directory($job_path);
202 return parent::processStatusChange($new_status, $update_parents);
218 return $GLOBALS[
'SQ_SYSTEM']->am->generateRawContent($details);