#!/usr/bin/perl -w use strict; use Net::Twitter; # Twitter username and password my $username = shift; my $password = shift; die "No username/password pair given" unless ($username && $password); # If $verbose is true, we will tell something about the message in the # twit - to who it was, from who, and what was the subject. This might be # a privacy concern for many. If $verbose is false, then just a generic # 'new email' alert is used. my $verbose = shift; my ($to,$from,$subject); # Read the email from STDIN. Get some header information. while(my $line = ) { if ($line =~ m/^To:/ && !$to) { $to = clean($line) || 'someone'; } elsif ($line =~ m/^From:/ && !$from) { $from = clean($line) || 'someone'; } elsif ($line =~ m/^Subject:/ && !$subject) { $subject = clean($line) || 'something'; } } # Create the message my $message = ''; if ($verbose) { $message = "Message from $from to $to about '$subject'\n"; } else { $message = "You've got mail"; } my $twit = Net::Twitter->new(username=>$username,password=>$password); $twit->update($message); # Get value of email header # Subject: something => something sub clean { my $header = shift; my $result = ''; if ($header) { $result = $header; $result =~ s/^\w+:\s*//; chomp($result); } return $result; }