function get_content()
 {
     global $SESSION, $CFG, $USER, $OUTPUT;
     // quick and simple way to prevent block from showing up on front page
     if (!isloggedin()) {
         $this->content = NULL;
         return $this->content;
     }
     // which field is the username in
     $this->userfield = get_config('blocks/gmail', 'username') ? get_config('blocks/gmail', 'username') : 'username';
     // quick and simple way to prevent block from showing up on users My Moodle if their email does not match the Google registered domain
     $this->domain = get_config('blocks/gmail', 'domainname') ? get_config('blocks/gmail', 'domainname') : get_config('auth/gsaml', 'domainname');
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     // This lib breaks install if left at top level only include
     // when we know we need it
     if ($USER->id !== 0) {
         require_once $CFG->libdir . '/simplepie/moodle_simplepie.php';
     }
     // Test for domain settings
     if (empty($this->domain)) {
         $this->content->items = array(get_string('mustusegoogleauthenticaion', 'block_gmail'));
         $this->content->icons = array();
         return $this->content;
     }
     if (!($this->oauthsecret = get_config('blocks/gmail', 'oauthsecret'))) {
         $this->content->items = array(get_string('missingoauthkey', 'block_gmail'));
         $this->content->icons = array();
         return $this->content;
     }
     $feederror = false;
     // Obtain gmail feed data
     $feeddata = $this->obtain_gmail_feed();
     if (empty($feeddata)) {
         $feederror = true;
     } else {
         // Parse google atom feed
         $feed = new moodle_simplepie();
         $feed->set_raw_data($feeddata);
         $status = $feed->init();
         $msgs = $feed->get_items();
     }
     if ($feederror) {
         $this->content->items[] = get_string('sorrycannotgetmail', 'block_gmail');
     } else {
         //$unreadmsgsstr = get_string('unreadmsgs','block_gmail');
         $unreadmsgsstr = '';
         $composestr = get_string('compose', 'block_gmail');
         $inboxstr = get_string('inbox', 'block_gmail');
         // Obtain link option
         $newwinlnk = get_config('blocks/gmail', 'newwinlink');
         $composelink = '<a ' . ($newwinlnk ? 'target="_new"' : '') . ' href="' . 'http://mail.google.com/a/' . $this->domain . '/?AuthEventSource=SSO#compose">' . $composestr . '</a>';
         $inboxlink = '<a ' . ($newwinlnk ? 'target="_new"' : '') . ' href="' . 'http://mail.google.com/a/' . $this->domain . '">' . $inboxstr . '</a>';
         $this->content->items[] = '<img src="' . $OUTPUT->pix_url('gmail', 'block_gmail') . '" alt="message" />&nbsp;' . $inboxlink . ' ' . $composelink . ' ' . $unreadmsgsstr . '<br/>';
         // Only show as many messages as specified in config
         $countmsg = true;
         if (!($msgnumber = get_config('blocks/gmail', 'msgnumber'))) {
             // 0 msg means as many as you want.
             $countmsg = false;
         }
         $mc = 0;
         // only show the detail if they have access to it
         if (!has_capability('block/gmail:viewlist', $this->page->context)) {
             $mc = count($msgs);
             $this->content->items[] = get_string('unread', 'block_gmail', $mc) . ($mc == 1 ? '' : 's') . '<br/>';
         } else {
             foreach ($msgs as $msg) {
                 if ($countmsg and $mc == $msgnumber) {
                     break;
                 }
                 $mc++;
                 // Displaying Message Data
                 $author = $msg->get_author();
                 $author->get_name();
                 $summary = $msg->get_description();
                 // Google partners need a special gmail url
                 $servicelink = $msg->get_link();
                 $servicelink = str_replace('http://mail.google.com/mail', 'http://mail.google.com/a/' . $this->domain, $servicelink);
                 // To Save Space given them option to show first and last or just last name
                 $authornames = explode(" ", $author->get_name());
                 $author_first = array_shift($authornames);
                 $author_last = array_shift($authornames);
                 // Show first Name
                 if (!($showfirstname = get_config('blocks/gmail', 'showfirstname'))) {
                     $author_first = '';
                 }
                 // Show last Name
                 if (!($showlastname = get_config('blocks/gmail', 'showlastname'))) {
                     $author_last = '';
                 }
                 // I should do clean_param($summary, PARAM_TEXT) But then ' will have \'
                 if ($newwinlnk) {
                     $text = '<a target="_new" title="' . format_string($summary);
                     $text .= '" href="' . $servicelink . '">' . format_string($msg->get_title()) . '</a> ' . $author_first . ' ' . $author_last;
                     $this->content->items[] = $text;
                 } else {
                     $text = '<a title="' . format_string($summary);
                     $text .= '" href="' . $servicelink . '">' . format_string($msg->get_title()) . '</a> ' . $author_first . ' ' . $author_last;
                     $this->content->items[] = $text;
                 }
             }
         }
     }
     return $this->content;
 }