#!/usr/bin/perl
use strict;
use warnings;
use Socialtext::Resting;
use Socialtext::MailArchive;
use Getopt::Long;

my %opts;
my @rest_opts = qw(server username password workspace);
GetOptions(
    \%opts,
    map { "$_=s" } @rest_opts,
) or usage();

for (@rest_opts) {
    usage("$_ is mandatory") unless $opts{$_};
}

my $r = Socialtext::Resting->new(%opts);

my $message;
{
    local $/;
    $message = <STDIN>;
}

Socialtext::MailArchive->new( rester => $r )->archive_mail($message);
exit;

sub usage {
    die <<EOT;
USAGE: $0 [options]

REST API Options:
  --server      Socialtext server to archive mail to
  --username    User to login as
  --password    User password
  --workspace   Workspace to archive mail to
EOT
}
