#!/usr/bin/perl # this script runs through the various bible verses daily # (incrementing number.txt) and mails em out. require '/usr/home/fso/libs/fso-g-lib.pl'; require '/usr/home/em/libs/em-defs.pl'; require '/usr/home/em/libs/em-g-lib.pl'; $| = 1; $DEBUG = 1; $LIST = "bibleverses"; $CONTENT = "$TOP_DIR/$LIST/verses/kjv"; $REPLYTO = "$LIST-reply\@SoupServer.com"; $OURMAIL = "$LIST\@SoupServer.com"; $BASE = "$SYSURL/daily"; $LAST_MAILED_CONTENT = "last.mailed.content"; # name of file where last send is kept $CHECK_FOR_DUPS = 1; # set it to prevent a dup submission from going through $SUBJECT = "Email Monkey - Bible Verses"; $NUMBER_FILE = "$CONTENT/number.txt"; open(LOG, ">>/var/tmp/$LIST.log"); $date = `/usr/bin/date`; chomp($date); print LOG "\n-----------------------------\nStarting $LIST send run - $date\n"; if ( ! -f $NUMBER_FILE ) { print LOG "Creating number.txt file for the first time.\n"; open(OUT, ">$NUMBER_FILE") or failure("EM - $LIST - couldn't open outfile number.txt"); print OUT "1\n"; close(OUT); } open(IN, "<$NUMBER_FILE") or failure("EM - $LIST - couldn't open infile number.txt"); $CURRENT = ; chomp($CURRENT); if ( $CURRENT !~ /\d+/ ) { # chk to make sure we got a digit or a few failure("EM - $LIST - didn't get a valid number from number.txt"); } close(IN); $NEW = $CURRENT; $NEW++; print LOG "Incrementing number from [$CURRENT] to [$NEW] for this send (has not been stored to disk yet)\n"; if ( length($NEW) == 2 ) { $NEW = '0' . $NEW; } if ( length($NEW) == 1 ) { $NEW = '00' . $NEW; } open(IN, "<$CONTENT/$NEW") or failure("EM - $LIST - couldn't open content file [$CONTENT/$NEW]"); $LINE1 = ; $LINE2 = ; print LOG "Successfully retrieved content for send.\n"; $page = "

Daily Bible Verse

"; $page .= ""; $page .= "
$LINE1
- $LINE2
\n"; $page .= "\n"; # stores what we send out and also does dups chking to make sure we don't send twice if ( -f "last.mailed.content" ) { open(IN, "<$LAST_MAILED_CONTENT"); $last_content = join("", ); if ( $last_content eq $page and $CHECK_FOR_DUPS ) { # check for duplicate sending print LOG "ERROR: Duplicate page detected. Exiting.\n"; exit; } close(IN); } open(OUT, ">$LAST_MAILED_CONTENT"); print OUT "$page"; close(OUT); # now submit to lyris $mid = &sendLyrisMail("$LIST", "$SUBJECT", "$REPLYTO", "$OURMAIL", "$page", "html", "$LIST.html"); print LOG "Message id: [$mid]\n"; if ( ! $mid ) { print LOG "ERROR: Message inject into lyris for $LIST has failed! [$mid]\n"; `/usr/local/bin/critsit "HTML $LIST [$mid] message into Lyris failed!"`; exit; } print LOG "Message inject successful.\n"; open(OUT, ">$NUMBER_FILE"); print OUT "$NEW\n"; close(OUT); print LOG "Incremented number from [$CURRENT] to [$NEW] on disk.\n"; print LOG "Done.\n\n"; exit;