@@latest_created_at_query||=db.prepare"SELECT created_at FROM message ORDER BY created_at DESC LIMIT 1"
@@latest_created_at_query.execute.next
end
defmessages
@@messages_query||=db.prepare"SELECT id, sender, recipients, subject, size, created_at FROM message ORDER BY created_at DESC"
@@messages_query.execute.to_a
end
defmessage(id)
@@message_query||=db.prepare"SELECT * FROM message WHERE id = ? LIMIT 1"
@@message_query.execute(id).next
end
defmessage_has_html?(id)
@@message_has_html_query||=db.prepare"SELECT 1 FROM message_part WHERE message_id = ? AND is_attachment = 0 AND type = 'text/html' LIMIT 1"
!!@@message_has_html_query.execute(id).next
end
defmessage_has_plain?(id)
@@message_has_html_query||=db.prepare"SELECT 1 FROM message_part WHERE message_id = ? AND is_attachment = 0 AND type = 'text/plain' LIMIT 1"
!!@@message_has_html_query.execute(id).next
end
defmessage_parts(id)
@@message_parts_query||=db.prepare"SELECT cid, type, filename, size FROM message_part WHERE message_id = ? ORDER BY filename ASC"
@@message_parts_query.execute(id).to_a
end
defmessage_attachments(id)
@@message_parts_query||=db.prepare"SELECT cid, type, filename, size FROM message_part WHERE message_id = ? AND is_attachment = 1 ORDER BY filename ASC"
@@message_parts_query.execute(id).to_a
end
defmessage_part(message_id,part_id)
@@message_part_query||=db.prepare"SELECT * FROM message_part WHERE message_id = ? AND id = ? LIMIT 1"