function connect()
    {
        if ( $this->mailbox !== null && $this->username !== null && $this->password !== null ) {
            if ( $this->stream = imap_open($this->mailbox, $this->username, $this->password) ) {
                return true;
            } else {
                throw new Exception(sprintf("Invalid IMAP stream (mailbox: %s, username: %s)", $this->mailbox, $this->username));
            }
        } else {
            throw new Exception(sprintf("Missing IMAP settings: mailbox, username, and/or password"));
        }
    }