FUD Perl module need tester

Etienne Goyer etienne.goyer at linuxquebec.com
Thu Jun 5 10:00:26 EDT 2003


Hi there,

I recently wrote a Perl module to interface to FUD.  It is very simple
and so far seem reliable.  I would like it to get a little testing
before Ipost it on CPAN.  If you are using, wheter successfully or not,
I would like to hear from you.  Your feedback are appreciated.

It is quite easy to use.  The following snippet of Perl would dump the
info available for a mailbox :

#!/usr/bin/perl

use warnings;
use Net::FUD;

my $fud = Net::FUD->new(server => "localhost");
my @ret = $fud->retr_info('egoyer', 'user.egoyer');
print  (join ' ', @ret) . "\n";
$fud->close;

Just copy the attached .pm inside of a Net folder somewhere in @INC.  It
is documented by POD, accessible by "perldoc Net::FUD".

I also have a module that interface to MUPDATE in the work.  It is not
ready for release (require cleanup and documentation), but if you really
need such a thing, contact me off-list and I will send it to you.

Thanks for your feedback.

-- 
Etienne Goyer                    Linux Québec Technologies Inc.
http://www.LinuxQuebec.com       etienne.goyer at linuxquebec.com
-------------- next part --------------
# Net::FUD.pm
# $Id: FUD.pm,v 1.2 2003/05/29 19:13:36 egoyer Exp $
#
# Copyright (c) 2003 Etienne Goyer, Linux Québec Technologies 
# <etienne.goyer at linuxquebec.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# This package retrieve information on mailbox from a FUD daemon, 
# such as bundled by Cyrus imapd. 
#

package Net::FUD;

use strict;
use vars qw($VERSION);
use IO::Socket::INET;

$VERSION = "0.01";

sub new {
    my $class = shift;
    my %self = @_;
    
    unless ($self{'server'}) { 
        return undef; 
    }
    
    unless ($self{'port'}) { $self{'port'} = 4201 }

    # Connect to server
    $self{'socket'} = IO::Socket::INET->new( PeerAddr => $self{'server'},
                                             PeerPort => $self{'port'},
				             Proto    => "udp" );
    if ($self{'socket'}->error) { 
        $self{'error'} = "Error connecting to $self{'server'}:$self{'port'}."; 
    }
  
    my $ret = \%self;
    bless ($ret, $class);
    return $ret;
}


sub retr_info {
    my $self = shift;
    my $user = shift;
    my $mbox = shift;
    my $fh = $self->{'socket'};
    my ($resp, @ret);

    unless ($user) { return }
    
    # FIXME : this make the assumption that the mailboxes separator is '.' 
    unless ($mbox) { $mbox = "user." . $user }

    print $fh "$user|$mbox";
    sysread($fh, $resp, 511);
    if ($resp eq "PERMDENY") {
        $self->{'error'} = "Permission denied";
    } elsif($resp eq "UNKNOWN") {
        $self->{'error'} = "User or mailbox unknown";
    } else {
        # Parse response
	@ret = split /\|/, $resp;
    }
    return @ret;
}

sub error {
    my $self = shift;
    return $self->{'error'};
}

# Not sure if these two are necessary

sub close {
    my $self = shift;
    $self->{'socket'}->close;
}

sub DESTROY {
    my $self = shift;
    $self->close;
}

1;

__END__


=head1 NAME

Net::FUD - FUD Client class

=head1 SYNOPSIS

    use Net::FUD;

    $fud = Net::FUD->new( server => "some.host.name", port => 4201);

    @info = $fud("johndoe", "user.johndoe.folder")

    $err = $fud->error

=head1 DESCRIPTION

C<Net::FUD> is a class implementing a simple client in Perl to the FUD daemon
as shipped with I<Cyrus imapd>.

=head1 CONSTRUCTOR

=over 4

=item new ( server => HOST [, port => PORT ])

Create a new C<Net::FUD> object where HOST is the host to connect to.  
Optionnally, you can specify the port PORT (default udp/4201).

=back

=head1 METHODS

=over 4

=item retr_info ( USER [, MAILBOX ])

Retrieve information for mailbox MAILBOX (default to "user.USER" if 
unspecified) and user USER.  Return an array of five elements on 
success, false otherwise.  The content of the array is as follow :

=over 5

=item * 

$ret[0] : The user for which the information was retrieved

=item *

$ret[1] : The mailbox for which the information was retrieved.

=item *

$ret[2] : Number of messages unseen by the user in this mailbox.

=item * 

$ret[3] : Last time I<user> have read the mailbox, in typical Unix timestamp 
(second since the epoch) suitable for C<localtime()>.

=item *

$ret[4] : Last time a message was delivered to the I<user>'s mailbox, in Unix 
timestamp.

=back

=item close

Close the connection. 

=item error

If there was an error then this method will return an error string.

=back

=head1 AUTHOR

Etienne Goyer <etienne.goyer at linuxquebec.com> Linux Québec Technologies 
inc.

=head1 COPYRIGHT
Copyright (c) 2003 Etienne Goyer, Linux Québec Technologies
<etienne.goyer at linuxquebec.com>. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut


More information about the Info-cyrus mailing list