private function view_mail()
 {
     $context = context_course::instance($this->courseid);
     if (!has_capability('block/course_message:viewmail', $context)) {
         echo get_string('usercannotviewmail', BLOCK_CM_LANG_TABLE);
         return;
     }
     $mailid = required_param('id', PARAM_INT);
     $folder = required_param('folder', PARAM_TEXT);
     $mail = new display_mail($mailid, $folder, $this->courseid);
     if (!$mail->check_user_identification($folder)) {
         echo get_string('baduseridentification', BLOCK_CM_LANG_TABLE);
         return 0;
     }
     $view = new mail_view($mail, $mailid, $folder);
     $view->display_mail();
 }
 /**
  * This function tests retrieving a threaded mail.  I test the end
  * point of the thread, the middle of the thread and the beginning
  * of the thread.
  *
  */
 public function test_threaded_message()
 {
     $this->setUser($this->friend);
     // 1) Last mail in thread has a parent + three message thread.
     $mailid = $this->mailids[self::LASTMAILID];
     $folder = 'inbox';
     $dm = new display_mail($mailid, $folder, $this->testcourseid, false);
     $this->assertTrue((bool) $dm->is_thread());
     $this->assertEquals(count($dm->threadmails), 3);
     // 2) Child (middle) mail in thread has a parent + three message thread.
     $mailid = $this->mailids[self::CHILDMAILID];
     $folder = 'sent';
     $dm = new display_mail($mailid, $folder, $this->testcourseid, false);
     $this->assertTrue((bool) $dm->is_thread());
     $this->assertEquals(count($dm->threadmails), 3);
     // 3) Parent mail: is parent, part of thread.
     $mailid = $this->mailids[self::PARENTMAILID];
     $folder = 'inbox';
     $dm = new display_mail($mailid, $folder, $this->testcourseid, false);
     $this->assertTrue((bool) $dm->is_thread());
     $this->assertEquals(count($dm->threadmails), 3);
 }