#!/usr/bin/perl -w

use strict;
use utf8;


=head1 NAME

dl10n-mail -- translator mailing lists (and BTS) robot for status updates

=head1 SYNOPSIS

dl10n-mail [options] lang+

=head1 DESCRIPTION

This script can receive mails from the debian-l10n-E<lt>languageE<gt>
mailing list or read an archivein thembox format.
It looks for emails which title follow a specific format
indicating what the author intend to translate, or the current status of
his work on this translation.

Those informations are saved to a dl10n database which can then be used to
build a l10n coordination page or any other useless statistics.

=cut

use Getopt::Long; #to parse the args
use Debian::L10n::Mail;


my $progname = $0;
   $progname = $1 if $progname =~ m,([^/])+$,;

my $VERSION = "1.0";			 # External Version Number
my $BANNER  = "Debian l10n infrastructure -- mailing list parser v$VERSION"; # Version Banner - text form

my $cmdline_file  = undef;
my $cmdline_msgid  = undef;
my $cmdline_mboxfolder  = undef;
my $check_bts=0;


=head1 Command line option parsing

=over

=item General options:

=over

=item -h, --help

display short help text

=item -V, --version

display version and exit

=item --check-bts

check the BTS

=back

=item Begin point of the crawling:

=over

=item --msgid=Message-ID

=back

if not specified, will crawl for new messages.

=item ...

=over

=item --mboxfolder=MBOX_FOLDER

...

=back

=item Database to fill:

=over

=item --sdb=STATUS_FILE

use STATUS_FILE as status file (instead of $STATUS_FILE)

=back

=back

=cut

# This is put into a block to avoid main namespace pollution
{
	sub syntax_msg {
		my $message = shift;
		if (defined $message) {
		        print "$progname: $message\n";
		} else {
		        print "$BANNER\n";
		}
		print <<EOF
Syntax: $0 [options] [lang]+
General options:
    -h, --help                display short help text
    -V, --version             display version and exit
    --check-bts               check the BTS

Begin point of the crawling:
    --msgid=Mesage-ID

    --mboxfolder=mbox_folder

    If not specified, will crawl for new messages.

Database to fill:
    --sdb=STATUS_FILE         use STATUS_FILE as status file
EOF
		;

		if (defined $message) {
			exit 1;
		} else {
			exit 0;
		}
	}


	# Display Version Banner
	# Options: -V|--version, --print-version
	sub banner {
		if ($_[0] eq 'print-version') {
			print "$VERSION\n";
		} else {
			print "$BANNER\n";
		}
		exit 0;
	}

	# Hash used to process commandline options
	my %opthash = (
		# ------------------ general options
		"help|h"    => \&syntax_msg,
		"version|V" => \&banner,
		"check-bts" => \$check_bts,

		# ------------------ configuration options
		"msgid=s"    => \$cmdline_msgid,

		"mboxfolder=s"=> \$cmdline_mboxfolder,

		"sdb=s"     => \$cmdline_file,
	);


	# init commandline parser
	Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');

	# process commandline options
	GetOptions(%opthash)
		or syntax_msg("error parsing options");
}


my @langs = @ARGV;

foreach my $l (@langs) {
	Mail::process($cmdline_mboxfolder, $l, $check_bts, $cmdline_msgid, $cmdline_file);
}

=head1 LICENSE

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; either version 2 of the License, or (at your option) any later
version.

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.

=head1 COPYRIGHT (C)

 2003,2004 Tim Dijkstra
 2004 Nicolas Bertolissio
 2004 Martin Quinson

=cut

1;
