/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

Unread Emails

Views:

This is simple moodle plugin which displays the number of unread emails for a user.

Some modification was required to the core moodle library to make this work, details can be seen in the "Authentication" section of the Moodle page.

/srv/www/moodle/public/blocks/unread_emails/block_unread_emails.php:

<?PHP

// This is a simple moodle block which was written in house at Varndean College, Brighton, UK

class block_unread_emails extends block_base {
    function init() {
        $this->title = 'College Email';
        $this->version = 2007010401;
    }

    function applicable_formats() {
        return array('site' => true);
    }

    function get_content () {
        global $USER, $CFG;
        $wwwroot = '';
        $signup = '';

        if ($this->content !== NULL) {
            return $this->content;
        }

        $username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();

        $this->content->footer = '';
        $this->content->text = '';

        if (!empty($USER->loggedin) && !isguest()) {   // Build and show the block
            $connectionUrl="{mail.varndean.ac.uk/novalidate-cert/norsh}";
            imap_timeout(1, 1);
            $mbox = imap_open($connectionUrl, $USER->username, $USER->clearPassword, OP_HALFOPEN);
            if ($mbox) {
                $count = 0;
                $folders = imap_listmailbox($mbox, $connectionUrl, "*");
                foreach ($folders as $val) {
                       if ($val != $connectionUrl.'Trash' && $val != $connectionUrl.'SPAM' && $val != $connectionUrl.'Sent' && $val != $connectionUrl.'Drafts') {
                           $status = imap_status($mbox, $val, SA_UNSEEN);
                           if ($status) {
                               $count = $count + $status->unseen;
                           }
                       }
                }
                imap_close($mbox);
            }
            else {
                $count = false;
            }
            if ($count !== false) {
                $this->content->text .= '<ul>';
                $this->content->text .= '<li>'.$count.' unread emails</li>';
                $this->content->text .= '<li><a href="https://mail.varndean.ac.uk/" target="_blank" title="Read College Email (in a new window)">Read Email</a></li>';
                $this->content->text .= '</ul>';
            }
        }

        return $this->content;
    }
}

?>

Main Menu

Personal tools

Toolbox