#! /usr/bin/perl -w ############################################################## # #cellmail -- perl script to send summary messages to pagers # cellmail (C) 2004, pettingers.org, All Rights reserved under GPL license: # http://www.gnu.org/licenses/gpl.txt # #This will grab the headers from incoming E-mail fed via procmail #or other mail pre-processor. It will then format and send a #message suitable for a text pager or SMS cell phone message. # #The following must be done first: # 1. Install MIME::Lite package from CPAN. Short summary: # [user]$ perl -MCPAN -e shell # cpan> install MIME::Lite # # 2. Add a recipe such as the following in your .procmailrc file: # :0Ehc # * !^FROM_MAILER # | /home/user/cellmail # # I put this very last, after all filtering and spam checking # (hence the 'E' option) although you can customize as required. # Be sure to consult "man procmialrc" if you don't know the details. # # 3. Unless you shut your device off at night (or need to get # alerts at odd hours) you'll want to limit the times when alerts # are sent (note this has NO effect of mail delivery to your inbox). # You can do this one of two ways: # # 3a. Use the user-configurable options below to set an "on hour" # and an "off hour". If you need more granualarity than the top of # the hour, see step 3b. If you need 24-hour alerts, just comment # out the timing section below near the top of the code (yes, I know, # it should be a subroutine....) # # 3b. If you need to define things down to the minute, make a # cron job to pull this program in and out. I make a secondary # script with the following: # #! /usr/bin/perl # exit; # # I then save that as cellmail.out and save a copy of cellmail as # cellmail.in # Then, just make a cron job to copy the .out file over the top of # cellmail at your bedtime. In the morning, have another cron job # copy cellman.in back to cellmail. You could also write two versions # of .procmailrc and do the same thing. Or just delete cellmail during # off hours and let procmail throw the error. # # 4. Set up the user defined variables to suit your needs # # 5. Don't blame me if it doesn't work ;-) # use strict; use MIME::Lite; ##################################### ####### User Defined Variables ###### # my $limit = 140; # Max characters for outbound message minus header my $offtime = 22; # Hour to suspend messages my $ontime = 7; # Hour to start allowing messages my $fromaddr = 'new@yourdomain.org'; # Who the message will come from my $celladdr = '1235551234@mobile.att.net'; # Pager or cell address (to) my $subj = 'New Mail!'; # Subject for the outbound message ##################################### undef $/; my %hdrs; my @loctime; my ($infrom, $insubject, $data, $message, $msg, $now) = ''; ##### ########### ########## # Comment out this section to use a cron job or receive 24-hour alerts @loctime = localtime; $now = $loctime[2]; if ( ($offtime > $ontime) and ($now >= $offtime or $now < $ontime) ) { exit; } if ( ($offtime < $ontime) and ($now >= $offtime and $now < $ontime) ) { exit; } # ##### ########### ######### $message = <>; $message =~ s/\n\s+/ /g; # Fix lines that wrap %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $message); # Hash the headers chop ($infrom = $hdrs{"From"}); # Find out who its from and chop the \n chop ($insubject = $hdrs{"Subject"}); # Get the subject and chop the \n # Need to check for From lines that don't have if ( $infrom =~ m/new( From =>$fromaddr, To =>$celladdr, Subject =>$subj, Data =>" -- $data" ); # Send it best way possible (usually sendmail) $msg->send; # end