diff --git a/lib/Scot/Inbox/Config.pm b/lib/Scot/Inbox/Config.pm index e29cb5a..4b640dd 100644 --- a/lib/Scot/Inbox/Config.pm +++ b/lib/Scot/Inbox/Config.pm @@ -63,8 +63,8 @@ sub build_config () { $mboxconf = { loginurl => $ENV{S4INBOX_GRAPH_LOGIN_URL}, graphurl => $ENV{S4INBOX_GRAPH_GRAPH_URL}, - scot => $ENV{S4INBOX_GRAPH_SCOPE}, - tenet_id => $ENV{S4INBOX_GRAPH_TENENT_ID}, + scope => $ENV{S4INBOX_GRAPH_SCOPE}, + tenet_id => $ENV{S4INBOX_GRAPH_TENET_ID}, client_id => $ENV{S4INBOX_GRAPH_CLIENT_ID}, client_secret => $ENV{S4INBOX_GRAPH_CLIENT_SECRET}, useraddress => $ENV{S4INBOX_GRAPH_USERADDRESS}, diff --git a/lib/Scot/Inbox/Imap.pm b/lib/Scot/Inbox/Imap.pm index 016841b..8a89297 100644 --- a/lib/Scot/Inbox/Imap.pm +++ b/lib/Scot/Inbox/Imap.pm @@ -512,6 +512,10 @@ sub inline_images ($self, $tree, $imgdb) { } } +sub delete_message ($self, @msgids) { + $self->client->delete_message(\@msgids); +} + 1; diff --git a/lib/Scot/Inbox/Msgraph.pm b/lib/Scot/Inbox/Msgraph.pm index dbf6e20..ef6bc26 100644 --- a/lib/Scot/Inbox/Msgraph.pm +++ b/lib/Scot/Inbox/Msgraph.pm @@ -1,4 +1,4 @@ -package Scot::Email::MSGraph; +package Scot::Inbox::Msgraph; use lib '../../../lib'; use strict; @@ -30,7 +30,7 @@ has permitted_senders => sub ($self) { $self->config->{permitted_senders} }; sub get_access_token { my ($self) = @_; - my $log = $self->env->log; + my $log = $self->log; my $url = join('', $self->loginurl, @@ -59,7 +59,7 @@ sub get_access_token { sub get_mail { my ($self, $start, $end) = @_; - my $log = $self->env->log; + my $log = $self->log; my $filter = '&$filter='; if ( $self->bydate ) { @@ -106,7 +106,6 @@ sub get_mail { my $cursor = Scot::Email::MSGraph::Cursor->new( ids => \@mids, msgraph => $self, - env => $self->env, ); } @@ -121,19 +120,19 @@ sub mark_message_read { ); my $update = {isRead => 'TRUE' }; $auth->{'Content-Type'} = "application/json"; - $self->env->log->debug("mark_read_url = ",{filter =>\&Dumper, value => $url}); - $self->env->log->debug("mark_read_json = ",{filter =>\&Dumper, value => $auth}); + $self->log->debug("mark_read_url = ",{filter =>\&Dumper, value => $url}); + $self->log->debug("mark_read_json = ",{filter =>\&Dumper, value => $auth}); my $tx = $self->ua->patch($url => $auth => json => $update); my $result = $tx->result; if ($result->is_error) { - $self->env->log->error("ERROR updating isRead status!"); + $self->log->error("ERROR updating isRead status!"); my $json = $result->json; - $self->env->log->error({filter => \&Dumper, value => $json}); + $self->log->error({filter => \&Dumper, value => $json}); return; } - $self->env->log->debug("$msgid isRead set to 1"); + $self->log->debug("$msgid isRead set to 1"); return; } @@ -141,7 +140,7 @@ sub build_message_id_list { my $self = shift; my $messages = shift; my @mids = (); - my $log = $self->env->log; + my $log = $self->log; MSG: foreach my $m (@$messages) { @@ -167,7 +166,7 @@ sub build_auth_token { sub get_message { my $self = shift; my $id = shift; - my $log = $self->env->log; + my $log = $self->log; my $url = join('', $self->graphurl, '/', $self->useraddress, @@ -213,13 +212,13 @@ sub get_html_body { if ( $body->{contentType} eq "html" ) { return $body->{content}; } - $self->env->log->warn("No HTML body found!"); + $self->log->warn("No HTML body found!"); return ''; } sub get_plain_body { my ($self, $url, $auth) = @_; - my $log = $self->env->log; + my $log = $self->log; $log->debug("attempting to get plain body"); $auth->{Prefer} = 'outlook.body-content-type="text"'; my $tx = $self->ua->get($url => $auth); @@ -230,7 +229,7 @@ sub get_plain_body { sub get_attachments { my ($self, $id) = @_; - my $log = $self->env->log; + my $log = $self->log; my $url = join('', $self->graphurl, '/messages/',$id,'/attachments'); @@ -270,7 +269,7 @@ sub get_mime { $url .= '/$value'; # will retrieve the mime version of the email $auth = $self->build_auth_token if (! defined $auth); - my $log = $self->env->log; + my $log = $self->log; $log->debug("Getting MIME message with $url"); my $tx = $self->ua->get($url => $auth); @@ -341,7 +340,7 @@ sub from_permitted_sender { my $self = shift; my $from = shift; my @oksenders = @{$self->permitted_senders}; - my $log = $self->env->log; + my $log = $self->log; # each permitted sender can be a regex, # a '*' match all wildcard, or and explicit diff --git a/lib/Scot/Inbox/Msgraph/Cursor.pm b/lib/Scot/Inbox/Msgraph/Cursor.pm index d85a5f4..5d1bf8d 100644 --- a/lib/Scot/Inbox/Msgraph/Cursor.pm +++ b/lib/Scot/Inbox/Msgraph/Cursor.pm @@ -14,12 +14,8 @@ has ids => ( } ); -has env => ( - is => 'ro', isa => 'Scot::Env', required => 1 -); - has msgraph => ( - is => 'rw', isa => 'Scot::Email::MSGraph', required => 1 + is => 'rw', isa => 'Scot::Inbox::Msgraph', required => 1 ); sub count { diff --git a/lib/Scot/Inbox/Processor.pm b/lib/Scot/Inbox/Processor.pm index 9aef1a8..6d9e6c6 100644 --- a/lib/Scot/Inbox/Processor.pm +++ b/lib/Scot/Inbox/Processor.pm @@ -106,7 +106,7 @@ sub delete ($self) { $log->logdie("Failed to create $class, unable to process inbox"); } - my $cursor = $client->get_mail; + my $cursor = $client->get_before_cursor; my $count = $cursor->count; my $index = 0; my $target = $config->{scot_queue};