[Bps-public-commit] app-wsgetmail branch, master, updated. 5dc806fe4e65f5bf8c65d7268fdcddaa2de84bfb

Aaron Trevena ast at bestpractical.com
Thu Aug 6 06:34:34 EDT 2020


The branch, master has been updated
       via  5dc806fe4e65f5bf8c65d7268fdcddaa2de84bfb (commit)
      from  665f34d79f5f102f73e5230d83bb0f5813005f8a (commit)

Summary of changes:
 Changes                           |   4 +-
 Makefile.PL                       |   8 +-
 README                            |  16 ++--
 lib/App/wsgetmail.pm              |  24 ++----
 lib/App/wsgetmail/MS360.pm        |  85 +++++++++++++++++++++
 lib/App/wsgetmail/MS360/Client.pm | 157 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 263 insertions(+), 31 deletions(-)
 create mode 100644 lib/App/wsgetmail/MS360.pm
 create mode 100644 lib/App/wsgetmail/MS360/Client.pm

- Log -----------------------------------------------------------------
commit 5dc806fe4e65f5bf8c65d7268fdcddaa2de84bfb
Author: Aaron Trevena <aaron at aarontrevena.co.uk>
Date:   Thu Aug 6 11:34:05 2020 +0100

    initial implementation

diff --git a/Changes b/Changes
index 300ae96..c8fb631 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,5 @@
 Revision history for App-wsgetmail
 
-0.01    Date/time
-        First version, released on an unsuspecting world.
+0.01    20/05/20
+        Initial Implementation
 
diff --git a/Makefile.PL b/Makefile.PL
index 7f38018..f11a543 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -17,8 +17,12 @@ my %WriteMakefileArgs = (
         'Test::More' => '0',
     },
     PREREQ_PM => {
-        #'ABC'              => '1.6',
-        #'Foo::Bar::Module' => '5.0401',
+        'Azure::AD::ClientCredentials',
+        'LWP::UserAgent',
+        'URI::Escape',
+        'URI::Query',
+        'Moo',
+        'JSON',
     },
     dist  => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
     clean => { FILES => 'App-wsgetmail-*' },
diff --git a/README b/README
index 38cb7ec..43c68c3 100644
--- a/README
+++ b/README
@@ -1,16 +1,10 @@
 App-wsgetmail
 
-The README is used to introduce the module and provide instructions on
-how to install the module, any machine dependencies it may have (for
-example C compilers and installed libraries) and any other information
-that should be provided before the module is installed.
-
-A README file is required for CPAN modules since CPAN extracts the README
-file from a module distribution so that people browsing the archive
-can use it to get an idea of the module's uses. It is usually a good idea
-to provide version information here so that people can decide whether
-fixes for the module are worth downloading.
+A simple command line application/script to fetch mail from the cloud
+using webservices instead of IMAP and POP.
 
+Configurable to mark fetched mail as read, or to delete it, and with
+configurable action with the fetched email.
 
 INSTALLATION
 
@@ -45,7 +39,7 @@ You can also look for information at:
 
 LICENSE AND COPYRIGHT
 
-This software is Copyright (c) 2020 by Aaron Trevena.
+This software is Copyright (c) 2020 by Best Practical Solutions, LLC.
 
 This is free software, licensed under:
 
diff --git a/lib/App/wsgetmail.pm b/lib/App/wsgetmail.pm
index c9dc090..4cf9dd4 100644
--- a/lib/App/wsgetmail.pm
+++ b/lib/App/wsgetmail.pm
@@ -6,7 +6,7 @@ use warnings;
 
 =head1 NAME
 
-App::wsgetmail - The great new App::wsgetmail!
+App::wsgetmail - Fetch mail from the cloud using webservices
 
 =head1 VERSION
 
@@ -16,23 +16,21 @@ Version 0.01
 
 our $VERSION = '0.01';
 
+=head1 DESCRIPTION
 
-=head1 SYNOPSIS
+A simple command line application/script to fetch mail from the cloud
+using webservices instead of IMAP and POP.
 
-Quick summary of what the module does.
+Configurable to mark fetched mail as read, or to delete it, and with
+configurable action with the fetched email.
 
-Perhaps a little code snippet.
+=head1 SYNOPSIS
 
     use App::wsgetmail;
 
     my $foo = App::wsgetmail->new();
     ...
 
-=head1 EXPORT
-
-A list of functions that can be exported.  You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
-
 =head1 SUBROUTINES/METHODS
 
 =head2 function1
