Getting kmail to work with OpenOffice 1.0


What we are trying to achieve

There are two functions that you may want to use kmail for in open office

  1. Clicking a mailto: link in a document and launching kmail with the address inserted into the To: field

  2. Attaching a document to an email usign the "File --> Send --> Document as email..." command

Openoffice provides a menu under "Tools --> Options --> OpenOffice.org --> External Programs" to allow setting an external email program.

Because of incompatible command lines passed to kmail you can't send the command directly to kmail but you need to create and specify a shell script to parse the commands before they reach kmail and change them into a format that kmail can handle.file:///home/james/Mail/kmail

Open Office Options Dialog Box

A bit of background

What OpenOffice Sends

When clicking a mailto: link the following is what OpenOffice passes to the external program (on one line)
mailto:[email protected]?subject=Resume%20of%20James%20McDonald

When sending an attachment OpenOffice sends the following to an external program (on one line)

-compose "attachment='file:///home/james/OpenOffice.org1.0/user/temp/soffice.tmp/svcip.tmp/kmail-openoffice_0.html'"

What kmail needs to to be able to use this command line for mailto and attachments respectively is

What kmail expects

mailto
/usr/bin/kmail --composer [email protected] --subject "Resume of James McDonald"
or
/usr/bin/kmail --composer [email protected]
attachments
/usr/bin/kmail --attach "/home/james/OpenOffice.org1.0/user/temp/soffice.tmp/svcip.tmp/kmail-openoffice_0.html"

Now the Script

So to accomplish the format change we need to pass the command lines to a script as show below or click here to download it.

#!/bin/sh
address="$@"

logfile=/home/james/Mail/openoffice-to-kmail.log

echo $@ > $logfile


if [ `echo $address | grep -q -c "attachment"` -eq 1 ] ; then

stringtochange=$address

kmailstep1=`echo $stringtochange | cut -d= -f2`

echo kmailstep1 $kmailstep1 >> $logfile

kmailstep2=`echo $kmailstep1 | sed s#^\'file://## -`

attachtokmail=`echo $kmailstep2 | sed s/\'\"$// -`

echo Atachtokmail $attachtokmail >> $logfile

/usr/bin/kmail --attach $attachtokmail

exit 0
fi

if [ `echo $address | grep -q -c "mailto:"` -eq 1 ] ; then

passtokmail=`echo $address | sed s/^mailto://`
echo passtokmail $passtokmail >> $logfile

if [ `echo $passtokmail | grep -q -c "subject"` -eq 1 ] ; then
echo inside 2nd if >> $logfile
emailaddress=`echo $passtokmail | cut -d? -f1`
subject=`echo $passtokmail | cut -d= -f2`
killspaces=`echo $subject | sed s/\%20/" "/g -`

/usr/bin/kmail --composer $emailaddress --subject "$killspaces"
else
emailaddress=$passtokmail
/usr/bin/kmail --composer $emailaddress
fi

exit 0

fi