See the database schema documentation for definitions of tables and columns.
SELECT mail_id FROM notes
SELECT mail_id FROM notes ORDER BY mail_id DESC LIMIT 20
SELECT mail_id FROM notes WHERE last_changed>=now()-'7 days'::INTERVAL
SELECT mail_id FROM attachments WHERE content_type LIKE 'image/%'
SELECT m.mail_id FROM mail m WHERE msg_date>=now()-'1 month'::INTERVAL AND status&256=256
(example: more than 20 recipients)
SELECT mail_id FROM mail_addresses WHERE addr_type=2 GROUP BY mail_id HAVING COUNT(*)>20
(example: more than 20)
SELECT mail_id FROM mail_addresses WHERE addr_type IN (2,3) GROUP BY mail_id HAVING COUNT(*)>20
SELECT a.mail_id FROM mail_addresses a JOIN addresses USING(addr_id) WHERE email_addr LIKE '%@example.com'
(example: bigger than 1Mb)
SELECT mail_id FROM attachments WHERE content_size > 1024*1024
See the database schema documentation for definitions of tables and columns.