How to convert voicemail emails

by labmin on December 4, 2010

My work upgraded our phones to the Droids! Unfortunately the Droid could not play our company voicemails from our PBX. So I wrote this script to intercept the voicemail emails, convert the wav file to an mp3 and then forward the voicemail to the original user.

#!/bin/bash

export EMAIL='PBX <pbx>'

cd /mail/drop/new

for i in $( ls ); do

  cd mail/drop/new

  # This removes system generated emails
  axBad=$( cat $i | grep X-Original-To: | sed 's/...............\(.*\)/\1/'  )
  
  
  if [ "$axBad" == "root" ]; then
     rm -f /zxa/mail/drop/new/$i
  else
    
    # Grab the to and from address
    axto=$( cat $i | grep "To: \"\"" $i | sed 's/........\(.*\)/\1/' | sed 's/\(.*\)................./\1/')
    axfrom=$( cat $i | grep From: | sed 's/.............\(.*\)/\1/' | sed 's/\(.*\)./\1/' )
    axsubject=$( cat $i | grep Subject: | sed 's/.........\(.*\)/\1/'  )
    axbody1=$( sed -n '30,30p'  $i )
    axbody2=$( sed -n '31,31p'  $i )
    axbody3=$( sed -n '32,32p'  $i )
    axbody4=$( sed -n '33,33p'  $i )
    axbody5=$( sed -n '34,34p'  $i )
    axbody6=$( sed -n '35,35p'  $i )
    
    echo $axbody1 > /etc/postfix/vmail/proc/body.txt
    echo $axbody2 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody3 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody4 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody5 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody6 >> /etc/postfix/vmail/proc/body.txt
    
    #Strip the wav file from the eml file
    uudeview -i -p /etc/postfix/vmail/proc +e .wav /mail/drop/new/$i > /dev/null 2>&1 

    # Convert the wav file to mp3
    /usr/local/bin/ffmpeg -i /etc/postfix/vmail/proc/msg0001.WAV -ab 8k /etc/postfix/vmail/proc/msg0001.mp3 > /dev/null 2>&1 

    #send the new email out
    cd /etc/postfix/vmail/proc
    mutt -n -s "$axsubject" -a msg0001.mp3   -- "$axto@mydoamin.com"  < body.txt

