#!/usr/bin/perl -w # feedmua.pl - (c) 2003 Godwin STEWART, all rights reserved. # Version 0.1 / 22-OCT-2003 # Released under the GNU General Public License Version 2, the terms of which # are available here: http://www.fsf.org/licenses/gpl.html # # This software is provided as is, with no guarantee of merchantability or # fitness for any purpose. Use it at your own risk. # bail out with an error condition if nothing was passed to the script 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/^cc=/i ) { ( $CC = $SEGMENT ) =~ s/^cc=(.*)/$1/i; next; } if ( $SEGMENT =~ m/^bcc=/i ) { ( $BCC = $SEGMENT ) =~ s/^bcc=(.*)/$1/i; next; } if ( $SEGMENT =~ m/^subject=/i ) { ( $SUBJECT = $SEGMENT ) =~ s/^subject=(.*)/$1/i; next; } if ( $SEGMENT =~ m/^body=/i ) { ( $BODY = $SEGMENT ) =~ s/^body=(.*)/$1/i; next; } } # From here onwards, the variables $RECIPIENT, $CC, $BCC, $SUBJECT # and $BODY contain what you'd expect them to contain. If the # corresponding item wasn't set in the mailto: link then the # variable contains an empty string. # # Now, all you have to do is build a command line which feeds these # variables to your mailer. # # For example, kmail expects a command line like this: # # kmail --composer -c -b -s --body # # Always enclose the values in quotes so that empty values are in fact counted as # empty arguments rather than just skipped altogether. So your command would look # something like this: # # $CMDLINE = "kmail --composer -c \"$CC\" -b \"$BCC\" -s \"$SUBJECT\" --body \"$BODY\" \"$RECIPIENT\""; # # See http://mozex.mozdev.org/arguments.html for details of the command line arguments # of other mailers. # No further processing is required in this script so hand the control over # to the mailer rather than forking and waiting. exec $CMDLINE;