A little bit late, but you can do your searching easily by creating views in your database and then do your searching.
/* to, from and subject*/
create view as EmailHeaders
select
`m`.`physmessage_id` AS `physmessage_id`,
`ph`.`internal_date` AS `internal_date`,
max(if(`n`.`headername` = 'from',`v`.`headervalue`,NULL)) AS `From`,
max(if(`n`.`headername` = 'to',`v`.`headervalue`,NULL)) AS `To`,
max(if(`n`.`headername` = 'subject',`v`.`headervalue`,NULL)) AS `Subject`
from
(
(
(`dbmail_messages` `m`
join `dbmail_header` `h` on (`m`.`physmessage_id` = `h`.`physmessage_id`)
)
join `dbmail_physmessage` `ph` on(`m`.`physmessage_id` = `ph`.`id`)
)
join `dbmail_headername` `n` on(`h`.`headername_id` = `n`.`id`)
)
join `dbmail_headervalue` `v` on(`h`.`headervalue_id` = `v`.`id`))
where
`n`.`headername` = 'to'
or `n`.`headername` = 'from'
or `n`.`headername` = 'subject'
group by `m`.`physmessage_id`
You can also create views to disaplay messages, but is not efficient (memory consuming) but you can use something like this
select
physmessage_id,
sum(prts.size) emailSize
from dbmail_partlists list, dbmail_mimeparts prts, EmailHeaders eh
where list.part_id=prts.id
and list.is_header=0
and eh.physmessage_id=list.physmessage_id
and prts like '%your_word_here%'
group by list.physmessage_id
For small servers these queries are enough, but for large ones, you may need to employ other methods, but essentially this is it.