public static function getOutbox($all = false)
    {
        global $PPHP;
        $db = $PPHP['db'];

        $q = $db->query("SELECT *, datetime(modified, 'localtime') AS localmodified FROM emails");
        $q->where('NOT isSent');
        if (!$all) {
            $q->and('sender = ?', $_SESSION['user']['id']);
        };
        $outbox = $db->selectArray($q);
        foreach ($outbox as $key => $email) {
            $roles = array();
            foreach (array('recipients', 'ccs', 'bccs') as $col) {
                $outbox[$key][$col] = dejoin(';', $outbox[$key][$col]);
                foreach ($outbox[$key][$col] as $uid) {
                    foreach (grab('user_roles', $uid) as $role) {
                        $roles[$role] = true;
                    };
                };
            };
            $outbox[$key]['files'] = json_decode($email['files']);
            unset($roles['admin'], $roles['member']);
            $outbox[$key]['roles'] = array_keys($roles);
        };
        return $outbox;
    }