#! /usr/bin/perl -w

use strict;

use lib '/usr/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_report_options();
$prog->add_email_options();
$prog->add_output_format_options();
$prog->add_common_options();

$prog->add_option( 'name' => 'log-file',
                   'section' => 'report',
                   'type' => '=s',
                   'help' => __( 'Sets the log file to convert instead of reading it from STDIN.' ) );
$prog->set_usage( __( '[<output options>] <dlf_converter> <recipients>+' ) );
$prog->set_help( __( 'Converts a log file using <dlf_converter> and email it to the recipients specified. The log file is read from STDIN unless the --log-file option is used.' ) );
$prog->parse_options();

my ( $converter, @emails ) = @ARGV;
$prog->usage( missing_argument_usage( 'dlf_converter' ) )
  unless defined $converter;
$prog->usage( __( 'You need at least one email argument.' ) )
  unless @emails;
my $logfile = $prog->get_option( 'log-file', '-' );

$prog->check_email_requirements();
$prog->check_output_format();
my $report = $prog->generate_report( $converter, $logfile );
$prog->email_report( $report, @emails );

exit(0);

__END__

=pod

=head1 NAME

B<lr_log2mail> - send a report generated from a log file by email

=head1 SYNOPSIS

B<lr_log2mail> B<[I<options>]> I<service> I<addresses>...

B<lr_log2report> B<--version>

B<lr_log2report> 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<--version>

Prints Lire's version and exits.

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

Selects the ouput format in which to generate the report. 

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

Uses the report configuration named I<name> to generate the report. 

=item B<--log-file> I<logfile>

Selects the log file that should be processed instead of STDIN.

=item B<--subject|-s> 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

The B<lr_log2mail> command is similar to the lr_log2report(1) command
with the difference that the report is sent by email. The log file is
read from STDIN or from the file specified using the B<--log-file>
option. The format of the log file is specified using the
I<dlf_converter> argument. Use the B<--help-dlf-converters> option to
get a list of all currently available DLF converters. All remaining
arguments are interpreted as email addresses to which to send the
report. In case the log is passed in a compressed format, it's
uncompressed on the fly, using gzip(1).

The report will be encapsulated in a MIME email appropriate for the
output format. For example, ASCII reports will be sent inline, PDF
reports will be sent as a file attachment and HTML reports should
appear inline in a HTML-capable mail reader.

The From and Reply-To headers in the outgoing emails are set to the
values of the I<lr_mail_from> and I<lr_mail_replyto> configuration
variables.

=head1 EXAMPLE

 % lr_log2mail -s "bind8 report" bind8_query \
     root "Joe User <joe@example.com>" < /var/log/query.log

=head1 SEE ALSO

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

=head1 AUTHORS

  Joost van Baal <joostvb@logreport.org>
  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

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

=head1 COPYRIGHT

Copyright (C) 2000-2004 Stichting LogReport Foundation
LogReport@LogReport.org

This program is part of Lire.

Lire 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:

