App-wsgetmail

 view release on metacpan or  search on metacpan

bin/wsgetmail  view on Meta::CPAN

            foreach my $code (@$method_codes) {
                if ($value eq 'delete') {
                    delete $response_matrix->{$method}{$code};
                }
                else {
                    $response_matrix->{$method}{$code} = $value;
                }
            }
        }
    }
}

$config->{response_matrix} = $response_matrix;

my $foldername = $config->{folder};

$foldername =~ s{/}{_}g;

my $lock_file_name = '/tmp/' . join( '.', 'wsgetmail', $config->{username}, $foldername, 'lock' );

open my $lock_file_fh, '>', $lock_file_name or die "unable to open lock file $lock_file_name ($!)";

if ( !flock $lock_file_fh, LOCK_EX | LOCK_NB ) {
    print "$0 is already running for $config->{username}/$config->{folder} ($!)\n" unless $quiet;
    exit;
}

my $getmail = App::wsgetmail->new({config => $config});

maybe_print("\nfetching mail using configuration $config_file\n");

my $done_count = 0;
my $error_count = 0;

while (my $message = $getmail->get_next_message()) {
    my $ok = $getmail->process_message($message);
    if ($ok) {
        $done_count++;
    }
    else {
        $error_count++;
    }
}

maybe_print("\nprocessed $done_count messages\n");

flush_and_die("there were errors with $error_count messages\n") if $error_count;

__END__

=head1 NAME

wsgetmail - get mail from cloud webservices

=head1 SYNOPSIS

Run:

    wsgetmail [options] --config=wsgetmail.json

where C<wsgetmail.json> looks like:

    {
    "client_id": "abcd1234-xxxx-xxxx-xxxx-1234abcdef99",
    "tenant_id": "abcd1234-xxxx-xxxx-xxxx-123abcde1234",
    "secret": "abcde1fghij2klmno3pqrst4uvwxy5~0",
    "global_access": 1,
    "username": "rt-comment@example.com",
    "folder": "Inbox",
    "command": "/opt/rt5/bin/rt-mailgate",
    "command_args": "--url=http://rt.example.com/ --queue=General --action=comment",
    "command_timeout": 30,
    "action_on_fetched": "mark_as_read"
    }

=head1 DESCRIPTION

wsgetmail retrieves mail from a folder available through a web services API
and delivers it to another system. Currently, it only knows how to retrieve
mail from the Microsoft Graph API, and deliver it by running another command
on the local system.

=head1 CONFIGURATION

For full setup and configuration instructions, see L<App::wsgetmail>.

    perldoc App::wsgetmail

=head1 ARGUMENTS

=over 4

=item --config, --configuration, -c

Path of the primary wsgetmail JSON configuration file to read. This argument
is required. The configuration file is documented in the next section.

=item --options

A string with a JSON object in the same format as the configuration
file. Configuration in this object will override the configuration file. You
can use this to extend a base configuration. For example, given the
configuration in the synopsis above, you can process a second folder the
same way by running:

    wsgetmail --config=wsgetmail.json --options='{"folder": "Other Folder"}'

=item --verbose, --debug, -v

Log additional information about each mail API request and any problems
delivering mail.

=item --quiet, -q

In "quiet" mode wsgetmail suppresses its normal output on stdout.  This output
identifies the configuration file used and how many messages were processed.

If there are any errors this information is sent to stderr after the error
messages.

This does not affect the additional logging generated by the verbose/debug



( run in 2.438 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )