Support mailclient oidc claim
Only apps with addon email have access to the claims' scopes
This commit is contained in:
30
src/mail.js
30
src/mail.js
@@ -6,6 +6,7 @@ import debugModule from 'debug';
|
||||
import dig from './dig.js';
|
||||
import dns from './dns.js';
|
||||
import eventlog from './eventlog.js';
|
||||
import groups from './groups.js';
|
||||
import mailer from './mailer.js';
|
||||
import mailServer from './mailserver.js';
|
||||
import net from 'node:net';
|
||||
@@ -829,6 +830,34 @@ async function listMailboxes(page, perPage) {
|
||||
return results;
|
||||
}
|
||||
|
||||
async function listMailboxesByUserId(userId) {
|
||||
assert.strictEqual(typeof userId, 'string');
|
||||
|
||||
const groupIds = await groups._getMembership(userId);
|
||||
|
||||
const baseQuery = 'SELECT m1.name AS name, m1.domain AS domain, m1.ownerId AS ownerId, m1.ownerType as ownerType, m1.active as active, JSON_ARRAYAGG(m2.name) AS aliasNames, JSON_ARRAYAGG(m2.domain) AS aliasDomains, m1.enablePop3 AS enablePop3, m1.storageQuota AS storageQuota, m1.messagesQuota AS messagesQuota '
|
||||
+ ` FROM (SELECT * FROM mailboxes WHERE type='${TYPE_MAILBOX}') AS m1`
|
||||
+ ` LEFT JOIN (SELECT * FROM mailboxes WHERE type='${TYPE_ALIAS}') AS m2`
|
||||
+ ' ON m1.name=m2.aliasName AND m1.domain=m2.aliasDomain AND m1.ownerId=m2.ownerId';
|
||||
|
||||
let whereClause = " WHERE (m1.ownerType = 'user' AND m1.ownerId = ?)";
|
||||
const args = [ userId ];
|
||||
if (groupIds.length > 0) {
|
||||
const placeholders = groupIds.map(() => '?').join(',');
|
||||
whereClause += ` OR (m1.ownerType = '${OWNERTYPE_GROUP}' AND m1.ownerId IN (${placeholders}))`;
|
||||
args.push(...groupIds);
|
||||
}
|
||||
|
||||
const query = baseQuery + whereClause + ' GROUP BY m1.name, m1.domain, m1.ownerId ORDER BY name';
|
||||
|
||||
const results = await database.query(query, args);
|
||||
|
||||
results.forEach(postProcessMailbox);
|
||||
results.forEach(postProcessAliases);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
async function delByDomain(domain) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
|
||||
@@ -1214,6 +1243,7 @@ export default {
|
||||
sendTestMail,
|
||||
listMailboxesByDomain,
|
||||
listMailboxes,
|
||||
listMailboxesByUserId,
|
||||
getMailbox,
|
||||
addMailbox,
|
||||
updateMailbox,
|
||||
|
||||
Reference in New Issue
Block a user