OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Re: feature request: delayed injection

From: Victor Duchovni (Victor.DuchovniMorganStanley.com)
Date: Tue Jun 06 2006 - 08:50:34 CDT


On Tue, Jun 06, 2006 at 02:46:37PM +0200, martin f krafft wrote:

> also sprach Wietse Venema <wietseporcupine.org> [2006.06.06.1443 +0200]:
> > Checking application/pgp-signature: FAILURE
>
> gpg --recv-key 330c4a75
>
> > Use at to maintain a queue of jobs to execute at a specified time.
> > Use postfix to send mail.
>
> I take that as a no. Oh well... thanks for your time.

Create a second non-running Postfix in /etc/postfix-freezer. Give it an
empty master.cf and don't start it. List its configuration directory in
the primary alternative_config_directories setting. List users (default
static:anyone) allowed to inject mail into the catatonic queue in the
secondary main.cf authorized_submit_users setting. Place the secondary
queue directory in the same filesystem (but different directory) as the
primary queue directory.

Inject mail via:

    /usr/local/bin/delaymail:

        #! /bin/sh

        # XXX: Sanity check the time
        when=$1; shift

        (echo "X-Release-At: $when"; cat message) |
        MAIL_CONFIG=/etc/postfix-freezer sendmail "$"

Periodically, scan the maildrop directory of the secondary instance,
looking for messages that are ready to be sent. Move them (same
file-system only!) to the maildrop directory of the primary instance,
and wake up the primary pickup service.

    # cd /var/spool
    # mv postfix-freezer/maildrop/$qid postfix/maildrop/$qid
    # postkick public pickup W

If the volume is high enough, you can shuffle the frozen queue files
out of the secondary maildrop into the hold queue of that instance
when you have examined the "X-Release-At:" header with symlinks in
another directory to indicate the release time.

    # cd /var/spool/postfix-freezer/maildrop
    # find . -type f -mode -0700 -print0 |
            xargs -0 /usr/local/bin/index_delayed_mail

    index_delayed_mail:

       #! /bin/sh

       release() {
                  mv $qid /var/spool/postfix/maildrop/.
           postkick public pickup W
       }

       for qid in "$"
       do
            when=$(postcat "$qid" |
                    perl -lne '/^X-Release-At: (\d+)$/ && do {print $1; exit; };' \
                    -e '/^$/ && exit;')

            if [ -z "$when" ]; then
                    release "$qid"
                continue
            fi

            # XXX: Sanity check the time, release now if bogus

            # In this order
            now=$(date +%Y%m%d%H%M%S)
            rm -f ../incoming/$when.$now.$qid
            ln -s "$qid" ../incoming/$when.$now.$qid
            mv "$qid" ../hold
       done

Indexed release just scans the incoming directory, looking for
symlinks to queueids that are ripe. This only requires reading
the directory, with readlink() only for symlinks that are ready
for release. Release the queue files with care:

        - First move the queue file from hold to the primary
          maildrop. (OK if gone).
        - Only then remove the symlink.
        - Finally "postkick public pickup W"

There a partial re-implementation of 'at'. Do you still want to
do this?

--
        Viktor.

P.S. Morgan Stanley is looking for a New York City based, Senior Unix
     system/email administrator to architect and sustain the Unix email
     environment. If you are interested, please drop me a note.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:majordomopostfix.org?body=unsubscribe%20postfix-users>

If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.