How to expose the civicase hashed value that gets sent in Subject when sending an email from case
Here's the override code I've used to make it accept some variations of case id (with and without the word case, with and without the # sign) as well as hash, prioritizing the fanciest to the plainest. It looks like the original code hasn't changed since 4.2 so this should work against 4.7 too.

Create an override for CRM/Activity/BAO/Activity.php, and in lines 607 thru 622 replace it with this:

$matches = array();
$subj_to_match = CRM_Utils_Array::value('subject', $params);
if (preg_match('/\[case #([0-9a-h]{7})\]/', $subj_to_match, $matches)) {
  $key        = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE SUBSTR(SHA1(CONCAT('$key', id)), 1, 7) = '$hash'";
} elseif (preg_match('/\[case #(\d+)\]/', $subj_to_match, $matches)) {
  $hash       = $matches[1];
  // this seems like an odd query but we are checking the id actually exists
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
} elseif (preg_match('/\[#(\d+)\]/', $subj_to_match, $matches)) {
  // technically this is a subset of the one below, but keeping it allows a subject that had both and prioritize this one
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
} elseif (preg_match('/\[(\d+)\]/', $subj_to_match, $matches)) {
  $hash       = $matches[1];
  $query      = "SELECT id FROM civicrm_case WHERE id = '$hash'";
}
if (!empty($matches)) {
  $caseParams = array(
    'activity_id' =&gt; $activity-&gt;id,
    'case_id' =&gt; CRM_Core_DAO::singleValueQuery($query),
  );
  if ($caseParams['case_id']) {
    CRM_Case_BAO_Case::processCaseActivity($caseParams);
  }
  else {
    self::logActivityAction($activity, "unknown case hash encountered: $hash");
  }
}


One interesting side effect of this is that saving a non-case activity using the normal civi UI but putting [1234] in the subject will save it as a case activity on case 1234!