select j.subject, j.text_body, j.text_header, j.text_footer,
j.html_body, j.html_header, j.html_footer, j.locale,
j.mime_type as mail_mime_type, l.mime_charset,
j.sender_email, j.track_links_p, template_p,
j.css_revision_id, j.list_id, j.selection_id,
j.sql_query, j.bind_vars, j.package_id
from ml_mail_jobs j, ad_locales l
where j.mail_job_id = :mail_job_id
and j.state = 'active'
and l.locale = j.locale
select u.user_id, p.first_names as user_first_names,
p.last_name as user_last_name, i.email as user_email
from ml_mailing_list_user_map m, users u, parties i, persons p
where u.user_id = m.user_id
and u.email_bouncing_p = 'f'
and m.list_id = :list_id
and m.subscribed_p = 't'
and i.party_id = u.user_id
and p.person_id = u.user_id
and u.email_verified_p = 't'
and u.email_bouncing_p = 'f'
insert into ml_email_log (user_id, mail_job_id)
values (:user_id, :mail_job_id)
update ml_mail_jobs
set state = 'finished',
mails_sent = :mail_count,
track_links_p = (select case when count(*) = 0 then 'f' else 't' end
from mail_link_mail_map m
where mail_id = :mail_job_id)
where mail_job_id = :mail_job_id
update ml_mail_jobs
set mails_bounced = mails_bounced + 1
where mail_job_id = :job_id