#!/bin/sh

rm -rf /tmp/pics/
rm -f /tmp/newfiles
mkdir -p /tmp/pics
	 
	for i in "$@"; do
		cp "${i}" /tmp/pics/    										# copy original imagess to a temp dir
		aaphoto /tmp/pics -a -r1024 -q75 --overwrite --jpg				# resize pics and save as .jpg's
		sleep 0
		find /tmp/pics/ ! -name "*.jpg" -type f -delete					# find all files in temp dir that are NOT .jpg's, and delete them	
	done

cd /tmp/pics															# change directory (into our temp dir)
ls -1 $PWD/*.* >> /tmp/newfiles											# create a list of our NEW images (full path and filename)
		
sleep 0
files=`awk -vORS=, '{ print $0 }' /tmp/newfiles | sed 's/,$//'`			# create our comma seperated list of files, to pass to seamonkey-mail
seamonkey -compose "attachment='$files'"								# start seamonkey-mail with our files as attachments