#clean up directory
rm -rf /etc/postfix/vmail/proc/*.*
rm -f /mail/drop/new/$i
fi

done

CentOS 5 Postfix

by labmin on December 4, 2010

Here is my sample setup for postfix running on CentOS 5

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
default_privs = nobody

myhostname = zlabx.com
mydomain = zlabx.com
myorigin = $mydomain

inet_interfaces = all
unknown_local_recipient_reject_code = 550
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no

# RECEIVING MAIL
inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost
show_user_unknown_table_name=no

#  RELAY CONTROL
mynetworks = 127.0.0.1, /etc/postfix/relay_allow_list

##  SMTPD

#  Simple SPAM restrictions
smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   check_policy_service unix:private/policy-spf,
   check_sender_access hash:/etc/postfix/black_list,
   check_sender_access hash:/etc/postfix/white_list,
   reject_invalid_hostname,
   reject_non_fqdn_hostname,
   reject_non_fqdn_sender,
   reject_non_fqdn_recipient,
   reject_unknown_sender_domain,
   reject_unknown_recipient_domain,
   reject_unauth_destination,
   reject_rbl_client zen.spamhaus.org,
   reject_rbl_client bl.spamcop.net,
   permit

smtpd_helo_required = yes

smtpd_client_restrictions =
   permit_mynetworks,
   reject_non_fqdn_hostname,
   reject_non_fqdn_sender,
   reject_unknown_sender_domain,
   permit

# Tarpit those bots/clients/spammers who send errors or scan for accounts
smtpd_error_sleep_time = 60
smtpd_soft_error_limit = 60
smtpd_hard_error_limit = 10

#Prevent email address harvesting attacks
disable_vrfy_command = yes

#Change reject codes to permanent
unverified_recipient_reject_code = 550
unverified_sender_reject_code = 550
unknown_local_recipient_reject_code = 550

alias_maps = hash:/etc/aliases

#Used to send outgoing mail through godaddy.
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
relayhost = [smtpout.secureserver.net]:80
smtp_sasl_password_maps = hash:/etc/postfix/godaddy_login
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes
smtp_cname_overrides_servername = no
smtp_sasl_security_options =

The line

check_policy_service unix:private/policy-spf,

Is not needed unless you have installed the postfix-policyd-spf-perl package from openspf.org. For more information on setting up spf see this howtoforge

I use godaddy for relaying my mail. Here is how to setup postfix to send your emails through an external provider, such as GoDaddy.

File: godaddy_login

[Your-Email-Server.com]:80	username@yourdomain.com:<your-password>

Don’t forget to run postmap on the godaddy_login file!

 [zlabx]$  postmap /etc/postfix/godadddy_login

Converting Videos with FFmpeg

by James on September 15, 2010

I have been working on a website for me wife and recently needed to conver some viedos that she made to flash to display on her website.  I have been playing around with different options to create a great output file to display on the web.  I tought it would be nice to post my results.

Here is the method that I am useing and how it breaks down.

/usr/bin/ffmpeg -i Demo-Video.avi -sameq -ab 22050 -ar 44100 -s 512x384 -aspect 4:3 -b 3000 -f flv Demo-Video.flv

Explanations :

(-i) Input file name
(-sameq) Use same video quality as source
(-ab) Audio bitrate (default = 64)
(-ar) Audio sampling frequency ( default = 44100 Hz )
(-aspect) Aspect ratio ( 4:3, 16:9 )
(-b) Video bitrate in bit/s ( default = 200k )
(-f) Force format
(-s) Set frame size ( Width x Height)

Here is the link to the  FFmpeg Documentation if you are looking for all the possible switches and what they mean.

Parse the Craigslist stream.

by James on September 14, 2010

Craigslist

So I am trying to find a house to rent.  Everyday I am checking Craigslist, but this gets old fast!  So finnaly I am like… I can write a script for that.  I fire up a bash prompt and get to work.

Here is what I came up with. It is a simple scripts that curls an rss feed, strips out all the html mumbo jumbo, looks for a list of specific cities that I am willing to move to, saves my results to a file, and then finally emails me the list . The next time the script runs it checks to make sure that it does not email me the same results. I am using mutt to send an email from the bash script.


#!/bin/bash

axold=0

if [ -f update.txt ];then
   rm -rf update.txt
fi
# The rss feed for my house search
rss="http://sandiego.craigslist.org/search/apa?query=house&srchType=A&minAsk=&maxAsk=&bedrooms=2&format=rss"

curl -s "$rss" | grep -E '<item rdf:about=|<title>' | sed s'/<item rdf:about="//'g \
        | sed s'/<title><!\[CDATA\[/ /'g | sed s'/">//'g  \
		| sed s'/]]><\/title>//'g \
		| sed s'/<title>craigslist san diego | apts\/housing for rent search &#x22;house&#x22;<\/title>/ /' \
		| sed -n -e ":a" -e "$ s/html\n/html /gp;N;b a" \
		| grep -i 'ocean beach\|point loma\|pacific beach\|southpark\|south park\|oceanbeach' > tmp.txt


# 1st loop for checking the new listings againts the old
while read newline
	do

    # 2nd loop loads the list of old matches to check
	while read line   
		do   
		   if [[ "$newline\n" == "$line\n" ]];then
				axold=1
				break
			fi
	done < oldlist.txt

	if [ $axold != 1 ];then
		echo "$newline" >> update.txt
		echo "$newline" >> oldlist.txt
	fi
	
	axold=0
	
done < tmp.txt

rm -rf tmp.txt

#send email if update.txt exists
if [ -f update.txt ];then
   mutt -n -s "New Craigslist Post"  -- "james@zlabx.com" < update.txt
fi

rm -rf update.txt

Now lets make it check craigslist every 15mins.

[zlabx]$ crontab -e
  */15 * * * * /path/to/my/script/housesearch.sh