/**
  * Searches the email body for signature tags {signature} or {xxx_signature} and replaces
  * it with a graphic that is of the user's signature
  */
 protected static function updateSignature(&$body)
 {
     $matches = array();
     $total = preg_match_all('/\\{(.*)signature\\}/', $body, $matches);
     if (!$total) {
         return;
     }
     $sigMatches = array_unique($matches[0]);
     $sigNames = array_unique($matches[1]);
     foreach ($sigMatches as $index => $match) {
         $name = $sigNames[$index];
         if (strlen($name) > 0) {
             // trim the trailing underscore
             $name = substr($name, 0, -1);
         }
         $filename = CRM_Simplemail_BAO_SimpleMailHelper::getSignatureFilename($name);
         $replacement = !empty($filename) ? '<img src="' . $filename . '" />' : '';
         $body = str_replace($sigMatches[$index], $replacement, $body);
     }
 }
 /**
  * Deletes all the attachments in the table that match the simple mail ID provided
  */
 public static function removeAll($simpleMailId)
 {
     if (!CRM_Core_Permission::check(SM_PERMISSION_DELETE)) {
         throw new CRM_Extension_Exception('Sorry! You do not have permission to delete attachments', 500);
     }
     // not the most efficient way but then I doubt we'll be deleting 100's of attachments
     // so this feels the most consistent way to do deletions
     $attachment = new CRM_Simplemail_DAO_SimpleMailInlineAttachment();
     $attachment->simplemail_id = $simpleMailId;
     $total = $attachment->find();
     while ($attachment->fetch()) {
         $filename = CRM_Simplemail_BAO_SimpleMailHelper::getUploadDirPath(static::DIRECTORY);
         $filename .= basename($attachment->url);
         $unlinkResult = unlink($filename);
         $attachment->delete();
     }
     return true;
 }