#! /usr/bin/perl -w

use strict;

use lib '/usr/local/share/perl5';

use Locale::TextDomain 'lire';

use Lire::Error qw/ missing_argument_usage /;
use Lire::LrCommand;

my $prog = new Lire::LrCommand();
$prog->init();
$prog->add_output_format_options();
$prog->add_email_options();
$prog->add_merging_options();
$prog->add_common_options();

$prog->set_usage( __( '[<options>] <report_file> <recipients>+' ) );
$prog->set_help( __( 'Formats the XML report <report_file> and sends it by email to the recipients specified as argument. Additional reports can be merged before formatting the report by using the --template and --merge options.' ) );
$prog->parse_options();

my ( $report_file, @emails ) = @ARGV;
$prog->usage( missing_argument_usage( 'report_file' ) )
  unless defined $report_file;
$prog->usage( __( 'You need at least one email argument.' ) )
  unless @emails;
$prog->check_email_requirements();
$prog->check_output_format();
my $report = $prog->merge_reports( $report_file );
$prog->email_report( $report, @emails );

exit(0);

__END__

=pod

=head1 NAME

lr_xml2mail - Formats a XML report and sends it by email

=head1 SYNOPSIS

B<lr_xml2mail> B<[>I<options>B<]> I<report.xml> I<recipieint>...

B<lr_xml2mail> B<--version>

B<lr_xml2mail> B<--help> B<[dlf-converters|output-formats|report-templates]>

=head1 OPTIONS

=over 4

=item B<--help> B<[>I<section>B<]>

If no argument is given, prints usage information and exits. Argument
can be one of the following:

=over 4

=item dlf-converters

Prints the list of available DLF converters and exits.

=item output-formats

Prints the list of available output formats and exits.

=item report-templates

Prints the list of available report templates and exits.

=back

=item B<--output-format> I<output format>

Selects the ouput format in which to generate the report. 

=item B<--template> I<name>

Uses the report configuration template named I<name> to merge the
reports. This option is required when using the B<--merge> option to
merge reports.

=item B<--merge> I<report_file>

Merge I<report_file> before formatting the report. This option can be
used multiple times to merge more than two reports.

=item B<--subject> I<subject>

Sets the subject of the email message. Defaults to 'Your I<format> report'.

=item B<--extra-file> I<file>

An additional text file that will be sent along the report. If the
output format is txt, it will be appended to the report.

=back

=head1 DESCRIPTION

B<lr_xml2mail> formats the XML reports generated by Lire to various
output format and sends it by email to the recipients specified as
remaining arguments.

The command will make sure the report is MIME encapsulated
properly depending on the output format chosen. For example, a PDF
report will be sent as an attachment and (X)HTML output will appear as
an HTML mail message. The content-type of the MIME message will also
be set properly.

From and Reply-To headers are initialized from the C<lr_from> and
C<lr_reply_to> configuration variables.

=head1 SEE ALSO

lr_log2mail(1), lr_log2report(1), lr_xml2report(1), lire(1), lire(7),
documentation in the Lire User Manual

=head1 AUTHOR

  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

$Id: lr_xml2mail.in,v 1.23 2006/07/23 13:16:33 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2002-2004 Stichting LogReport Foundation LogReport@LogReport.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; 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 (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.

=cut

# Local Variables:
# mode: cperl
# End:

