/** * NotifyOwner * This will notify the list owner(s) of job runs. * This will send the appropriate message depending on the state of the job, the message is passed in so this function doesn't need to work anything out. * * @param String $subject Subject of the email to send. * @param String $message The message to send the owner. * * @see Jobs_Send::ActionJob * @see Jobs_Bounce::ActionJob * * @return Void Doesn't return anything. */ function NotifyOwner($subject=false, $message=false) { $this->Email_API->ForgetEmail(); $owner = GetUser($this->jobowner); $this->Email_API->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); if ($owner->smtpserver) { $this->Email_API->SetSmtp($owner->smtpserver, $owner->smtpusername, $owner->smtppassword, $owner->smtpport); } $this->Email_API->Set('Subject', $subject); if ($owner->fullname) { $this->Email_API->Set('FromName', $owner->fullname); } else { $this->Email_API->Set('FromName', GetLang('SendingSystem')); } if ($owner->emailaddress) { $this->Email_API->Set('FromAddress', $owner->emailaddress); } else { $this->Email_API->Set('FromAddress', GetLang('SendingSystem_From')); } $this->Email_API->Set('Multipart', false); $this->Email_API->AddBody('text', $message); $this->Email_API->ClearAttachments(); $this->Email_API->ClearRecipients(); $query = "SELECT listid, ownername, owneremail FROM " . SENDSTUDIO_TABLEPREFIX . "lists WHERE listid IN(" . implode(',', $this->jobdetails['Lists']) . ")"; // if we're processing bounces, we don't want to email list owners who cannot edit their bounce settings if ($this->jobtype == 'bounce') { $query = "SELECT l.listid, l.ownername, l.owneremail FROM ". SENDSTUDIO_TABLEPREFIX . "lists l, " . SENDSTUDIO_TABLEPREFIX . "usergroups_permissions p, " . SENDSTUDIO_TABLEPREFIX . "users u WHERE l.listid IN(" . implode(',', $this->jobdetails['Lists']) . ") AND l.ownerid = u.userid AND u.groupid = p.groupid AND p.area = 'lists' AND p.subarea = 'bouncesettings'"; } $result = $this->Db->Query($query); $notified = false; while ($row = $this->Db->Fetch($result)) { $this->Email_API->AddRecipient($row['owneremail'], $row['ownername'], 't'); $notified = true; } // notify the system administrator if there's no one else to tell if (!$notified) { $this->Email_API->AddRecipient(SENDSTUDIO_EMAIL_ADDRESS, '', 't'); } $this->Email_API->Send(); $this->Email_API->ForgetEmail(); }
/** * SetupJob * This sets up the 'send job' ready to go. * - It checks the "queue" is set up. If it's not, this will return false. * - It loads the newsletter based on the "Newsletter" in the jobdetails array. If it's not a valid newsletter, then this will return false. * - The newsletter gets stored in the newsletter array for easy access. * - Loads the user object (so we can easily look at the per-hour & other sending limits). * - It gets a list of attachments for the newsletter and gives them to the email class * - Sets smtp details for the email class * - Sets stat/listid's for the email class headers to use * - Sets open/link tracking for the email class * - Sets the charset for the email class * - Sets up the rest of the details the email class needs (from details, bounce address, reply-to etc) * - Works out the "userpause" time which is used later on to sleep for a period of time between each email sent * - Gets the custom fields from the content so later on we know which fields to load for each subscriber * - Works out the "to" custom fields so later on we know which fields to load for each subscriber * * @uses IsQueue * @uses Newsletters_API::Load * @uses GetUser * @uses newsletter * @uses SendStudio_Functions::GetAttachments * @uses Email_API * @uses Email_API::AddAttachment * @uses Email_API::AddBody * @uses Email_API::AppendBody * @uses Email_API::ClearAttachments * @uses Email_API::ForceLinkChecks * @uses Email_API::ForgetEmail * @uses Email_API::GetCustomFields * @uses Email_API::Set * @uses Email_API::SetSmtp * @uses Email_API::TrackLinks * @uses Email_API::TrackOpens * @uses userpause * @uses User_API::perhour * @uses custom_fields_to_replace * @uses to_customfields * * @return Boolean Returns false if the 'send queue' isn't set up already, or if the newsletter can't be loaded or doesn't exist. * Otherwise sets up the email class and other details ready for use, and returns true. */ function SetupJob($jobid=0, $queueid=0) { $is_queue = $this->IsQueue($queueid, 'send'); if (!$is_queue) { return false; } // if we can't load the newsletter, pause it and immediately stop. $news_loaded = $this->Newsletters_API->Load($this->jobdetails['Newsletter']); if (!$news_loaded) { return false; } $this->user = GetUser($this->jobowner); $this->newsletter = array(); $this->newsletter['Format'] = $this->Newsletters_API->Get('format'); $this->newsletter['Subject'] = $this->Newsletters_API->Get('subject'); $this->newsletter['TextBody'] = $this->Newsletters_API->Get('textbody'); $this->newsletter['HTMLBody'] = $this->Newsletters_API->Get('htmlbody'); $this->newsletter['Attachments'] = $this->sendstudio_functions->GetAttachments('newsletters', $this->jobdetails['Newsletter'], true); $this->Email_API->ForgetEmail(); $this->Email_API->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); $this->Email_API->Set('statid', $this->statid); $this->Email_API->Set('listids', $this->jobdetails['Lists']); if (SENDSTUDIO_FORCE_UNSUBLINK) { $this->Email_API->ForceLinkChecks(true); } if ($this->jobdetails['TrackLinks']) { $this->Email_API->TrackLinks(true); } if ($this->jobdetails['TrackOpens']) { $this->Email_API->TrackOpens(true); } $this->Email_API->Set('CharSet', $this->jobdetails['Charset']); if (!SENDSTUDIO_SAFE_MODE) { $this->Email_API->Set('imagedir', TEMP_DIRECTORY . '/send.' . $jobid . '.' . $queueid); } else { $this->Email_API->Set('imagedir', TEMP_DIRECTORY . '/send'); } // clear out the attachments just to be safe. $this->Email_API->ClearAttachments(); if ($this->newsletter['Attachments']) { $path = $this->newsletter['Attachments']['path']; $files = $this->newsletter['Attachments']['filelist']; foreach ($files as $p => $file) { $this->Email_API->AddAttachment($path . '/' . $file); } } $this->Email_API->Set('Subject', $this->newsletter['Subject']); $this->Email_API->Set('FromName', $this->jobdetails['SendFromName']); $this->Email_API->Set('FromAddress', $this->jobdetails['SendFromEmail']); $this->Email_API->Set('ReplyTo', $this->jobdetails['ReplyToEmail']); $this->Email_API->Set('BounceAddress', $this->jobdetails['BounceEmail']); $this->Email_API->Set('Multipart', $this->jobdetails['Multipart']); $this->Email_API->Set('EmbedImages', $this->jobdetails['EmbedImages']); $this->Email_API->Set('SentBy', $this->user->Get('userid')); if ($this->jobdetails['Multipart']) { if ($this->newsletter['TextBody'] && $this->newsletter['HTMLBody'] && $this->newsletter['Format'] == 'b') { $sent_format = 'm'; } else { $this->Email_API->Set('Multipart', false); } } if ($this->newsletter['TextBody'] && in_array($this->newsletter['Format'], array('t', 'b'))) { $this->Email_API->AddBody('text', $this->newsletter['TextBody']); $this->Email_API->AppendBody('text', $this->user->Get('textfooter')); $this->Email_API->AppendBody('text', stripslashes(SENDSTUDIO_TEXTFOOTER)); } if ($this->newsletter['HTMLBody'] && in_array($this->newsletter['Format'], array('h', 'b'))) { $this->Email_API->AddBody('html', $this->newsletter['HTMLBody']); $this->Email_API->AppendBody('html', $this->user->Get('htmlfooter')); $this->Email_API->AppendBody('html', stripslashes(SENDSTUDIO_HTMLFOOTER)); } if ($this->user->smtpserver) { $this->Email_API->SetSmtp($this->user->smtpserver, $this->user->smtpusername, $this->user->smtppassword, $this->user->smtpport); } /* * The following code pauses the sending depending on if userpause * (undescriptive variable name) is set or if the user has gone over * their hourly limit. */ if (is_null($this->userpause)) { $pause = $pausetime = 0; $hourlyRate = $this->user->group->limit_hourlyemailsrate; /* * If the hourly rate is greater than 0, set the pause time to it. * * Why originally pause was set to this is logically bad and creates * unclear code. This should be written differently or at least use * better variable names and have been originally commented. * * @todo refactor */ if ($hourlyRate > 0) { $pause = $hourlyRate; } // in case the system rate is less than the user rate, lower it. if (SENDSTUDIO_MAXHOURLYRATE > 0) { if ($pause == 0) { $pause = SENDSTUDIO_MAXHOURLYRATE; } else { $pause = min($pause, SENDSTUDIO_MAXHOURLYRATE); } } if ($pause > 0) { $pausetime = 3600 / $pause; } $this->userpause = $pausetime; } $this->custom_fields_to_replace = $this->Email_API->GetCustomFields(); $to_customfields = array(); if ($this->jobdetails['To_FirstName']) { $to_customfields[] = $this->jobdetails['To_FirstName']; } if ($this->jobdetails['To_LastName']) { $to_customfields[] = $this->jobdetails['To_LastName']; } $this->to_customfields = array_unique($to_customfields); return true; }