dbpath = /data/lanqin.db
query = SELECT 'vhosts/' || d.name || '/' || m.local_part || '/Maildir/' FROM mailboxes m JOIN domains d ON d.id=m.domain_id WHERE d.name=lower(substr('%s', instr('%s', '@') + 1)) AND m.local_part=lower(CASE WHEN instr(substr('%s', 1, instr('%s', '@') - 1), '+') > 0 THEN substr(substr('%s', 1, instr('%s', '@') - 1), 1, instr(substr('%s', 1, instr('%s', '@') - 1), '+') - 1) ELSE substr('%s', 1, instr('%s', '@') - 1) END) AND m.status='active' AND d.status='active' UNION SELECT 'vhosts/' || lower(substr('%s', instr('%s', '@') + 1)) || '/__unregistered__/Maildir/' WHERE EXISTS (SELECT 1 FROM system_settings WHERE key='catchAllEnabled' AND value='true') AND EXISTS (SELECT 1 FROM domains WHERE name=lower(substr('%s', instr('%s', '@') + 1)) AND status='active') AND NOT EXISTS (SELECT 1 FROM mailboxes m JOIN domains d ON d.id=m.domain_id WHERE d.name=lower(substr('%s', instr('%s', '@') + 1)) AND m.local_part=lower(CASE WHEN instr(substr('%s', 1, instr('%s', '@') - 1), '+') > 0 THEN substr(substr('%s', 1, instr('%s', '@') - 1), 1, instr(substr('%s', 1, instr('%s', '@') - 1), '+') - 1) ELSE substr('%s', 1, instr('%s', '@') - 1) END) AND m.status='active')
