File: IMAP4.pod

package info (click to toggle)
libmail-box-perl 2.068-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,576 kB
  • ctags: 1,493
  • sloc: perl: 22,358; makefile: 49
file content (604 lines) | stat: -rw-r--r-- 12,556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604

=head1 NAME

Mail::Transport::IMAP4 - proxy to Mail::IMAPClient


=head1 INHERITANCE

 Mail::Transport::IMAP4
   is a Mail::Transport::Receive
   is a Mail::Transport
   is a Mail::Reporter


=head1 SYNOPSIS

 my $imap = Mail::Transport::IMAP4->new(...);
 my $message = $imap->receive($id);
 $imap->send($message);


=head1 DESCRIPTION

****** UNDER DEVELOPMENT *****, please help testing

The IMAP4 protocol is quite complicated: it is feature rich and allows
verious asynchronous actions.  The main document describing IMAP is
rfc3501 (which obsoleted the original specification of protocol 4r1
in rfc2060 in March 2003).

This package, as part of MailBox, does not implement the actual
protocol itself but uses Mail::IMAPClient to do the work.  The task
for this package is to hide as many differences between that module's
interface and the common L<Mail::Box|Mail::Box> folder types.  Multiple
L<Mail::Box::IMAP4|Mail::Box::IMAP4> folders can share one L<Mail::Transport::IMAP4|Mail::Transport::IMAP4>
connection.



=head1 METHODS


$obj-E<gt>B<url>

=over 4

Represent this imap4 connection as URL.

=back

=head2 Constructors


Mail::Transport::IMAP4-E<gt>B<new>(OPTIONS)

=over 4

Create the IMAP connection to the server.  IMAP servers can handle
multiple folders for a single user, which means that connections
may get shared.  This is sharing is hidden for the user.

When an C<imap_client> is specified, then the options C<hostname>,
C<port>, C<username>, and C<password> are extracted from it.

 Option      --Defined in     --Default
 authenticate                   'AUTO'
 domain                         <server_name>
 executable    Mail::Transport  undef
 hostname      Mail::Transport  'localhost'
 imap_client                    Mail::IMAPClient
 interval      Mail::Transport  30
 log           Mail::Reporter   'WARNINGS'
 password      Mail::Transport  undef
 port          Mail::Transport  143
 proxy         Mail::Transport  undef
 retry         Mail::Transport  <false>
 timeout       Mail::Transport  120
 trace         Mail::Reporter   'WARNINGS'
 username      Mail::Transport  undef
 via           Mail::Transport  'imap'

. authenticate TYPE|ARRAY-OF-TYPES

=over 4

Authenthication method to L<login()|Mail::Transport::IMAP4/"Protocol [internals]">, which will be passed to
L<Mail::IMAPClient> method authenticate().  See the latter method for
the available types.

=back

. domain WINDOWS_DOMAIN

=over 4

Used for NTLM authentication.

=back

. executable FILENAME

. hostname HOSTNAME|ARRAY-OF-HOSTNAMES

. imap_client OBJECT|CLASS

=over 4

When an OBJECT is supplied, that client will be used for the implementation
of the IMAP4 protocol. Information about server and such are extracted from
the OBJECT to have the accessors to produce correct results. The OBJECT
shall be a L<Mail::IMAPClient|Mail::IMAPClient>.

When a CLASS is given, an object of that type is created for you.  The created
object can be retreived via L<imapClient()|Mail::Transport::IMAP4/"Protocol [internals]">, and than configured as
defined by L<Mail::IMAPClient|Mail::IMAPClient>.

=back

. interval SECONDS

. log LEVEL

. password STRING

. port INTEGER

. proxy PATH

. retry NUMBER|undef

. timeout SECONDS

. trace LEVEL

. username STRING

. via CLASS|NAME

=back

=head2 Receiving mail


$obj-E<gt>B<receive>([UNIQUE-MESSAGE-ID])

=over 4

See L<Mail::Transport::Receive/"Receiving mail">

=back

=head2 Server connection


$obj-E<gt>B<findBinary>(NAME [, DIRECTORIES])

=over 4

See L<Mail::Transport/"Server connection">

=back

$obj-E<gt>B<remoteHost>

=over 4

See L<Mail::Transport/"Server connection">

=back

$obj-E<gt>B<retry>

=over 4

See L<Mail::Transport/"Server connection">

=back

=head2 Attributes


$obj-E<gt>B<authentication>(['AUTO'|TYPE|LIST-OF-TYPES])

=over 4

Returned is a list of pairs (ref arrays) each describing one possible
way to contact the server. Each pair contains a mechanism name and
a challange callback (which may be C<undef>).

The settings are used by L<login()|Mail::Transport::IMAP4/"Protocol [internals]"> to get server access.  The initial
value origins from L<new(authenticate)|Mail::Transport::IMAP4/"METHODS">, but may be changed later.

Available basic TYPES are C<CRAM-MD5>, C<NTLM>, and C<PLAIN>.  With
C<AUTO>, all available types will be tried.  When the Authen::NTLM
is not installed, the C<NTLM> option will silently be skipped.  Be warned
that, because of C<PLAIN>, erroneous username/password combinations will
be passed readible as last attempt!

The C<NTLM> authentication requires Authen::NTLM to be installed.  Other
methods may be added later.  Besides, you may also specify a CODE
reference which implements some authentication.

An ARRAY as TYPE can be used to specify both mechanism as callback.  When
no array is used, callback of the pair is set to C<undef>.  See
L<Mail::IMAPClient/authenticate> for the gory details.

I<Example:> 

 $transporter->authentication('CRAM-MD5', [MY_AUTH => \&c], 'PLAIN');

 foreach my $pair ($transporter->authentication)
 {   my ($mechanism, $challange) = @$pair;
     ...
 }

=back

$obj-E<gt>B<domain>([DOMAIN])

=over 4

Used in NTLM authentication to define the Windows domain which is
accessed.  Initially set by L<new(domain)|Mail::Transport::IMAP4/"METHODS"> and defaults to the
server's name.

=back

=head2 Exchanging Information


=head2 Protocol [internals]

The follow methods handle protocol internals, and should not be used
by a normal user of this class.

$obj-E<gt>B<appendMessage>(MESSAGE, FOLDERNAME)

=over 4

Write the message to the server.

=back

$obj-E<gt>B<createFolder>(NAME)

=over 4

Add a folder.

=back

$obj-E<gt>B<createImapClient>(CLASS)

=over 4

Create an object of CLASS, which extends L<Mail::IMAPClient>.

=back

$obj-E<gt>B<currentFolder>([FOLDERNAME])

=over 4

Be sure that the specific FOLDER is the current one selected.  If the
folder is already selected, no IMAP traffic will be produced.

The boolean return value indicates whether the folder is selectable. It
will return undef if it does not exist.

=back

$obj-E<gt>B<deleteFolder>(NAME)

=over 4

Remove one folder.

=back

$obj-E<gt>B<destroyDeleted>

=over 4

Command the server to delete for real all messages which are flagged to
be deleted.

=back

$obj-E<gt>B<fetch>(ARRAY-OF-MESSAGES, INFO)

=over 4

Get some INFO about the MESSAGES from the server.  The specified messages
shall extend L<Mail::Box::Net::Message|Mail::Box::Net::Message>, Returned is a list
of hashes, each info about one result.  The contents of the hash
differs per INFO, but at least a C<message> field will be present, to
relate to the message in question.

The right folder should be selected before this method is called. When
the connection was lost, C<undef> is returned.  Without any
messages, and empty array is returned.  The retrieval is done by
L<Mail::IMAPClient|Mail::IMAPClient> method C<fetch()>, which is then
parsed.

=back

$obj-E<gt>B<flagsToLabels>(WHAT|FLAGS)

Mail::Transport::IMAP4-E<gt>B<flagsToLabels>(WHAT|FLAGS)

=over 4

In SCALAR context, a hash with labels is returned.  In LIST context, pairs
are returned.

The WHAT parameter can be C<'SET'>, C<'CLEAR'>, or C<'REPLACE'>.  With the
latter, all standard imap flags do not appear in the list will be ignored:
their value may either by set or cleared.  See L<getFlags()|Mail::Transport::IMAP4/"Protocol [internals]">

