==== Sample SQL queries ==== See the [[http://www.manitou-mail.org/doc/mdx/database-schema.html|database schema documentation]] for definitions of tables and columns. === Messages with a private note attached === SELECT mail_id FROM notes === The last 20 messages that have a private note === SELECT mail_id FROM notes ORDER BY mail_id DESC LIMIT 20 === Messages with a private note which has been added or modified during the last 7 days === SELECT mail_id FROM notes WHERE last_changed>=now()-'7 days'::interval === Messages with one or more pictures attached === select mail_id from attachments where content_type like 'image/%' === Outgoing messages that have been composed less than one month ago === SELECT m.mail_id FROM mail m WHERE msg_date>=now()-'1 month'::interval AND status&256=256 === Messages with many recipients in To field === (example: more than 20 recipients) SELECT mail_id FROM mail_addresses WHERE addr_type=2 GROUP BY mail_id having count(*)>20 === Messages with many recipients in To/Cc field === (example: more than 20) SELECT mail_id FROM mail_addresses WHERE addr_type in (2,3) GROUP BY mail_id having count(*)>20 === Messages with any sender or recipient from a given domain === select a.mail_id from mail_addresses a join addresses using(addr_id) where email_addr like '%@example.com' === Messages with attachments bigger than a given size === (example: bigger than 1Mb) select mail_id from attachments where content_size > 1024*1024 ---- See the [[http://www.manitou-mail.org/doc/mdx/database-schema.html|database schema documentation]] for definitions of tables and columns.