Assuming that on the jabber server your MTA is sendmail you can do this:

Edit your sendmail.cf to listen for external connections:
dnl #  DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

Set a catch all for the server or domain in /etc/mail/virtusertable:
@your.jabber.org                mailerscript

Add an alias for the script in /etc/aliases (don't forget to run
newaliases as root):
mailerscript    |smtp2jabber.pl

Manually register a bot user on your jabber server and set the user/pass
to mailer/password (if you use other credentials, edit the script
accordingly).
Save the attached script as smtp2jabber.pl and place it in /etc/smrsh or
link it from there. Remember to chmod it to be world executable.

Use cpan or your favourite package manager to install the perl modules
at the top of the script. Restart sendmail and test.


Bart...



#!/usr/bin/perl

use strict;
use Mail::Message;
use Mail::Message::Field;
use Mail::Message::Construct::Read;
use Mail::Message::Attachment::Stripper;
use Mail::Message::Body;
use Net::Jabber;

use constant SERVER   => "your.jabber.org";
use constant PORT     => 5222;
use constant USERNAME => "mailer";
use constant PASSWORD => "password";
use constant RESOURCE => "Perl Script";


# The email message come in on STDIN
my $msg = Mail::Message->read(\*STDIN);

# Pick out the recipient, subject and sender
my $rcpt    = $msg->head->get('to');
my $subject = $msg->head->get('subject');
my $sender  = $msg->head->get('from');

# Remove the angle brackets
$rcpt =~ s/^<//;
$rcpt =~ s/>$//;
$sender =~ s/^<//;
$sender =~ s/>$//;

# Remove the attachment(s) from the message
my $stripper = Mail::Message::Attachment::Stripper->new($msg);
my Mail::Message $textonly  = $stripper->message;
my $body = $textonly->body;

# Connect to jabber
my $jabber = &setup_Jabber(SERVER, PORT, USERNAME, PASSWORD, RESOURCE,
"normal/forwarding email");

# Compose the message
my $jabmsg->SetMessage(
              "to"      => "$rcpt",
              "subject" => "$sender emailed: $subject",
              "body"    => "$body");

# And send it
$jabber->Send($jabmsg);

# Close the connection and exit
$jabber->Disconnect();
exit(0);


sub setup_Jabber {
  my ($server, $port, $user, $pass, $resource, $initial_status) = @_;
  my $connection = new Net::Jabber::Client;

  # Connect
  my $status = $connection->Connect( hostname => $server,
                                     port     => $port );
  die "Cannot connect to Jabber server $server on port $port\n"
    unless $status;

  # Callbacks
  $connection->SetCallBacks( presence => \&InPresence );

  # Ident/Auth
  my @result = $connection->AuthSend( username => $user,
                                      password => $pass,
                                      resource => $resource );
  die "Ident/Auth failed: $result[0] - $result[1]\n"
    if $result[0] ne "ok";

  # Roster
  $connection->RosterGet();

  # Set initial presence
  &set_presence($connection, $initial_status);

  return $connection;
}

sub InPresence
{
  my $presence = $_[1];
  my $type = $presence->GetType();

  if ($type eq "subscribe") {
    $jabber->Send($presence->Reply(type => 'subscribed'));
  }
  elsif ($type eq "unsubscribe") {
    $jabber->Send($presence->Reply(type => 'unsubscribed'));
  }
}

sub set_presence {
  my ($connection, $s) = @_;
  my $presence = Net::Jabber::Presence->new();
  my ($show, $status) = split("/", $s, 2);
  $presence->SetPresence( show   => $show,
                          status => $status );
  $connection->Send($presence);
}

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Peter Saint-Andre
Sent: 14 December 2005 23:53
To: Jabber software development list
Subject: Re: [jdev] jabberSMTP

Jon Scottorn wrote:
> Hi all,
> 
>    I have been trying to locate a jabber smtp transport, does anyone 
> know of any such thing.  I basically need something that will parse an

> email sent to say [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> and 
> reformat it into a xmpp message and send it to the user.  I don't 
> really care about attachments, it will only be text.
> 
> Does anyone know of this type of item?

The old theoretic-smtp project did something like that, but it
disappeared after the JabberStudio rootkit. I've sent the code to Jon on
an as-is basis. If anyone else has code like this (more recent than
theoretic-smtp), feel free to post to the list. :-)

Peter


Reply via email to