procmail
[Top] [All Lists]

Renewal processor, help debug this code?

1998-04-09 22:24:39

I need help from people smarter than me again. Anybody care to collaborate
on this? Karl Pinc and I were talking, and I said:

Renewal processor. Forces listees to confirm that they still want to
receive the list by returning a cookie, else it drops them. Renewals can
happen at any interval, set by the maintainer, from 1 to 365 days. Listees
have a certain number of days (set by the maintainer) to return the cookie
before they are dropped.

I used this when my list was running out of LSoft and it cut the growth of
the list by more than half, which hurts you in bragging rights but saves
oodles of bandwidth.

And he said:

0: h
* Subject:.*[ ]keepme[ ]
{ # Take the user off the kill list.
  killfile \
   = `formail -x "Subject:" | sed 's/.*: keepme *\([^ ]*\)\(.*\)/\1/'`
  subscriber \
   = `formail -x "Subject:" | sed 's/.*: keepme * [^ ]*.* *\([^ ]*\).*/\1/'`
  # I don't know if grep -x is standard, you may need:
  # grep -v "^${subscriber}$" ...
  # Do we really need a temporary file?

  # [Karl suggested later for below:
  # sed "s/^ *\([^(_at_)]*@[^ ]*\).*/\1/" > .killdir/$killfile
  # ]

  0: w : $killfile  # kill file exists?
  * ? test -f .killdir/$killfile
  | grep -v  -x "$subscriber" .killdir/$killfile > .killdir/${killfile}.tmp \
    ; cat .killdir/${killfile}.tmp > .killdir/$killfile \
    ; rm .killdir/${$killfile}.tmp
  0: aw
  |  formail -r -i "Subject: You have been renewed to $list." | \
     $SENDMAIL $sendmailOPTS -t
  0: Ecw  # Failed renewals get help, etc...
  |  formail -r -i "Subject: Your renewal to $list didn't take." | \
    $SENDMAIL $sendmailOPTS -t
}

--------------------------

To install, put rc.local.20 in list dir.
uncoment the rc.local.20 line in rc.custom or rc.init.
mkdir <listname>/.killfile

---------<forcerenew executable file>---------
#!/bin/sh
listdir="$1"
gracedays="$2"

# Constants
killfile="$(date +%Y%m%d%s)"
listaddress="$(basename $listdir)@$(dnsdomainame)"

cd $listdir

# lock list for 17 min
touch rc.lock

# Make list of users to unsubscribe.
cut -d " " -f 1 dist > .killdir/$killfile

# When time's up, unsubscribe everybody who's left on the list.
# gnu batch
cat - <<-EOF |batch now + ${gracedays} days
#!/bin/sh
# unsubscribe all the users in the killfile

cd $listdir
touch rc.lock

for address in $(cat .killdir/$killfile) ; do
  # Bug for addresses with regexp chars in them?  Can addresses contain
  # regexp chars?  Yes.  Need to test for them and escape them. (See also grep
in rc.local.r20.)
  # This is serious, as you don't want to unsubscribe people who renewed.
  # Get someone to write an ugly sed script or something.
  # prolly multigram would do better than grep.
  grep -v "^${address} " dist > dist.tmp
  cat dist.tmp > dist
  echo "You did not renew your subscription." \
  | mail -s "You have been removed from the list $listaddress" "${address}"
done
rm dist.tmp

rm rc.lock
EOF

# Tell everybody on the kill list they need to renew.
for address in $(cat .killdir/$killfile) ; do
  cat - <<-EOF | mail -s "Reply to renew your subscription to $listaddress:
keepme $killfile $address"
   You must reply to this e-mail message within $gracedays days to
   remain subscribed to the $listaddress mailing list.
EOF
done

rm .killdir/$killfile

rm rc.lock

exit 0

--------------<cut here>---------

Add lines to crontab for each list like:

# Force everybody on mylist to renew every 3 months, give em 30 days to reply.
* * * 1,4,7,10 *   forcerenew /home/slist/mylist 30

--------------------------------------
Of course, this won't work.  You'll have to debug it.

There are "virtual host" issues that are not resolved. (easy, pass arg)

Removing users from the kill list is inefficent, but works.

Likewise unsubscribing.  (There should really be a unsubscribe shell
script that can be called from shell!)

Dosen't remove from accept, or accept2.  (probably unnecessary)

To stagger renewals instead of having them en-masse, you probably need
a real database, which may as well also replace the smartlist dist file.

Should really get address to re-subscribe from the e-mail headers, but
I don't know a quick way to interpert rfc822 headers to remove
comments and whatnot to get just the address.  (It's some undocumented
munging that multigram does.)  That would also greatly speed up the
mailing out process because you could just mail the list with the
right subject!

Bug the smartlist people to document multigram e-mail address
extraction and write an unsubscribe script.  Then it should work
cleanly.

Or, an awk script would work instead of grep -v, everywhere above.
(To fix the regexp in e-mail address bug.)  But I'm tired of this and
don't want to write it.  You also need to be careful to allow e-mail
addresses that contain spaces, the above does not.  (Because of the
cut, I think.)  awk should work.

--Ken
  68 Westy, Admin --type2-- The Volkswagen Bus Mailing List


<Prev in Thread] Current Thread [Next in Thread>