@@ -46,9 +44,6 @@ sub function1 {
 
 =cut
 
-sub function2 {
-}
-
 =head1 AUTHOR
 
 Aaron Trevena, C<< <ast at bestpractical.com> >>
@@ -59,9 +54,6 @@ Please report any bugs or feature requests to C<bug-app-wsgetmail at rt.cpan.org
 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-wsgetmail>.  I will be notified, and then you'll
 automatically be notified of progress on your bug as I make changes.
 
-
-
-
 =head1 SUPPORT
 
 You can find documentation for this module with the perldoc command.
@@ -97,7 +89,7 @@ L<https://metacpan.org/release/App-wsgetmail>
 
 =head1 LICENSE AND COPYRIGHT
 
-This software is Copyright (c) 2020 by Aaron Trevena.
+This software is Copyright (c) 2020 by Best Practical Solutions, LLC
 
 This is free software, licensed under:
 
diff --git a/lib/App/wsgetmail/MS360.pm b/lib/App/wsgetmail/MS360.pm
new file mode 100644
index 0000000..b922871
--- /dev/null
+++ b/lib/App/wsgetmail/MS360.pm
@@ -0,0 +1,85 @@
+package App::wsgetmail::MS360;
+
+=head1 NAME
+
+App::wsgetmail::MS360 - Fetch mail from Microsoft 360
+
+=head1 DESCRIPTION
+
+Fetch mail from Microsoft 360 mailboxes using the Graph REST API
+
+=cut
+
+use strict;
+use Moo;
+
+use Azure::AD::ClientCredentials;
+use URI::Escape;
+use URI::Query;
+use JSON;
+
+
+=head1 ATTRIBUTES
+
+=over 4
+
+=item client - 
+
+=back
+
+=cut
+
+has client => (
+    isa => 'App::wsgetmail::MS360::Client',
+    is => 'rw'
+);
+
+
+=head1 METHODS
+
+=head2 get_message_list
+
+=cut
+
+sub get_message_list {
+    my ($self, $username) = @_;
+    # add error handling!
+    my $response = $self->ua->get_request('users', $username, 'messages');
+    my $message_list = decode_json( $response->content );
+    return $message_list;
+}
+
+=head2 get_message_mime_content
+
+=cut
+
+sub get_message_mime_content {
+    my ($self, $username, $message_id) = @_;
+    my $response = $self->ua->get_request('users', $username, 'messages', $message_id, '$value');
+    my $raw_message = $response->content;
+    return $raw_message;
+}
+
+
+
+=head1 SEE ALSO
+
+=over 4
+
+=item App::wsgetmail::MS360::Client
+
+=back
+
+=head1 LICENSE AND COPYRIGHT
+
+This software is Copyright (c) 2020 by Best Practical Solutions, LLC
+
+This is free software, licensed under:
+
+  The Artistic License 2.0 (GPL Compatible)
+
+
+=cut
+
+
+1;
diff --git a/lib/App/wsgetmail/MS360/Client.pm b/lib/App/wsgetmail/MS360/Client.pm
new file mode 100644
index 0000000..83069fa
--- /dev/null
+++ b/lib/App/wsgetmail/MS360/Client.pm
@@ -0,0 +1,157 @@
+package App::wsgetmail::MS360::Client;
+
+=head1 NAME
+
+App::wsgetmail::MS360 - Fetch mail from Microsoft 360
+
+=cut
+
+use Moo;
+use LWP::UserAgent;
+use Azure::AD::ClientCredentials;
+
+=head1 DESCRIPTION
+
+Fetch mail from Microsoft 360 mailboxes using the Graph REST API
+=head1 SYNOPSIS
+
+
+=head1 ATTRIBUTES
+
+=over 4
+
+=item ua
+
+=item secret
+
+=item client_id
+
+=item tenant_id
+
+=item credentials
+
+=item access_token
+
+=back
+
+=cut
+
+has ua => (
+    isa => 'LWP::UserAgent',
+    builder   => '_build_authorised_ua',
+    is => 'ro',
+    lazy => 1,
+);
+
+has secret  => (
+    is => 'ro',
+    required => 1,
+);
+
+has client_id => (
+    is => 'ro',
+    required => 1,
+);
+
+has tenant_id => (
+    is => 'ro',
+    required => 1,
+);
+
+has credentials => (
+    is => 'ro',
+    lazy => 1,
+    builder => '_build_credentials',
+);
+
+has access_token => (
+    is => 'ro',
+    lazy => 1,
+    builder => '_build_access_token',
+);
+
+my $graph_v1_url = 'https://graph.microsoft.com/v1.0/';
+
+=head1 METHODS
+
+=head2 build_rest_uir
+
+=cut
+
+sub build_rest_uri {
+    my ($self, @endpoint_parts) = @_;
+    return join('/', $graph_v1_url, @endpoint_parts);
+}
+
+=head2 get_request
+
+=cut
+
+sub get_request {
+    my ($self, $parts) = @_;
+    # add error handling!
+    my $url = $self->build_rest_uri(@$parts);
+    return $self->ua->get($url);
+}
+
+# sub post_request {
+#     my ($self, $path_parts, $post_data) = @_;
+#     my $url = $self->build_rest_uri(@$path_parts);
+#     return $self->ua->post($url,$post_data);
+# }
+
+# sub patch_request {
+#     my ($self, $path_parts, $patch_data) = @_;
+#     my $url = $self->build_rest_uri(@$path_parts);
+#     return $self->ua->patch($url,$patch_data);
+# }
+
+######
+
+sub _build_authorised_ua {
+    my $ua = LWP::UserAgent->new();
+    $ua->default_header( Authorization => $self->access_token() );
+    return $ua;
+}
+
+sub _build_access_token {
+    my $self = shift;
+    my $access_token = $self->credentials->access_token;
+    return $access_token;
+}
+
+sub _build_credentials {
+    my $self = shift;
+    my $creds = Azure::AD::ClientCredentials->new(
+        resource_id => 'https://graph.microsoft.com/',
+        client_id => $self->client_id,
+        secret_id => $self->secret,
+        tenant_id => $self->tenant_id
+    );
+    return $creds;
+}
+
+
+
+
+=head1 SEE ALSO
+
+=over 4
+
+=item App::wsgetmail::Client
+
+=back
+
+=head1 LICENSE AND COPYRIGHT
+
+This software is Copyright (c) 2020 by Best Practical Solutions, LLC
+
+This is free software, licensed under:
+
+  The Artistic License 2.0 (GPL Compatible)
+
+
+=cut
+
+
+1;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list