[24421] in Source-Commits

home help back first fref pref prev next nref lref last post

/svn/athena r24013 - in trunk/debathena/debathena: . libmail-expandaliases-perl libmail-expandaliases-perl/debian libmail-expandaliases-perl/t

daemon@ATHENA.MIT.EDU (Evan Broder)
Sun Sep 20 20:03:23 2009

Date: Sun, 20 Sep 2009 20:02:12 -0400
From: Evan Broder <broder@MIT.EDU>
Message-Id: <200909210002.n8L02CMj008283@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: broder
Date: 2009-09-20 20:02:12 -0400 (Sun, 20 Sep 2009)
New Revision: 24013

Added:
   trunk/debathena/debathena/libmail-expandaliases-perl/
   trunk/debathena/debathena/libmail-expandaliases-perl/Changes
   trunk/debathena/debathena/libmail-expandaliases-perl/ExpandAliases.pm
   trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST
   trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST.SKIP
   trunk/debathena/debathena/libmail-expandaliases-perl/META.yml
   trunk/debathena/debathena/libmail-expandaliases-perl/Makefile.PL
   trunk/debathena/debathena/libmail-expandaliases-perl/README
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/changelog
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/compat
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/control
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/copyright
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/rules
   trunk/debathena/debathena/libmail-expandaliases-perl/debian/watch
   trunk/debathena/debathena/libmail-expandaliases-perl/expand-alias
   trunk/debathena/debathena/libmail-expandaliases-perl/t/
   trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases
   trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases.t
   trunk/debathena/debathena/libmail-expandaliases-perl/t/expand-alias.t
   trunk/debathena/debathena/libmail-expandaliases-perl/t/incfile
   trunk/debathena/debathena/libmail-expandaliases-perl/t/self-referential-aliases
Log:
Create a package for the Mail::ExpandAliases Perl module.

This will be used for an updated version of the debathena-msmtp-mta
which can understand /etc/aliases files.



Added: trunk/debathena/debathena/libmail-expandaliases-perl/Changes
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/Changes	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/Changes	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,24 @@
+# ----------------------------------------------------------------------
+# Changelog for Mail::ExpandAliases
+# ----------------------------------------------------------------------
+
+# ----------------------------------------------------------------------
+# Version 0.46                                         November 24, 2008
+# ----------------------------------------------------------------------
+
+* Changed the parser to understand whitespace before the colon on the
+  LHS of an alias, as suggested by Terry Williams
+  <williams.terry.r@gmail.com>.
+
+# ----------------------------------------------------------------------
+# Version 0.45                                              (Unreleased)
+# ----------------------------------------------------------------------
+
+* Added patch from Thomas Kishel <tom@kishel.net>, which adds a method
+  that returns a list of all of the aliases in the aliase file.
+
+# ----------------------------------------------------------------------
+# Version 0.44                                        September 22, 2004 
+# ----------------------------------------------------------------------
+
+* Initial import from old CVS repository.

