Skip to content

Commit

Permalink
fix(MailMgr) show and relate with TO in Sent folder
Browse files Browse the repository at this point in the history
  • Loading branch information
joebordes committed Apr 4, 2023
1 parent 56b5d8c commit 4504fb7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Smarty/templates/modules/MailManager/Folder.Open.tpl
Expand Up @@ -76,7 +76,7 @@
<tr class="mm_lvtColData {if $MAIL->isRead()}mm_normal{else}mm_bold{/if} mm_clickable"
id="_mailrow_{$MAIL->msgNo()}" onmouseover='MailManager.highLightListMail(this);' onmouseout='MailManager.unHighLightListMail(this);'>
<td width="3%" class="cblds-p_mediumlarge"><input type='checkbox' value = "{$MAIL->msgNo()}" name = 'mc_box' class='small' onclick='MailManager.toggleSelectMail(this.checked, this);'></td>
<td width="27%" class="cblds-p_mediumlarge" onclick="MailManager.mail_open('{$FOLDER->name()}', {$MAIL->msgNo()});">{$MAIL->from(30)}</td>
<td width="27%" class="cblds-p_mediumlarge" onclick="MailManager.mail_open('{$FOLDER->name()}', {$MAIL->msgNo()});">{if $FOLDER->name()=='Sent'}{$MAIL->to(30)}{else}{$MAIL->from(30)}{/if}</td>
<td class="cblds-p_mediumlarge" onclick="MailManager.mail_open('{$FOLDER->name()}', {$MAIL->msgNo()});">{$MAIL->subject()}</td>
<td class="cblds-p_mediumlarge cblds-t-align_right" width="17%" align="right" onclick="MailManager.mail_open('{$FOLDER->name()}', {$MAIL->msgNo()});">{$MAIL->date(true)}</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion modules/MailManager/MailManager.js
Expand Up @@ -571,7 +571,7 @@ if (typeof(MailManager) == 'undefined') {
method: 'POST',
url: 'index.php?'+MailManager._baseurl() + '_operation=relation&_operationarg=find&_mfrom=' + encodeURIComponent(meta['from']) +
'&_folder=' + encodeURIComponent(meta['folder']) + '&_msgno=' + encodeURIComponent(meta['msgno']) + '&_msguid=' +
encodeURIComponent(meta['msguid'].replace('<', '&lt;').replace('>', '&gt;'))
encodeURIComponent(meta['msguid'].replace('<', '&lt;').replace('>', '&gt;')) + '&_mto=' + encodeURIComponent(meta['to'])
}).done(function (transport) {
jQuery('#_mailrecord_findrel_btn_').html(MailManager.i18n('JSLBL_Find_Relation_Now'));
jQuery('#_mailrecord_findrel_btn_').prop('disabled', false);
Expand Down
1 change: 1 addition & 0 deletions modules/MailManager/src/controllers/MailController.php
Expand Up @@ -48,6 +48,7 @@ public function process(MailManager_Request $request) {

$metainfo = array(
'from' => $mail->from(),
'to' => $mail->to(),
'subject' => $mail->subject(),
'msgno' => $mail->msgNo(),
'msguid' => $mail->uniqueid(),
Expand Down
55 changes: 32 additions & 23 deletions modules/MailManager/src/controllers/RelationController.php
Expand Up @@ -57,19 +57,20 @@ public function process(MailManager_Request $request) {
$results = array();
$modules = array();
$allowedModules = $this->getCurrentUserMailManagerAllowedModules();
foreach (self::$MODULES as $MODULE) {
if (!in_array($MODULE, $allowedModules)) {
continue;
}

$from = $request->get('_mfrom');
if (empty($from)) {
continue;
$fname = $request->get('_folder');
$relateWith = $request->get('_mfrom');
if ($fname=='Sent') {
$relateWith = $request->get('_mto');
}
if (!empty($relateWith)) {
foreach (self::$MODULES as $MODULE) {
if (!in_array($MODULE, $allowedModules)) {
continue;
}
$results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $relateWith, $msguid);
$describe = $this->wsDescribe($MODULE);
$modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix'] );
}

$results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $from, $msguid);
$describe = $this->wsDescribe($MODULE);
$modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix'] );
}
$viewer->assign('LOOKUPS', $results);
$viewer->assign('MODULES', $modules);
Expand All @@ -78,7 +79,7 @@ public function process(MailManager_Request $request) {
$viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
$viewer->assign('AllowedModules', $allowedModules);
$viewer->assign('MSGNO', $request->get('_msgno'));
$viewer->assign('FOLDER', $request->get('_folder'));
$viewer->assign('FOLDER', $fname);
$response->setResult(array('ui' => $viewer->fetch($this->getModuleTpl('Relationship.tpl'))));
} elseif ('link' == $request->getOperationArg()) {
$linkto = $request->get('_mlinkto');
Expand Down Expand Up @@ -111,7 +112,7 @@ public function process(MailManager_Request $request) {
$validationData = $qcreate_array['data'];
$data = split_validationdataArray($validationData);

$qcreate_array['form'] = $this->processFormData($qcreate_array['form'], $mail);
$qcreate_array['form'] = $this->processFormData($qcreate_array['form'], $mail, $foldername);
$viewer->assign('QUICKCREATE', $qcreate_array['form']);
if ($moduleName == 'HelpDesk') {
$viewer->assign('QCMODULE', getTranslatedString('Ticket', 'HelpDesk'));
Expand Down Expand Up @@ -163,8 +164,12 @@ public function process(MailManager_Request $request) {

switch ($linkModule) {
case 'HelpDesk':
$from = $mail->from();
$focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $from);
if ($foldername=='Sent') {
$relwith = $mail->to();
} else {
$relwith = $mail->from();
}
$focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $relwith);
break;

case 'ModComments':
Expand Down Expand Up @@ -229,11 +234,11 @@ public function process(MailManager_Request $request) {
* @param array Email Address of the received mail
* @return integer - Parent(crmid)
*/
public function setParentForHelpDesk($parent, $from) {
public function setParentForHelpDesk($parent, $relwith) {
global $current_user;
if (empty($parent)) {
if (!empty($from)) {
$parentInfo = MailManager::lookupMailInVtiger($from[0], $current_user);
if (!empty($relwith)) {
$parentInfo = MailManager::lookupMailInVtiger($relwith[0], $current_user);
if (!empty($parentInfo[0]['record'])) {
$parentId = vtws_getIdComponents($parentInfo[0]['record']);
return $parentId[1];
Expand All @@ -250,11 +255,15 @@ public function setParentForHelpDesk($parent, $from) {
* @param MailManager_Model_Message $mail
* @return array
*/
public function processFormData($qcreate_array, $mail) {
public function processFormData($qcreate_array, $mail, $foldername = '') {
$subject = $mail->subject();
$from = $mail->from();
if (!empty($from)) {
$mail_fromAddress = implode(',', $from);
if ($foldername=='Sent') {
$relwith = $mail->to();
} else {
$relwith = $mail->from();
}
if (!empty($relwith)) {
$mail_fromAddress = implode(',', (array)$relwith);
}
if (!empty($mail_fromAddress)) {
$name = explode('@', $mail_fromAddress);
Expand Down
12 changes: 10 additions & 2 deletions modules/MailManager/src/models/Message.php
Expand Up @@ -450,8 +450,15 @@ public function from($maxlen = 0) {
* @param string Email from
*/
public function setFrom($from) {
$mailFrom = str_replace('_', ' ', $from);
$this->_from = @self::__mime_decode($mailFrom);
$this->_from = @self::__mime_decode(str_replace('_', ' ', $from));
}

/**
* Sets the Mail To Email Address
* @param string Email to
*/
public function setTo($to) {
$this->_to = @self::__mime_decode(str_replace('_', ' ', $to));
}

/**
Expand Down Expand Up @@ -577,6 +584,7 @@ public static function parseOverview($result) {
$instance = new self();
$instance->setSubject(isset($result->subject) ? $result->subject : '');
$instance->setFrom((isset($result->from) ? $result->from : ''));
$instance->setTo((isset($result->to) ? $result->to : ''));
$instance->setDate($result->date);
$instance->setRead($result->seen);
$instance->setMsgNo($result->msgno);
Expand Down

0 comments on commit 4504fb7

Please sign in to comment.