Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-20855

Disabling "Search Primary Details Only" causes partial CiviMail delivery failure

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No

      Description

      The "Search Primary Details Only" setting is a very useful setting for administrators: By disabling they can easily search for contacts with multiple email addresses (which in my experience is quite a common need).

      Unfortunately it breaks mailing delivery.  At https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/BAO/Query.php#L2637 

      if (Civi::settings()->get('searchPrimaryDetailsOnly') || $apiEntity) {
        $searchPrimary = "AND {$name}.is_primary = 1";
      }
      

      we need to pass in $apiEntity if we want to search primary emails only. However getTokenDetails() at https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/Token.php#L1240 leaves $apiEntity argument at its default value NULL.  This results in multiple rows being returned for contacts with multiple email addresses, and because of the query limit being set to the number of contacts being looked up, some contacts do not have a row in the results.

      Because these contacts are missing their preferred email format (HTML, Text, etc.) an email message cannot be composed for them.  Delivery status will be unknown and this error will be logged: "CiviMail will not send an empty mail body, Skipping: "

        Attachments

          Activity

            People

            • Assignee:
              monish.deb Monish Deb
              Reporter:
              mfb Mark Burdett
            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: