line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EWS::Client; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
14175
|
$EWS::Client::VERSION = '1.143070'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
220
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with qw/ |
8
|
|
|
|
|
|
|
EWS::Client::Role::SOAP |
9
|
|
|
|
|
|
|
EWS::Client::Role::GetItem |
10
|
|
|
|
|
|
|
EWS::Client::Role::FindItem |
11
|
|
|
|
|
|
|
EWS::Client::Role::FindFolder |
12
|
|
|
|
|
|
|
EWS::Client::Role::GetFolder |
13
|
|
|
|
|
|
|
EWS::Client::Role::ExpandDL |
14
|
|
|
|
|
|
|
/; |
15
|
|
|
|
|
|
|
use EWS::Client::Contacts; |
16
|
|
|
|
|
|
|
use EWS::Client::Calendar; |
17
|
|
|
|
|
|
|
use EWS::Client::Folder; |
18
|
|
|
|
|
|
|
use EWS::Client::DistributionList; |
19
|
|
|
|
|
|
|
use URI::Escape (); |
20
|
|
|
|
|
|
|
use Log::Report; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has username => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'Str', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has password => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has server => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
required => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has contacts => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
isa => 'EWS::Client::Contacts', |
43
|
|
|
|
|
|
|
lazy_build => 1, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _build_contacts { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
return EWS::Client::Contacts->new({ client => $self }); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has calendar => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
isa => 'EWS::Client::Calendar', |
54
|
|
|
|
|
|
|
lazy_build => 1, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_calendar { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
return EWS::Client::Calendar->new({ client => $self }); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has folders => ( |
63
|
|
|
|
|
|
|
is => 'ro', |
64
|
|
|
|
|
|
|
isa => 'EWS::Client::Folder', |
65
|
|
|
|
|
|
|
lazy_build => 1, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _build_folders { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
return EWS::Client::Folder->new({ client => $self }); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has distribution_list => ( |
74
|
|
|
|
|
|
|
is => 'ro', |
75
|
|
|
|
|
|
|
isa => 'EWS::Client::DistributionList', |
76
|
|
|
|
|
|
|
lazy_build => 1, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _build_distribution_list { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
return EWS::Client::DistributionList->new({ client => $self }); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub BUILDARGS { |
85
|
|
|
|
|
|
|
my ($class, @rest) = @_; |
86
|
|
|
|
|
|
|
my $params = (scalar @rest == 1 ? $rest[0] : {@rest}); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# collect EWS password from environment as last resort |
89
|
|
|
|
|
|
|
$params->{password} ||= $ENV{EWS_PASS}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return $params; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub BUILD { |
95
|
|
|
|
|
|
|
my ($self, $params) = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
if ($self->use_negotiated_auth) { |
98
|
|
|
|
|
|
|
die "please install LWP::Authen::Ntlm" |
99
|
|
|
|
|
|
|
unless eval { require LWP::Authen::Ntlm && $LWP::Authen::Ntlm::VERSION }; |
100
|
|
|
|
|
|
|
die "please install Authen::NTLM" |
101
|
|
|
|
|
|
|
unless eval { require Authen::NTLM && $Authen::NTLM::VERSION }; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# change email style username to win-domain style |
104
|
|
|
|
|
|
|
if ($self->username =~ m/(.+)@(.+)/) { |
105
|
|
|
|
|
|
|
$self->username( $2 .'\\'. $1 ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
|
|
|
|
|
|
# URI escape the username and password |
110
|
|
|
|
|
|
|
$self->password( URI::Escape::uri_escape($self->password) ); |
111
|
|
|
|
|
|
|
$self->username( URI::Escape::uri_escape($self->username) ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
116
|
|
|
|
|
|
|
no Moose; |
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# ABSTRACT: Microsoft Exchange Web Services Client |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |
123
|
|
|
|
|
|
|
=pod |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
EWS::Client - Microsoft Exchange Web Services Client |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
version 1.143070 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SYNOPSIS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Set up your Exchange Web Services client. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
use EWS::Client; |
138
|
|
|
|
|
|
|
use DateTime; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $ews = EWS::Client->new({ |
141
|
|
|
|
|
|
|
server => 'exchangeserver.example.com', |
142
|
|
|
|
|
|
|
username => 'oliver', |
143
|
|
|
|
|
|
|
password => 's3krit', # or set in $ENV{EWS_PASS} |
144
|
|
|
|
|
|
|
}); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Then perform operations on the Exchange server: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $entries = $ews->calendar->retrieve({ |
149
|
|
|
|
|
|
|
start => DateTime->now(), |
150
|
|
|
|
|
|
|
end => DateTime->now->add( months => 1 ), |
151
|
|
|
|
|
|
|
}); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
print "I retrieved ". $entries->count ." items\n"; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
while ($entries->has_next) { |
156
|
|
|
|
|
|
|
print $entries->next->Subject, "\n"; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $contacts = $ews->contacts->retrieve; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 DESCRIPTION |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This module acts as a client to the Microsoft Exchange Web Services API. From |
164
|
|
|
|
|
|
|
here you can access calendar and contact entries in a nicely abstracted |
165
|
|
|
|
|
|
|
fashion. Query results are generally available in an iterator and convenience |
166
|
|
|
|
|
|
|
methods exist to access the properties of each entry. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHENTICATION |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Depending on the configuration of the Microsoft Exchange server, you can use |
171
|
|
|
|
|
|
|
either HTTP Basic Access Auth, or NTLM Negotiated Auth, from this module. The |
172
|
|
|
|
|
|
|
default is HTTP Basic Access Auth, so if using NTLM, the following additional |
173
|
|
|
|
|
|
|
option to C<new()> is required: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
use_negotiated_auth => 1, |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 METHODS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 EWS::Client->new( \%arguments ) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Instantiates a new EWS client. There won't be any connection to the server |
182
|
|
|
|
|
|
|
until you call one of the calendar or contacts retrieval methods. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item C<server> => Fully Qualified Domain Name (required) |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The host name of the Exchange server to which the module should connect. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item C<username> => String (required) |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The account username under which the module will connect to Exchange. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
For Basic Access Auth this value will be URI encoded by the module, meaning |
195
|
|
|
|
|
|
|
you don't have to worry about escaping any special characters. For NTLM |
196
|
|
|
|
|
|
|
Negotiated Auth, pass a C<user@domain> format username and it will |
197
|
|
|
|
|
|
|
automatically be converted into Windows' C<domain\user> format for you. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C<password> => String OR via C<$ENV{EWS_PASS}> (required) |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
The password of the account under which the module will connect to Exchange. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
For Basic Access Auth this value will be URI encoded by the module. You can |
204
|
|
|
|
|
|
|
also provide the password via the C<EWS_PASS> environment variable. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item C<use_negotiated_auth> => True or False value |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
The module will assume you wish to use HTTP Basic Access Auth, in which case |
209
|
|
|
|
|
|
|
you should enable that in your Exchange server. However for negotiated methods |
210
|
|
|
|
|
|
|
such as NTLM set this to a True value. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item C<schema_path> => String (optional) |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
A folder on your file system which contains the WSDL and two further Schema |
215
|
|
|
|
|
|
|
files (messages, and types) which describe the Exchange 2007 Web Services SOAP |
216
|
|
|
|
|
|
|
API. They are shipped with this module so your providing this is optional. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item C<server_version> => String (optional) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
In each request to the server is specified the API version we expect to use. |
221
|
|
|
|
|
|
|
By default this is set to C<Exchange2007_SP1> but you have the opportunity to |
222
|
|
|
|
|
|
|
set it to C<Exchange2007> if you wish using this option. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 $ews->calendar() |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Retrieves the L<EWS::Client::Calendar> object which allows search and |
229
|
|
|
|
|
|
|
retrieval of calendar entries and their various properties. See that linked |
230
|
|
|
|
|
|
|
manual page for more details. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 $ews->contacts() |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Retrieves the L<EWS::Client::Contacts> object which allows retrieval of |
235
|
|
|
|
|
|
|
contact entries and their telephone numbers. See that linked manual page for |
236
|
|
|
|
|
|
|
more details. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 $ews->folders() |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Retrieves the L<EWS::Client::Folder> object which allows retrieval of |
241
|
|
|
|
|
|
|
mailbox folder entries and their sizes. See that linked manual page for |
242
|
|
|
|
|
|
|
more details. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 $ews->dls() |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Retrieves the L<EWS::Client::DistributionList> object which allows retrieval of |
247
|
|
|
|
|
|
|
distribution list entries and their email addresses and names. See that linked |
248
|
|
|
|
|
|
|
manual page for more details. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 KNOWN ISSUES |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over 4 |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * No handling of time zone information, sorry. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * The C<SOAPAction> Header might be wrong for Exchange 2010. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=back |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 THANKS |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
To Greg Shaw for sending patches for NTLM Authentication support and User |
263
|
|
|
|
|
|
|
Impersonation. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 AUTHOR |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Oliver Gorwits <oliver@cpan.org> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
This software is copyright (c) 2014 by University of Oxford. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
274
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|