Answers.Body: <p>For Emails sent from Manage Case to case roles, there is hook_civicrm_alterMailParams that can be used to alter the subject. Here's some (maybe-not-the-greatest) code I have from an earlier customization. Note that the logic here will remove the hash whether it actually finds the case or not, which was desirable at the time but in those weird scenarios you might prefer it to leave the hash, in which case just move that part down inside the <code>if ($case_id)</code> block.</p>
  
  <pre><code>function myextension_civicrm_alterMailParams( &amp;$params )
  {
      if (preg_match('/\[case #([0-9a-h]{7})\]/', $params['subject'], $matches)) {
          $key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
          $hash = $matches[1];
          $sqlParams = array(1 =&gt; array($hash, 'String'));
          $case_id = null;
          $dao = CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('$key', id)), 1, 7) = %1", $sqlParams);
          if ($dao-&gt;fetch()) {
              $case_id = $dao-&gt;id;
          }
          $dao-&gt;free();
  
          // remove the case # part - can't do it through message templates since hardcoded in Contact/Form/Task/EmailCommon.php. Note also Activity/BAO/Activity.php removes it before saving on the case but that's after it sends it.
          $pos = strpos( $params['subject'] , '] ' );
          if ( $pos !== FALSE ) {
              $params['subject'] = substr( $params['subject'], $pos + 2 );
          }
  
          // Now add the real case id if found
          if ($case_id) {
              $params['subject'] .= " [case #{$case_id}]";
          }
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-26T23:11:02.290Z
Answers.LastActivityDate: 2018-11-26T23:29:25.977Z
Answers.LastEditDate: 2018-11-26T23:29:25.977Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>There's now an extension for this, with a couple additional features: <a href="https://lab.civicrm.org/extensions/caseidinsubject" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/caseidinsubject</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T14:36:28.243Z
Answers.Text: Awesome. I'll get to testing and implementing that!!
Answers.UserDisplayName: RayWright
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T03:13:47.357Z
Answers.LastActivityDate: 2020-08-04T03:13:47.357Z
Answers.UserDisplayName: Demerit
Body: <p>I'm looking to swap out the hashed ID for the case ID in Case emails (now that email processing works for this and you can search by case id.) </p>
  
  <p>I've looked through the two related posts here on stack and <a href="https://issues.civicrm.org/jira/browse/CRM-21446" rel="nofollow noreferrer">the issue on JIRA</a> but can't find specifics.</p>
  
  <p>I can adjust the <strong>Cases - Send Copy of an Activity</strong> template but that only affects copies of any activity sent, NOT emails that are sent. (In case it's helpful to anyone finding this post - the token is {$caseID}.)</p>
  
  <p>In this <a href="https://civicrm.stackexchange.com/questions/7791/case-id-in-e-mails-from-case">post answer</a> Demerit says "we removed the hash and just use the actual case id by editing the civimail template" but I've not had any luck yet with the one case template there is.</p>
  
  <p>(Civi 5.5.3)</p>
  
Tags: <civicase>
Title: Email from case - subject line change to Case ID
ThreadText: # Email from case - subject line change to Case ID
  
  (Asked by: username_0 on 2018-11-26)
  
  I'm looking to swap out the hashed ID for the case ID in Case emails (now that email processing works for this and you can search by case id.)
  
  I've looked through the two related posts here on stack and [the issue on JIRA](https://issues.civicrm.org/jira/browse/CRM-21446) but can't find specifics.
  
  I can adjust the **Cases - Send Copy of an Activity** template but that only affects copies of any activity sent, NOT emails that are sent. (In case it's helpful to anyone finding this post - the token is {$caseID}.)
  
  In this [post answer](https://civicrm.stackexchange.com/questions/7791/case-id-in-e-mails-from-case) username_1 says "we removed the hash and just use the actual case id by editing the civimail template" but I've not had any luck yet with the one case template there is.
  
  (Civi 5.5.3)
  
  **Tags:** civicase
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-11-26. Score: 2 | Accepted answer
  
  For Emails sent from Manage Case to case roles, there is hook_civicrm_alterMailParams that can be used to alter the subject. Here's some (maybe-not-the-greatest) code I have from an earlier customization. Note that the logic here will remove the hash whether it actually finds the case or not, which was desirable at the time but in those weird scenarios you might prefer it to leave the hash, in which case just move that part down inside the if ($case_id) block.
  function myextension_civicrm_alterMailParams( &$params )
  {
      if (preg_match('/\[case #([0-9a-h]{7})\]/', $params['subject'], $matches)) {
          $key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
          $hash = $matches[1];
          $sqlParams = array(1 => array($hash, 'String'));
          $case_id = null;
          $dao = CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('$key', id)), 1, 7) = %1", $sqlParams);
          if ($dao->fetch()) {
              $case_id = $dao->id;
          }
          $dao->free();
  
          // remove the case # part - can't do it through message templates since hardcoded in Contact/Form/Task/EmailCommon.php. Note also Activity/BAO/Activity.php removes it before saving on the case but that's after it sends it.
          $pos = strpos( $params['subject'] , '] ' );
          if ( $pos !== FALSE ) {
              $params['subject'] = substr( $params['subject'], $pos + 2 );
          }
  
          // Now add the real case id if found
          if ($case_id) {
              $params['subject'] .= " [case #{$case_id}]";
          }
      }
  }
  
  
  ---
  
  ### Answer by username_1 on 2020-08-04. Score: 2
  
  There's now an extension for this, with a couple additional features: <https://lab.civicrm.org/extensions/caseidinsubject>
  
  > **Comments:**
  > **username_0**: Awesome. I'll get to testing and implementing that!!  
  
  ---
  
  