#!/bin/sh

# Exit if package was removed but not purged.
test -x /usr/sbin/masqmail || exit 0


if [ -n "$PPP_IFACE" ]; then
    # Set the provider according to the value of PPP_IPPARAM
    PROVIDER="$PPP_IPPARAM"
fi


if [ -n "$PROVIDER" ]; then

    # Record the provider name in a file. This is necessary if we're using
    # the "online_detect = file" method (cf. /etc/masqmail/masqmail.conf)
    echo -n "$PROVIDER" > /tmp/connect_route
    chmod 0644 /tmp/connect_route

    # When the connection goes up, we flush the MasqMail queue using the route
    # defined for the provider by "connect_route.$PROVIDER" 
    # in /etc/masqmail/masqmail.conf
    /usr/sbin/masqmail -qo &

fi


if grep -qsx "^get.$PROVIDER.*=.*" /etc/masqmail/masqmail.conf; then

    # optionally fetch mails from POP servers, if a get method is defined
    # in /etc/masqmail/masqmail.conf
    /usr/sbin/masqmail -g &

fi
