NAME
App::wsgetmail::MS365 - Fetch mail from Microsoft 365
SYNOPSIS
my $ms365 = App::wsgetmail::MS365->new({
client_id => "client UUID",
tenant_id => "tenant UUID",
secret => "random secret token",
global_access => 1,
folder => "Inbox",
post_fetch_action => "mark_message_as_read",
debug => 0,
response_matrix => hash,
})
DESCRIPTION
Moo class providing methods to connect to and fetch mail from Microsoft 365 mailboxes using the Graph REST API.
ATTRIBUTES
You must provide client_id, tenant_id, post_fetch_action, and authentication details. If global_access is false (the default), you must provide username and user_password. If you set global_access to a true value, you must provide secret.
client_id
A string with the UUID of the client application to use for authentication.
tenant_id
A string with the UUID of your Microsoft 365 tenant to use for authentication.
username
A string with a username email address. If global_access is false (the default), the client authenticates with this username. If global_access is true, the client accesses this user's mailboxes.
user_password
A string with the user password to use for authentication without global access.
folder
A string with the name of the email folder to read. Default "Inbox".
global_access
A boolean. If false (the default), the client will authenticate using username and user_password. If true, the client will authenticate using its secret token.
size_limit
An integer. Messages with size in bytes bigger than it will be skipped.
Default is 0, which means no limit.
body_size_limit
An integer. Messages with body size in bytes bigger than it will be skipped.
Default is 0, which means no limit.
secret
A string with the client secret to use for global authentication. This should look like a long string of completely random characters, not a UUID or other recognizable format.
post_fetch_action
A string with the name of a method to call after reading a message. You probably want to pass either "mark_message_as_read" or "delete_message". In principle, you can pass the name of any method that accepts a message ID string argument.
stripcr
A boolean. If true, the message content will have CRLF line terminators converted to LF line terminators.
debug
A boolean. If true, the object will issue a warning with details about each request it issues.
response_matrix
A hash describing special handling for combinations of API calls and non-success HTTP response codes.
The recognized API call labels, based on the Perl internal method names, are:
- get_message_mime_content
- delete_message
- mark_message_as_read
- get_folder_details
- _fetch_messages
- _get_message_list
Instead of one of these API call labels default can be used to specify the behavior for all labels without a value specified for that code.
In addition to specific response codes it is also valid to use xx as the last two digits of the code to match all codes with the same first digit, except where a specific code has its own value.
The lookup priority order is:
The only value with defined behavior is ignore, which indicates that nothing should be logged and that the code should be treated as success as closely as possible.
The defaults in App::wsgetmail could be represented as:
$example_response_matrix = {
delete_message => { '400' => 'ignore', '404' => 'ignore' },
default => { '5xx' => 'ignore' },
};
METHODS
new
Class constructor method, returns new App::wsgetmail::MS365 object
get_next_message
Object method, returns the next message as an App::wsgetmail::MS365::Message object if there is one.
Will lazily fetch messages until the list is exhausted.
get_message_mime_content
Object method, takes message id and returns filename of fetched raw mime file for that message.
delete_message
Object method, takes message id and deletes that message from the outlook365 mailbox
mark_message_as_read
Object method, takes message id and marks that message as read in the outlook365 mailbox
get_folder_details
Object method, returns hashref of details of the configured mailbox folder.
AUTHOR
Best Practical Solutions, LLC <modules@bestpractical.com>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2020 by Best Practical Solutions, LLC.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991