Added: trunk/debathena/debathena/libmail-expandaliases-perl/ExpandAliases.pm
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/ExpandAliases.pm	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/ExpandAliases.pm	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,451 @@
+package Mail::ExpandAliases;
+
+# -------------------------------------------------------------------
+# Mail::ExpandAliases - Expand aliases from /etc/aliases files
+# Copyright (C) 2002 darren chamberlain <darren@cpan.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+# -------------------------------------------------------------------
+# Design of this class:
+#
+#   - Read aliases file
+#
+#   - Parse aliases file
+#
+#       o Read file, normalize
+#
+#           + Skip malformed lines
+#
+#           + Join multi-line entries
+#
+#           + Discard comments
+#
+#       o Create internal structure
+#
+#   - On call to expand
+#
+#       o Start with first alias, and expand
+#
+#       o Expand each alias, unless:
+#
+#           + It is non-local
+#
+#           + It has already been seen
+#
+#   - Return list of responses
+# -------------------------------------------------------------------
+
+use strict;
+use vars qw($VERSION $DEBUG @POSSIBLE_ALIAS_FILES);
+
+$VERSION = 0.46;
+$DEBUG = 0 unless defined $DEBUG;
+@POSSIBLE_ALIAS_FILES = qw(/etc/aliases
+                           /etc/mail/aliases
+                           /etc/postfix/aliases
+                           /etc/exim/aliases);
+
+use constant PARSED  => 0;  # Parsed aliases
+use constant CACHED  => 1;  # Caches lookups
+use constant FILE    => 2;  # "Main" aliases file
+
+# ----------------------------------------------------------------------
+# import(@files)
+#
+# Allow for compile-time additions to @POSSIBLE_ALIAS_FILES
+# ----------------------------------------------------------------------
+sub import {
+    my $class = shift;
+    unshift @POSSIBLE_ALIAS_FILES, $_ for @_;
+}
+
+sub new {
+    my ($class, $file) = @_;
+    my $self = bless [ { }, { }, "" ] => $class;
+
+    $self->[ FILE ] = (grep { -e $_ && -r _ }
+                       ($file, @POSSIBLE_ALIAS_FILES))[0];
+    $self->debug("Using alias file " . $self->[ FILE ]);
+    $self->init();
+
+    return $self;
+}
+
+sub debug {
+    my $class = shift;
+    $class = ref $class || $class;
+    if ($DEBUG) {
+        warn "[ $class ] $_\n"
+            for (@_);
+    }
+}
+
+# ----------------------------------------------------------------------
+# init($file)
+#
+# Parse file, extracting aliases.  Note that this is a (more or less)
+# literal representation of the file; expansion of aliases happens at
+# run time, as aliases are requested.
+# # ----------------------------------------------------------------------
+sub init {
+    my $self = shift;
+    my $file = shift || $self->[ FILE ];
+    return $self unless defined $file;
+
+    # Chapter 24 of the sendmail book
+    # (www.oreilly.com/catalog/sendmail/) describes the process of
+    # looking for aliases thusly:
+    #
+    # "The aliases(5) file is composed of lines of text.  Any line that
+    # begins with a # is a comment and is ignored.  Empty lines (those
+    # that contain only a newline character) are also ignored.  Any
+    # lines that begins with a space or tab is joined (appended) to the
+    # line above it.  All other lines are text are viewed as alias
+    # lines.  The format for an alias line is:
+    #
+    #   local: alias
+    #
+    # "The local must begin a line. It is an address in the form of a
+    # local recipient address...  The colon follows the local on
+    # the same line and may be preceded with spaces or tabs.  If the
+    # colon is missing, sendmail prints and syslog(3)'s the following
+    # error message and skips that alias line:
+    #
+    #   missing colon
+    #
+    # "The alias (to the right of the colon) is one or more addresses on
+    # the same line.  Indented continuation lines are permitted.  Each
+    # address should be separated from the next by a comma and optional
+    # space characters. A typical alias looks like this:
+    #
+    #   root: jim, sysadmin@server, gunther ^ | indenting whitespace
+    #
+    # "Here, root is hte local address to be aliases.  When mail is to
+    # be locally delivered to root, it is looked up in the aliases(5)
+    # file.  If found, root is replaced with the three addresses show
+    # earlier, and mail is instead delivered to those other three
+    # addresses.
+    #
+    # "This process of looking up and possibly aliases local recipients
+    # is repeated for each recipient until no more aliases are found in
+    # the aliases(5) file.  That is, for example, if one of the aliases
+    # for root is jim, and if jim also exists to the left of a colon in
+    # the aliases file, he too is replaced with his alias:
+    #
+    #   jim: jim@otherhost
+    #
+    # "The list of addresses to the right of the colon may be mail
+    # addresses (such as gunther or jim@otherhost), the name of a
+    # program to run (such as /etc/relocated), the name of a file onto
+    # which to append (such as /usr/share/archive), or the name of a
+    # file to read for additional addresses (using :include:)."
+
+    $self->debug("Opening alias file '$file'");
+    my $fh = File::Aliases->new($file)
+        or die "Can't open $file: $!";
+
+    while (my $line = $fh->next) {
+        chomp($line);
+        next if $line =~ /^#/;
+        next if $line =~ /^\s*$/;
+
+        $line =~ s/\s+/ /g;
+        my ($orig, $alias, @expandos);
+
+        $orig = $line;
+        if ($line =~ s/^([^:\s]+)\s*:\s*//) {
+            $alias = lc $1;
+            $self->debug("$. => '$alias'");
+        }
+        else {
+            local $DEBUG = 1;
+            $self->debug("$file line $.: missing colon");
+            next;
+        }
+
+        @expandos =
+            #grep !/^$alias$/,
+            map { s/^\s*//; s/\s*$//; $_ }
+            split /,/, $line;
+
+        $self->debug($alias, map "\t$_", @expandos);
+        $self->[ PARSED ]->{ $alias } = \@expandos;
+    }
+
+    return $self;
+}
+
+# ----------------------------------------------------------------------
+# expand($name)
+#
+# Expands $name to @addresses.  If @addresses is empty, return $name.
+# In list context, returns a list of the matching expansions; in
+# scalar context, returns a reference to an array of expansions.
+# ----------------------------------------------------------------------
+sub expand {
+    my ($self, $name, $original, $lcname, %answers, @answers, @names, $n);
+    $self = shift;
+    $name = shift || return $name;
+    $original = shift;
+    $lcname = lc $name;
+
+    return $name if (defined $original && $name eq $original);
+
+    return @{ $self->[ CACHED ]->{ $lcname } }
+        if (defined $self->[ CACHED ]->{ $lcname });
+
+    if (@names = @{ $self->[ PARSED ]->{ $lcname } || [ ] }) {
+        my $c = $self->[ CACHED ]->{ $lcname } = [ ];
+
+        for $n (@names) {
+            $n =~ s/^[\s'"]*//g;
+            $n =~ s/['"\s]*$//g;
+            my $type = substr $n, 0, 1;
+
+            if ($type eq '|' or $type eq '/') {
+                # |/path/to/program
+                # /path/to/mbox
+                $answers{ $n }++;
+                push @$c, $n;
+            }
+
+            elsif ($type eq ':') {
+                # :include:
+                #$n =~ s/:include:\s*//ig;
+                #$self->parse($n);
+                warn "Skipping include file $n\n";
+            }
+
+            elsif ($type eq '\\') {
+                # \foo
+                # literal, non-escaped value, useful for
+                # aliases like:
+                #   foo: \foo, bar
+                # where mail to foo, a local user, should also
+                # go to bar.
+                $n =~ s/^\\//;
+                $answers{ $n }++;
+                push @$c, $n;
+            }
+
+            else {
+                for ($self->expand($n, $original || $name)) {
+                    $answers{ $_ }++
+                }
+            }
+        }
+
+        # Add to the cache
+        @answers = sort keys %answers;
+        $self->[ CACHED ]->{ $lcname } = \@answers;
+        return wantarray ? @answers : \@answers;
+    }
+
+    return $name;
+}
+
+# ----------------------------------------------------------------------
+# reload()
+#
+# Reset the instance.  Clears out parsed aliases and empties the cache.
+# ----------------------------------------------------------------------
+sub reload {
+    my ($self, $file) = @_;
+
+    %{ $self->[ PARSED ] } = ();
+    %{ $self->[ CACHED ] } = ();
+    $self->[ FILE ] = $file if defined $file;
+
+    $self->parse;
+
+    return $self;
+}
+
+# ----------------------------------------------------------------------
+# aliases()
+#
+# Lists the aliases.
+# In list context, returns an array;
+# in scalar context, returns a reference to an array.
+#
+# From a patch submitted by Thomas Kishel <tom@kishel.net>
+# ----------------------------------------------------------------------
+sub aliases {
+    my ($self, @answers);
+    $self = shift;
+    @answers = sort keys %{ $self->[ PARSED ] };
+    return wantarray ? @answers : \@answers;
+}
+
+package File::Aliases;
+use constant FH     => 0;
+use constant BUFFER => 1;
+
+use IO::File;
+
+# This package ensures that each read (i.e., calls to next() --
+# I'm too lazy to implement this as a tied file handle so it can
+# be used in <>) returns a single alias entry, which may span
+# multiple lines.
+#
+# XXX I suppose I could simply subclass IO::File, and rename next
+# to readline.
+
+sub new {
+    my $class = shift;
+    my $file = shift;
+    my $fh = IO::File->new($file);
+
+    my $self = bless [ $fh, '' ] => $class;
+    $self->[ BUFFER ] = <$fh>
+        if $fh;
+
+    return $self;
+}
+
+sub next {
+    my $self = shift;
+    my $buffer = $self->[ BUFFER ];
+    my $fh = $self->[ FH ];
+
+    return ""
+        unless defined $fh;
+
+    $self->[ BUFFER ] = "";
+    while (<$fh>) {
+        if (/^\S/) {
+            $self->[ BUFFER ] = $_;
+            last;
+        } else {
+            $buffer .= $_;
+        }
+    }
+
+    return $buffer;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Mail::ExpandAliases - Expand aliases from /etc/aliases files
+
+=head1 SYNOPSIS
+
+  use Mail::ExpandAliases;
+
+  my $ma = Mail::ExpandAliases->new("/etc/aliases");
+  my @list = $ma->expand("listname");
+
+=head1 DESCRIPTION
+
+I've looked for software to expand aliases from an alias file for a
+while, but have never found anything adequate.  In this day and age,
+few public SMTP servers support EXPN, which makes alias expansion
+problematic.  This module, and the accompanying C<expand-alias>
+script, attempts to address that deficiency.
+
+=head1 USAGE
+
+Mail::ExpandAliases is an object oriented module, with a constructor
+named C<new>:
+
+  my $ma = Mail::ExpandAliases->new("/etc/mail/aliases");
+
+C<new> takes the filename of an aliases file; if not supplied, or if
+the file specified does not exist or is not readable,
+Mail::ExpandAliases will look in a predetermined set of default
+locations and use the first one found.  See L<"ALIAS FILE LOCATIONS">,
+below, for details on this search path and how to modify it.
+
+Lookups are made using the C<expand> method:
+
+  @aliases = $ma->expand("listname");
+
+C<expand> returns a list of expanded addresses, sorted alphabetically.
+These expanded addresses are also expanded, whenever possible.
+
+A non-expandible alias (no entry in the aliases file) expands to
+itself, i.e., does not expand.
+
+In scalar context, C<expand> returns a reference to a list.
+
+Note that Mail::ExpandAliases provides read-only access to the alias
+file.  If you are looking for read access, see Mail::Alias, which is a
+more general interface to alias files.
+
+Mail::ExpandAliases make a resonable attempt to handle aliases the way
+C<sendmail> does, including loop detection and support for escaped
+named.  See chapter 24, "Aliases", in I<Sendmail>
+(E<lt>http://www.oreilly.com/catalog/sendmail/E<gt>) for full details
+about this process.
+
+=head1 ALIAS FILE LOCATIONS
+
+Paths to the aliases file can be added globally at compile time:
+
+  use Mail::ExpandAliases qw(/etc/exim/aliases);
+
+Alias file locations can also be specified to instances when they
+are constructed:
+
+  my $ma = Mail::ExpandAliases->new("/etc/exim/aliases");
+
+Alias file locations are stored in the package global @POSSIBLE_ALIAS_FILES,
+which can be assigned to directly if you're not impressed with encapsulation:
+
+  @Mail::ExpandAliases::POSSIBLE_ALIAS_FILES = ("/etc/aliases");
+
+By default, @POSSIBLE_ALIAS_FILES contains F</etc/aliases>,
+F</etc/mail/aliases>, F</etc/postfix/aliases>, and
+F</etc/exim/aliases>.  If your alias file is ones of these, the
+filename can be omitted from the constructor; Mail::ExpandAliases will
+look in @POSSIBLE_ALIAS_FILES until it finds a file that exists.
+
+Note that it is not (necessarily) an error if none of these files
+exists.  An alias file can be added by passing a filename to the
+init() method:
+
+  my $ma = Mail::ExpandAliases->new();
+
+  # Write a temporary aliases file in /tmp/aliases-$<
+  $ma->init("/tmp/aliases-$<");
+
+Calling expand before setting an alias file will, of course, produce
+no useful expansions.
+
+If the constructor is called with the name of a file that exists but
+cannot be opened, Mail::ExpandAliases will die with an error detailing
+the problem.
+
+=head1 BUGS / SHORTCOMINGS
+
+If you were telnet mailhost 25, and the server had EXPN turned on,
+then sendmail would read a user's .forward file.  This software cannot
+do that, and makes no attempt to.  Only the invoking user's .forward
+file should be readable (if any other user's .forward file was
+readable, sendmail would not read it, making this feature useless),
+and the invoking user should not need this module to read their own
+.forward file.
+
+Any other shortcomings, bugs, errors, or generally related complaints
+and requests should be reported via the appropriate queue at
+<http://rt.cpan.org/>.
+
+=head1 AUTHOR
+
+darren chamberlain E<lt>darren@cpan.orgE<gt>

Added: trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,13 @@
+Changes
+expand-alias
+ExpandAliases.pm
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+README
+t/aliases
+t/aliases.t
+t/expand-alias.t
+t/incfile
+t/self-referential-aliases
+META.yml                                 Module meta-data (added by MakeMaker)

Added: trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST.SKIP
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST.SKIP	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/MANIFEST.SKIP	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,2 @@
+.*CVS.*
+\.git

Added: trunk/debathena/debathena/libmail-expandaliases-perl/META.yml
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/META.yml	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/META.yml	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Mail-ExpandAliases
+version:      0.46
+version_from: ExpandAliases.pm
+installdirs:  site
+requires:
+    IO::File:                      
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30_01

Added: trunk/debathena/debathena/libmail-expandaliases-perl/Makefile.PL
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/Makefile.PL	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/Makefile.PL	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,62 @@
+package Mail::ExpandAliases;
+
+# ----------------------------------------------------------------------
+# Makefile.PL - Generate a Makefile
+# Copyright (C) 2002 darren chamberlain <darren@cpan.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+# ----------------------------------------------------------------------
+
+use strict;
+
+use ExtUtils::MakeMaker;
+use File::Basename qw(basename);
+
+my $dist = '$(DISTNAME)-$(VERSION).tar.gz';
+my @EXE_FILES = ('expand-alias');
+my %PREREQ_PM = ('IO::File');
+my %clean     = ('FILES' => "$dist $dist.asc distdir");
+my %macro     = (
+    'GPG' => 'gpg',
+    'AUTHOR' => 'darren@cpan.org',
+    'SIGN'  => '--detach-sign --armor',
+);
+
+WriteMakefile(
+    NAME            => __PACKAGE__,
+    VERSION_FROM    => 'ExpandAliases.pm',
+    EXE_FILES       => \@EXE_FILES,
+    PREREQ_PM       => \%PREREQ_PM,
+    clean           => \%clean,
+    macro           => \%macro,
+);
+
+package MY;
+sub dist_dir {
+	my $self = shift;
+	my $stuff = $self->SUPER::dist_dir(@_);
+
+	return "$stuff\ttouch distdir\n\n";
+}
+
+sub postamble {
+    return <<'P';
+distsign :: $(DISTVNAME).tar$(SUFFIX)
+	$(GPG) $(SIGN) -u $(AUTHOR) $(DISTVNAME).tar$(SUFFIX)
+	@cat $(DISTVNAME).tar$(SUFFIX).asc
+P
+}
+
+__END__

Added: trunk/debathena/debathena/libmail-expandaliases-perl/README
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/README	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/README	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,104 @@
+NAME
+    Mail::ExpandAliases - Expand aliases from /etc/aliases files
+
+SYNOPSIS
+      use Mail::ExpandAliases;
+
+      my $ma = Mail::ExpandAliases->new("/etc/aliases");
+      my @list = $ma->expand("listname");
+
+DESCRIPTION
+    I've looked for software to expand aliases from an alias file for a
+    while, but have never found anything adequate. In this day and age, few
+    public SMTP servers support EXPN, which makes alias expansion
+    problematic. This module, and the accompanying "expand-alias" script,
+    attempts to address that deficiency.
+
+USAGE
+    Mail::ExpandAliases is an object oriented module, with a constructor
+    named "new":
+
+      my $ma = Mail::ExpandAliases->new("/etc/mail/aliases");
+
+    "new" takes the filename of an aliases file; if not supplied, or if the
+    file specified does not exist or is not readable, Mail::ExpandAliases
+    will look in a predetermined set of default locations and use the first
+    one found. See the section on "ALIAS FILE LOCATIONS", below, for details
+    on this search path and how to modify it.
+
+    Lookups are made using the "expand" method:
+
+      @aliases = $ma->expand("listname");
+
+    "expand" returns a list of expanded addresses, sorted alphabetically.
+    These expanded addresses are also expanded, whenever possible.
+
+    A non-expandible alias (no entry in the aliases file) expands to itself,
+    i.e., does not expand.
+
+    In scalar context, "expand" returns a reference to a list.
+
+    Note that Mail::ExpandAliases provides read-only access to the alias
+    file. If you are looking for read access, see Mail::Alias, which is a
+    more general interface to alias files.
+
+    Mail::ExpandAliases make a resonable attempt to handle aliases the way
+    "sendmail" does, including loop detection and support for escaped named.
+    See chapter 24, "Aliases", in *Sendmail*
+    (<http://www.oreilly.com/catalog/sendmail/>) for full details about this
+    process.
+
+ALIAS FILE LOCATIONS
+    Paths to the aliases file can be added globally at compile time:
+
+      use Mail::ExpandAliases qw(/etc/exim/aliases);
+
+    Alias file locations can also be specified to instances when they are
+    constructed:
+
+      my $ma = Mail::ExpandAliases->new("/etc/exim/aliases");
+
+    Alias file locations are stored in the package global
+    @POSSIBLE_ALIAS_FILES, which can be assigned to directly if you're not
+    impressed with encapsulation:
+
+      @Mail::ExpandAliases::POSSIBLE_ALIAS_FILES = ("/etc/aliases");
+
+    By default, @POSSIBLE_ALIAS_FILES contains /etc/aliases,
+    /etc/mail/aliases, /etc/postfix/aliases, and /etc/exim/aliases. If your
+    alias file is ones of these, the filename can be omitted from the
+    constructor; Mail::ExpandAliases will look in @POSSIBLE_ALIAS_FILES
+    until it finds a file that exists.
+
+    Note that it is not (necessarily) an error if none of these files
+    exists. An alias file can be added by passing a filename to the init()
+    method:
+
+      my $ma = Mail::ExpandAliases->new();
+
+      # Write a temporary aliases file in /tmp/aliases-$<
+      $ma->init("/tmp/aliases-$<");
+
+    Calling expand before setting an alias file will, of course, produce no
+    useful expansions.
+
+    If the constructor is called with the name of a file that exists but
+    cannot be opened, Mail::ExpandAliases will die with an error detailing
+    the problem.
+
+BUGS / SHORTCOMINGS
+    If you were telnet mailhost 25, and the server had EXPN turned on, then
+    sendmail would read a user's .forward file. This software cannot do
+    that, and makes no attempt to. Only the invoking user's .forward file
+    should be readable (if any other user's .forward file was readable,
+    sendmail would not read it, making this feature useless), and the
+    invoking user should not need this module to read their own .forward
+    file.
+
+    Any other shortcomings, bugs, errors, or generally related complaints
+    and requests should be reported via the appropriate queue at
+    <http://rt.cpan.org/>.
+
+AUTHOR
+    darren chamberlain <darren@cpan.org>
+

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/changelog
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/changelog	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/changelog	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,5 @@
+libmail-expandaliases-perl (0.46-1) unstable; urgency=low
+
+  * Initial Release.
+
+ -- Evan Broder <broder@mit.edu>  Sun, 20 Sep 2009 19:50:21 -0400

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/compat
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/compat	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/compat	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1 @@
+5

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/control
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/control	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/control	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,13 @@
+Source: libmail-expandaliases-perl
+Section: perl
+Priority: optional
+Build-Depends: cdbs, debhelper (>= 5), perl (>= 5.6.10-12)
+Maintainer: Debathena Project <debathena@mit.edu>
+Standards-Version: 3.8.0
+Homepage: http://search.cpan.org/dist/Mail-ExpandAliases/
+
+Package: libmail-expandaliases-perl
+Architecture: all
+Depends: ${perl:Depends}, ${misc:Depends}
+Description: Expand aliases from /etc/aliases files
+ This Perl module supports expanding aliases from an aliases file.

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/copyright
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/copyright	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/copyright	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,34 @@
+This package was created as part of the Debathena Project
+<http://debathena.mit.edu> of the MIT Student Information Processing
+Board.
+
+It was downloaded from http://search.cpan.org/dist/Mail-ExpandAliases/
+
+Upstream Author:
+
+  Darren Chamberlain <darren@cpan.org>.
+
+Copyright:
+
+  Copyright (C) 2002 Darren Chamberlain
+
+License:
+
+    This package is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; version 2.
+
+    This package is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this package; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL-2'.
+
+The Debian packaging is (C) 2009, Evan Broder <broder@mit.edu> and
+is licensed under the same terms as the software itself (see above).

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/rules
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/rules	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/rules	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,4 @@
+#!/usr/bin/make -f
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+include /usr/share/cdbs/1/class/perlmodule.mk


Property changes on: trunk/debathena/debathena/libmail-expandaliases-perl/debian/rules
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/debathena/debathena/libmail-expandaliases-perl/debian/watch
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/debian/watch	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/debian/watch	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,4 @@
+# format version number, currently 3; this line is compulsory!
+version=3
+# URL to the package page followed by a regex to search
+http://search.cpan.org/dist/Mail-ExpandAliases/   .*/Mail-ExpandAliases-v?(\d[\d_.-]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip)$

Added: trunk/debathena/debathena/libmail-expandaliases-perl/expand-alias
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/expand-alias	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/expand-alias	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,181 @@
+#!/usr/bin/perl
+
+# ----------------------------------------------------------------------
+# expand-alias - expand an alias from /etc/aliases
+# Copyright (C) 2002 darren chamberlain <darren@cpan.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+# ----------------------------------------------------------------------
+
+use strict;
+use vars qw($VERSION $opt_h $opt_f $opt_t $opt_v
+                     $opt_n $opt_c $opt_s $opt_D
+                     $joint);
+
+use Getopt::Std;
+use Mail::ExpandAliases;
+
+getopts("Dtcnhf:sv");
+
+if ($opt_h) {
+    exec("perldoc $0");
+    exit 0;
+}
+
+if (($opt_t + $opt_c + $opt_n + $opt_s) > 1) {
+    die "Please specify only one of -t, -n, -c, or -s.";
+}
+
+$joint = $opt_t ? "\t" : $opt_c ? ", " : $opt_n ? "\n" : " ";
+
+$Mail::ExpandAliases::DEBUG =1 if $opt_D;
+my $expander = Mail::ExpandAliases->new($opt_f);
+
+for (@ARGV) {
+    my $alias = $opt_v ? "$_: " : "";
+    if ($opt_s) {
+        my (@expandos, $last, $comma, $num, $str);
+
+        @expandos = $expander->expand($_);
+        if (@expandos > 2) {
+            my $last = pop @expandos;
+            print $alias, join(", ", @expandos), ", and ", $last;
+        } elsif (@expandos == 2) {
+            print $alias, join " and ", @expandos;
+        } else {
+            print $alias, @expandos;
+        }
+    } else {
+        print $alias, join $joint, $expander->expand($_);
+    }
+    print "\n";
+}
+
+exit(0);
+
+__END__
+
+=head1 NAME
+
+expand-alias - expand mail aliases from /etc/aliases
+
+=head1 SYNOPSIS
+
+    $ expand-alias MAILER-DAEMON
+    root
+
+    $ expand-alias -c listname
+    addr1, addr2, addr3
+
+    $ expand-alias -n listname
+    addr1
+    addr2
+    addr3
+
+    $ expand-alias -t listname
+    addr1	addr2	addr3
+
+    $ expand-alias -f ~/my.aliases friends
+    friend1@isp.net other.friend@isp2.net
+
+    $ expand-alias -f ~/my.aliases -s friends
+    friend1@isp.net and other.friend@isp2.net
+
+=head1 DESCRIPTION
+
+C<expand-alias> expands aliases from an aliases file, as implemented
+by the Mail::ExpandAliases module.
+
+=head1 USE
+
+C<expand-alias> takes 0 or more aliases as arguments:
+
+    $ expand-alias postmaster
+    darren@cpan.org
+
+    $ expand-alias foo
+    foo
+
+Note that unknown aliases expand to themselves; that is, they don't
+expand.
+
+C<expand-alias> has several command line swicthes that control the
+output:
+
+=over 4
+
+=item -c
+
+comma-separated output:
+
+    $ expand-alias -c listname
+    addr1, addr2, addr3
+
+=item -t
+
+tab-separated output
+
+    $ expand-alias -c listname
+    addr1	addr2	addr3
+
+=item -n
+
+newline separated output
+
+    $ expand-alias -n listname
+    addr1
+    addr2
+    addr3
+
+=item -s
+
+"sentence" form (a, b, and c).
+
+    $ expand-alias -s listname
+    addr1, addr2, and addr3
+
+=back
+
+The default separator is a single space:
+
+    $ expand-alias listname
+    addr1 addr2 addr3
+
+This is useful in shell scripts:
+
+    $ for addr in `expand-alias -f ~/my.lists friends`; do
+    > mail -s 'For your eyes only!' $addr < secret-file
+    > done
+
+C<expand-alias> also takes a C<-f> option, as hinted above, which
+indicates the file to be used; see L<Mail::ExpandAliases> for details
+about alias files search paths.
+
+If the C<-v> (verbose) flag is set, alias expansions are prefixed by
+the alias itself.  This is useful when specifying multiple aliases on
+the command line:
+
+    $ expand-alias -vc listone listtwo listthree
+    listone: addr1, addr2, addr3
+    listtwo: addr4, addr3, addr2
+    listthree: addr1, addr4, addr3
+
+=head1 AUTHOR
+
+darren chamberlain E<lt>darren@cpan.orgE<gt>
+
+=head1 SEE ALSO
+
+L<Perl>, L<Mail::ExpandAliases>


Property changes on: trunk/debathena/debathena/libmail-expandaliases-perl/expand-alias
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,36 @@
+#
+# This aliases file contains several types of aliases:
+#   * normal aliases
+#   * programs (| /some/path)
+#   * files (/dev/null)
+#   * groups (multiple aliases)
+#
+# I'll use the unresolvable.perl.org domain for examples
+
+Postmaster: /dev/null
+MAILER-DAEMON: postmaster
+nobody: /dev/null
+spam:   /dev/null
+
+### Individual aliases
+tjones: Tom_Jones@unresolvable.perl.org
+bjones: Barnaby_Jones@unresolvable.perl.org
+bjones2: Bridget_Jones@unresolvable.perl.org
+qjones: Quincy_Jones@unresolvable.perl.org
+### Lists
+jones: tjones,bjones,bjones2,qjones
+crap:
+        tjones,
+        bjones,
+        bjones2
+
+archive: /var/mail/archive, root
+redist: "| /path/to/redist"
+
+silly: silly, stuff
+
+backslashed: \jones
+
+nothing: nothing
+
+spacetest  : spam

Added: trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases.t
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases.t	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases.t	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,98 @@
+#!/usr/bin/perl -w
+# ----------------------------------------------------------------------
+# vim: set ft=perl:
+# ----------------------------------------------------------------------
+# All email addresses in this file go to unresolvable.perl.org, which
+# I think I made up.  My apologies to Tom, Barnaby, Bridget, and Quincy
+# if you get mail at these addresses.
+# ----------------------------------------------------------------------
+
+use strict;
+use FindBin qw($Bin);
+use Mail::ExpandAliases;
+use File::Spec::Functions qw(catfile);
+use Test::More;
+
+my ($aliases_file, $m, @a, $a);
+BEGIN {
+    plan tests => 16;
+}
+
+use_ok("Mail::ExpandAliases");
+
+$aliases_file = catfile($Bin, "aliases");
+
+ok(defined($m = Mail::ExpandAliases->new($aliases_file)));
+
+@a = $m->expand('spam');
+is($a[0], '/dev/null', "'spam' => '$a[0]'");
+undef @a;
+
+# Lists of addresses are sorted
+@a = $m->expand('jones');
+$a = join ',', @a;
+is($a, 'Barnaby_Jones@unresolvable.perl.org,Bridget_Jones@unresolvable.perl.org,Quincy_Jones@unresolvable.perl.org,Tom_Jones@unresolvable.perl.org', "'jones' => '$a'");
+undef @a;
+
+# Standard MAILER-DAEMON expansion test
+@a = $m->expand('MAILER-DAEMON');
+is($a[0], '/dev/null', "'MAILER-DAEMON' => '$a[0]'");
+undef @a;
+
+# An alias that is not in the file; should "expand" to itself.
+@a = $m->expand('not-there');
+is($a[0], 'not-there', "'not-there' => '$a[0]'");
+undef @a;
+
+# Just a regular alias (see next test for why this one is here)
+@a = $m->expand('tjones');
+is($a[0], 'Tom_Jones@unresolvable.perl.org', "'tjones' => '$a[0]'");
+undef @a;
+
+# Different capitalization of the above alias -- they should return
+# the same value.
+@a = $m->expand('TJones');
+is($a[0], 'Tom_Jones@unresolvable.perl.org', "'TJones' => '$a[0]'");
+undef @a;
+
+# Another pair of capitilization tests
+@a = $m->expand('postmaster');
+is($a[0], '/dev/null', "'postmaster' => '$a[0]'");
+undef @a;
+
+@a = $m->expand('Postmaster');
+is($a[0], '/dev/null', "'Postmaster' => '$a[0]'");
+undef @a;
+
+
+# Expands to a command.
+@a = $m->expand("redist");
+is($a[0], '| /path/to/redist', "'redist' => '$a[0]'");
+undef @a;
+
+# Expands to a path
+@a = $m->expand("archive");
+is($a[0], '/var/mail/archive', "'redist' => '$a[0]'");
+undef @a;
+
+# Backslashed alias:
+# backslashed: \jones
+# Note that jones is another alias in this file; the backslash
+# should prevent it from being further expanded.
+@a = $m->expand("backslashed");
+is($a[0], "jones", "'backslashed' => '$a[0]'");
+undef @a;
+
+# Self-referential alias:
+# nothing: nothing
+@a = $m->expand("nothing");
+is($a[0], "nothing", "'nothing' => '$a[0]'");
+undef @a;
+
+@a = $m->expand("silly");
+$a = join ",", @a;
+is($a, "silly,stuff", "'silly' => '$a'");
+undef @a;
+
+@a = $m->expand("spacetest");
+is($a[0], "/dev/null", "'spacetest' => '$a[0]'");

Added: trunk/debathena/debathena/libmail-expandaliases-perl/t/expand-alias.t
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/t/expand-alias.t	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/t/expand-alias.t	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,27 @@
+#!/usr/bin/perl -w
+# ----------------------------------------------------------------------
+# vim: set ft=perl: -*-cperl-*-
+# ----------------------------------------------------------------------
+
+use strict;
+use Config;
+use Test;
+
+my $result;
+my $cmd = "$Config{'perlpath'} -Mblib expand-alias -f t/aliases 2>/dev/null";
+
+BEGIN {
+    plan test => 4;
+}
+
+chomp ($result = `$cmd spam`);
+ok($result, "/dev/null");
+
+chomp ($result = `$cmd tjones`);
+ok($result, 'Tom_Jones@unresolvable.perl.org');
+
+chomp ($result = `$cmd redist`);
+ok($result, '| /path/to/redist');
+
+chomp ($result = `$cmd jones`);
+ok($result, 'Barnaby_Jones@unresolvable.perl.org Bridget_Jones@unresolvable.perl.org Quincy_Jones@unresolvable.perl.org Tom_Jones@unresolvable.perl.org');

Added: trunk/debathena/debathena/libmail-expandaliases-perl/t/incfile
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/t/incfile	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/t/incfile	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,2 @@
+commits:
+	tjones,bjones

Added: trunk/debathena/debathena/libmail-expandaliases-perl/t/self-referential-aliases
===================================================================
--- trunk/debathena/debathena/libmail-expandaliases-perl/t/self-referential-aliases	2009-09-20 20:10:52 UTC (rev 24012)
+++ trunk/debathena/debathena/libmail-expandaliases-perl/t/self-referential-aliases	2009-09-21 00:02:12 UTC (rev 24013)
@@ -0,0 +1,3 @@
+bar:    bar                                                                                                         
+foo:    bar
+


home help back first fref pref prev next nref lref last post