Unknown flags in LIST are stripped from their backslash and lower-cased.
For instance, '\SomeWeirdFlag' will become `someweirdflag => 1'.

I<Example:> translating IMAP4 flags into MailBox flags


 my @flags  = ('\Seen', '\Flagged');
 my $labels = Mail::Transport::IMAP4->flags2labels(SET => @flags);

=back

$obj-E<gt>B<folders>([FOLDERNAME])

=over 4

Returns a list of folder names which are sub-folders of the specified
FOLDERNAME.  Without FOLDERNAME, the top-level foldernames are returned.

=back

$obj-E<gt>B<getFields>(UID, NAME, [NAME, ...])

=over 4

Get the records with the specified NAMES from the header.  The header
fields are returned as list of L<Mail::Message::Field::Fast|Mail::Message::Field::Fast> objects.
When the name is C<ALL>, the whole header is returned.

=back

$obj-E<gt>B<getFlags>(FOLDER, ID)

=over 4

Returns the values of all flags which are related to the message with the
specified ID.  These flags are translated into the names which are
standard for the MailBox suite.

A HASH is returned.  Names which do not appear will also provide
a value in the returned: the negative for the value is it was present.

=back

$obj-E<gt>B<getMessageAsString>(MESSAGE|UID)

=over 4

Returns the whole text of the specified message: the head and the body.

=back

$obj-E<gt>B<ids>

=over 4

Returns a list of UIDs which are defined by the IMAP server.

=back

$obj-E<gt>B<imapClient>

=over 4

Returns the object which implements the IMAP4 protocol, an instance
of a Mail::IMAPClient, which is logged-in and ready to use.

If the contact to the server was still present or could be established,
an Mail::IMAPClient object is returned.  Else, C<undef> is returned and
no further actions should be tried on the object.

=back

$obj-E<gt>B<labelsToFlags>(HASH|PAIRS)

Mail::Transport::IMAP4-E<gt>B<labelsToFlags>(HASH|PAIRS)

=over 4

Convert MailBox labels into IMAP flags.  Returned is a string.  Unsupported
labels are ignored.

=back

$obj-E<gt>B<listFlags>

=over 4

Returns all predefined flags as list.

=back

$obj-E<gt>B<login>

=over 4

Establish a new connection to the IMAP4 server, using username and password.

=back

$obj-E<gt>B<setFlags>(ID, LABEL, VALUE, [LABEL, VALUE], ...)

=over 4

Change the flags on the message which are represented by the label.  The
value which can be related to the label will be lost, because IMAP only
defines a boolean value, where MailBox labels can contain strings.

Returned is a list of LABEL=>VALUE pairs which could not be send to
the IMAP server.  These values may be cached in a different way.

=back

=head2 Error handling


$obj-E<gt>B<AUTOLOAD>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<addReport>(OBJECT)

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])

Mail::Transport::IMAP4-E<gt>B<defaultTrace>([LEVEL]|[LOGLEVEL, TRACELEVEL]|[LEVEL, CALLBACK])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<errors>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<log>([LEVEL [,STRINGS]])

Mail::Transport::IMAP4-E<gt>B<log>([LEVEL [,STRINGS]])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<logPriority>(LEVEL)

Mail::Transport::IMAP4-E<gt>B<logPriority>(LEVEL)

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<logSettings>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<notImplemented>

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<report>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<reportAll>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<trace>([LEVEL])

=over 4

See L<Mail::Reporter/"Error handling">

=back

$obj-E<gt>B<warnings>

=over 4

See L<Mail::Reporter/"Error handling">

=back

=head2 Cleanup


$obj-E<gt>B<DESTROY>

=over 4

The connection is cleanly terminated when the program is
terminated.

=back

$obj-E<gt>B<inGlobalDestruction>

=over 4

See L<Mail::Reporter/"Cleanup">

=back




=head1 DIAGNOSTICS

I<Error:> Cannot connect to $host:$port for IMAP4: $!


I<Error:> IMAP cannot connect to $host: $@


I<Notice:> IMAP4 authenication $mechanism to $host:$port successful


I<Error:> IMAP4 requires a username and password


I<Error:> IMAP4 username $username requires a password


I<Error:> Package $package does not implement $method.

Fatal error: the specific package (or one of its superclasses) does not
implement this method where it should. This message means that some other
related classes do implement this method however the class at hand does
not.  Probably you should investigate this and probably inform the author
of the package.






=head1 REFERENCES

See the MailBox website at L<http://perl.overmeer.net/mailbox/> for more details.

=head1 COPYRIGHTS

Distribution version 2.068.
Written by Mark Overmeer (mark@overmeer.net).  See the ChangeLog for
other contributors.

Copyright (c) 2001-2006 by the author(s). All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.