protected function checkValidAttachment($filename, &$error) {
    if (!is_string($filename)) {
      $error = sprintf("Filename must be a string but was type %s",
                       gettype($filename));
      return false;
    }

    $path_parts = pathinfo($filename);
    if (isset($path_parts['extension'])) {
      if (in_array($path_parts['extension'], self::$extension_blacklist)) {
        $error = sprintf("'%s' is a blacklisted file extension.",
                         $path_parts['extension']);
        return false;
      }
    }

    return true;
  }