Forum OpenACS Q&A: Re: ns_sendmail replacement?

Collapse
Posted by Tilmann Singer on
I've added this to my version of acs-mail-lite ( http://tils.net/acs-mail-lite.tgz ). I hope to be able to integrate this into the toolkit some time.

The advantage of having it in acs-mail-lite is that one can make use of a db sequence, and you can make acs_mail_lite::send return the generated id (or the re-used one if one was specified explicitely), so that the caller can save it for future references, e.g. for generating a References: header.

    ad_proc -private generate_message_id {
        {-sequence_value ""}
    } {
        Generate an id suitable as a Message-Id: header for an email.

        @param sequence_value the value of acs_mail_lite_id_seq to use - when empty a new value will be fetched
    } {

        if { [empty_string_p $sequence_value] } {
            set sequence_value [db_string get_next_message_id "select nextval('acs_mail_lite_id_seq')"]
        }

        # The combination of time accurate to the second and sequence
        # value should be pretty unique. It's unlikely that the
        # sequence gets recreated and two mails are being sent all
        # within one second.
        return "[ns_fmttime [ns_time] "%Y%m%d%H%M%S"].$sequence_value.oacs@[ad_host]"

    }