#!/bin/sh
    # kde-gmail - a script that passes kde mailto links to gmail in your browser
    # Copyright (c) 2006 Treviño <http://italy.copybase.ch/blog/>
    # Version: 1.0

    # Mainly based on gnome-gmail by Matthew C Ruschmann <http://matthew.ruschmann.net>

    # Adapted from ymail - by David L Norris <dave@webaugur.com>
    # http://webaugur.com/wares/files/ymail

    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; either version 2 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU Library General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

    # Riceve da KDE il comando per lanciare il browser.

    KDE_HOME=$(kde-config –localprefix)
    BROWSER=$(cat $KDE_HOME/share/config/kdeglobals| grep BrowserApplication| cut -f2 -d‘!’ -s)

    # Use konqueror if no other browser is set
    if [ -z $BROWSER ];
     then
      BROWSER=$(which konqueror)
    else
      BROWSER=$(which $BROWSER)
    fi

    # Nessun browser trovato: esci
    if [ -z $BROWSER ];
     then
      echo ‘No browser available’
      exit
    fi

    # Se non ci sono argomenti a riga di comando, lancia Gmail
    if test -z "${*}"
    then
    ${BROWSER} "http://www.gmail.com"
    exit
    fi

    # Riceve gli argomenti e li passa a Gmail
    TOMAIL=`echo "${*}" | sed -e ’s/mailto://g’`
    TOMAIL=`echo "$TOMAIL" | sed -e ’s/?/\&/g’`
    TOMAIL=`echo "$TOMAIL" | sed -e ’s/&subject=/\&su=/g’`

    # Questo è l'url che Yahoo! Companion and Yahoo! Toolbar usano per inviare email:
    TOURL="https://mail.google.com/mail?view=cm&cmid=0&fs=1&tearoff=1&to="

    # Stampa quello che stiamo facendo
    echo ${BROWSER} "${TOURL}${TOMAIL}"

    # Esegui il comando
    ${BROWSER} "${TOURL}${TOMAIL}"
