Stop displaying "implicitly linked" emails

On the accounts page, in the email panel, I see emails from other accounts.   From what I can gather, sugar displays "implicitly linked" emails if an email address attached to the account is found in the TO: or CC: or BCC: of the email.   For various reasons, I have some email addresses that are linked to 100's of accounts.   Any time an email is saved/archived to sugar and that email address is copied, that email shows up on all of the 100's of accounts because it's picked up as an implicitly linked email - even though the email went to a totally different account.

These implicitly linked emails aren't actually linked to the account in any real way, they are just picked up in the email panel display because they contain an email address linked to the account.   I'd like to turn this behavior off.   Is there any way turn off the implicit link functionality?

Note, I'm aware of the setting in the email admin section that allows you to view emails from linked contacts for Accounts/Opportunities/Cases.  I actually like that feature.   I just want to see emails for actual linked accounts though.  Not any email that references a linked email address - even if it's from a contact that isn't even linked to the account.

Parents
  • Note, I have an on-site install that is currently 12.0.3.  However, I'm in the process of upgrading to 14.x and I believe the functionality is the same.

  • Hello  , 



    Thanks for your patience while we got back to you.
    This topic is a bit nuanced, and there are a few different things going on here, so I’ll try to break it down.
    I’m making some assumptions as I don't know your instance — please feel free to correct me if I’ve misunderstood anything.

    From what I see, you have too many emails in the Email subpanel that are implicitly related to Accounts.
    These implicitly related emails in the Emails subpanel come from two sources:


    1. Emails that match the account’s own email_address field (to, from or cc)




    2. Emails that match the email_address of a Contact related to that account

     


    Now, you’ve already found that you can turn off the Contact-related emails via Admin > Related Contacts Emails — so that rules out scenario #2.





    That leaves us with scenario #1 to look into.

    You mentioned that emails are showing up under hundreds of different accounts, which is odd. In theory, two different accounts shouldn’t be sharing the same email address — so it’s worth checking why that happens in the first place. 

    A Simple Fix:

    If you’re able to remove or the duplicate email_addresses across accounts, the issue will resolve itself. Emails would only appear under the accounts with the exact matching email, which is the expected behavior.

    Would that be a viable option for you?

    If the fix doesn't work for you:

    If you still need to completely remove implicit emails from showing, it’s possible to do so through customisation—if you’re comfortable with that approach.

    It involves creating a new class based on the default ArchivedEmailsBeanLink that prevents implicit emails from showing up.

    The file that contains the logic that does this is the following one: 

    modules/Emails/ArchivedEmailsBeanLink.php

    If you want to try it yourself you’d need to create two files:

    1. A vardef file to override the archived_emails field definition to point to the new class. 

      custom/Extension/modules/Accounts/Ext/Vardefs/custom_archived_emails_link.php

      <?php
      
      $dictionary['Account']['fields']['archived_emails']['link_class'] ='Sugarcrm\\Sugarcrm\\custom\\modules\\Emails\\CustomArchivedEmailsBeanLink';


    2. A custom class, based on the default ArchivedEmailsBeanLink, where the part that adds implicit emails to the subpanel is commented out.

      custom/modules/Emails/CustomArchivedEmailsBeanLink.php

      <?php
      
      
      namespace Sugarcrm\Sugarcrm\custom\modules\Emails;
      
      use ArchivedEmailsBeanLink;
      
      require_once 'modules/Emails/ArchivedEmailsBeanLink.php';
      
      class CustomArchivedEmailsBeanLink extends ArchivedEmailsBeanLink
      {
      protected function getEmailsSubquery($relation)
          {
              $rel_module = $this->focus->$relation->getRelatedModuleName();
              $rel_join = $this->focus->$relation->getJoin(
                  ['join_table_alias' => 'link_bean', 'join_table_link_alias' => 'linkt']
              );
      
              $bean_id = $this->db->quoted($this->focus->id);
              $rel_join = str_replace("{$this->focus->table_name}.id", $bean_id, $rel_join);
      
              $hideHistoryContactsEmails
                  = !empty($GLOBALS['sugar_config']['hide_history_contacts_emails'][$this->focus->module_name]);
      
              $source = $this->addSource ? ', 1 /* direct */ source' : '';
              // directly assigned emails
              $subQuery = "SELECT eb.bean_id AS id, eb.email_id $source FROM emails_beans eb
                  WHERE eb.bean_module = '{$this->focus->module_dir}' AND eb.bean_id = $bean_id AND eb.deleted=0\n";
      
              // Commented to prevent implicit emails to show 
      
              // $source = $this->addSource ? ', 2 /* related */ source' : '';
              // $subQuery .= ' UNION ' .
              // Related by directly by email
              //   "SELECT DISTINCT eabr.bean_id AS id, eear.email_id $source from emails_email_addr_rel eear
              //   INNER JOIN email_addr_bean_rel eabr
              //   ON eabr.bean_id = $bean_id AND eabr.bean_module = '{$this->focus->module_dir}' AND
              //   eabr.email_address_id = eear.email_address_id and eabr.deleted=0 where eear.deleted=0\n";
      
              if (!$hideHistoryContactsEmails) {
                  // Assigned to contacts
                  $source = $this->addSource ? ', 4 /* contact */ source' : '';
                  $subQuery .= ' UNION ' .
                      "SELECT DISTINCT $bean_id AS id, eb.email_id $source FROM emails_beans eb
                      $rel_join AND link_bean.id = eb.bean_id
                      where eb.bean_module = '$rel_module' AND eb.deleted=0\n";
                  // Related by email to linked contact
                  $source = $this->addSource ? ', 8 /* related_contact */  source' : '';
                  $subQuery .= " UNION SELECT DISTINCT $bean_id AS id, eear.email_id $source
                      FROM emails_email_addr_rel eear
                      INNER JOIN email_addr_bean_rel eabr
                      ON eabr.email_address_id=eear.email_address_id AND eabr.bean_module = '$rel_module' AND eabr.deleted=0
                      $rel_join AND link_bean.id = eabr.bean_id
                      where eear.deleted=0\n";
              }
              return $subQuery;
          }
      
      }




    This worked well in my local environment, so feel free to use it as a starting point if it helps with your setup. Just a heads-up: I used the files from the latest 25.1 version. If you’re on version 12, the file structure is mostly the same, but there are some syntax differences — so make sure to copy the function from the core file that matches your version to avoid any issues.


    Let me know if this helps or if i am misunderstanding something on your use case. 

    Cheers,

    André



