- $res = XDB::query('SELECT p.deathdate IS NULL AS alive, e.last,
- IF(e.email IS NOT NULL, e.email,
- IF(FIND_IN_SET(\'googleapps\', eo.storage), \'googleapps\', NULL)) AS email
- FROM email_options AS eo
- LEFT JOIN account_profiles AS ap ON (ap.uid = eo.uid AND FIND_IN_SET(\'owner\', ap.perms))
- LEFT JOIN profiles AS p ON (p.pid = ap.pid)
- LEFT JOIN emails AS e ON (e.flags = \'active\' AND e.uid = eo.uid)
- WHERE eo.uid = {?}
- ORDER BY e.panne_level, e.last', $user->id());
+ $res = XDB::query('SELECT p.deathdate IS NULL AS alive, r.last, IF(r.type = \'googleapps\', \'googleapps\', r.redirect) AS active_email
+ FROM accounts AS a
+ LEFT JOIN email_redirect_account AS r ON (a.uid = r.uid AND r.type IN (\'smtp\', \'googleapps\') AND r.flags = \'active\')
+ LEFT JOIN account_profiles AS ap ON (ap.uid = r.uid AND FIND_IN_SET(\'owner\', ap.perms))
+ LEFT JOIN profiles AS p ON (p.pid = ap.pid)
+ WHERE a.uid = {?}
+ ORDER BY r.broken_level, r.last',
+ $user->id());