DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Tiny Email-to-twitter Daemon Source From Http://colo.doxpara.com/etweet.pl

06.16.2009
| 2504 views |
  • submit to reddit
        // Dan Kaminsky (twitter.com/dakami) Tiny email-to-twitter daemon source from http://colo.doxpara.com/etweet.pl

use Carp;
  use Net::SMTP::Server;
  use Net::SMTP::Server::Client;
  use Net::Twitter;
  

  $server = new Net::SMTP::Server('localhost', 25) ||
    croak("Unable to handle client connection: $!\n");

  while($conn = $server->accept()) {
    # We can perform all sorts of checks here for spammers, ACLs,
    # and other useful stuff to check on a connection.

    # Handle the client's connection and spawn off a new parser.
    # This can/should be a fork() or a new thread,
    # but for simplicity...
    my $client = new Net::SMTP::Server::Client($conn) ||
        croak("Unable to handle client connection: $!\n");

    # Process the client.  This command will block until
    # the connecting client completes the SMTP transaction.
    $client->process || next;

    my $msg = $client->{MSG};
    my @tmp = split(' ', $msg);
    my $username = shift @tmp;
    my $password = shift @tmp;
    my $msg = join(' ', @tmp);
    print "user: $username \n pass: $password \n $msg \n";

  my $nt = Net::Twitter->new(
      traits   => [qw/API::REST/],
      username => $username,
      password => $password
  );

   $nt->update($msg);

    
  }