Reply
  • Hello  , 



    Thanks for your patience while we got back to you.
    This topic is a bit nuanced, and there are a few different things going on here, so I’ll try to break it down.
    I’m making some assumptions as I don't know your instance — please feel free to correct me if I’ve misunderstood anything.

    From what I see, you have too many emails in the Email subpanel that are implicitly related to Accounts.
    These implicitly related emails in the Emails subpanel come from two sources:


    1. Emails that match the account’s own email_address field (to, from or cc)




    2. Emails that match the email_address of a Contact related to that account

     


    Now, you’ve already found that you can turn off the Contact-related emails via Admin > Related Contacts Emails — so that rules out scenario #2.





    That leaves us with scenario #1 to look into.

    You mentioned that emails are showing up under hundreds of different accounts, which is odd. In theory, two different accounts shouldn’t be sharing the same email address — so it’s worth checking why that happens in the first place. 

    A Simple Fix:

    If you’re able to remove or the duplicate email_addresses across accounts, the issue will resolve itself. Emails would only appear under the accounts with the exact matching email, which is the expected behavior.

    Would that be a viable option for you?

    If the fix doesn't work for you:

    If you still need to completely remove implicit emails from showing, it’s possible to do so through customisation—if you’re comfortable with that approach.

    It involves creating a new class based on the default ArchivedEmailsBeanLink that prevents implicit emails from showing up.

    The file that contains the logic that does this is the following one: 

    modules/Emails/ArchivedEmailsBeanLink.php

    If you want to try it yourself you’d need to create two files:

    1. A vardef file to override the archived_emails field definition to point to the new class. 

      custom/Extension/modules/Accounts/Ext/Vardefs/custom_archived_emails_link.php

      <?php
      
      $dictionary['Account']['fields']['archived_emails']['link_class'] ='Sugarcrm\\Sugarcrm\\custom\\modules\\Emails\\CustomArchivedEmailsBeanLink';


    2. A custom class, based on the default ArchivedEmailsBeanLink, where the part that adds implicit emails to the subpanel is commented out.

      custom/modules/Emails/CustomArchivedEmailsBeanLink.php

      <?php
      
      
      namespace Sugarcrm\Sugarcrm\custom\modules\Emails;
      
      use ArchivedEmailsBeanLink;
      
      require_once 'modules/Emails/ArchivedEmailsBeanLink.php';
      
      class CustomArchivedEmailsBeanLink extends ArchivedEmailsBeanLink
      {
      protected function getEmailsSubquery($relation)
          {
              $rel_module = $this->focus->$relation->getRelatedModuleName();
              $rel_join = $this->focus->$relation->getJoin(
                  ['join_table_alias' => 'link_bean', 'join_table_link_alias' => 'linkt']
              );
      
              $bean_id = $this->db->quoted($this->focus->id);
              $rel_join = str_replace("{$this->focus->table_name}.id", $bean_id, $rel_join);
      
              $hideHistoryContactsEmails
                  = !empty($GLOBALS['sugar_config']['hide_history_contacts_emails'][$this->focus->module_name]);
      
              $source = $this->addSource ? ', 1 /* direct */ source' : '';
              // directly assigned emails
              $subQuery = "SELECT eb.bean_id AS id, eb.email_id $source FROM emails_beans eb
                  WHERE eb.bean_module = '{$this->focus->module_dir}' AND eb.bean_id = $bean_id AND eb.deleted=0\n";
      
              // Commented to prevent implicit emails to show 
      
              // $source = $this->addSource ? ', 2 /* related */ source' : '';
              // $subQuery .= ' UNION ' .
              // Related by directly by email
              //   "SELECT DISTINCT eabr.bean_id AS id, eear.email_id $source from emails_email_addr_rel eear
              //   INNER JOIN email_addr_bean_rel eabr
              //   ON eabr.bean_id = $bean_id AND eabr.bean_module = '{$this->focus->module_dir}' AND
              //   eabr.email_address_id = eear.email_address_id and eabr.deleted=0 where eear.deleted=0\n";
      
              if (!$hideHistoryContactsEmails) {
                  // Assigned to contacts
                  $source = $this->addSource ? ', 4 /* contact */ source' : '';
                  $subQuery .= ' UNION ' .
                      "SELECT DISTINCT $bean_id AS id, eb.email_id $source FROM emails_beans eb
                      $rel_join AND link_bean.id = eb.bean_id
                      where eb.bean_module = '$rel_module' AND eb.deleted=0\n";
                  // Related by email to linked contact
                  $source = $this->addSource ? ', 8 /* related_contact */  source' : '';
                  $subQuery .= " UNION SELECT DISTINCT $bean_id AS id, eear.email_id $source
                      FROM emails_email_addr_rel eear
                      INNER JOIN email_addr_bean_rel eabr
                      ON eabr.email_address_id=eear.email_address_id AND eabr.bean_module = '$rel_module' AND eabr.deleted=0
                      $rel_join AND link_bean.id = eabr.bean_id
                      where eear.deleted=0\n";
              }
              return $subQuery;
          }
      
      }




    This worked well in my local environment, so feel free to use it as a starting point if it helps with your setup. Just a heads-up: I used the files from the latest 25.1 version. If you’re on version 12, the file structure is mostly the same, but there are some syntax differences — so make sure to copy the function from the core file that matches your version to avoid any issues.


    Let me know if this helps or if i am misunderstanding something on your use case. 

    Cheers,

    André



Children
  • Thank you for your reply.  This is exactly the information I need.  I ended up using a version of your simple fix that wasn't all that simple, but it's probably not worth trying to explain why since it's probably fairly unique to us.   However, now I know how to do the real fix, which would be to turn off the implicit email display.  I'm in the middle of an upgrade, but will probably give this a try in my sandbox environment once things settle down.  I appreciate you taking the time to respond.