#!/usr/bin/perl -w use URI::Escape; exit(1) if ( scalar(@ARGV) < 1 ); # declare a few local variables my ($LINK, $RECIPIENT, $CC, $BCC, $SUBJECT, $BODY) = ("", "", "", "", "", ""); my (@PARTS, $SEGMENT, $CMDLINE); # grab the link passed to us $LINK = $ARGV[0]; # bail out with an error condition if it doesn't begin with "mailto:" exit(1) unless ( $LINK =~ m/^mailto\:/i ); # strip the mailto at the beginning $LINK =~ s/^mailto\:(.*)/$1/i; # bail out with an error condition if nothing's left exit(1) if ( length($LINK) == 0 ); # What we have now is something of the form # # address?variable1&variable2&variable3&... # # Replace the '?' with a '&' and then split the string on '&' boundaries. $LINK =~ s/\?/&/g; @PARTS = split("&",$LINK); # Treat @PARTS as a stack and pop elements off it as and when. # # The first element should be the recipient. $RECIPIENT = shift(@PARTS); # bail out with an "ok" condition if this was all there was in the link exit(0) if ( scalar(@PARTS) == 0 ); # now loop through the remaining elements parsing them until there are # none left while ( scalar(@PARTS) ) { $SEGMENT = shift(@PARTS); if ( $SEGMENT =~ m/^subject=/i ) { ( $SUBJECT = $SEGMENT ) =~ s/^subject=(.*)/$1/i; next; } if ( $SEGMENT =~ m/^body=/i ) { ( $BODY = $SEGMENT ) =~ s/^body=(.*)/$1/i; next; } } $SUBJECT = uri_unescape($SUBJECT); $SUBJECT =~ s/\"/\\\"/g; $BODY = uri_unescape($BODY); $BODY =~ s/\"/\\\"/g; $CMDLINE = "kmail --composer --body \"$BODY\" -s \"$SUBJECT\" \"$RECIPIENT\""; exec $CMDLINE;