예제 #1
0
    /**
     * returns the HTML for InboundEmail system settings
     * @return string HTML
     */
    function getSystemSettingsForm()
    {
        global $sugar_config;
        global $mod_strings;
        global $app_strings;
        global $app_list_strings;
        ////	Case Macro
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td>
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="detail view">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }
예제 #2
0
 /**
  * For mailboxes of type "Support" parse for '[CASE:%1]'
  *
  * @param string $emailName The subject line of the email
  * @param aCase  $aCase     A Case object
  *
  * @return string|boolean   Case ID or FALSE if not found
  */
 function getCaseIdFromCaseNumber($emailName, $aCase)
 {
     //$emailSubjectMacro
     $exMacro = explode('%1', $aCase->getEmailSubjectMacro());
     $open = $exMacro[0];
     $close = $exMacro[1];
     if ($sub = stristr($emailName, $open)) {
         // eliminate everything up to the beginning of the macro and return the rest
         // $sub is [CASE:XX] xxxxxxxxxxxxxxxxxxxxxx
         $sub2 = str_replace($open, '', $sub);
         // $sub2 is XX] xxxxxxxxxxxxxx
         $sub3 = substr($sub2, 0, strpos($sub2, $close));
         // case number is supposed to be numeric
         if (ctype_digit($sub3)) {
             // filter out deleted records in order to create a new case
             // if email is related to deleted one (bug #49840)
             $query = 'SELECT id FROM cases WHERE case_number = ' . $this->db->quoted($sub3) . ' and deleted = 0';
             $r = $this->db->query($query, true);
             $a = $this->db->fetchByAssoc($r);
             if (!empty($a['id'])) {
                 return $a['id'];
             }
         }
     }
     return false;
 }
