Re: [exim] announce mailing list using postgresql - lookup o…

Top Page
Delete this message
Reply to this message
Author: Gary Stainburn
Date:  
To: exim-users
Subject: Re: [exim] announce mailing list using postgresql - lookup only once
Just to let everyone know how I've sorted my problem. Firstly i've added
one_time to the router, but I've also changed my psql select function to
avoid a race condition and also ensure a consistant select.

my router has the line

  data    = ${lookup pgsql{select * from mailing_list_send('${quote_pgsql:
$local_part}','${quote_pgsql:$sender_address}','${quote_pgsql:
$h_subject:}','${quote_pgsql:$message_id}')}}


and in postgresql I have the following function.

create or replace function mailing_list_send(list text, sender text, subject 
text, messageId text) returns setof varchar as $$
DECLARE
  recordCount int4;
BEGIN
  select into recordCount count(ml_id) from mailing_list_log where ml_id = 
messageId;
  IF ( recordCount = 0) THEN
    insert into mailing_list_log (ml_name, ml_recipient, ml_sender, 
ml_subject, ml_id)
       select list, ml_recipient, sender, subject, messageId from 
mailing_list_recipients
         where ml_name = list and ml_disabled is null;
  END IF;
  return query select ml_recipient from mailing_list_log
       where ml_id = messageId;
  return;
END;
$$
    LANGUAGE plpgsql;


I've also added the 'one_time' statement to the router. I know it's belts and
braces but it seems to do the job.
--
Gary Stainburn
Group I.T. Manager
Ringways Garages
http://www.ringways.co.uk