public function testEmailImport() { $this->_login(); $nv = array('from_addr' => '*****@*****.**', 'parent_type' => 'Accounts', 'parent_id' => $this->acc->id, 'description' => 'test', 'name' => 'Test Subject'); $result = $this->_soapClient->call('set_entry', array('session' => $this->_sessionId, "module_name" => 'Emails', 'name_value_list' => $nv)); $this->email_id = $result['id']; $email = new Email(); $email->retrieve($this->email_id); $email->load_relationship('accounts'); $acc = $email->accounts->get(); $this->assertEquals($this->acc->id, $acc[0]); }
/** * Link the Lead to the Email from which the lead was created * Also set the assigned user to current user and mark email as read. * TODO: This logic is brought over from LeadFormBase->handleSave() - need refactoring to use Link2? * * @param $emailId * @param $leadId */ protected function linkLeadToEmail($emailId, $leadId) { global $current_user; $email = new Email(); $email->retrieve($emailId); $email->parent_type = 'Leads'; $email->parent_id = $leadId; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('leads'); $email->leads->add($leadId); }
/** * @param $api * @param $args * @return array */ public function updateMail($api, $args) { $email = new Email(); if (isset($args['email_id']) && !empty($args['email_id'])) { if (!$email->retrieve($args['email_id']) || $email->id != $args['email_id']) { throw new SugarApiExceptionMissingParameter(); } if ($email->status != 'draft') { throw new SugarApiExceptionRequestMethodFailure(); } } else { throw new SugarApiExceptionInvalidParameter(); } return $this->handleMail($api, $args); }
function getQuotesRelatedData($bean) { $return = array(); $emailId = $_REQUEST['recordId']; require_once "modules/Emails/EmailUI.php"; $email = new Email(); $email->retrieve($emailId); $return['subject'] = $email->name; $return['body'] = from_html($email->description_html); $return['toAddress'] = $email->to_addrs; $ret = array(); $ret['uid'] = $emailId; $ret = EmailUI::getDraftAttachments($ret); $return['attachments'] = $ret['attachments']; $return['email_id'] = $emailId; return $return; }
function handleSave($prefix, $redirect = true, $useRequired = false) { global $theme, $current_user; require_once 'include/formbase.php'; global $timedate; $focus = new Contact(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } if (!empty($_POST[$prefix . 'new_reports_to_id'])) { $focus->retrieve($_POST[$prefix . 'new_reports_to_id']); $focus->reports_to_id = $_POST[$prefix . 'record']; } else { $focus = populateFromPost($prefix, $focus); if (!empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) { $focus->portal_password = md5($focus->portal_password); } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 0; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 0; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') { if (!empty($_POST[$prefix . 'sync_contact'])) { $focus->contacts_users_id = $current_user->id; } else { if (!isset($focus->users)) { $focus->load_relationship('user_sync'); } $focus->contacts_users_id = null; $focus->user_sync->delete($focus->id, $current_user->id); } } if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['dup_checked'])) { $duplicateContacts = $this->checkForDuplicates($prefix); if (isset($duplicateContacts)) { $location = 'module=Contacts&action=ShowDuplicates'; $get = ''; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Contactsrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Contactsrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Contacts{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate contact id's in redirect get string $i = 0; foreach ($duplicateContacts as $contact) { $get .= "&duplicate[{$i}]=" . $contact['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Contacts"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } //else $get .= "DetailView"; if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } $_SESSION['SHOW_DUPLICATES'] = $get; //now redirect the post to modules/Contacts/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } global $current_user; if (is_admin($current_user)) { if (!isset($_POST[$prefix . 'portal_active'])) { $focus->portal_active = '0'; } //if no password is set set account to inactive for portal if (empty($_POST[$prefix . 'portal_name'])) { $focus->portal_active = '0'; } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { // fake this case like it's already saved. $focus->save($check_notify); $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Contacts'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('contacts'); $email->contacts->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); $trackerManager = TrackerManager::getInstance(); $timeStamp = TimeDate::getInstance()->nowDb(); if ($monitor = $trackerManager->getMonitor('tracker')) { $monitor->setValue('action', 'detailview'); $monitor->setValue('user_id', $GLOBALS['current_user']->id); $monitor->setValue('module_name', 'Contacts'); $monitor->setValue('date_modified', $timeStamp); $monitor->setValue('visible', 1); if (!empty($this->bean->id)) { $monitor->setValue('item_id', $return_id); $monitor->setValue('item_summary', $focus->get_summary_text()); } $trackerManager->saveMonitor($monitor, true, true); } return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Contacts'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&first_name=' . urlencode($focus->first_name); $get .= '&last_name=' . urlencode($focus->last_name); $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { $this->handleRedirect($return_id); } else { return $focus; } }
function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null) { require_once 'modules/Campaigns/utils.php'; require_once 'include/formbase.php'; if (empty($exist_lead)) { $focus = new Lead(); } else { $focus = $exist_lead; } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 0; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 0; } if ($do_save) { if (!empty($GLOBALS['check_notify'])) { $focus->save($GLOBALS['check_notify']); } else { $focus->save(FALSE); } } $return_id = $focus->id; if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) { $prospect = new Prospect(); $prospect->retrieve($_POST[$prefix . 'prospect_id']); $prospect->lead_id = $focus->id; $prospect->save(); //if prospect id exists, make sure we are coming from prospect detail if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') { //create campaing_log entry if (isset($focus->campaign_id) && $focus->campaign_id != null) { campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead'); } } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { if (!isset($current_user)) { global $current_user; } // fake this case like it's already saved. $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Leads'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('leads'); $email->leads->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, 'Leads'); } else { return $focus; } }
/** * shiny new importOneEmail() method * @param msgNo int */ function importOneEmail($msgNo) { $GLOBALS['log']->debug('InboundEmail processing 1 email-----------------------------------------------------------------------------------------'); global $timedate; global $app_list_strings; global $sugar_config; global $current_user; $header = imap_headerinfo($this->conn, $msgNo); $fullHeader = imap_fetchheader($this->conn, $msgNo); // raw headers /////////////////////////////////////////////////////////////////////// //// DUPLICATE CHECK if ($this->importDupeCheck($header->message_id, $msgNo, $header, $fullHeader)) { $GLOBALS['log']->debug('*********** NO duplicate found, continuing with processing.'); $structure = imap_fetchstructure($this->conn, $msgNo); // map of email /////////////////////////////////////////////////////////////////// //// CREATE SEED EMAIL OBJECT if (!class_exists('Email')) { require_once 'modules/Emails/Email.php'; } $email = new Email(); $email->mailbox_id = $this->id; $message = array(); $email->id = create_guid(); $email->new_with_id = true; //forcing a GUID here to prevent double saves. //// END CREATE SEED EMAIL /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// GET RAW EMAIL $GLOBALS['log']->debug('*********** Importing RAW email.'); $raw = $this->importRaw($msgNo); $email->raw_source = $raw; //// END GET RAW EMAIL /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// PREP SYSTEM USER if (empty($current_user)) { // I-E runs as admin, get admin prefs require_once 'modules/Users/User.php'; $current_user = new User(); $current_user->getSystemUser(); } $tPref = $current_user->getUserDateTimePreferences($current_user); //// END USER PREP /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// CALCULATE CORRECT SENT DATE/TIME FOR EMAIL if (!empty($header->date)) { $headerDate = isset($header->date) && !empty($header->date) ? $header->date : $header->Date; // need to hack PHP/windows' bad handling of strings when using POP3 if (strstr($headerDate, '+0000 GMT')) { $headerDate = str_replace('GMT', '', $headerDate); } elseif (!strtotime($headerDate)) { $headerDate = 'now'; // catch non-standard format times. } else { // cn: bug 9196 parse the GMT offset if (strpos($headerDate, '-') || strpos($headerDate, '+')) { // make sure last 5 chars are [+|-]nnnn $gmtEmail = trim(substr($headerDate, -5, 5)); $posNeg = substr($gmtEmail, 0, 1); $gmtHours = substr($gmtEmail, 1, 2); $gmtMins = substr($gmtEmail, -2, 2); // get seconds $secsHours = $gmtHours * 60 * 60; $secsTotal = $secsHours + $gmtMins * 60; $secsTotal = $posNeg == '-' ? $secsTotal : -1 * $secsTotal; } } } else { $headerDate = 'now'; } $unixHeaderDate = strtotime($headerDate); if (isset($secsTotal)) { // this gets the timestamp to true GMT-0 $unixHeaderDate += $secsTotal; } if (strtotime('Jan 1, 2001') > $unixHeaderDate) { $unixHeaderDate = strtotime('now'); } // now get it to user's datetime format for save $gmt0dateTime = $timedate->to_display_date_time(date('Y-m-d H:i:s', $unixHeaderDate)); $gmt0dateTime = $timedate->swap_formats($gmt0dateTime, $timedate->get_date_time_format(), $timedate->get_db_date_time_format()); $unixHeaderDate = strtotime($gmt0dateTime); //// END CALCULATE CORRECT SENT DATE/TIME FOR EMAIL /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// ASSIGN APPROPRIATE ATTRIBUTES TO NEW EMAIL OBJECT // handle UTF-8/charset encoding in the ***headers*** $email->name = $this->handleMimeHeaderDecode($header->subject); //handleCharsetTranslation($subjectDecoded[0]->text, $subjectDecoded[0]->charset); $email->date_start = date($tPref['date'], $unixHeaderDate); $email->time_start = date($tPref['time'], $unixHeaderDate); $email->type = 'inbound'; $email->date_created = date($tPref['date'] . " " . $tPref['time'], $unixHeaderDate); $email->status = 'unread'; // this is used in Contacts' Emails SubPanel if (!empty($header->toaddress)) { $email->to_name = $this->handleTranserEncoding($this->handleMimeHeaderDecode($header->toaddress), $structure->encoding); } if (!empty($header->to)) { $email->to_addrs = $this->convertImapToSugarEmailAddress($header->to); } $email->from_name = $this->handleTranserEncoding($this->handleMimeHeaderDecode($header->fromaddress), $structure->encoding); $email->from_addr = $this->convertImapToSugarEmailAddress($header->from); if (!empty($header->cc)) { $email->cc_addrs = $this->convertImapToSugarEmailAddress($header->cc); } $email->reply_to_name = $this->handleTranserEncoding($this->handleMimeHeaderDecode($header->reply_toaddress), $structure->encoding); $email->reply_to_email = $this->convertImapToSugarEmailAddress($header->reply_to); $email->intent = $this->mailbox_type; $email->message_id = $this->compoundMessageId; // filled by importDupeCheck(); // handle multi-part email bodies $email->description = $this->getMessageText($msgNo, 'PLAIN', $structure, $fullHeader); // runs through handleTranserEncoding() already $email->description_html = $this->getMessageText($msgNo, 'HTML', $structure, $fullHeader); // runs through handleTranserEncoding() already // empty() check for body content if (empty($email->description)) { $GLOBALS['log']->debug('InboundEmail Message (id:' . $email->message_id . ') has no body'); } // assign_to group $email->assigned_user_id = $this->group_id; $email->save(); $email->new_with_id = false; // to allow future saves by UPDATE, instead of INSERT //// ASSIGN APPROPRIATE ATTRIBUTES TO NEW EMAIL OBJECT /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// HANDLE EMAIL ATTACHEMENTS OR HTML TEXT // parts defines attachements - be mindful of .html being interpreted as an attachment if ($structure->type == 1 && !empty($structure->parts)) { $GLOBALS['log']->debug('InboundEmail found multipart email - saving attachments if found.'); $this->saveAttachments($msgNo, $structure->parts, $email->id); } elseif ($structure->type == 0) { $uuemail = $this->isUuencode($email->description) ? true : false; /* * UUEncoded attachments - legacy, but still have to deal with it * format: * begin 777 filename.txt * UUENCODE * * end */ // set body to the filtered one if ($uuemail) { $email->description = $this->handleUUEncodedEmailBody($email->description, $email->id); $email->retrieve($email->id); $email->save(); } } else { if ($this->port != 110) { $GLOBALS['log']->debug('InboundEmail found a multi-part email (id:' . $messageId . ') with no child parts to parse.'); } else { $GLOBALS['log']->debug('InboundEmail found a multi-part email with no child parts to parse - BUT we\'re using POP3, so we suck.'); } } //// END HANDLE EMAIL ATTACHEMENTS OR HTML TEXT /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// LINK APPROPRIATE BEANS TO NEWLY SAVED EMAIL $contactAddr = $this->handleLinking($email); //// END LINK APPROPRIATE BEANS TO NEWLY SAVED EMAIL /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// MAILBOX TYPE HANDLING $this->handleMailboxType($email, $header); //// END MAILBOX TYPE HANDLING /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //// SEND AUTORESPONSE $this->handleAutoresponse($email, $contactAddr); //// END SEND AUTORESPONSE /////////////////////////////////////////////////////////////////// //// END IMPORT ONE EMAIL /////////////////////////////////////////////////////////////////// } else { // only log if not POP3; pop3 iterates through ALL mail if ($this->protocol != 'pop3') { $GLOBALS['log']->info("InboundEmail found a duplicate email: " . $header->message_id); } } //// END DUPLICATE CHECK /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// //// DEAL WITH THE MAILBOX imap_setflag_full($this->conn, $msgNo, '\\SEEN'); // if delete_seen, mark msg as deleted if ($this->delete_seen == 1) { imap_setflag_full($this->conn, $msgNo, '\\DELETED'); } $GLOBALS['log']->debug('********************************* InboundEmail finished import of 1 email: ' . $email->name); //// END DEAL WITH THE MAILBOX /////////////////////////////////////////////////////////////////////// }
/** * moves emails from folder to folder * @param string $fromIe I-E id * @param string $fromFolder IMAP path to folder in which the email lives * @param string $toIe I-E id * @param string $toFolder * @param string $uids UIDs of emails to move, either Sugar GUIDS or IMAP * UIDs * @param bool $copy Default false * @return bool True on successful execution */ function moveEmails($fromIe, $fromFolder, $toIe, $toFolder, $uids, $copy = false) { global $app_strings; global $current_user; // same I-E server if ($fromIe == $toIe) { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to I-E"); //$exDestFolder = explode("::", $toFolder); //preserve $this->mailbox if (isset($this->mailbox)) { $oldMailbox = $this->mailbox; } $this->retrieve($fromIe); $this->mailbox = $fromFolder; $this->connectMailserver(); $exUids = explode('::;::', $uids); $uids = implode(",", $exUids); // imap_mail_move accepts comma-delimited lists of UIDs if ($copy) { if (imap_mail_copy($this->conn, $uids, $toFolder, CP_UID)) { $this->mailbox = $toFolder; $this->connectMailserver(); $newOverviews = imap_fetch_overview($this->conn, $uids, FT_UID); $this->updateOverviewCacheFile($newOverviews, 'append'); if (isset($oldMailbox)) { $this->mailbox = $oldMailbox; } return true; } else { $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_copy() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); } } else { if (imap_mail_move($this->conn, $uids, $toFolder, CP_UID)) { $GLOBALS['log']->info("INBOUNDEMAIL: imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); imap_expunge($this->conn); // hard deletes moved messages // update cache on fromFolder $newOverviews = $this->getOverviewsFromCacheFile($uids, $fromFolder, true); $this->deleteCachedMessages($uids, $fromFolder); // update cache on toFolder $this->checkEmailOneMailbox($toFolder, true, true); if (isset($oldMailbox)) { $this->mailbox = $oldMailbox; } return true; } else { $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); } } } elseif ($toIe == 'folder' && $fromFolder == 'sugar::Emails') { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from SugarFolder to SugarFolder"); // move from sugar folder to sugar folder require_once "include/SugarFolders/SugarFolders.php"; $sugarFolder = new SugarFolder(); $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); foreach ($exUids as $id) { if ($copy) { $sugarFolder->copyBean($fromIe, $toFolder, $id, "Emails"); } else { $fromSugarFolder = new SugarFolder(); $fromSugarFolder->retrieve($fromIe); $toSugarFolder = new SugarFolder(); $toSugarFolder->retrieve($toFolder); $email = new Email(); $email->retrieve($id); $email->status = 'unread'; // when you move from My Emails to Group Folder, Assign To field for the Email should become null if ($fromSugarFolder->is_dynamic && $toSugarFolder->is_group) { $email->assigned_user_id = ""; $email->save(); if (!$toSugarFolder->checkEmailExistForFolder($id)) { $fromSugarFolder->deleteEmailFromAllFolder($id); $toSugarFolder->addBean($email); } } elseif ($fromSugarFolder->is_group && $toSugarFolder->is_dynamic) { $fromSugarFolder->deleteEmailFromAllFolder($id); $email->assigned_user_id = $current_user->id; $email->save(); } else { // If you are moving something from personal folder then delete an entry from all folder if (!$fromSugarFolder->is_dynamic && !$fromSugarFolder->is_group) { $fromSugarFolder->deleteEmailFromAllFolder($id); } // if if ($fromSugarFolder->is_dynamic && !$toSugarFolder->is_dynamic && !$toSugarFolder->is_group) { $email->assigned_user_id = ""; $toSugarFolder->addBean($email); } // if if (!$toSugarFolder->checkEmailExistForFolder($id)) { if (!$toSugarFolder->is_dynamic) { $fromSugarFolder->deleteEmailFromAllFolder($id); $toSugarFolder->addBean($email); } else { $fromSugarFolder->deleteEmailFromAllFolder($id); $email->assigned_user_id = $current_user->id; } } else { $sugarFolder->move($fromIe, $toFolder, $id); } // else $email->save(); } // else } } return true; } elseif ($toIe == 'folder') { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to SugarFolder"); // move to Sugar folder require_once "include/SugarFolders/SugarFolders.php"; $sugarFolder = new SugarFolder(); $sugarFolder->retrieve($toFolder); //Show the import form if we don't have the required info if (!isset($_REQUEST['delete'])) { $json = getJSONobj(); if ($sugarFolder->is_group) { $_REQUEST['showTeam'] = false; $_REQUEST['showAssignTo'] = false; } $ret = $this->email->et->getImportForm($_REQUEST, $this->email); $ret['move'] = true; $ret['srcFolder'] = $fromFolder; $ret['srcIeId'] = $fromIe; $ret['dstFolder'] = $toFolder; $ret['dstIeId'] = $toIe; $out = trim($json->encode($ret, false)); echo $out; return true; } // import to Sugar $this->retrieve($fromIe); $this->mailbox = $fromFolder; $this->connectMailserver(); // If its a group folder the team should be of the folder team if ($sugarFolder->is_group) { $_REQUEST['team_id'] = $sugarFolder->team_id; $_REQUEST['team_set_id'] = $sugarFolder->team_set_id; } else { // TODO - set team_id, team_set for new UI } // else $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); if (!empty($sugarFolder->id)) { $count = 1; $return = array(); $json = getJSONobj(); foreach ($exUids as $k => $uid) { $msgNo = $uid; if ($this->isPop3Protocol()) { $msgNo = $this->getCorrectMessageNoForPop3($uid); } else { $msgNo = imap_msgno($this->conn, $uid); } if (!empty($msgNo)) { $importStatus = $this->importOneEmail($msgNo, $uid); // add to folder if ($importStatus) { $sugarFolder->addBean($this->email); if (!$copy && isset($_REQUEST['delete']) && $_REQUEST['delete'] == "true" && $importStatus) { $GLOBALS['log']->error("********* delete from mailserver [ {explode(", ", {$uids})} ]"); // delete from mailserver $this->deleteMessageOnMailServer($uid); $this->deleteMessageFromCache($uid); } // if } $return[] = $app_strings['LBL_EMAIL_MESSAGE_NO'] . " " . $count . ", " . $app_strings['LBL_STATUS'] . " " . ($importStatus ? $app_strings['LBL_EMAIL_IMPORT_SUCCESS'] : $app_strings['LBL_EMAIL_IMPORT_FAIL']); $count++; } // if } // foreach echo $json->encode($return); return true; } else { $GLOBALS['log']->error("********* SUGARFOLDER - failed to retrieve folder ID [ {$toFolder} ]"); } } else { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() called with no passing criteria"); } return false; }
/** * Sends Email * @return bool True on success */ function send() { global $mod_strings, $app_strings; global $current_user; global $sugar_config; global $locale; $OBCharset = $locale->getPrecedentPreference('default_email_charset'); $mail = new SugarPHPMailer(); foreach ($this->to_addrs_arr as $addr_arr) { if (empty($addr_arr['display'])) { $mail->AddAddress($addr_arr['email'], ""); } else { $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } } foreach ($this->cc_addrs_arr as $addr_arr) { if (empty($addr_arr['display'])) { $mail->AddCC($addr_arr['email'], ""); } else { $mail->AddCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } } foreach ($this->bcc_addrs_arr as $addr_arr) { if (empty($addr_arr['display'])) { $mail->AddBCC($addr_arr['email'], ""); } else { $mail->AddBCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset)); } } $mail = $this->setMailer($mail); // FROM ADDRESS if (!empty($this->from_addr)) { $mail->From = $this->from_addr; } else { $mail->From = $current_user->getPreference('mail_fromaddress'); $this->from_addr = $mail->From; } // FROM NAME if (!empty($this->from_name)) { $mail->FromName = $this->from_name; } else { $mail->FromName = $current_user->getPreference('mail_fromname'); $this->from_name = $mail->FromName; } //Reply to information for case create and autoreply. if (!empty($this->reply_to_name)) { $ReplyToName = $this->reply_to_name; } else { $ReplyToName = $mail->FromName; } if (!empty($this->reply_to_addr)) { $ReplyToAddr = $this->reply_to_addr; } else { $ReplyToAddr = $mail->From; } $mail->Sender = $mail->From; /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */ $mail->AddReplyTo($ReplyToAddr, $locale->translateCharsetMIME(trim($ReplyToName), 'UTF-8', $OBCharset)); //$mail->Subject = html_entity_decode($this->name, ENT_QUOTES, 'UTF-8'); $mail->Subject = $this->name; /////////////////////////////////////////////////////////////////////// //// 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 = $sugar_config['upload_dir'] . $note->id; $filename = $note->file->original_file_name; $mime_type = $note->file->mime_type; } else { // attachment coming from template/forward $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $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 = getcwd() . '/' . $GLOBALS['sugar_config']['upload_dir'] . $filePathName; $mime_type = $note->file_mime_type; } // strip out the "Email attachment label if exists $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename); //is attachment in our list of bad files extensions? If so, append .txt to file location //get position of last "." in file name $file_ext_beg = strrpos($file_location, "."); $file_ext = ""; //get file extension if ($file_ext_beg > 0) { $file_ext = substr($file_location, $file_ext_beg + 1); } //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 } } $mail->AddAttachment($file_location, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $mime_type); // embedded Images if ($note->embed_flag == true) { $cid = $filename; $mail->AddEmbeddedImage($file_location, $cid, $filename, 'base64', $mime_type); } } //// END ATTACHMENTS /////////////////////////////////////////////////////////////////////// $mail = $this->handleBody($mail); $GLOBALS['log']->debug('Email sending --------------------- '); /////////////////////////////////////////////////////////////////////// //// I18N TRANSLATION $mail->prepForOutbound(); //// END I18N TRANSLATION /////////////////////////////////////////////////////////////////////// if ($mail->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(); } $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful'); //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////// return true; } $GLOBALS['log']->debug($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo); return false; }
/** * distributes emails to 1 user * @param $user users to dist to * @param $mailIds array of email ids to push * @return boolean true on success */ function distDirect($user, $mailIds) { foreach ($mailIds as $k => $mailId) { $email = new Email(); $email->retrieve($mailId); $email->assigned_user_id = $user; $email->status = 'unread'; $email->save(); } return true; }
* these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ global $current_user; $focus = new Email(); // Get Group User IDs $groupUserQuery = 'SELECT name, group_id FROM inbound_email ie INNER JOIN users u ON (ie.group_id = u.id AND u.is_group = 1)'; _pp($groupUserQuery); $r = $focus->db->query($groupUserQuery); $groupIds = ''; while ($a = $focus->db->fetchByAssoc($r)) { $groupIds .= "'" . $a['group_id'] . "', "; } $groupIds = substr($groupIds, 0, strlen($groupIds) - 2); $query = 'SELECT emails.id AS id FROM emails'; $query .= " WHERE emails.deleted = 0 AND emails.status = 'unread' AND emails.assigned_user_id IN ({$groupIds})"; //$query .= ' LIMIT 1'; //_ppd($query); $r2 = $focus->db->query($query); $count = 0; $a2 = $focus->db->fetchByAssoc($r2); $focus->retrieve($a2['id']); $focus->assigned_user_id = $current_user->id; $focus->save(); if (!empty($a2['id'])) { header('Location: index.php?module=Emails&action=ListView&type=inbound&assigned_user_id=' . $current_user->id); } else { header('Location: index.php?module=Emails&action=ListView&show_error=true&type=inbound&assigned_user_id=' . $current_user->id); }
* these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ /********************************************************************************* * Description: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ global $mod_strings; global $app_strings; $focus = new Email(); if (!empty($_REQUEST['record'])) { $result = $focus->retrieve($_REQUEST['record']); if ($result == null) { sugar_die($app_strings['ERROR_NO_RECORD']); } } else { header("Location: index.php?module=Emails&action=index"); } //needed when creating a new email with default values passed in if (isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) { $focus->contact_name = $_REQUEST['contact_name']; } if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) { $focus->contact_id = $_REQUEST['contact_id']; } echo getClassicModuleTitle($mod_strings['LBL_SEND'], array($mod_strings['LBL_SEND']), true); $GLOBALS['log']->info("Email detail view");
function handleSave($prefix, $redirect = true, $useRequired = false) { global $theme, $current_user; $theme_path = "themes/" . $theme . "/"; require_once 'modules/Contacts/Contact.php'; require_once $theme_path . 'layout_utils.php'; require_once 'include/utils.php'; require_once 'include/formbase.php'; require_once 'XTemplate/xtpl.php'; global $timedate; $focus = new Contact(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } if (!empty($_POST[$prefix . 'new_reports_to_id'])) { $focus->retrieve($_POST[$prefix . 'new_reports_to_id']); $focus->reports_to_id = $_POST[$prefix . 'record']; } else { $focus = populateFromPost($prefix, $focus); if (isset($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) { $focus->portal_password = md5($focus->portal_password); } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 'off'; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 'off'; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') { if (isset($_POST[$prefix . 'sync_contact'])) { $focus->contacts_users_id = $current_user->id; } else { if (!isset($focus->users)) { $focus->load_relationship('user_sync'); } $focus->contacts_users_id = null; $focus->user_sync->delete($focus->id, $current_user->id); } } if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateContacts = $this->checkForDuplicates($prefix); if (isset($duplicateContacts)) { $get = 'module=Contacts&action=ShowDuplicates'; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Contacts{$field}=" . urlencode($focus->{$field}); } } //create list of suspected duplicate contact id's in redirect get string $i = 0; foreach ($duplicateContacts as $contact) { $get .= "&duplicate[{$i}]=" . $contact['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Contacts"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= "DetailView"; } if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } //now redirect the post to modules/Contacts/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $get)); } else { if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$get}"); } return null; } } global $current_user; if (is_admin($current_user)) { if (!isset($_POST[$prefix . 'portal_active'])) { $focus->portal_active = '0'; } //if no password is set set account to inactive for portal if (empty($_POST[$prefix . 'portal_name'])) { $focus->portal_active = '0'; } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { // fake this case like it's already saved. $focus->save($check_notify); require_once 'modules/Emails/Email.php'; $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Contacts'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('contacts'); $email->contacts->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of " . $return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $get = '&module='; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= 'Contacts'; } $get .= '&action='; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } else { $get .= 'Popup'; } if (!empty($_POST['return_id'])) { $get .= '&return_id=' . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } if (!empty($_POST['to_pdf'])) { $get .= '&to_pdf=' . $_POST['to_pdf']; } $get .= '&first_name=' . $focus->first_name; $get .= '&last_name=' . $focus->last_name; $get .= '&query=true'; header("Location: index.php?{$get}"); return; } if ($redirect) { $this->handleRedirect($return_id); } else { return $focus; } }
* details. * * You should have received a copy of the GNU Affero General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'show_raw') { if (!class_exists("Email")) { } $email = new Email(); $email->retrieve($_REQUEST['metadata']); echo nl2br(SugarCleaner::cleanHtml($email->raw_source)); } else { require_once 'include/Popups/Popup_picker.php'; $popup = new Popup_Picker(); echo $popup->process_page(); }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'modules/Leads/Lead.php'; require_once 'include/formbase.php'; $focus = new Lead(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 'off'; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 'off'; } if (!empty($GLOBALS['check_notify'])) { $focus->save($GLOBALS['check_notify']); } else { $focus->save(FALSE); } $return_id = $focus->id; if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) { if (!class_exists('Prospect')) { require_once 'modules/Prospects/Prospect.php'; } $prospect = new Prospect(); $prospect->retrieve($_POST[$prefix . 'prospect_id']); $prospect->lead_id = $focus->id; $prospect->save(); $linked_beans = $prospect->get_linked_beans('campaigns', 'CampaignLog'); if (empty($linked_beans)) { $linked_beans = array(); } foreach ($linked_beans as $thebean) { $thebean->id = null; $thebean->target_id = $focus->id; $thebean->target_type = 'Leads'; $thebean->archived = 1; $thebean->save(); } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { if (!isset($current_user)) { global $current_user; } // fake this case like it's already saved. require_once 'modules/Emails/Email.php'; $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Leads'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('leads'); $email->leads->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, 'Leads'); } else { return $focus; } }
function getQuotesRelatedData($data) { $return = array(); $emailId = $data['recordId']; require_once "modules/Emails/EmailUI.php"; $email = new Email(); $email->retrieve($emailId); $return['subject'] = $email->name; $return['body'] = from_html($email->description_html); $return['toAddress'] = $email->to_addrs; $ret = array(); $ret['uid'] = $emailId; $ret = EmailUI::getDraftAttachments($ret); $return['attachments'] = $ret['attachments']; $return['email_id'] = $emailId; $return['parent_type'] = $email->parent_type; $return['parent_id'] = $email->parent_id; $return['parent_name'] = ''; if (isset($return['parent_type']) && !empty($return['parent_type']) && isset($return['parent_id']) && !empty($return['parent_id'])) { global $beanList; global $beanFiles; $class = $beanList[$return['parent_type']]; require_once $beanFiles[$class]; $bean = new $class(); $bean->retrieve($return['parent_id']); if (isset($bean->full_name)) { $parentName = $bean->full_name; } elseif (isset($bean->name)) { $parentName = $bean->name; } else { $parentName = ''; } $parentName = from_html($parentName); $return['parent_name'] = $parentName; $return['toAddress'] = from_html($bean->full_name) . " <" . from_html($bean->emailAddress->getPrimaryAddress($bean)) . ">"; } return $return; }
if (isset($_REQUEST['opportunity_id']) && is_null($focus->parent_id)) { $focus->parent_id = $_REQUEST['opportunity_id']; } if (isset($_REQUEST['account_name']) && is_null($focus->parent_name)) { $focus->parent_name = $_REQUEST['account_name']; } if (isset($_REQUEST['account_id']) && is_null($focus->parent_id)) { $focus->parent_id = $_REQUEST['account_id']; } // un/READ flags if (!empty($focus->status)) { // "Read" flag for InboundEmail if ($focus->status == 'unread') { // creating a new instance here to avoid data corruption below $e = new Email(); $e->retrieve($focus->id); $e->status = 'read'; $e->save(); $email_type = $e->status; } else { $email_type = $focus->status; } } elseif (!empty($_REQUEST['type'])) { $email_type = $_REQUEST['type']; } /////////////////////////////////////////////////////////////////////////////// //// OUTPUT /////////////////////////////////////////////////////////////////////////////// echo "\n<p>\n"; $GLOBALS['log']->info("Email detail view"); if ($email_type == 'archived') {
$focus->description = $quoted; // don't know what i was thinking: ''; // this will be filled on save/send $focus->description_html = $quotedHtml; // cn: bug 7357 - htmlentities() breaks FCKEditor $focus->parent_type = $ieMail->parent_type; $focus->parent_id = $ieMail->parent_id; $focus->parent_name = $ieMail->parent_name; $focus->name = $ieMailName; $xtpl->assign('INBOUND_EMAIL_ID', $_REQUEST['inbound_email_id']); // un/READ flags if (!empty($ieMail->status)) { // "Read" flag for InboundEmail if ($ieMail->status == 'unread') { // creating a new instance here to avoid data corruption below $e = new Email(); $e->retrieve($ieMail->id); $e->status = 'read'; $e->save(); $email_type = $e->status; } } /////////////////////////////////////////////////////////////////////////// //// PRIMARY PARENT LINKING if (empty($focus->parent_type) && empty($focus->parent_id)) { $focus->fillPrimaryParentFields(); } //// END PRIMARY PARENT LINKING /////////////////////////////////////////////////////////////////////////// // setup for my/mailbox email switcher $mbox = $ieMail->getMailboxDefaultEmail(); $user = $current_user->getPreferredEmail();
function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null) { require_once 'modules/Campaigns/utils.php'; require_once 'include/formbase.php'; if (empty($exist_lead)) { $focus = new Lead(); } else { $focus = $exist_lead; } if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //Check for duplicate Leads if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateLeads = $this->checkForDuplicates($prefix); if (isset($duplicateLeads)) { //Set the redirect location to call the ShowDuplicates action. This will map to view.showduplicates.php $location = 'module=Leads&action=ShowDuplicates'; $get = ''; if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) { $get .= '&inbound_email_id=' . $_POST['inbound_email_id']; } if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Leadsrelate_to=' . $_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Leadsrelate_id=' . $_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->{$field}) && !is_object($focus->{$field})) { $get .= "&Leads{$field}=" . urlencode($focus->{$field}); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->{$field})) { $get .= "&Leads{$field}=" . urlencode($focus->{$field}); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name => $field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Leads{$name}=" . urlencode($focus->{$name}); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate lead ids in redirect get string $i = 0; foreach ($duplicateLeads as $lead) { $get .= "&duplicate[{$i}]=" . $lead['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $get .= "&return_module="; if (!empty($_POST['return_module'])) { $get .= $_POST['return_module']; } else { $get .= "Leads"; } $get .= "&return_action="; if (!empty($_POST['return_action'])) { $get .= $_POST['return_action']; } if (!empty($_POST['return_id'])) { $get .= "&return_id=" . $_POST['return_id']; } if (!empty($_POST['popup'])) { $get .= '&popup=' . $_POST['popup']; } if (!empty($_POST['create'])) { $get .= '&create=' . $_POST['create']; } // for InboundEmail flow if (!empty($_POST['start'])) { $get .= '&start=' . $_POST['start']; } $_SESSION['SHOW_DUPLICATES'] = $get; if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } else { if (!empty($_REQUEST['ajax_load'])) { echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>"; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf=' . $_POST['to_pdf']; } header("Location: index.php?{$location}"); } } return null; } } if (!isset($_POST[$prefix . 'email_opt_out'])) { $focus->email_opt_out = 0; } if (!isset($_POST[$prefix . 'do_not_call'])) { $focus->do_not_call = 0; } if ($do_save) { if (!empty($GLOBALS['check_notify'])) { $focus->save($GLOBALS['check_notify']); } else { $focus->save(FALSE); } } $return_id = $focus->id; if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) { $prospect = new Prospect(); $prospect->retrieve($_POST[$prefix . 'prospect_id']); $prospect->lead_id = $focus->id; // Set to keep email in target $prospect->in_workflow = true; $prospect->save(); //if prospect id exists, make sure we are coming from prospect detail if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') { //create campaing_log entry if (isset($focus->campaign_id) && $focus->campaign_id != null) { campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead'); } } } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { if (!isset($current_user)) { global $current_user; } // fake this case like it's already saved. $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Leads'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('leads'); $email->leads->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// $GLOBALS['log']->debug("Saved record with id of " . $return_id); if ($redirect) { handleRedirect($return_id, 'Leads'); } else { return $focus; } }
/** * distributes emails to 1 user * @param $user users to dist to * @param $mailIds array of email ids to push * @return boolean true on success */ function distDirect($user, $mailIds) { foreach ($mailIds as $k => $mailId) { $email = new Email(); $email->retrieve($mailId); if ($email->checkPessimisticLock()) { $email->assigned_user_id = $user; $email->save(); } else { $GLOBALS['log']->debug('Emails: Least-busy distribution hit a Pessimistic Lock. Skipping email(' . $email->id . ').'); } } return true; }
} $in = ' IN ('; foreach ($ids as $k => $id) { $in .= '"' . $id . '", '; } $in = substr($in, 0, strlen($in) - 2); $in .= ') '; $team = ''; $qE = 'SELECT count(id) AS c FROM emails WHERE deleted = 0 AND assigned_user_id' . $in . $team . 'LIMIT 1'; $rE = $next->db->query($qE); $aE = $next->db->fetchByAssoc($rE); if ($aE['c'] > 0) { $qE = 'SELECT id FROM emails WHERE deleted = 0 AND assigned_user_id' . $in . $team . 'LIMIT 1'; $rE = $next->db->query($qE); $aE = $next->db->fetchByAssoc($rE); $next->retrieve($aE['id']); $next->assigned_user_id = $current_user->id; $next->save(); header('Location: index.php?module=Emails&action=DetailView&record=' . $next->id); } else { // no free items header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true'); } } else { // no groups header('Location: index.php?module=Emails&action=ListView&type=inbound&group=true'); } } ?> <table width="100%" cellpadding="12" cellspacing="0" border="0"> <tr>
} $out[] = $msg; } echo $json->encode($out); } else { echo "error: no UID"; } break; case "getMultipleMessagesFromSugar": $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getMultipleMessagesFromSugar"); if (isset($_REQUEST['uid']) && !empty($_REQUEST['uid'])) { $exIds = explode(",", $_REQUEST['uid']); $out = array(); foreach ($exIds as $id) { $e = new Email(); $e->retrieve($id); $e->description_html = from_html($e->description_html); $ie->email = $e; $out[] = $ie->displayOneEmail($id, $_REQUEST['mbox']); } echo $json->encode($out); } break; //// END MESSAGE HANDLING /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// LIST VIEW //// END MESSAGE HANDLING /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// LIST VIEW
* Description: * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights * Reserved. Contributor(s): ______________________________________.. *********************************************************************************/ /////////////////////////////////////////////////////////////////////////////// //// EMAIL SEND/SAVE SETUP $focus = new Email(); if (!isset($prefix)) { $prefix = ''; } if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) { $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(), $_POST[$prefix . 'meridiem']); } //retrieve the record if (isset($_POST['record']) && !empty($_POST['record'])) { $focus->retrieve($_POST['record']); } if (isset($_REQUEST['user_id'])) { $focus->assigned_user_id = $_REQUEST['user_id']; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!empty($_POST['assigned_user_id']) && $focus->assigned_user_id != $_POST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) { $check_notify = TRUE; } //populate the fields of this Email $allfields = array_merge($focus->column_fields, $focus->additional_column_fields); foreach ($allfields as $field) { if (isset($_POST[$field])) {
public function delete($id) { $email = new Email(); $email->delete($id); $result = $email->retrieve($id); $this->assertEquals(null, $result); }
$focus->date_due = ''; } //if only the time is passed in, without a date, then string length will be 7 if (isset($_REQUEST['date_start']) && strlen(trim($_REQUEST['date_start'])) < 8) { //no date set, so clear out field, and set the rest flag to true $focus->date_start_flag = 1; $focus->date_start = ''; } /////////////////////////////////////////////////////////////////////////////// //// INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) { // fake this case like it's already saved. $focus->save(); $email = new Email(); $email->retrieve($_REQUEST['inbound_email_id']); $email->parent_type = 'Tasks'; $email->parent_id = $focus->id; $email->assigned_user_id = $current_user->id; $email->status = 'read'; $email->save(); $email->load_relationship('tasks'); $email->tasks->add($focus->id); header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id); exit; } //// END INBOUND EMAIL HANDLING /////////////////////////////////////////////////////////////////////////////// // CCL - Bugs 41103 and 43751. 41103 address the issue where the parent_id is set, but // the relate_id field overrides the relationship. 43751 fixes the problem where the relate_id and // parent_id are the same value (in which case it should just use relate_id) by adding the != check
/** * 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; }