예제 #3
0
파일: EmailUI.php 프로젝트: NALSS/SuiteCRM
 /**
  * Formats email body on reply/forward
  * @param object email Email object in focus
  * @param string type
  * @return object email
  */
 function handleReplyType($email, $type)
 {
     global $mod_strings;
     $GLOBALS['log']->debug("****At Handle Reply Type: {$type}");
     switch ($type) {
         case "reply":
         case "replyAll":
             $header = $email->getReplyHeader();
             if (!preg_match('/^(re:)+/i', $email->name)) {
                 $email->name = "{$mod_strings['LBL_RE']} {$email->name}";
             }
             if ($type == "reply") {
                 $email->cc_addrs = "";
                 if (!empty($email->reply_to_addr)) {
                     $email->from_addr = $email->reply_to_addr;
                 }
                 // if
             } else {
                 if (!empty($email->reply_to_addr)) {
                     $email->to_addrs = $email->to_addrs . "," . $email->reply_to_addr;
                 }
                 // if
             }
             // else
             break;
         case "forward":
             $header = $email->getForwardHeader();
             if (!preg_match('/^(fw:)+/i', $email->name)) {
                 $email->name = "{$mod_strings['LBL_FW']} {$email->name}";
             }
             $email->cc_addrs = "";
             break;
         case "replyCase":
             $GLOBALS['log']->debug("EMAILUI: At reply case");
             $header = $email->getReplyHeader();
             $myCase = new aCase();
             $myCase->retrieve($email->parent_id);
             $myCaseMacro = $myCase->getEmailSubjectMacro();
             $email->parent_name = $myCase->name;
             $GLOBALS['log']->debug("****Case # : {$myCase->case_number} macro: {$myCaseMacro}");
             if (!strpos($email->name, str_replace('%1', $myCase->case_number, $myCaseMacro))) {
                 $GLOBALS['log']->debug("Replacing");
                 $email->name = str_replace('%1', $myCase->case_number, $myCaseMacro) . ' ' . $email->name;
             }
             $email->name = "{$mod_strings['LBL_RE']} {$email->name}";
             break;
     }
     $html = trim($email->description_html);
     $plain = trim($email->description);
     $desc = !empty($html) ? $html : $plain;
     $email->description = $header . $email->quoteHtmlEmailForNewEmailUI($desc);
     return $email;
 }
    /**
     * returns the HTML for InboundEmail system settings
     * @return string HTML
     */
    function getSystemSettingsForm()
    {
        global $sugar_config;
        global $mod_strings;
        global $app_strings;
        global $app_list_strings;
        ////	Case Macro
        if (!class_exists('aCase')) {
        }
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        ////	Save Raw Source
        $saveRawYes = 'CHECKED';
        $saveRawNo = 'CHECKED';
        if (isset($sugar_config['email_inbound_save_raw']) && $sugar_config['email_inbound_save_raw'] == true) {
            $saveRawNo = '';
        } else {
            $saveRawYes = '';
        }
        ////	max auto-response
        $maxAuto = isset($sugar_config['email_num_autoreplies_24_hours']) && !empty($sugar_config['email_num_autoreplies_24_hours']) ? $sugar_config['email_num_autoreplies_24_hours'] : 10;
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td>
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="detail view">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_SAVE_RAW']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input type='radio' name='email_inbound_save_raw' value="1"{$saveRawYes}> {$app_list_strings['checkbox_dom']['1']}&nbsp;
\t\t\t\t\t\t\t<input type='radio' name='email_inbound_save_raw' value="2"{$saveRawNo}> {$app_list_strings['checkbox_dom']['2']}
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_SAVE_RAW_DESC_1']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_SAVE_RAW_DESC_2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" width='10%' NOWRAP scope="row">
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_MAX_AUTO_REPLIES']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input type='text' class='input' name='email_num_autoreplies_24_hours' value="{$maxAuto}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_MAX_AUTO_REPLIES_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<!-- i>{$mod_strings['LBL_SAVE_RAW_DESC_2']}</i-->
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }
예제 #5
0
    $xtpl->assign('FROM_ADDR_GROUP', $useGroup);
}
////	END INBOUND EMAIL HANDLING
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////	SUBJECT FIELD MANIPULATION
$name = '';
if (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type'])) {
    $focus->parent_id = $_REQUEST['parent_id'];
    $focus->parent_type = $_REQUEST['parent_type'];
}
if (!empty($focus->parent_id) && !empty($focus->parent_type)) {
    if ($focus->parent_type == 'Cases') {
        $myCase = new aCase();
        $myCase->retrieve($focus->parent_id);
        $myCaseMacro = $myCase->getEmailSubjectMacro();
        if (isset($ieMail->name) && !empty($ieMail->name)) {
            // if replying directly to an InboundEmail
            $oldEmailSubj = $ieMail->name;
        } elseif (isset($_REQUEST['parent_name']) && !empty($_REQUEST['parent_name'])) {
            $oldEmailSubj = $_REQUEST['parent_name'];
        } else {
            $oldEmailSubj = $focus->name;
            // replying to an email using old subject
        }
        if (!preg_match('/^re:/i', $oldEmailSubj)) {
            $oldEmailSubj = 'RE: ' . $oldEmailSubj;
        }
        $focus->name = $oldEmailSubj;
        if (strpos($focus->name, str_replace('%1', $myCase->case_number, $myCaseMacro))) {
            $name = $focus->name;
예제 #6
0
 function handleCreateCase($email, $userId)
 {
     global $current_user, $mod_strings, $current_language;
     $mod_strings = return_module_language($current_language, "Emails");
     $GLOBALS['log']->debug('In handleCreateCase in AOPInboundEmail');
     $c = new aCase();
     $this->getCaseIdFromCaseNumber($email->name, $c);
     if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) {
         // create a case
         $GLOBALS['log']->debug('retrieveing email');
         $email->retrieve($email->id);
         $c = new aCase();
         $notes = $email->get_linked_beans('notes', 'Notes');
         $noteIds = array();
         foreach ($notes as $note) {
             $noteIds[] = $note->id;
         }
         if ($email->description_html) {
             $c->description = $this->processImageLinks(SugarCleaner::cleanHtml($email->description_html), $noteIds);
         } else {
             $c->description = $email->description;
         }
         $c->assigned_user_id = $userId;
         $c->name = $email->name;
         $c->status = 'New';
         $c->priority = 'P1';
         if (!empty($email->reply_to_email)) {
             $contactAddr = $email->reply_to_email;
         } else {
             $contactAddr = $email->from_addr;
         }
         $GLOBALS['log']->debug('finding related accounts with address ' . $contactAddr);
         if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) {
             if (sizeof($accountIds) == 1) {
                 $c->account_id = $accountIds[0];
                 $acct = new Account();
                 $acct->retrieve($c->account_id);
                 $c->account_name = $acct->name;
             }
             // if
         }
         // if
         $contactIds = $this->getRelatedId($contactAddr, 'contacts');
         if (!empty($contactIds)) {
             $c->contact_created_by_id = $contactIds[0];
         }
         $c->save(true);
         $caseId = $c->id;
         $c = new aCase();
         $c->retrieve($caseId);
         if ($c->load_relationship('emails')) {
             $c->emails->add($email->id);
         }
         // if
         if (!empty($contactIds) && $c->load_relationship('contacts')) {
             if (!$accountIds && count($contactIds) == 1) {
                 $contact = BeanFactory::getBean('Contacts', $contactIds[0]);
                 if ($contact->load_relationship('accounts')) {
                     $acct = $contact->accounts->get();
                     if ($c->load_relationship('accounts') && !empty($acct[0])) {
                         $c->accounts->add($acct[0]);
                     }
                 }
             }
             $c->contacts->add($contactIds);
         }
         // if
         foreach ($notes as $note) {
             //Link notes to case also
             $newNote = BeanFactory::newBean('Notes');
             $newNote->name = $note->name;
             $newNote->file_mime_type = $note->file_mime_type;
             $newNote->filename = $note->filename;
             $newNote->parent_type = 'Cases';
             $newNote->parent_id = $c->id;
             $newNote->save();
             $srcFile = "upload://{$note->id}";
             $destFile = "upload://{$newNote->id}";
             copy($srcFile, $destFile);
         }
         $c->email_id = $email->id;
         $email->parent_type = "Cases";
         $email->parent_id = $caseId;
         // assign the email to the case owner
         $email->assigned_user_id = $c->assigned_user_id;
         $email->name = str_replace('%1', $c->case_number, $c->getEmailSubjectMacro()) . " " . $email->name;
         $email->save();
         $GLOBALS['log']->debug('InboundEmail created one case with number: ' . $c->case_number);
         $createCaseTemplateId = $this->get_stored_options('create_case_email_template', "");
         if (!empty($this->stored_options)) {
             $storedOptions = unserialize(base64_decode($this->stored_options));
         }
         if (!empty($createCaseTemplateId)) {
             $fromName = "";
             $fromAddress = "";
             if (!empty($this->stored_options)) {
                 $fromAddress = $storedOptions['from_addr'];
                 $fromName = from_html($storedOptions['from_name']);
                 $replyToName = !empty($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : $fromName;
                 $replyToAddr = !empty($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : $fromAddress;
             }
             // if
             $defaults = $current_user->getPreferredEmail();
             $fromAddress = !empty($fromAddress) ? $fromAddress : $defaults['email'];
             $fromName = !empty($fromName) ? $fromName : $defaults['name'];
             $to[0]['email'] = $contactAddr;
             // handle to name: address, prefer reply-to
             if (!empty($email->reply_to_name)) {
                 $to[0]['display'] = $email->reply_to_name;
             } elseif (!empty($email->from_name)) {
                 $to[0]['display'] = $email->from_name;
             }
             $et = new EmailTemplate();
             $et->retrieve($createCaseTemplateId);
             if (empty($et->subject)) {
                 $et->subject = '';
             }
             if (empty($et->body)) {
                 $et->body = '';
             }
             if (empty($et->body_html)) {
                 $et->body_html = '';
             }
             $et->subject = "Re:" . " " . str_replace('%1', $c->case_number, $c->getEmailSubjectMacro() . " " . $c->name);
             $html = trim($email->description_html);
             $plain = trim($email->description);
             $email->email2init();
             $email->from_addr = $email->from_addr_name;
             $email->to_addrs = $email->to_addrs_names;
             $email->cc_addrs = $email->cc_addrs_names;
             $email->bcc_addrs = $email->bcc_addrs_names;
             $email->from_name = $email->from_addr;
             $email = $email->et->handleReplyType($email, "reply");
             $ret = $email->et->displayComposeEmail($email);
             $ret['description'] = empty($email->description_html) ? str_replace("\n", "\n<BR/>", $email->description) : $email->description_html;
             $reply = new Email();
             $reply->type = 'out';
             $reply->to_addrs = $to[0]['email'];
             $reply->to_addrs_arr = $to;
             $reply->cc_addrs_arr = array();
             $reply->bcc_addrs_arr = array();
             $reply->from_name = $fromName;
             $reply->from_addr = $fromAddress;
             $reply->reply_to_name = $replyToName;
             $reply->reply_to_addr = $replyToAddr;
             $reply->name = $et->subject;
             $reply->description = $et->body . "<div><hr /></div>" . $email->description;
             if (!$et->text_only) {
                 $reply->description_html = $et->body_html . "<div><hr /></div>" . $email->description;
             }
             $GLOBALS['log']->debug('saving and sending auto-reply email');
             //$reply->save(); // don't save the actual email.
             $reply->send();
         }
         // if
     } else {
         echo "First if not matching\n";
         if (!empty($email->reply_to_email)) {
             $contactAddr = $email->reply_to_email;
         } else {
             $contactAddr = $email->from_addr;
         }
         $this->handleAutoresponse($email, $contactAddr);
     }
     echo "End of handle create case\n";
 }
예제 #7
0
 public function testgetEmailSubjectMacro()
 {
     $aCase = new aCase();
     $result = $aCase->getEmailSubjectMacro();
     $this->assertEquals('[CASE:%1]', $result);
 }
    /**
     * returns the HTML for the Case macro setting
     * @return string form
     */
    function getCaseMacroForm()
    {
        global $mod_strings;
        global $app_strings;
        if (!class_exists('aCase')) {
            require_once 'modules/Cases/Case.php';
        }
        $c = new aCase();
        $macro = $c->getEmailSubjectMacro();
        $ret = <<<eoq
\t\t\t<form action="index.php" method="post" name="Macro" id="form">
\t\t\t\t\t\t<input type="hidden" name="module" value="InboundEmail">
\t\t\t\t\t\t<input type="hidden" name="action" value="ListView">
\t\t\t\t\t\t<input type="hidden" name="save" value="true">

\t\t\t<table width="100%" cellpadding="0" cellspacing="0" border="0">
\t\t\t\t<tr>
\t\t\t\t\t<td style="padding-bottom: 2px;">
\t\t\t\t\t\t<input \ttitle="{$app_strings['LBL_SAVE_BUTTON_TITLE']}"
\t\t\t\t\t\t\t\taccessKey="{$app_strings['LBL_SAVE_BUTTON_KEY']}"
\t\t\t\t\t\t\t\tclass="button"
\t\t\t\t\t\t\t\tonclick="this.form.return_module.value='InboundEmail'; this.form.return_action.value='ListView';"
\t\t\t\t\t\t\t\ttype="submit" name="Edit" value="  {$app_strings['LBL_SAVE_BUTTON_LABEL']}  ">
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>

\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabDetailView">
\t\t\t\t<tr>
\t\t\t\t\t<td valign="top" class="tabDetailViewDL" width='10%' NOWRAP>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<b>{$mod_strings['LBL_CASE_MACRO']}:</b>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" class="tabDetailViewDF" width='20%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t<input name="inbound_email_case_macro" type="text" value="{$macro}">
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t\t<td valign="top" class="tabDetailViewDF" width='70%'>
\t\t\t\t\t\t<slot>
\t\t\t\t\t\t\t{$mod_strings['LBL_CASE_MACRO_DESC']}
\t\t\t\t\t\t\t<br />
\t\t\t\t\t\t\t<i>{$mod_strings['LBL_CASE_MACRO_DESC2']}</i>
\t\t\t\t\t\t</slot>
\t\t\t\t\t</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t\t</form>
eoq;
        return $ret;
    }