#!/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'; use Date::Manip; use File::Copy; use Text::Wrap qw($columns wrap); $columns = 55; # TOP_DIR hack $TOP_DIR = "${TOP_DIR}/bv"; $lyris::config_filename = "/opt/lyris/cgi/lyris.plc"; my $rc = &lyris::init; $| = 1; $DEBUG = 1; $N_DATE = &UnixDate('today', '%m-%d-%Y'); # MMDDYY $AD_DATE = "ad.txt." . &UnixDate('today', '%m%d%y'); $BIBLE_TYPE{ASV} = "American Standard Version"; $BIBLE_TYPE{KJV} = "King James Version"; $BIBLE_TYPE{NAS} = "New American Standard"; $BIBLE_TYPE{NIV} = "New International Version"; $BIBLE_TYPE{NKJ} = "New King James Version"; $LIST = "bibleverses"; $CONTENT = "$TOP_DIR/$LIST/verses/combined"; $REPLYTO = "bv-text-reply\@DailyInbox.com"; $OURMAIL = "bv-text\@DailyInbox.com"; $BASE = "$SYSURL/daily"; $LAST_MAILED_CONTENT = "last.mailed.bv.txt"; # name of file where last send is kept $CHECK_FOR_DUPS = 1; # set it to prevent a dup submission from going through $SUBJECT = "DailyInbox.com - Bible Verses - $N_DATE"; $NUMBER_FILE = "$TOP_DIR/$LIST/verses/kjv/number.txt"; open(LOG, ">>/opt/bv_send.log"); $date = `/usr/bin/date`; chomp($date); print LOG "\n-----------------------------\nStarting [bv_text.pl] $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); print LOG "ID: $CURRENT\n"; $NEW = $CURRENT; open(IN, "<$CONTENT/$NEW") or failure("EM - $LIST - couldn't open content file [$CONTENT/$NEW]"); $LINE1 = ; @LINES = ; print LOG "Successfully retrieved content for send.\n"; $SUBJECT = "DailyInBox.com - Bible Verses - $LINE1 - $N_DATE"; open (DAILY, "> $TOP_DIR/daily.txt"); print DAILY "$page \n"; close DAILY; my $ad_text = ""; # if the ad file exists, insert it... if ( -f "$TOP_DIR/bibleverses/ads/$AD_DATE" ) { print LOG "Ad file [$AD_DATE] exists...processing.\n"; open (STOP, "< $TOP_DIR/bibleverses/ads/$AD_DATE"); my @slurp = ; foreach $what (@slurp) { $ad_text .= $what; } print LOG "-> Copying [$AD_DATE] to [ad.txt]\n"; copy ("$TOP_DIR/bibleverses/ads/$AD_DATE", "$TOP_DIR/bibleverses/ads/ad.txt"); } else { # else, just but a byte in the file (it must exist) print LOG "Creating empty [ad.txt]\n"; open (STOP, "> $TOP_DIR/bibleverses/ads/ad.txt"); print STOP ""; close STOP; } $page = " ______________________________________________________ \n\n"; $page .= " DailyInBox: Bible Verses\n\n"; $page .= " A free e-mail service from DailyInbox.com featuring \n"; $page .= " verses from the Bible. \n"; $page .= " ______________________________________________________ \n\n"; # include the ad text if needed... if ( $ad_text ) { $page .= $ad_text; $page .= " ______________________________________________________ \n\n"; } $page .= " Today's selection is $LINE1\n"; foreach (@LINES) { if ( /FRONTLET.(.*)/ ) { $first_part = $BIBLE_TYPE{$1}; } else { $bla = wrap('', ' ', $_); $page .= " * $first_part\n $bla\n"; } } $page .= " ______________________________________________________ \n\n"; $page .= " Subscribe a Friend: http://MailRoom.DailyInBox.com/bv/f.iphtml \n"; $page .= " You may unsubscribe here: http://DailyInBox.com/bv/unsubscribe.shtml\n"; $page .= " Visit our website: http://DailyInBox.com\n"; $page .= " You are subscribed with: \$subst('Recip.EmailAddr')\n"; $page .= " ______________________________________________________ \n\n"; #print $page; #exit; #open(OUT, ">$LAST_MAILED_CONTENT"); #print OUT "$page"; #close(OUT); # now submit to lyris $mid = &sendLyrisMail("bv-text-test", "$SUBJECT", "$REPLYTO", "$OURMAIL", "$page", "txt", "$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 "Not incrementing number [$CURRENT]\n"; print LOG "Done.\n\n"; exit;