with('response')->begin()-> isRedirected()-> followRedirect()-> end()-> with('response')->begin()-> matches('/ok/')-> end() ; $b->test()->ok(file_exists($uploadedFile), 'file is uploaded'); $b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded'); $c = new Criteria(); $c->add(AttachmentPeer::NAME, $name); $attachments = AttachmentPeer::doSelect($c); $b->test()->is(count($attachments), 1, 'the attachment has been saved in the database'); $b->test()->ok($attachments[0]->getArticleId(), 'the attachment is tied to an article'); $b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database'); // sfValidatorPropelUnique // create a category with a unique name $b-> get('/unique/category')-> with('request')->begin()-> isParameter('module', 'unique')-> isParameter('action', 'category')-> end()-> with('response')->isStatusCode(200)->
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = AttachmentPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setArticleId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setName($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setFile($arr[$keys[3]]); } }
/** * Returns the number of related Attachment objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Attachment objects. * @throws PropelException */ public function countAttachments(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(ArticlePeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collAttachments === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(AttachmentPeer::ARTICLE_ID, $this->id); $count = AttachmentPeer::doCount($criteria, false, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(AttachmentPeer::ARTICLE_ID, $this->id); if (!isset($this->lastAttachmentCriteria) || !$this->lastAttachmentCriteria->equals($criteria)) { $count = AttachmentPeer::doCount($criteria, false, $con); } else { $count = count($this->collAttachments); } } else { $count = count($this->collAttachments); } } return $count; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(AttachmentPeer::DATABASE_NAME); $criteria->add(AttachmentPeer::ID, $pks, Criteria::IN); $objs = AttachmentPeer::doSelect($criteria, $con); } return $objs; }
public function countAttachments(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(ArticlePeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collAttachments === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(AttachmentPeer::ARTICLE_ID, $this->id); $count = AttachmentPeer::doCount($criteria, $con); } } else { if (!$this->isNew()) { $criteria->add(AttachmentPeer::ARTICLE_ID, $this->id); if (!isset($this->lastAttachmentCriteria) || !$this->lastAttachmentCriteria->equals($criteria)) { $count = AttachmentPeer::doCount($criteria, $con); } else { $count = count($this->collAttachments); } } else { $count = count($this->collAttachments); } } return $count; }
function sendEmail($mail, $save_emails = 1, $testmode = false) { $success = false; $this->test = $testmode; global $sugar_config; global $mod_strings; global $locale; $OBCharset = $locale->getPrecedentPreference('default_email_charset'); $mod_strings = return_module_language($sugar_config['default_language'], 'EmailMan'); //get tracking entities locations. if (!isset($this->tracking_url)) { $admin = Administration::getSettings('massemailer'); //retrieve all admin settings. if (isset($admin->settings['massemailer_tracking_entities_location_type']) and $admin->settings['massemailer_tracking_entities_location_type'] == '2' and isset($admin->settings['massemailer_tracking_entities_location'])) { $this->tracking_url = $admin->settings['massemailer_tracking_entities_location']; } else { $this->tracking_url = $sugar_config['site_url']; } } //make sure tracking url ends with '/' character $strLen = strlen($this->tracking_url); if ($this->tracking_url[$strLen - 1] != '/') { $this->tracking_url .= '/'; } $module = BeanFactory::getBean($this->related_type, $this->related_id); if (empty($module)) { return false; } $module->emailAddress->handleLegacyRetrieve($module); //check to see if bean has a primary email address if (!$this->is_primary_email_address($module)) { //no primary email address designated, do not send out email, create campaign log //of type send error to denote that this user was not emailed $this->set_as_sent($module->email1, true, null, null, 'send error'); //create fatal logging for easy review of cause. $GLOBALS['log']->fatal('Email Address provided is not Primary Address for email with id ' . $module->email1 . "' Emailman id={$this->id}"); return true; } if (!$this->valid_email_address($module->email1)) { $this->set_as_sent($module->email1, true, null, null, 'invalid email'); $GLOBALS['log']->fatal('Encountered invalid email address' . $module->email1 . " Emailman id={$this->id}"); return true; } if ((!isset($module->email_opt_out) || $module->email_opt_out !== 'on' && $module->email_opt_out !== 1 && $module->email_opt_out !== '1') && (!isset($module->invalid_email) || $module->invalid_email !== 'on' && $module->invalid_email !== 1 && $module->invalid_email !== '1')) { $lower_email_address = strtolower($module->email1); //test against indivdual address. if (isset($this->restricted_addresses) and isset($this->restricted_addresses[$lower_email_address])) { $this->set_as_sent($lower_email_address, true, null, null, 'blocked'); return true; } //test against restricted domains $at_pos = strrpos($lower_email_address, '@'); if ($at_pos !== false) { foreach ($this->restricted_domains as $domain => $value) { $pos = strrpos($lower_email_address, $domain); if ($pos !== false && $pos > $at_pos) { //found $this->set_as_sent($lower_email_address, true, null, null, 'blocked'); return true; } } } //test for duplicate email address by marketing id. $dup_query = "select id from campaign_log where more_information='" . $module->email1 . "' and marketing_id='" . $this->marketing_id . "'"; $dup = $this->db->query($dup_query); $dup_row = $this->db->fetchByAssoc($dup); if (!empty($dup_row)) { //we have seen this email address before $this->set_as_sent($module->email1, true, null, null, 'blocked'); return true; } $this->target_tracker_key = create_guid(); //fetch email marketing. if (empty($this->current_emailmarketing) or !isset($this->current_emailmarketing)) { if (!class_exists('EmailMarketing')) { } $this->current_emailmarketing = BeanFactory::getBean('EmailMarketing'); } if (empty($this->current_emailmarketing->id) or $this->current_emailmarketing->id !== $this->marketing_id) { $this->current_emailmarketing->retrieve($this->marketing_id); $this->newmessage = true; } //fetch email template associate with the marketing message. if (empty($this->current_emailtemplate) or $this->current_emailtemplate->id !== $this->current_emailmarketing->template_id) { if (!class_exists('EmailTemplate')) { } $this->current_emailtemplate = BeanFactory::getBean('EmailTemplates'); $this->current_emailtemplate->retrieve($this->current_emailmarketing->template_id); //escape email template contents. $this->current_emailtemplate->subject = from_html($this->current_emailtemplate->subject); $this->current_emailtemplate->body_html = from_html($this->current_emailtemplate->body_html); $this->current_emailtemplate->body = from_html($this->current_emailtemplate->body); $q = "SELECT * FROM notes WHERE parent_id = '" . $this->current_emailtemplate->id . "' AND deleted = 0"; $r = $this->db->query($q); // cn: bug 4684 - initialize the notes array, else old data is still around for the next round $this->notes_array = array(); if (!class_exists('Note')) { require_once 'modules/Notes/Note.php'; } while ($a = $this->db->fetchByAssoc($r)) { $noteTemplate = BeanFactory::getBean('Notes', $a['id']); $this->notes_array[] = $noteTemplate; } } // fetch mailbox details.. if (empty($this->current_mailbox)) { if (!class_exists('InboundEmail')) { } $this->current_mailbox = BeanFactory::getBean('InboundEmail'); $this->current_mailbox->disable_row_level_security = true; } if (empty($this->current_mailbox->id) or $this->current_mailbox->id !== $this->current_emailmarketing->inbound_email_id) { $this->current_mailbox->retrieve($this->current_emailmarketing->inbound_email_id); //extract the email address. $this->mailbox_from_addr = $this->current_mailbox->get_stored_options('from_addr', '*****@*****.**', null); } // fetch campaign details.. if (empty($this->current_campaign)) { if (!class_exists('Campaign')) { } $this->current_campaign = BeanFactory::getBean('Campaigns'); } if (empty($this->current_campaign->id) or $this->current_campaign->id !== $this->current_emailmarketing->campaign_id) { $this->current_campaign->retrieve($this->current_emailmarketing->campaign_id); //load defined tracked_urls $this->current_campaign->load_relationship('tracked_urls'); $query_array = $this->current_campaign->tracked_urls->getQuery(true); $query_array['select'] = "SELECT tracker_name, tracker_key, id, is_optout "; $result = $this->current_campaign->db->query(implode(' ', $query_array)); $this->has_optout_links = false; $this->tracker_urls = array(); while (($row = $this->current_campaign->db->fetchByAssoc($result)) != null) { $this->tracker_urls['{' . $row['tracker_name'] . '}'] = $row; //has the user defined opt-out links for the campaign. if ($row['is_optout'] == 1) { $this->has_optout_links = true; } } } try { $from = new EmailIdentity($this->mailbox_from_addr, $this->current_emailmarketing->from_name); $mail->setHeader(EmailHeaders::From, $from); $mail->setHeader(EmailHeaders::Sender, $from); //CL - Bug 25256 Check if we have a reply_to_name/reply_to_addr value from the email marketing table. If so use email marketing entry; otherwise current mailbox (inbound email) entry $replyToAddr = $this->current_emailmarketing->reply_to_addr; if (empty($replyToAddr)) { $replyToAddr = $this->current_mailbox->get_stored_options('reply_to_addr', $this->mailbox_from_addr, null); } $replyToName = $this->current_emailmarketing->reply_to_name; if (empty($replyToName)) { $this->current_mailbox->get_stored_options('reply_to_name', $this->current_emailmarketing->from_name, null); } $mail->setHeader(EmailHeaders::ReplyTo); // resets Reply-To to null if (!empty($replyToAddr)) { $mail->setHeader(EmailHeaders::ReplyTo, new EmailIdentity($replyToAddr, $replyToName)); } $mail->setHeader("X-CampTrackID", $this->target_tracker_key); //parse and replace bean variables. $macro_nv = array(); $focus_name = 'Contacts'; if ($module->module_dir == 'Accounts') { $focus_name = 'Accounts'; } $template_data = $this->current_emailtemplate->parse_email_template(array('subject' => $this->current_emailtemplate->subject, 'body_html' => $this->current_emailtemplate->body_html, 'body' => $this->current_emailtemplate->body), $focus_name, $module, $macro_nv); //add email address to this list. $macro_nv['sugar_to_email_address'] = $module->email1; $macro_nv['email_template_id'] = $this->current_emailmarketing->template_id; //parse and replace urls. //this is new style of adding tracked urls to a campaign. $tracker_url_template = $this->tracking_url . 'index.php?entryPoint=campaign_trackerv2&track=%s' . '&identifier=' . $this->target_tracker_key; $removeme_url_template = $this->tracking_url . 'index.php?entryPoint=removeme&identifier=' . $this->target_tracker_key; $template_data = $this->current_emailtemplate->parse_tracker_urls($template_data, $tracker_url_template, $this->tracker_urls, $removeme_url_template); $mail->clearRecipients(); $mail->addRecipientsTo(new EmailIdentity($module->email1, $module->name)); //refetch strings in case they have been changed by creation of email templates or other beans. $mod_strings = return_module_language($sugar_config['default_language'], 'EmailMan'); $subject = $template_data['subject']; if ($this->test) { $subject = $mod_strings['LBL_PREPEND_TEST'] . $template_data['subject']; } $mail->setSubject($subject); //check if this template is meant to be used as "text only" $text_only = false; if (isset($this->current_emailtemplate->text_only) && $this->current_emailtemplate->text_only) { $text_only = true; } //if this template is textonly, then just send text body. Do not add tracker, opt out, //or perform other processing as it will not show up in text only email if ($text_only) { $mail->setTextBody($template_data['body']); $mail->setHtmlBody(); } else { $textBody = $template_data['body']; $htmlBody = $template_data['body_html']; if (!empty($tracker_url)) { $htmlBody = str_replace('TRACKER_URL_START', "<a href='" . $tracker_url . "'>", $htmlBody); $htmlBody = str_replace('TRACKER_URL_END', "</a>", $htmlBody); $textBody .= "\n" . $tracker_url; } //do not add the default remove me link if the campaign has a trackerurl of the opotout link if ($this->has_optout_links == false) { $htmlBody .= "<br /><span style='font-size:0.8em'>{$mod_strings['TXT_REMOVE_ME']} <a href='" . $this->tracking_url . "index.php?entryPoint=removeme&identifier={$this->target_tracker_key}'>{$mod_strings['TXT_REMOVE_ME_CLICK']}</a></span>"; $textBody .= "\n\n\n{$mod_strings['TXT_REMOVE_ME_ALT']} " . $this->tracking_url . "index.php?entryPoint=removeme&identifier={$this->target_tracker_key}"; } // cn: bug 11979 - adding single quote to comform with HTML email RFC $htmlBody .= "<br /><img alt='' height='1' width='1' src='{$this->tracking_url}index.php?entryPoint=image&identifier={$this->target_tracker_key}' />"; $mail->setTextBody($textBody); $mail->setHtmlBody(wordwrap($htmlBody, 900)); } $mail->clearAttachments(); // need to clear the attachments because the mailer is reused for different emails // cn: bug 4684, handle attachments in email templates. if (!empty($this->notes_array)) { foreach ($this->notes_array as $note) { $attachment = AttachmentPeer::attachmentFromSugarBean($note); $mail->addAttachment($attachment); } } $mail->send(); $success = true; $email_id = null; if ($save_emails == 1) { $email_id = $this->create_indiv_email($module, $mail); } else { //find/create reference email record. all campaign targets reveiving this message will be linked with this message. $decodedFromName = mb_decode_mimeheader($this->current_emailmarketing->from_name); $fromAddressName = "{$decodedFromName} <{$this->mailbox_from_addr}>"; $email_id = $this->create_ref_email($this->marketing_id, $this->current_emailtemplate->subject, $this->current_emailtemplate->body, $this->current_emailtemplate->body_html, $this->current_campaign->name, $this->mailbox_from_addr, $this->user_id, $this->notes_array, $macro_nv, $this->newmessage, $fromAddressName); $this->newmessage = false; } $this->set_as_sent($module->email1, true, $email_id, 'Emails', 'targeted'); } catch (MailerException $me) { //log send error. save for next attempt after 24hrs. no campaign log entry will be created. $this->set_as_sent($module->email1, false, null, null, 'send error'); $GLOBALS['log']->error("Emailman::sendMail - Campaign Email Send Error:" . $me->getMessage()); } } else { $this->target_tracker_key = create_guid(); if (isset($module->email_opt_out) && ($module->email_opt_out === 'on' || $module->email_opt_out == '1' || $module->email_opt_out == 1)) { $this->set_as_sent($module->email1, true, null, null, 'removed'); } else { if (isset($module->invalid_email) && ($module->invalid_email == 1 || $module->invalid_email == '1')) { $this->set_as_sent($module->email1, true, null, null, 'invalid email'); } else { $this->set_as_sent($module->email1, true, null, null, 'send error'); } } } return $success; }
/** * Sends Email * @return bool True on success */ function send() { global $mod_strings, $app_strings, $current_user, $sugar_config; try { $mailConfig = OutboundEmailConfigurationPeer::getSystemMailConfiguration($current_user); $mailerFactoryClass = $this->MockMailerFactoryClass; $mailer = $mailerFactoryClass::getMailer($mailConfig); if (is_array($this->to_addrs_arr)) { foreach ($this->to_addrs_arr as $addr_arr) { try { $mailer->addRecipientsTo(new EmailIdentity($addr_arr['email'], $addr_arr['display'])); } catch (MailerException $me) { // eat the exception } } } if (is_array($this->cc_addrs_arr)) { foreach ($this->cc_addrs_arr as $addr_arr) { try { $mailer->addRecipientsCc(new EmailIdentity($addr_arr['email'], $addr_arr['display'])); } catch (MailerException $me) { // eat the exception } } } if (is_array($this->bcc_addrs_arr)) { foreach ($this->bcc_addrs_arr as $addr_arr) { try { $mailer->addRecipientsBcc(new EmailIdentity($addr_arr['email'], $addr_arr['display'])); } catch (MailerException $me) { // eat the exception } } } // SENDER Info if (empty($this->from_addr)) { $this->from_addr = $current_user->getPreference('mail_fromaddress'); } if (empty($this->from_name)) { $this->from_name = $current_user->getPreference('mail_fromname'); } // REPLY-TO Info if (empty($this->reply_to_addr)) { $this->reply_to_addr = $this->from_addr; $this->reply_to_name = $this->from_name; } $mailer->setHeader(EmailHeaders::From, new EmailIdentity($this->from_addr, $this->from_name)); $mailer->setHeader(EmailHeaders::ReplyTo, new EmailIdentity($this->reply_to_addr, $this->reply_to_name)); $mailer->setSubject($this->name); /////////////////////////////////////////////////////////////////////// //// ATTACHMENTS if (is_array($this->saved_attachments)) { foreach ($this->saved_attachments as $note) { $mime_type = 'text/plain'; if ($note->object_name == 'Note') { if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) { // brandy-new file upload/attachment $file_location = "upload://{$note->id}"; $filename = $note->file->original_file_name; $mime_type = $note->file->mime_type; } else { // attachment coming from template/forward $file_location = "upload://{$note->id}"; // cn: bug 9723 - documents from EmailTemplates sent with Doc Name, not file name. $filename = !empty($note->filename) ? $note->filename : $note->name; $mime_type = $note->file_mime_type; } } elseif ($note->object_name == 'DocumentRevision') { // from Documents $filePathName = $note->id; // cn: bug 9723 - Emails with documents send GUID instead of Doc name $filename = $note->getDocumentRevisionNameForDisplay(); $file_location = "upload://{$note->id}"; $mime_type = $note->file_mime_type; } // strip out the "Email attachment label if exists $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename); $file_ext = pathinfo($filename, PATHINFO_EXTENSION); //is attachment in our list of bad files extensions? If so, append .txt to file location //check to see if this is a file with extension located in "badext" foreach ($sugar_config['upload_badext'] as $badExt) { if (strtolower($file_ext) == strtolower($badExt)) { //if found, then append with .txt to filename and break out of lookup //this will make sure that the file goes out with right extension, but is stored //as a text in db. $file_location = $file_location . ".txt"; break; // no need to look for more } } $attachment = null; if ($note->embed_flag == true) { $cid = $filename; $attachment = AttachmentPeer::embeddedImageFromSugarBean($note, $cid); } else { $attachment = AttachmentPeer::attachmentFromSugarBean($note); } $mailer->addAttachment($attachment); } } //// END ATTACHMENTS /////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['description_html'])) { $this->description_html = $_REQUEST['description_html']; } $htmlBody = $this->description_html; $textBody = $this->description; //------------------- HANDLEBODY() --------------------------------------------- if (isset($_REQUEST['setEditor']) && $_REQUEST['setEditor'] == 1 && trim($this->description_html) != '' && $current_user->getPreference('email_editor_option', 'global') !== 'plain') { $htmlBody = $this->decodeDuringSend($htmlBody); $textBody = $this->decodeDuringSend($textBody); } else { $textBody = str_replace(" ", " ", $textBody); $textBody = str_replace("</p>", "</p><br />", $textBody); $textBody = strip_tags(br2nl($textBody)); $textBody = str_replace("&", "&", $textBody); $textBody = str_replace("'", "'", $textBody); $textBody = $this->decodeDuringSend($textBody); } $mailer->setHtmlBody($htmlBody); $mailer->setTextBody($textBody); $mailer->send(); /////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING // mark replied if (!empty($_REQUEST['inbound_email_id'])) { $ieMail = new Email(); $ieMail->retrieve($_REQUEST['inbound_email_id']); $ieMail->status = 'replied'; $ieMail->save(); } return true; } catch (MailerException $me) { $GLOBALS["log"]->error($me->getLogMessage()); } catch (Exception $e) { $GLOBALS['log']->error($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $e->getMessage()); } return false; }