I receive email notification of voicemail messages, including the Caller ID
of the caller, and a MIME attachment of the voicemail. The subject looks
like this:
You have a voicemail message waiting from 12125551212
Using Procmail, I forward a copy of just the subject to my pager's email
address. However, I want the subject to contain only the phone number, so I
have written a recipe that does that:
ORIGSUB=`formail -zxSubject:`
NEWSUB=`echo ${ORIGSUB} |sed -e 's/[[:alpha:][:blank:]]//g' -e 's/1//' `
DATETIME= `date`
:0fbw
| sed -e 'd' \
|echo ${DATETIME}
:0w
| formail -k -X "From:" -X "Subject:" \
-I "From: me(_at_)mydomain(_dot_)com" \
-I "Subject: VM: ${NEWSUB} " \
-A "X-Loop: yes" \
| $SENDMAIL mypager(_at_)mypagingcompany(_dot_)com
The variable section removes all non-digit characters, leaving just the
number in NEWSUB, then strips off the first '1' of the phone number. (just
because it bugs me!)
The first recipe (:0fbw) strips off the entire body (which includes the MIME
voicemail attachment), and replaces it with a variable DATETIME, which I set
earlier to the current date/time. This is because my pager will delete an
old message that is identical to a new message. I want to know how many
times somebody called me, so I put in the date and time to make each message
unique.
The second recipe sends the message, with the modified subject, to my
pager's email address. (I send an unmangled version to my regular email
address at the beginning of the file, and the whole thing is surrounded by a
test for loops to avoid, uh, loops.)
SO... What is my problem? Well, I would like to add dashes in the phone
number in the subject field to make it more readable, and I cannot figure
out how to do it with either Procmail or formail or sed.
Now, I never used Procmail or sed or formail before two days ago, when I
started this project, so I am no expert on any of it, but I have scoured
every web site I can, mostly looking for some way for sed to just output x
number of characters from a stream, such as output the first three
characters, then a dash, then the next three characters, etc. But I can only
find references to handling whole lines at a time.
(I was ecstatic to get the !(_at_)#$%^ thing to work finally, and now I am
obsessing over this last little detail!)
I have included my (almost) entire recipe, so that others may be able to use
what I just spent the last two days figuring out how to do - sorry for the
long post.
I am using a Linux server, (RedHat 8.0) with the most up to date version of
all programs. I am also the Administrator, so I have full access rights to
set up or config (or break) anything necessary. I am thinking there is
probably another way (other than sed) to do what I want to do, so I can
install or configure whatever is necessary.
Thanks in advance for any help. Also, feel free to point out any mistakes I
may have made in my recipe above, or make suggestions for improvements.
Griffin
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail