Subversion Repositories sysadmin_scripts

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 rodolico 1
package Mail::IMAPClient;
2
 
3
# $Id: IMAPClient.pod,v 20001010.1 2003/06/12 21:35:53 dkernen Exp $
4
 
5
$Mail::IMAPClient::VERSION = '2.2.7';
6
$Mail::IMAPClient::VERSION = '2.2.7';  	# do it twice to make sure it takes
7
 
8
=head1 NAME 
9
 
10
Mail::IMAPClient - An IMAP Client API
11
 
12
=head1 DESCRIPTION 
13
 
14
This module provides methods implementing the IMAP protocol. It allows
15
perl scripts to interact with IMAP message stores.
16
 
17
The module is used by constructing or instantiating a new IMAPClient
18
object via the L<new> constructor method. Once the object has been
19
instantiated, the L<connect> method is either implicitly or explicitly
20
called. At that point methods are available that implement the IMAP
21
client commands as specified in I<RFC2060>. When processing is
22
complete, the I<logoff> object method should be called.
23
 
24
This documentation is not meant to be a replacement for RFC2060, and
25
the wily programmer will have a copy of that document handy when coding
26
IMAP clients. 
27
 
28
Note that this documentation uses the term I<folder> in place of
29
RFC2060's use of I<mailbox>. This documentation reserves the use of the
30
term I<mailbox> to refer to the set of folders owned by a specific IMAP
31
id.
32
 
33
RFC2060 defines four possible states for an IMAP connection: not
34
authenticated, authenticated, selected, and logged out. These
35
correspond to the B<IMAPClient> constants C<Connected>,
36
C<Authenticated>, C<Selected>, and C<Unconnected>, respectively. These
37
constants are implemented as class methods, and can be used in
38
conjunction with the L<Status> method to determine the status of an
39
B<IMAPClient> object and its underlying IMAP session. Note that an
40
B<IMAPClient> object can be in the C<Unconnected> state both before a
41
server connection is made and after it has ended. This differs slightly
42
from RFC2060, which does not define a pre-connection status. For a
43
discussion of the methods available for examining the B<IMAPClient>
44
object's status, see the section labeled L<"Status Methods">, below.
45
 
46
=head2 Advanced Authentication Mechanisms
47
 
48
RFC2060 defines two commands for authenticating to an IMAP server: LOGIN for
49
plain text authentication and AUTHENTICATE for more secure authentication
50
mechanisms. Currently Mail::IMAPClient supports CRAM-MD5 and plain text 
51
authentication. There are also a number of methods and parameters that you 
52
can use to build your own authentication mechanism. Since this topic is a source
53
of many questions, I will provide a quick overview here. All of the methods and
54
parameters discussed here are described in more detail elsewhere in this document;
55
this section is meant to help you get started.
56
 
57
First of all, if you just want to do plain text authentication and your server is
58
okay with that idea then you don't even need to read this section. 
59
 
60
Second of all, the intent of this section is to help you implement the authentication
61
mechanism of your choice, but you will have to understand how that mechanism works.
62
There are I<lots> of authentication mechanisms and most of them are not available to
63
me to test with for one reason or another. Even if this section does not answer
64
all of your authentication questions it I<does> contain all the answers that I have,
65
which I admit are scant.
66
 
67
Third of all, if you manage to get any advanced authentication mechanisms to work then
68
please consider donating them to this module. I don't quite have a framework visualized
69
for how different authentication mechanisms could "plug in" to this module but I would
70
like to eventually see this module distributed with a number of helper modules to 
71
implement various authentication schemes.
72
 
73
The B<Mail::IMAPClient>'s support for add-on authentication mechanisms is pretty straight
74
forward and is built upon several assumptions. Basically you create a callback to be used to
75
provide the response to the server's challenge. The I<Authcallback> parameter contains a 
76
reference to the callback, which  can be an anonymous subroutine or a named subroutine. 
77
Then, you identify your authentication mechanism, either via the I<Authmechanism> parameter 
78
or as an argument to L<authenticate>. 
79
 
80
You may also need to provide a subroutine to encrypt (or whatever) data before it is sent
81
to the server. The I<Prewritemethod> parameter must contain a reference to this subroutine.
82
And, you will need to decrypt data from the server; a reference to the subroutine that 
83
does this must be stored in the I<Readmethod> parameter.
84
 
85
This framework is based on the assumptions that a) the mechanism you are using requires
86
a challenge-response exchange, and b) the mechanism does not fundamentally alter the 
87
exchange between client and server but merely wraps the exchange in a layer of 
88
encryption. It particularly assumes that the line-oriented nature of the IMAP conversation
89
is preserved; authentication mechanisms that break up messages into blocks of a 
90
predetermined size may still be possible but will certainly be more difficult to implement.
91
 
92
Alternatively, if you have access to B<imtest>, a utility included in the Cyrus IMAP
93
distribution, you can use that utility to broker your communications with the IMAP server.
94
This is quite easy to implement. An example, L<examples/imtestExample.pl>, can be found in 
95
the C<examples> subdirectory of the source distribution. 
96
 
97
The following list summarizes the methods and parameters that you may find useful in 
98
implementing advanced autentication:
99
 
100
=over 4
101
 
102
=item authenticate method
103
 
104
This method implements the AUTHENTICATE IMAP client command as documented in RFC2060.
105
If you have set the I<Authmechanism> parameter then the L<login> method will call
106
L<authenticate> instead of doing a clear text login, which is its normal behavior.
107
If you don't want B<login> to call B<authenticate> on your behalf then you can call
108
it yourself. Instead of setting an I<Authmechanism> you can just pass the authmechanism
109
as the first argument to AUTHENTICATE. 
110
 
111
=item Socket Parameter
112
 
113
The I<Socket> parameter holds a reference to the socket connection. Normally this
114
is set for you by the L<connect> method, but if you are implementing an advanced 
115
authentication technique you may choose to set up your own socket connection and then
116
set this parameter manually, bypassing the B<connect> method completely.
117
 
118
=item State, Server, Password, and User Parameters
119
 
120
If you need to make your own connection to the server and perform your authentication
121
manually, then you can set these parameters to keep your B<Mail::IMAPClient> object
122
in sync with its actual status. Of these, only the I<State> parameter is always necessary.
123
The others need to be set only if you think your program will need them later.
124
 
125
=item Authmechanism 
126
 
127
Set this to the value that AUTHENTICATE should send to the server as the authentication
128
mechanism. If you are brokering your own authentication then this parameter may be less
129
useful. It is also not needed by the L<authenticate> method. It exists solely so that you
130
can set it when you call L<new> to instantiate your object. The B<new> method will call
131
L<connect>, who will call L<login>. If B<login> sees that you've set an I<Authmechanism>
132
then it will call B<authenticate>, using your I<Authmechanism> and I<Authcallback> 
133
parameters as arguments.
134
 
135
=item Authcallback 
136
 
137
The I<Authcallback> parameter, if set, should contain a pointer to a subroutine. The
138
L<login> method will use this as the callback argument to the B<authenticate> method
139
if the I<Authmechanism> and I<Authcallback> parameters are both set. If you set
140
I<Authmechanism> but not I<Authcallback> then the default callback for your mechanism
141
will be used. Unfortunately only the CRAM-MD5 authentication mechanism has a default
142
callback; in every other case not supplying the callback results in an error.
143
 
144
Most advanced authentication mechanisms require a challenge-response exchange. After the
145
L<authenticate> method sends "<tag> AUTHENTICATE <Authmechanism>\r\n"  to the IMAP 
146
server, the server replies with a challenge. The B<authenticate> method then invokes 
147
the code whose reference is stored in the I<Authcallback> parameter as follows:
148
 
149
	$Authcallback->($challenge,$imap)
150
 
151
where C<$Authcallback> is the code reference stored in the I<Authcallback> parameter,
152
C<$challenge> is the challenge received from the IMAP server, and C<$imap> is a pointer
153
to the B<Mail::IMAPClient> object. The return value from the I<Authcallback> routine 
154
should be the response to the challenge, and that return value will be sent by the 
155
L<authenticate> method to the server.
156
 
157
=item Readmethod 
158
 
159
The I<Readmethod> parameter points to a routine that will read data from the socket
160
connection. This read method will replace the B<sysread> that would otherwise be
161
performed by B<Mail::IMAPClient>. The replacement method is called with five 
162
arguments. The first is a pointer to the B<Mail::IMAPClient> object; the rest
163
are the four arguments required by the B<sysread> function. Note the third argument
164
(which corresponds to the second argument to B<sysread>) is a buffer to read into;
165
this will be a pointer to a scalar. So for example if your I<Readmethod> were just 
166
going to replace B<sysread> without any intervening processing (which would be silly
167
but this is just an example after all) then you would set your I<Readmethod> like this:
168
 
169
	$imap->Readmethod( 
170
		sub { 
171
			my($self) = shift; 
172
			my($handle,$buffer,$count,$offset) = @_;
173
			return sysread( $handle, $$buffer, $count, $offset);
174
		}
175
	);
176
 
177
Note particularly the double dollar signs in C<$$buffer> in the B<sysread> call; this
178
is not a typo!
179
 
180
=item Prewritemethod
181
 
182
The I<Prewritemethod>, if defined, should contain a pointer to a subroutine.
183
It is called immediately prior to writing to the
184
socket connection. It is called by B<Mail::IMAPClient> with two arguments:
185
a reference to the B<Mail::IMAPClient> object and the ASCII text string to be written. 
186
It should return another string that will be the actual string sent to the IMAP server. 
187
The idea here is that your I<Prewritemethod> will do whatever encryption is necessary 
188
and then return the result to the caller so it in turn can be sent to the server.
189
 
190
=back
191
 
192
=head2 Errors
193
 
194
If you attempt an operation that results in an error, then you can
195
retrieve the text of the error message by using the L<LastError>
196
method. However, since the L<LastError> method is an object method (and
197
not a class method) you will only be able to use this method if you've
198
successfully created your object. Errors in the L<new> method can
199
prevent your object from ever being created. Additionally, if you
200
supply the I<Server>, I<User>, and I<Password> parameters to L<new>, it
201
will attempt to call B<connect> and B<login>, either of which could
202
fail and cause your L<new> method call to return C<undef> (in which case
203
your object will have been created but its reference will have been
204
discarded before ever having been returned to you).
205
 
206
If this happens to you, you can always check C<$@>. B<Mail::IMAPClient>
207
will populate that variable with something useful if either of the
208
L<new>, L<connect>, or L<login> methods fail. In fact, as of version 2,
209
the C<$@> variable will always contain error info from the last error,
210
so you can print that instead of calling L<LastError> if you wish. 
211
 
212
If you run your script with warnings turned on (which I'm sure you'll
213
do at some point because it's such a good idea) then any error message
214
that gets placed into the L<LastError> slot (and/or in C<$@>) will
215
automatically generate a warning. 
216
 
217
=head2 Transactions
218
 
219
RFC2060 requires that each line in an IMAP conversation be prefixed
220
with a tag. A typical conversation consists of the client issuing a
221
tag-prefixed command string, and the server replying with one of more
222
lines of output. Those lines of output will include a command
223
completion status code prefixed by the same tag as the original command
224
string.
225
 
226
The B<IMAPClient> module uses a simple counter to ensure that each
227
client command is issued with a unique tag value. This tag value is
228
referred to by the B<IMAPClient> module as the transaction number. A
229
history is maintained by the B<IMAPClient> object documenting each
230
transaction. The L<Transaction> method returns the number of the last
231
transaction, and can be used to retrieve lines of text from the
232
object's history. 
233
 
234
The L<Clear> parameter is used to control the size of the session
235
history so that long-running sessions do not eat up unreasonable
236
amounts of memory. See the discussion of L<Clear> under L<"Parameters">
237
for more information.
238
 
239
The L<Report> transaction returns the history of the entire IMAP
240
session since the initial connection or for the last I<Clear>
241
transactions. This provides a record of the entire conversation,
242
including client command strings and server responses, and is a
243
wonderful debugging tool as well as a useful source of raw data for
244
custom parsing.
245
 
246
=head1 CLASS METHODS
247
 
248
There are a couple of methods that can be invoked as class methods.
249
Generally they can be invoked as an object method as well, as a
250
convenience to the programmer. (That is, as a convenience to the
251
programmer who wrote this module, as well as the programmers using it.
252
It's easier I<not> to enforce a class method's classiness.) Note that
253
if the L<new> method is called as an object method, the object returned
254
is identical to what have would been returned if L<new> had been called
255
as a class method. It doesn't give you a copy of the original object or
256
anything like that.
257
 
258
=head2 new
259
 
260
Example:
261
 
262
	Mail::IMAPClient->new(%args) or die "Could not new: $@\n";
263
 
264
The L<new> method creates a new instance of an B<IMAPClient> object. If
265
the I<Server> parameter is passed as an argument to B<new>, then B<new>
266
will implicitly call the L<connect> method, placing the new object in
267
the I<Connected> state. If I<User> and I<Password> values are also
268
provided, then L<connect> will in turn call L<login>, and the resulting
269
object will be returned from B<new> in the I<Authenticated> state.
270
 
271
If the I<Server> parameter is not supplied then the B<IMAPClient>
272
object is created in the I<Unconnected> state.
273
 
274
If the B<new> method is passed arguments then those arguments will be
275
treated as a list of key=>value pairs. The key should be one of the
276
parameters as documented under L<"Parameters">, below. 
277
 
278
Here are some examples:
279
 
280
	use Mail::IMAPClient;
281
 
282
	# returns an unconnected Mail::IMAPClient object:
283
	my $imap = Mail::IMAPClient->new;	
284
	#	...				
285
	# intervening code using the 1st object, then:
286
	# (returns a new, authenticated Mail::IMAPClient object)
287
	$imap = Mail::IMAPClient->new(	
288
			Server => $host,
289
			User 	=> $id,
290
			Password=> $pass,
291
			Clear	=> 5,	# Unnecessary since '5' is the default
292
	#		...		# Other key=>value pairs go here
293
	)	or die "Cannot connect to $host as $id: $@";
294
 
295
See also L<"Parameters">, below, and L<"connect"> and L<"login"> for
296
information on how to manually connect and login after B<new>.
297
 
298
=cut
299
 
300
=head2 Authenticated
301
 
302
Example:
303
 
304
	$Authenticated = $imap->Authenticated();
305
	# or:
306
	$imap->Authenticated($new_value);  # But you'll probably never need to do this
307
 
308
returns a value equal to the numerical value associated with an object
309
in the B<Authenticated> state. This value is normally maintained by the
310
B<Mail::IMAPClient> module, so you typically will only query it and 
311
won't need to set it.
312
 
313
B<NOTE:> For a more programmer-friendly idiom, see the L<IsUnconnected>,
314
L<IsConnected>, L<IsAuthenticated>, and L<IsSelected> object methods. You 
315
will usually want to use those methods instead of one of the above.
316
 
317
=head2 Connected
318
 
319
Example:
320
 
321
	$Connected = $imap->Connected();
322
	# or:
323
	$imap->Connected($new_value); # But you'll probably never need to do this 
324
 
325
returns a value equal to the numerical value associated with an object
326
in the B<Connected> state.  This value is normally maintained by the
327
B<Mail::IMAPClient> module, so you typically will only query it and 
328
won't need to set it.
329
 
330
B<NOTE:> For a more programmer-friendly idiom, see the L<IsUnconnected>,
331
L<IsConnected>, L<IsAuthenticated>, and L<IsSelected> object methods. You 
332
will usually want to use those methods instead of one of the above.
333
 
334
=head2 Quote
335
 
336
Example:
337
 
338
	$imap->search(HEADER => 'Message-id' => $imap->Quote($msg_id));
339
 
340
The B<Quote> method accepts a value as an argument.  It returns its 
341
argument as a correctly quoted string or a literal string.
342
 
343
Note that you should not use this on folder names, since methods that accept
344
folder names as an argument will quote the folder name arguments appropriately
345
for you. (Exceptions to this rule are methods that come with IMAP extensions 
346
that are not explicitly supported by B<Mail::IMAPClient>.)
347
 
348
If you are getting unexpected results when running methods with values that 
349
have (or might have) embedded spaces, double quotes, braces, or parentheses, 
350
then you may wish to call B<Quote> to quote these values. You should B<not> 
351
use this method with foldernames or with arguments that are wrapped in quotes 
352
or parens if those quotes or parens are there because the RFC2060 spec requires 
353
them. So, for example, if RFC requires an argument in this format:
354
 
355
	( argument )
356
 
357
and your argument is (or might be) "pennies (from heaven)", then you could just
358
use: 
359
 
360
	$argument = "(" . $imap->Quote($argument) . ")" 
361
 
362
and be done with it.
363
 
364
Of course, the fact that sometimes these characters are sometimes required 
365
delimiters is precisely the reason you must quote them when they are I<not> 
366
delimiting. For example:
367
 
368
 
369
	$imap->Search('SUBJECT',"(no subject)");
370
	# WRONG! Sends this to imap server: 
371
	#<TAG> Search SUBJECT (no subject)\r\n
372
 
373
	$imap->Search('SUBJECT',$imap->Quote("(no subject)"));
374
	# Correct! Sends this to imap server: 
375
	#<TAG> Search SUBJECT "(no subject)"\r\n
376
 
377
 
378
On the other hand:
379
 
380
	$imap->store('+FLAGS',$imap->Quote("(\Deleted)"));
381
	# WRONG! Sends this to imap server: 
382
	#<TAG> [UID] STORE +FLAGS "(\Deleted)"\r\n
383
 
384
 
385
	$imap->store($imap->Quota('+FLAGS'),"(\Deleted)");
386
	# CORRECT! Sends this to imap server: 
387
	#<TAG> [UID] STORE +FLAGS (\Deleted)\r\n
388
 
389
In the above, I had to abandon the many methods available to 
390
B<Mail::IMAPClient> programmers (such as L<delete_message> and all-lowercase 
391
L<search>) for the sake of coming up with an example. However, there are 
392
times when unexpected values in certain places will force you to B<Quote>. 
393
An example is RFC822 Message-id's, which I<usually> don't contain quotes or 
394
parens. So you don't worry about it, until suddenly searches for certain 
395
message-id's fail for no apparent reason. (A failed search is not simply a 
396
search that returns no hits; it's a search that flat out didn't happen.) 
397
This normally happens to me at about 5:00 pm on the one day when I was hoping 
398
to leave on time. (By the way, my experience is that any character that can 
399
possibly find its way into a Message-Id eventually will, so when dealing
400
with these values take proactive, defensive measures from the very start.
401
In fact, as I was typing the above, a buddy of mine came in to ask advice about
402
a logfile parsing routine he was writing in which the fields were delimited
403
by colons. One of the fields was a Message Id, and, you guessed it, some of the
404
message id's in the log had (unescaped!) colons embedded in them and were 
405
screwing up his C<split()>.  So there you have it, it's not just me. This is 
406
everyone's problem.)
407
 
408
=head2 Range
409
 
410
Example:
411
 
412
	my %parsed = $imap->parse_headers(
413
				$imap->Range($imap->messages),
414
				"Date",
415
				"Subject"
416
	);
417
 
418
The B<Range> method will condense a list of message sequence numbers or
419
message UID's into the most compact format supported by RFC2060. It accepts
420
one or more arguments, each of which can be:
421
 
422
=over 8
423
 
424
=item a) a message number,
425
 
426
=item b) a comma-separated list of message numbers,
427
 
428
=item c) a colon-separated range of message numbers (i.e. "$begin:$end")
429
 
430
=item d) a combination of messages and message ranges, separated by commas
431
(i.e. 1,3,5:8,10), or
432
 
433
=item e) a reference to an array whose elements are like I<a)> through I<d)>.
434
 
435
=back
436
 
437
The B<Range> method returns a reference to a B<Mail::IMAPClient::MessageSet>
438
object. The object has all kinds of magic properties, one of which being that
439
if you treat it as if it were just a string it will act like it's just a 
440
string. This means you can ignore its objectivity and just treat it like a
441
string whose value is your message set expressed in compact format.
442
 
443
You may want to use this method if you find that fetch operations on large
444
message sets seem to take a really long time, or if your server rejects
445
these requests with the claim that the input line is too long. You may also
446
want to use this if you need to add or remove messages to your message set
447
and want an easy way to manage this. 
448
 
449
For more information on the capabilities of the returned object reference,
450
see L<Mail::IMAPClient::MessageSet>.
451
 
452
=head2 Rfc2060_date
453
 
454
Example:
455
 
456
	$Rfc2060_date = $imap->Rfc2060_date($seconds);
457
	# or:
458
	$Rfc2060_date = Mail::IMAPClient->Rfc2060_date($seconds);
459
 
460
The B<Rfc2060_date> method accepts one input argument, a number of
461
seconds since the epoch date. It returns an RFC2060 compliant date
462
string for that date (as required in date-related arguments to SEARCH,
463
such as "since", "before", etc.). 
464
 
465
=head2 Rfc822_date
466
 
467
Example:
468
 
469
	$Rfc822_date = $imap->Rfc822_date($seconds);
470
	# or:
471
	$Rfc822_date = Mail::IMAPClient->Rfc822_date($seconds);
472
 
473
The B<Rfc822_date> method accepts one input argument, a number of
474
seconds since the epoch date. It returns an RFC822 compliant date
475
string for that date (without the 'Date:' prefix). Useful for putting
476
dates in message strings before calling L<append>, L<search>, etcetera.
477
 
478
=head2 Selected
479
 
480
Example:
481
 
482
	$Selected = $imap->Selected();
483
	# or:
484
	$imap->Selected($new_value); # But you'll probably never need to do this
485
 
486
returns a value equal to the numerical value associated with an object
487
in the B<Selected> state.  This value is normally maintained by the
488
B<Mail::IMAPClient> module, so you typically will only query it and 
489
won't need to set it.
490
 
491
B<NOTE:> For a more programmer-friendly idiom, see the L<IsUnconnected>,
492
L<IsConnected>, L<IsAuthenticated>, and L<IsSelected> object methods. You 
493
will usually want to use those methods instead of one of the above.
494
 
495
=head2 Strip_cr
496
 
497
Example:
498
 
499
	$Strip_cr = $imap->Strip_cr();
500
	# or:
501
	$imap->Strip_cr($new_value);
502
 
503
The B<Strip_cr> method strips carriage returns from IMAP client command
504
output. Although RFC2060 specifies that lines in an IMAP conversation
505
end with <CR><LF>, it is often cumbersome to have the carriage returns
506
in the returned data. This method accepts one or more lines of text as
507
arguments, and returns those lines with all <CR><LF> sequences changed
508
to <LF>. Any input argument with no carriage returns is returned
509
unchanged. If the first argument (not counting the class name or object
510
reference) is an array reference, then members of that array are
511
processed as above and subsequent arguments are ignored. If the method
512
is called in scalar context then an array reference is returned instead
513
of an array of results.
514
 
515
Taken together, these last two lines mean that you can do something
516
like:
517
 
518
	my @list = $imap->some_imap_method ;
519
        @list = $imap->Strip_cr(@list) ; 
520
	# or: 
521
	my $list = [ $imap->some_imap_method ] ; # returns an array ref
522
	$list = $imap->Strip_cr($list);
523
 
524
B<NOTE: Strip_cr> does not remove new line characters.
525
 
526
=cut
527
 
528
=head2 Unconnected
529
 
530
Example:
531
 
532
	$Unconnected = $imap->Unconnected();
533
	# or:
534
	$imap->Unconnected($new_value);
535
 
536
returns a value equal to the numerical value associated with an object
537
in the B<Unconnected> state.  This value is normally maintained by the
538
B<Mail::IMAPClient> module, so you typically will only query it and 
539
won't need to set it.
540
 
541
B<NOTE:> For a more programmer-friendly idiom, see the L<IsUnconnected>,
542
L<IsConnected>, L<IsAuthenticated>, and L<IsSelected> object methods. You 
543
will usually want to use those methods instead of one of the above.
544
 
545
=head1 OBJECT METHODS
546
 
547
Object methods must be invoked against objects created via the L<new>
548
method. They cannot be invoked as class methods, which is why they are
549
called "object methods" and not "class methods". 
550
 
551
There are basically two types of object methods--mailbox methods, which 
552
participate in the IMAP session's conversation (i.e. they issue IMAP 
553
client commands) and object control methods, which do not result in 
554
IMAP commands but which may affect later commands or provide details
555
of previous ones. This latter group can be further broken down into
556
two types, Parameter accessor methods, which affect the behavior of 
557
future mailbox methods, and Status methods, which report on the affects
558
of previous mailbox methods.
559
 
560
Methods that do not result in new IMAP client commands being issued 
561
(such as the L<Transaction>, L<Status>, and L<History> methods) all 
562
begin with an uppercase letter, to distinguish them from methods that 
563
do correspond to IMAP client commands. Class methods and eponymous 
564
parameter methods likewise begin with an uppercase letter because 
565
they also do not correspond to an IMAP client command.
566
 
567
As a general rule, mailbox control methods return C<undef> on failure 
568
and something besides C<undef> when they succeed. This rule is modified 
569
in the case of methods that return search results. When called in a list 
570
context, searches that do not find matching results return an empty list. 
571
When called in a scalar context, searches with no hits return 'undef' 
572
instead of an array reference. If you want to know why you received no hits,
573
you should check C<$@>, which will be empty if the search was successful
574
but had no matching results but populated with an error message if the 
575
search encountered a problem (such as invalid parameters).
576
 
577
A number of IMAP commands do not have corresponding B<Mail::IMAPClient>
578
methods. Instead, they are implemented via a default method and Perl's 
579
L<AUTOLOAD|perlsub/autoload> facility. If you are looking for a specific
580
IMAP client command (or IMAP extension) and do not see it documented in this
581
pod, then that does not necessarily mean you can not use B<Mail::IMAPClient> to
582
issue the command. In fact, you can issue almost any IMAP client
583
command simply by I<pretending> that there is a corresponding 
584
B<Mail::IMAPClient> method.  See the section on 
585
L<"Other IMAP Client Commands and the Default Object Method">
586
below for details on the default method.
587
 
588
=head1 Mailbox Control Methods
589
 
590
=head2 append
591
 
592
Example:
593
 
594
	my $uid = $imap->append($folder,$msg_text) 
595
		or die "Could not append: $@\n";
596
 
597
The B<append> method adds a message to the specified folder. It takes
598
two arguments, the name of the folder to append the message to, and the
599
text of the message (including headers). Additional arguments are added
600
to the message text, separated with <CR><LF>.
601
 
602
The B<append> method returns the UID of the new message (a true value)
603
if successful, or C<undef> if not, if the IMAP server has the UIDPLUS
604
capability. If it doesn't then you just get true on success and undef
605
on failure.
606
 
607
Note that many servers will get really ticked off if you try to append
608
a message that contains "bare newlines", which is the titillating term
609
given to newlines that are not preceded by a carrage return. To protect
610
against this, B<append> will insert a carrage return before any newline
611
that is "bare". If you don't like this behavior then you can avoid it
612
by not passing naked newlines to B<append>.
613
 
614
Note that B<append> does not allow you to specify the internal date or
615
initial flags of an appended message. If you need this capability then
616
use L<append_string>, below.
617
 
618
=cut
619
 
620
=head2 append_file
621
 
622
Example:
623
 
624
	my $new_msg_uid = $imap->append_file(
625
		$folder,
626
		$filename 
627
		[ , $input_record_separator ]	# optional (not arrayref)
628
	) 	or die "Could not append_file: $@\n";
629
 
630
The B<append_file> method adds a message to the specified folder. It
631
takes two arguments, the name of the folder to append the message to,
632
and the file name of an RFC822-formatted message.
633
 
634
An optional third argument is the value to use for
635
C<input_record_separator>. The default is to use "" for the first read
636
(to get the headers) and "\n" for the rest. Any valid value for C<$/>
637
is acceptable, even the funky stuff, like C<\1024>. (See L<perlvar|perlvar> 
638
for more information on C<$/>). (The brackets in the example indicate
639
that this argument is optional; they do not mean that the argument 
640
should be an array reference.)
641
 
642
The B<append_file> method returns the UID of the new message (a true
643
value) if successful, or C<undef> if not, if the IMAP server has the
644
UIDPLUS capability. If it doesn't then you just get true on success and
645
undef on failure. If you supply a filename that doesn't exist then you
646
get an automatic C<undef>. The L<LastError> method will remind you of this
647
if you forget that your file doesn't exist but somehow manage to
648
remember to check L<LastError>.
649
 
650
In case you're wondering, B<append_file> is provided mostly as a way to
651
allow large messages to be appended without having to have the whole
652
file in memory. It uses the C<-s> operator to obtain the size of the
653
file and then reads and sends the contents line by line (or not,
654
depending on whether you supplied that optional third argument).
655
 
656
=cut
657
 
658
=head2 append_string
659
 
660
Example:
661
 
662
	# brackets indicate optional arguments (not array refs):
663
 
664
	my $uid = $imap->append_string( $folder, $text [ , $flags [ , $date ] ]) 	
665
		or die "Could not append_string: $@\n";
666
 
667
The B<append_string> method adds a message to the specified folder. It
668
requires two arguments, the name of the folder to append the message
669
to, and the text of the message (including headers). The message text
670
must be included in a single string (unlike L<append>, above).
671
 
672
You can optionally specify a third and fourth argument to
673
B<append_string>. The third argument, if supplied, is the list of flags
674
to set for the appended message. The list must be specified as a
675
space-separated list of flags, including any backslashes that may be
676
necessary. The enclosing parentheses that are required by RFC2060 are
677
optional for B<append_string>. The fourth argument, if specified, is
678
the date to set as the internal date. It should be in the format
679
described for I<date_time> fields in RFC2060, i.e. "dd-Mon-yyyy
680
hh:mm:ss +0000".
681
 
682
If you want to specify a date/time but you don't want any flags then
683
specify I<undef> as the third argument.
684
 
685
The B<append_string> method returns the UID of the new message (a true
686
value) if successful, or C<undef> if not, if the IMAP server has the
687
UIDPLUS capability. If it doesn't then you just get true on success and
688
undef on failure.
689
 
690
Note that many servers will get really ticked off if you try to append
691
a message that contains "bare newlines", which is the titillating term
692
given to newlines that are not preceded by a carrage return. To protect
693
against this, B<append_string> will insert a carrage return before any
694
newline that is "bare". If you don't like this behavior then you can
695
avoid it by not passing naked newlines to B<append_string>.
696
 
697
=cut
698
 
699
=head2 authenticate
700
 
701
Example:
702
 
703
	$imap->authenticate($authentication_mechanism, $coderef) 
704
		or die "Could not authenticate: $@\n";
705
 
706
The B<authenticate> method accepts two arguments, an authentication
707
type to be used (ie CRAM-MD5) and a code or subroutine reference to
708
execute to obtain a response. The B<authenticate> method assumes that 
709
the authentication type specified in the first argument follows a
710
challenge-response flow. The B<authenticate> method issues the IMAP
711
Client AUTHENTICATE command and receives a challenge from the server.
712
That challenge (minus any tag prefix or enclosing '+' characters but
713
still in the original base64 encoding) is passed as the only argument
714
to the code or subroutine referenced in the second argument. The return
715
value from the 2nd argument's code is written to the server as is,
716
except that a <CR><NL> sequence is appended if neccessary.
717
 
718
If one or both of the arguments are not specified in the call to
719
B<authenticate> but their corresponding parameters have been set
720
(I<Authmechanism> and I<Authcallback>, respectively) then the parameter
721
values are used. Arguments provided to the method call however will
722
override parameter settings.
723
 
724
If you do not specify a second argument and you have not set the 
725
I<Authcallback> parameter, then the first argument must be
726
one of the authentication mechanisms for which B<Mail::IMAPClient> has
727
built in support. Currently there is only built in support for CRAM-MD5, 
728
but I hope to add more in future releases. 
729
 
730
If you are interested in doing NTLM authentication then please see Mark
731
Bush's L<Authen::NTLM>, which can work with B<Mail::IMAPClient> to
732
provide NTLM authentication.
733
 
734
See also the L<login> method, which is the simplest form of
735
authentication defined by RFC2060.
736
 
737
=cut
738
 
739
=head2 before
740
 
741
Example:
742
 
743
	my @msgs = $imap->before($Rfc2060_date) 
744
		or warn "No messages found before $Rfc2060_date.\n";
745
 
746
The B<before> method works just like the L<"since"> method, below,
747
except it returns a list of messages whose internal system dates are
748
before the date supplied as the argument to the B<before> method.
749
 
750
=cut
751
 
752
=head2 body_string
753
 
754
Example:
755
 
756
	my $string = $imap->body_string($msgId) 
757
		or die "Could not body_string: $@\n";
758
 
759
The B<body_string> method accepts a message sequence number (or a
760
message UID, if the L<Uid> parameter is set to true) as an argument and
761
returns the message body as a string. The returned value contains the
762
entire message in one scalar variable, without the message headers.
763
 
764
=cut
765
 
766
=head2 bodypart_string
767
 
768
Example:
769
 
770
	my $string=$imap->bodypart_string( 	$msgid, $part_number , 
771
						$length ,$offset  
772
	) 	or die "Could not get bodypart string: $@\n";
773
 
774
 
775
The B<bodypart_string> method accepts a message sequence number (or a
776
message UID, if the L<Uid> parameter is set to true) and a body part as
777
arguments and returns the message part as a string. The returned value
778
contains the entire message part (or, optionally, a portion of the part) 
779
in one scalar variable.
780
 
781
If an optional third argument is provided, that argument is the number
782
of bytes to fetch. (The default is the whole message part.) If an
783
optional fourth argument is provided then that fourth argument is the
784
offset into the part at which the fetch should begin. The default is
785
offset zero, or the beginning of the message part.
786
 
787
If you specify an offset without specifying a length then the offset
788
will be ignored and the entire part will be returned.
789
 
790
B<bodypart_string> will return C<undef> if it encounters an error.
791
 
792
=cut
793
 
794
=head2 capability
795
 
796
Example:
797
 
798
	my @features = $imap->capability
799
		or die "Could not determine capability: $@\n";
800
 
801
The B<capability> method returns an array of capabilities as returned
802
by the CAPABILITY IMAP Client command, or a reference to an array of
803
capabilities if called in scalar context. If the CAPABILITY IMAP Client
804
command fails for any reason then the B<capability> method will return
805
C<undef>.
806
 
807
=head2 close
808
 
809
Example:
810
 
811
	$imap->close or die "Could not close: $@\n";
812
 
813
The B<close> method is implemented via the default method and is used
814
to close the currently selected folder via the CLOSE IMAP client
815
command. According to RFC2060, the CLOSE command performs an implicit
816
EXPUNGE, which means that any messages that you've flagged as
817
I<\Deleted> (say, with the L<delete_message> method) will now be
818
deleted. If you haven't deleted any messages then B<close> can be
819
thought of as an "unselect".
820
 
821
Note again that this closes the currently selected folder, not the 
822
IMAP session.
823
 
824
See also L<delete_message>, L<expunge>, and your tattered copy of
825
RFC2060.
826
 
827
=head2 connect
828
 
829
Example:
830
 
831
	$imap->connect or die "Could not connect: $@\n";
832
 
833
The B<connect> method connects an imap object to the server. It returns
834
C<undef> if it fails to connect for any reason. If values are available
835
for the I<User> and I<Password> parameters at the time that B<connect>
836
is invoked, then B<connect> will call the L<login> method after
837
connecting and return the result of the L<login> method to B<connect>'s
838
caller. If either or both of the I<User> and I<Password> parameters are
839
unavailable but the connection to the server succeeds then B<connect>
840
returns a pointer to the B<IMAPClient> object.
841
 
842
The I<Server> parameter must be set (either during L<new> method
843
invocation or via the L<Server> object method) before invoking
844
B<connect>. If the L<Server> parameter is supplied to the L<new> method
845
then B<connect> is implicitly called during object construction.
846
 
847
The B<connect> method sets the state of the object to C<connected> if
848
it successfully connects to the server. It returns C<undef> on failure.
849
 
850
=head2 copy
851
 
852
Example:
853
 
854
	# Here brackets indicate optional arguments:
855
	my $uidList = $imap->copy($folder, $msg_1 [ , ... , $msg_n ]) 
856
	or die "Could not copy: $@\n";
857
 
858
Or:
859
 
860
	# Now brackets indicate an array ref!
861
	my $uidList = $imap->copy($folder, [ $msg_1, ... , $msg_n ]) 
862
	or die "Could not copy: $@\n";
863
 
864
 
865
The B<copy> method requires a folder name as the first argument, and a
866
list of one or more messages sequence numbers (or messages UID's, if
867
the I<UID> parameter is set to a true value). The message sequence
868
numbers or UID's should refer to messages in the currenly selected
869
folder. Those messages will be copied into the folder named in the
870
first argument.
871
 
872
The B<copy> method returns C<undef> on failure and a true value if
873
successful. If the server to which the current Mail::IMAPClient object
874
is connected supports the UIDPLUS capability then the true value
875
returned by B<copy> will be a comma separated list of UID's, which are
876
the UID's of the newly copied messages in the target folder. 
877
 
878
=cut
879
 
880
=head2 create
881
 
882
Example:
883
 
884
	$imap->create($new_folder) 
885
		or die "Could not create $new_folder: $@\n";
886
 
887
The B<create> method accepts one argument, the name of a folder (or
888
what RFC2060 calls a "mailbox") to create. If you specifiy additional
889
arguments to the B<create> method and your server allows additional
890
arguments to the CREATE IMAP client command then the extra argument(s)
891
will be passed to your server. 
892
 
893
If you specifiy additional arguments to the B<create> method and your
894
server does not allow additional arguments to the CREATE IMAP client
895
command then the extra argument(s) will still be passed to your server
896
and the create will fail, so don't do that.
897
 
898
B<create> returns a true value on success and C<undef> on failure, as
899
you've probably guessed.
900
 
901
=head2 date
902
 
903
Example:
904
 
905
	my $date = $imap->date($msg);
906
 
907
 
908
The B<date> method accepts one argument, a message sequence number (or a
909
message UID if the I<Uid> parameter is set to a true value). It returns 
910
the date of message as specified in the message's RFC822 "Date: " header,
911
without the "Date: " prefix.
912
 
913
The B<date> method is a short-cut for:
914
 
915
	my $date = $imap->get_header($msg,"Date");
916
 
917
 
918
=head2 delete
919
 
920
Example:
921
 
922
	$imap->delete($folder) or die "Could not delete $folder: $@\n";
923
 
924
The B<delete> method accepts a single argument, the name of a folder to
925
delete. It returns a true value on success and C<undef> on failure.
926
 
927
=head2 delete_message
928
 
929
Example:
930
 
931
	my @msgs = $imap->seen;
932
	scalar(@msgs) and $imap->delete_message(\@msgs) 
933
		or die "Could not delete_message: $@\n";
934
 
935
The above could also be rewritten like this:
936
 
937
	# scalar context returns array ref
938
	my $msgs = scalar($imap->seen);	
939
 
940
	scalar(@$msgs) and $imap->delete_message($msgs) 
941
		or die "Could not delete_message: $@\n";
942
 
943
Or, as a one-liner:
944
 
945
 
946
	$imap->delete_message( scalar($imap->seen) )
947
		or warn "Could not delete_message: $@\n";
948
	# just give warning in case failure is 
949
	# due to having no 'seen' msgs in the 1st place!
950
 
951
 
952
The B<delete_message> method accepts a list of arguments. If the L<Uid>
953
parameter is not set to a true value, then each item in the list should
954
be either: 
955
 
956
=over 4
957
 
958
=item > a message sequence number,
959
 
960
=item > a comma-separated list of message sequence numbers, 
961
 
962
=item > a reference to an array of message sequence numbers, or
963
 
964
=back
965
 
966
If the L<Uid> parameter is set to a true value, then each item in the
967
list should be either: 
968
 
969
=over 4
970
 
971
=item > a message UID, 
972
 
973
=item > a comma-separated list of UID's, or 
974
 
975
=item > a reference to an array of message UID's.
976
 
977
=back
978
 
979
The messages identified by the sequence numbers or UID's will be
980
deleted. If successful, B<delete_message> returns the number 
981
of messages it was told to delete. However, since the delete is 
982
done by issuing the I<+FLAGS.SILENT> option of the STORE IMAP 
983
client command, there is no guarantee that the delete was successful 
984
for every message. In this manner the B<delete_message> method sacrifices 
985
accuracy for speed. Generally, though, if a single message in a list 
986
of messages fails to be deleted it's because it was already deleted,
987
which is what you wanted anyway so why worry about it? If there is
988
a more severe error, i.e. the server replies "NO", "BAD", or, 
989
banish the thought, "BYE", then B<delete_message> will return C<undef>.
990
 
991
If you must have guaranteed results then use the IMAP STORE client
992
command (via the default method) and use the +FLAGS (\Deleted) option,
993
and then parse your results manually.
994
 
995
Eg: 
996
 
997
	$imap->store($msg_id,'+FLAGS (\Deleted)');
998
	my @results = $imap->History($imap->Transaction);
999
	...			# code to parse output goes here
1000
 
1001
 
1002
 
1003
(Frankly I see no reason to bother with any of that; if a message doesn't get 
1004
deleted it's almost always because it's already not there, which is what you 
1005
want anyway. But 'your milage may vary' and all that.)
1006
 
1007
The B<IMAPClient> object must be in C<Selected> status to use the
1008
B<delete_message> method. 
1009
 
1010
B<NOTE:> All the messages identified in the input argument(s) must be
1011
in the currently selected folder. Failure to comply with this
1012
requirement will almost certainly result in the wrong message(s) being
1013
deleted. This would be a crying shame. 
1014
 
1015
B<NOTE SOME MORE:> In the grand tradition of the IMAP protocol,
1016
deleting a message doesn't actually delete the message. Really. If you
1017
want to make sure the message has been deleted, you need to expunge the
1018
folder (via the L<expunge> method, which is implemented via the default
1019
method). Or at least L<close> it. This is generally considered a
1020
feature, since after deleting a message, you can change your mind and
1021
undelete it at any time before your L<expunge> or L<close>.
1022
 
1023
I<See also:> The L<delete> method, to delete a folder, the L<expunge>
1024
method, to expunge a folder, the L<restore_message> method to undelete
1025
a message, and the L<close> method (implemented here via the default
1026
method) to close a folder. Oh, and don't forget about RFC2060. 
1027
 
1028
=cut
1029
 
1030
=head2 deny_seeing
1031
 
1032
Example:
1033
 
1034
	# Reset all read msgs to unread 
1035
	# (produces error if there are no seen msgs):
1036
	$imap->deny_seeing( scalar($imap->seen) ) 
1037
		or die "Could not deny_seeing: $@\n" ;
1038
 
1039
The B<deny_seeing> method accepts a list of one or more message
1040
sequence numbers, or a single reference to an array of one or more
1041
message sequence numbers, as its argument(s). It then unsets the
1042
"\Seen" flag for those messages (so that you can "deny" that you ever 
1043
saw them). Of course, if the L<Uid> parameter is set to a true value 
1044
then those message sequence numbers should be unique message id's. 
1045
 
1046
Note that specifying C<$imap-E<gt>deny_seeing(@msgs)> is just a
1047
shortcut for specifying C<$imap-E<gt>unset_flag("Seen",@msgs)>. 
1048
 
1049
=cut
1050
 
1051
=head2 disconnect
1052
 
1053
Example:
1054
 
1055
	$imap->disconnect or warn "Could not disconnect: $@\n";
1056
 
1057
Disconnects the B<IMAPClient> object from the server. Functionally
1058
equivalent to the L<logout> method. (In fact it's actually a synonym
1059
for L<logout>.)
1060
 
1061
=cut
1062
 
1063
=head2 done
1064
 
1065
Example:
1066
 
1067
	my $idle = $imap->idle or warn "Couldn't idle: $@\n";
1068
	&goDoOtherThings;
1069
	$imap->done($idle) or warn "Error from done: $@\n";
1070
 
1071
The B<done> method tells the IMAP server that the connection is finished
1072
idling. See L<idle> for more information. It accepts one argument, 
1073
which is the transaction number you received from the previous call
1074
to L<idle>.
1075
 
1076
If you pass the wrong transaction number to B<done> then your perl program
1077
will probably hang. If you don't pass any transaction number to B<done>
1078
then it will try to guess, and if it guesses wrong it will hang.
1079
 
1080
If you call done without previously having called L<idle> then your 
1081
server will mysteriously respond with I<* BAD Invalid tag>.
1082
 
1083
If you try to run any other mailbox method after calling L<idle> but
1084
before calling L<done>, then that method will not only fail but also
1085
take you out of the IDLE state. This means that when you eventually
1086
remember to call B<done> you will just get that I<* BAD Invalid tag>
1087
thing again.
1088
 
1089
=head2 examine
1090
 
1091
Example:
1092
 
1093
	$imap->examine($folder) or die "Could not examine: $@\n";
1094
 
1095
The B<examine> method selects a folder in read-only mode and changes
1096
the object's state to "Selected". The folder selected via the
1097
B<examine> method can be examined but no changes can be made unless it
1098
is first selected via the L<select> method. 
1099
 
1100
The B<examine> method accepts one argument, which is the name of the
1101
folder to select. 
1102
 
1103
=cut
1104
 
1105
=head2 exists
1106
 
1107
Example:
1108
 
1109
	$imap->exists($folder) or warn "$folder not found: $@\n";
1110
 
1111
Accepts one argument, a folder name. Returns true if the folder exists
1112
or false if it does not exist.
1113
 
1114
=cut
1115
 
1116
=head2 expunge
1117
 
1118
Example:
1119
 
1120
	$imap->expunge($folder) or die "Could not expunge: $@\n";
1121
 
1122
The B<expunge> method accepts one optional argument, a folder name. It
1123
expunges the folder specified as the argument, or the currently
1124
selected folder if no argument is supplied. 
1125
 
1126
Although RFC2060 does not permit optional arguments (like a folder
1127
name) to the EXPUNGE client command, the L<expunge> method does, which
1128
is especially interesting given that the L<expunge> method doesn't
1129
technically exist. In case you're curious, expunging a folder deletes
1130
the messages that you thought were already deleted via
1131
L<delete_message> but really weren't, which means you have to use a
1132
method that doesn't exist to delete messages that you thought didn't
1133
exist. (Seriously, I'm not making any of this stuff up.)
1134
 
1135
Or you could use the L<close> method, which de-selects as well as
1136
expunges and which likewise doesn't technically exist. As with any IMAP
1137
client command, that fact that these methods don't exist will not stop
1138
them from working anyway. This is a feature of the B<Mail::IMAPClient>
1139
module. (See L<"Other IMAP Client Commands and the Default Object Method"> 
1140
if you still don't believe me.)
1141
 
1142
=cut
1143
 
1144
=head2 fetch
1145
 
1146
Example:
1147
 
1148
	my $output = $imap->fetch(@args) or die "Could not fetch: $@\n";
1149
 
1150
The B<fetch> method implements the FETCH IMAP client command. It
1151
accepts a list of arguments, which will be converted into a
1152
space-delimited list of arguments to the FETCH IMAP client command. If
1153
no arguments are supplied then B<fetch> does a FETCH ALL. If the L<Uid>
1154
parameter is set to a true value then the first argument will be
1155
treated as a UID or list of UID's, which means that the UID FETCH IMAP
1156
client command will be run instead of FETCH. (It would really be a good
1157
idea at this point to review RFC2060.) 
1158
 
1159
If called in array context, B<fetch> will return an array of output
1160
lines. The output lines will be returned just as they were received
1161
from the server, so your script will have to be prepared to parse out
1162
the bits you want. The only exception to this is literal strings, which
1163
will be inserted into the output line at the point at which they were
1164
encountered (without the {nnn} literal field indicator). See RFC2060
1165
for a description of literal fields.
1166
 
1167
If B<fetch> is called in a scalar context, then a reference to an array
1168
(as described above) is returned instead of the entire array. 
1169
 
1170
B<fetch> returns C<undef> on failure. Inspect L<LastError> or C<$@> for
1171
an explanation of your error.
1172
 
1173
=cut
1174
 
1175
=head2 fetch_hash
1176
 
1177
Example:
1178
	my $hashref = {} ;
1179
	$imap->fetch_hash("RFC822.SIZE",$hashref) ;
1180
	print "Msg #$m is $hashref->{$m} bytes\n" foreach my $m (keys %$hashref);
1181
 
1182
The B<fetch_hash> method accepts a list of message attributes to be fetched 
1183
(as described in RFC2060). It returns a hash whose keys are all the messages 
1184
in the currently selected folder and whose values are key-value pairs of fetch 
1185
keywords and the message's value for that keyword (see sample output below).
1186
 
1187
If B<fetch_hash> is called in scalar context, it returns a reference to the hash
1188
instead of the hash itself. If the last argument is a hash reference, then that 
1189
hash reference will be used as the place where results are stored (and that 
1190
reference will be returned upon successful completion). If the last argument is 
1191
not a reference then it will be treated as one of the FETCH attributes and a new 
1192
hash will be created and returned (either by value or by reference, depending on 
1193
the context in which B<fetch_hash> was called).
1194
 
1195
For example, if you have a folder with 3 messages and want the size and internal 
1196
date for each of them, you could do the following:
1197
 
1198
	use Mail::IMAPClient;
1199
	use Data::Dumper;
1200
	# ...	other code goes here
1201
	$imap->select($folder);
1202
	my $hash = $imap->fetch_hash("RFC822.SIZE","INTERNALDATE");
1203
	# (Same as:
1204
	#  my $hash = $imap->fetch_hash("RFC822.SIZE");
1205
	#  $imap->fetch_hash("INTERNALDATE",$hash);
1206
	# ).
1207
	print Data::Dumper->Dumpxs([$hash],['$hash']);
1208
 
1209
This would result in L<Data::Dumper> output similar to the following:
1210
 
1211
   $hash = {
1212
	'1' => {
1213
                          'INTERNALDATE' => '21-Sep-2002 18:21:56 +0000',
1214
                          'RFC822.SIZE' => '1586',
1215
               },
1216
	'2' => {
1217
                          'INTERNALDATE' => '22-Sep-2002 11:29:42 +0000',
1218
                          'RFC822.SIZE' => '1945',
1219
               },
1220
	'3' => {
1221
                          'INTERNALDATE' => '23-Sep-2002 09:16:51 +0000',
1222
                          'RFC822.SIZE' => '134314',
1223
	       }
1224
     };
1225
 
1226
You can specify I<BODY[HEADER.FIELDS ($fieldlist)> as an argument, but you
1227
should keep the following in mind if you do:
1228
 
1229
B<1.>	You can only specify one argument of this type per call. If you need
1230
multiple fields, then you'll have to call B<fetch_hashref> multiple times, 
1231
each time specifying a different FETCH attribute but the same.  
1232
 
1233
B<2.>	Fetch operations that return RFC822 message headers return the whole
1234
header line, including the field name and the colon. For example, if you
1235
do a C<$imap-E<gt>fetch_hash("BODY[HEADER.FIELDS (Subject)]")>, you will
1236
get back subject lines that start with "Subject: ".
1237
 
1238
By itself this method may be useful for, say, speeding up programs that 
1239
want the size of every message in a folder. It issues one command and 
1240
receives one (possibly long!) response from the server. However, it's true
1241
power lies in the as-yet-unwritten methods that will rely on this method
1242
to deliver even more powerful result hashes (and which may even remove the
1243
restrictions mentioned in B<1> and B<2>, above). Look for more new function
1244
in later releases.
1245
 
1246
This method is new with version 2.2.3 and is thus still experimental. If you
1247
decide to try this method and run into problems, please see the section on
1248
L<REPORTING BUGS>.
1249
 
1250
=cut
1251
 
1252
=head2 flags
1253
 
1254
Example:
1255
 
1256
	my @flags = $imap->flags($msgid) 
1257
		or die "Could not flags: $@\n";
1258
 
1259
The B<flags> method implements the FETCH IMAP client command to list a
1260
single message's flags. It accepts one argument, a message sequence
1261
number (or a message UID, if the L<Uid> parameter is true), and returns
1262
an array (or a reference to an array, if called in scalar context)
1263
listing the flags that have been set. Flag names are provided with
1264
leading backslashes.
1265
 
1266
As of version 1.11, you can supply either a list of message id's or a
1267
reference to an array of of message id's (which means either sequence
1268
number, if the Uid parameter is false, or message UID's, if the Uid
1269
parameter is true) instead of supplying a single message sequence
1270
number or UID. If you do, then the return value will not be an array or
1271
array reference; instead, it will be a hash reference, with each key
1272
being a message sequence number (or UID) and each value being a
1273
reference to an array of flags set for that message.
1274
 
1275
For example, if you want to display the flags for every message in the
1276
folder where you store e-mail related to your plans for world
1277
domination, you could do something like this:
1278
 
1279
	use Mail::IMAPClient;
1280
	my $imap = Mail::IMAPClient->new( Server => $imaphost,
1281
					  User   => $login,
1282
					  Password=> $pass,
1283
					  Uid => 1,		# optional
1284
	);
1285
 
1286
	$imap->select("World Domination");
1287
	# get the flags for every message in my 'World Domination' folder 
1288
	$flaghash = $imap->flags( scalar($imap->search("ALL"))) ;
1289
 
1290
	# pump through sorted hash keys to print results:
1291
	for my $k (sort { $flaghash->{$a} <=> $flaghash->{$b} } keys %$flaghash) {
1292
		# print: Message 1: \Flag1, \Flag2, \Flag3
1293
		print "Message $k:\t",join(", ",@{$flaghash->{$k}}),"\n";
1294
	}
1295
 
1296
 
1297
=cut
1298
 
1299
=head2 folders
1300
 
1301
Example:
1302
 
1303
	$imap->folders	or die "Could not list folders: $@\n";
1304
 
1305
The B<folders> method returns an array listing the available folders.
1306
It will only be successful if the object is in the I<Authenticated> or
1307
I<Selected> states.
1308
 
1309
The B<folders> argument accepts one optional argument, which is a prefix.
1310
If a prefix is supplied to the B<folders> method, then only folders beginning 
1311
with the prefix will be returned. 
1312
 
1313
For example:
1314
 
1315
	print join(", ",$imap->folders),".\n";
1316
	# Prints: 
1317
	# INBOX, Sent, Projects, Projects/Completed, Projects/Ongoing, Projects Software.
1318
	print join(", ",$imap->folders("Projects"),".\n";
1319
	# Prints: 
1320
	# Projects, Projects/Completed, Projects/Ongoing, Projects Software.
1321
	print join(", ",$imap->folders("Projects" . $imap->separator),".\n";
1322
	# Prints: 
1323
	# Projects/Completed, Projects/Ongoing
1324
 
1325
Notice that if you just want to list a folder's subfolders (and not the 
1326
folder itself), then you need to include the hierarchy separator character 
1327
(as returned by the L<separator> method).
1328
 
1329
=cut
1330
 
1331
=head2 has_capability
1332
 
1333
Example:
1334
 
1335
	my $has_feature = $imap->has_capability($feature) 
1336
		or die "Could not do has_capability($feature): $@\n";
1337
 
1338
Returns true if the IMAP server to which the B<IMAPClient> object is
1339
connected has the capability specified as an argument to
1340
B<has_capability>.
1341
 
1342
=head2 idle
1343
 
1344
Example:
1345
 
1346
	my $idle = $imap->idle or warn "Couldn't idle: $@\n";
1347
	&goDoOtherThings;
1348
	$imap->done($idle) or warn "Error from done: $@\n";
1349
 
1350
The B<idle> method places the IMAP connection in an IDLE state. Your
1351
server must support the IMAP IDLE extension to use this method. (See
1352
RFC2177 for a discussion of the IDLE IMAP extension.) The B<idle> method
1353
accepts no arguments and returns a transaction number. This transaction 
1354
number must be supplied as the argument for L<done> when the L<done>
1355
method is later called.
1356
 
1357
Use the L<done> method to tell the IMAP server that the connection is 
1358
finished idling. 
1359
 
1360
If you attempt to use the B<idle> method against a server that does not
1361
have the IDLE capability then the B<idle> method will return C<undef>.
1362
If you then attempt to use the B<idle> method a second time the B<idle> 
1363
method will return C<undef> again.
1364
 
1365
If you successfully run the B<idle> method, then you must use the L<done>
1366
method to stop idling (or to continue, in the parlance of RFC2177). 
1367
Failure to do so will only encourage your server to call you I<BAD> 
1368
and to rant about a I<Bogus IDLE continuation>.
1369
 
1370
If you try to run any other mailbox method after calling L<idle> but
1371
before calling L<done>, then that method will not only fail but also
1372
take you out of the IDLE state. This means that when you eventually
1373
remember to call B<done> you will just get an I<* BAD Invalid tag>
1374
message.
1375
 
1376
=head2 imap4rev1
1377
 
1378
Example:
1379
 
1380
	$imap->imap4rev1 or die "Could not imap4rev1: $@\n";
1381
 
1382
Returns true if the IMAP server to which the B<IMAPClient> object is
1383
connected has the IMAP4REV1 capability.
1384
 
1385
=head2 internaldate
1386
 
1387
Example:
1388
 
1389
	my $msg_internal_date = $imap->internaldate($msgid) 
1390
		or die "Could not internaldate: $@\n";
1391
 
1392
B<internaldate> accepts one argument, a message id (or UID if the
1393
L<Uid> parameter is true), and returns that message's internal date.
1394
 
1395
=head2 get_bodystructure
1396
 
1397
Example:
1398
 
1399
	my $bodyStructObject = $imap->get_bodystructure($msgid) 
1400
		or die "Could not get_bodystructure: $@\n";
1401
 
1402
The B<get_bodystructure> method accepts one argument, a message
1403
sequence number or, if L<Uid> is true, a message UID. It obtains the
1404
message's body structure and returns a parsed
1405
L<Mail::IMAPClient::BodyStructure> object for the message.
1406
 
1407
=head2 get_envelope
1408
 
1409
Example:
1410
 
1411
	my $envObject = $imap->get_envelope(@args) 
1412
		or die "Could not get_envelope: $@\n";
1413
 
1414
The B<get_envelope> method accepts one argument, a message sequence
1415
number or, if L<Uid> is true, a message UID. It obtains the message's
1416
envelope and returns a B<Mail::IMAPClient::BodyStructure::Envelope>
1417
object for the envelope, which is just a version of the envelope that's
1418
been parsed into a perl object.
1419
 
1420
For more information on how to use this object once you've gotten it,
1421
see the L<Mail::IMAPClient::BodyStructure> documention. (As of this
1422
writing there is no separate pod document for
1423
B<Mail::IMAPClient::BodyStructure::Envelope>.)
1424
 
1425
=head2 getacl
1426
 
1427
Example:
1428
 
1429
	my $hash = $imap->getacl($folder) 
1430
		or die "Could not getacl for $folder: $@\n";
1431
 
1432
B<getacl> accepts one argument, the name of a folder. If no argument is
1433
provided then the currently selected folder is used as the default. It
1434
returns a reference to a hash. The keys of the hash are userids that
1435
have access to the folder, and the value of each element are the
1436
permissions for that user. The permissions are listed in a string in
1437
the order returned from the server with no whitespace or punctuation
1438
between them.
1439
 
1440
=cut
1441
 
1442
=head2 get_header
1443
 
1444
Example:
1445
 
1446
	my $messageId = $imap->get_header($msg, "Message-Id") ;
1447
 
1448
The B<get_header> method accepts two arguments, a message sequence number
1449
or UID and the name of an RFC822 header (without the trailing colon). It returns 
1450
the value for that header in the message whose sequence number or UID
1451
was passed as the first argument. If no value can be found it returns C<undef>;
1452
if multiple values are found it returns the first one. Its return value is 
1453
always a scalar. B<get_header> uses case insensitive matching to get the value,
1454
so you do not have to worry about the case of your second argument.
1455
 
1456
The B<get_header> method is a short-cut for:
1457
 
1458
	my $messageId = $imap->parse_headers($msg,"Subject")->{"Subject"}[0];
1459
 
1460
 
1461
 
1462
=head2 is_parent
1463
 
1464
Example:
1465
 
1466
	my $hasKids = $imap->is_parent($folder) ;
1467
 
1468
The B<is_parent> method accepts one argument, the name of a folder. It
1469
returns a value that indicates whether or not the folder has children.
1470
The value it returns is either 1) a true value (indicating that the
1471
folder has children), 2) 0 if the folder has no children at this time,
1472
or 3) C<undef> if the folder is not permitted to have children.
1473
 
1474
Eg:
1475
 
1476
	my $parenthood = $imap->is_parent($folder);
1477
	if (defined($parenthood)) { 
1478
		if ($parenthood) {
1479
			print "$folder has children.\n" ;
1480
		} else {
1481
			print "$folder is permitted children, but has none.\n";
1482
		}
1483
	} else {
1484
		print "$folder is not permitted to have children.\n";
1485
	}
1486
 
1487
 
1488
=cut
1489
 
1490
=head2 list
1491
 
1492
Example:
1493
 
1494
	my @raw_output = $imap->list(@args) 
1495
		or die "Could not list: $@\n";
1496
 
1497
The B<list> method implements the IMAP LIST client command. Arguments
1498
are passed to the IMAP server as received, separated from each other by
1499
spaces. If no arguments are supplied then the default list command
1500
C<tag LIST "" '*'> is issued.
1501
 
1502
The B<list> method returns an array (or an array reference, if called
1503
in a scalar context). The array is the unadulterated output of the LIST
1504
command. (If you want your output adulterated then see the L<folders>
1505
method, above.)
1506
 
1507
=cut
1508
 
1509
=head2 listrights
1510
 
1511
Example:
1512
 
1513
	$imap->listrights($folder,$user) 
1514
		or die "Could not listrights: $@\n";
1515
 
1516
The B<listrights> method implements the IMAP LISTRIGHTS client command
1517
(L<RFC2086>). It accepts two arguments, the foldername and a user id.
1518
It returns the rights the specified user has for the specified folder.
1519
If called in a scalar context then the rights are returned a strings, with
1520
no punction or whitespace or any nonsense like that. If called in array
1521
context then B<listrights> returns an array in which each element is one
1522
right.
1523
 
1524
=head2 login
1525
 
1526
Example:
1527
 
1528
	$imap->login or die "Could not login: $@\n";
1529
 
1530
The B<login> method uses the IMAP LOGIN client command (as defined in
1531
RFC2060) to log into the server. The I<User> and I<Password> parameters
1532
must be set before the B<login> method can be invoked. If successful,
1533
the B<login> method returns a pointer to the B<IMAPClient> object and
1534
sets the object status to I<Authenticated>. If unsuccessful, it returns
1535
undef. See the L<new> method for more information on how B<login> can
1536
be called automatically from L<new>.
1537
 
1538
B<login> is sometimes called automatically by L<connect>, which in turn
1539
is sometimes called automatically by L<new>. You can predict this 
1540
behavior once you've read the section on the L<new> method.
1541
 
1542
=cut
1543
 
1544
=head2 logout
1545
 
1546
Example:
1547
 
1548
	$imap->logout or die "Could not logout: $@\n";
1549
 
1550
The B<logout> method issues the LOGOUT IMAP client commmand. Since the
1551
LOGOUT IMAP client command causes the server to end the connection,
1552
this also results in the B<IMAPClient> client entering the
1553
I<Unconnected> state. This method does not, however, destroy the
1554
B<IMAPClient> object, so a program can re-invoke the L<connect> and
1555
L<login> methods if it wishes to reestablish a session later in the
1556
program.
1557
 
1558
According to the standard, a well-behaved client should log out before
1559
closing the socket connection. Therefore, B<Mail::IMAPClient> will 
1560
attempt to log out of the server during B<DESTROY> processing if the
1561
object being destroyed is in the L<Connected> state.
1562
 
1563
=cut
1564
 
1565
=head2 lsub
1566
 
1567
Example:
1568
 
1569
	$imap->lsub(@args) or die "Could not lsub: $@\n";
1570
 
1571
The B<lsub> method implements the IMAP LSUB client command. Arguments
1572
are passed to the IMAP server as received, separated from each other
1573
by spaces. If no arguments are supplied then the default lsub command
1574
C<tag LSUB "" '*'> is issued.
1575
 
1576
The B<lsub> method returns an array (or an array reference, if called
1577
in a scalar context). The array is the unaltered output of the LSUB
1578
command. If you want an array of subscribed folders then see the
1579
L<subscribed> method, below.
1580
 
1581
=cut
1582
 
1583
=head2 mark
1584
 
1585
Example:
1586
 
1587
	$imap->mark(@msgs) or die "Could not mark: $@\n";
1588
 
1589
The B<mark> method accepts a list of one or more messages sequence
1590
numbers, or a single reference to an array of one or more message
1591
sequence numbers, as its argument(s). It then sets the "\Flagged" flag
1592
for those message(s). Of course, if the L<Uid> parameter is set to a
1593
true value then those message sequence numbers had better be unique
1594
message id's.
1595
 
1596
Note that specifying C<$imap-E<gt>see(@msgs)> is just a shortcut for
1597
specifying C<$imap-E<gt>set_flag("Flagged",@msgs)>. 
1598
 
1599
=cut
1600
 
1601
=head2 Massage
1602
 
1603
Example:
1604
 
1605
	$imap->search(HEADER => 'Message-id' => $imap->Massage($msg_id,1));
1606
 
1607
The B<Massage> method accepts a value as an argument and, optionally, a second 
1608
value that, when true, indicates that the first argument is not the name of an 
1609
existing folder.
1610
 
1611
It returns its argument as a correctly quoted string or a literal string.
1612
 
1613
Note that you should rarely use this on folder names, since methods that accept
1614
folder names as an argument will call B<Massage> for you. In fact, it was originally 
1615
developed as an undocumented helper method meant for internal Mail::IMAPClient methods 
1616
only. 
1617
 
1618
You may also want to see the L<Quote> method, which is related to this method.
1619
 
1620
=head2 message_count
1621
 
1622
Example:
1623
 
1624
	my $msgcount = $imap->message_count($folder); 
1625
	defined($msgcount) or die "Could not message_count: $@\n";
1626
 
1627
The B<message_count> method accepts the name of a folder as an argument
1628
and returns the number of messages in that folder. Internally, it
1629
invokes the L<status> method (see above) and parses out the results to
1630
obtain the number of messages. If you don't supply an argument to
1631
B<message_count> then it will return the number of messages in the
1632
currently selected folder (assuming of course that you've used the
1633
L<select> or L<examine> method to select it instead of trying something
1634
funky). Note that RFC2683 contains warnings about the use of the IMAP
1635
I<STATUS> command (and thus the L<status> method and therefore the 
1636
B<message_count> method) against the currenlty selected folder.
1637
You should carefully consider this before using B<message_count> 
1638
on the currently selected folder. You may be better off using 
1639
L<search> or one of its variants (especially L<messages>), and then
1640
counting the results. On the other hand, I regularly violate this
1641
rule on my server without suffering any dire consequences. Your 
1642
milage may vary.
1643
 
1644
=cut
1645
 
1646
=head2 message_string
1647
 
1648
Example:
1649
 
1650
	my $string = $imap->message_string($msgid) 
1651
		or die "Could not message_string: $@\n";
1652
 
1653
The B<message_string> method accepts a message sequence number (or
1654
message UID if L<Uid> is true) as an argument and returns the message
1655
as a string. The returned value contains the entire message in one
1656
scalar variable, including the message headers. Note that using this
1657
method will set the message's "\Seen" flag as a side effect, unless
1658
I<Peek> is set to a true value.
1659
 
1660
=cut
1661
 
1662
=head2 message_to_file
1663
 
1664
Example:
1665
 
1666
	$imap->message_to_file($file,@msgs) 
1667
		or die "Could not message_to_file: $@\n";
1668
 
1669
The B<message_to_file> method accepts a filename or file handle and one
1670
or more message sequence numbers (or message UIDs if L<Uid> is true) as
1671
arguments and places the message string(s) (including RFC822 headers)
1672
into the file named in the first argument (or prints them to the
1673
filehandle, if a filehandle is passed). The returned value is true on
1674
succes and C<undef> on failure. 
1675
 
1676
If the first argument is a reference, it is assumed to be an open
1677
filehandle and will not be closed when the method completes, If it is a
1678
file, it is opened in append mode, written to, then closed.
1679
 
1680
Note that using this method will set the message's "\Seen" flag as a
1681
side effect. But you can use the L<deny_seeing> method to set it back,
1682
or set the L<Peek> parameter to a true value to prevent setting the
1683
"\Seen" flag at all.
1684
 
1685
This method currently works by making some basic assumptions about the
1686
server's behavior, notably that the message text will be returned as a
1687
literal string but that nothing else will be. If you have a better idea
1688
then I'd like to hear it. 
1689
 
1690
=cut
1691
 
1692
=head2 message_uid
1693
 
1694
Example:
1695
 
1696
	my $msg_uid = $imap->message_uid($msg_seq_no) 
1697
		or die "Could not get uid for $msg_seq_no: $@\n";
1698
 
1699
The B<message_uid> method accepts a message sequence number (or message
1700
UID if L<Uid> is true) as an argument and returns the message's UID.
1701
Yes, if L<Uid> is true then it will use the IMAP UID FETCH UID client
1702
command to obtain and return the very same argument you supplied. This
1703
is an IMAP feature so don't complain to me about it.
1704
 
1705
=cut
1706
 
1707
=head2 messages
1708
 
1709
Example:
1710
 
1711
	# Get a list of messages in the current folder:
1712
	my @msgs = $imap->messages or die "Could not messages: $@\n";
1713
	# Get a reference to an array of messages in the current folder:
1714
	my $msgs = $imap->messages or die "Could not messages: $@\n";
1715
 
1716
If called in list context, the B<messages> method returns a list of all
1717
the messages in the currenlty selected folder. If called in scalar
1718
context, it returns a reference to an array containing all the messages
1719
in the folder. If you have the L<Uid> parameter turned off, then this
1720
is the same as specifying C<1 ... $imap-E<gt>L<message_count>>; if you
1721
have UID set to true then this is the same as specifying
1722
C<$imap-E<gt>L<search>("ALL")>. 
1723
 
1724
=cut
1725
 
1726
=head2 migrate
1727
 
1728
Example:
1729
 
1730
	$imap->migrate($imap_2, "ALL", $targetFolder ) 
1731
		or die "Could not migrate: $@\n";
1732
 
1733
The B<migrate> method copies the indicated messages B<from> the
1734
currently selected folder B<to> another B<Mail::IMAPClient> object's
1735
session. It requires these arguments:
1736
 
1737
=over 4
1738
 
1739
=item 1. 
1740
 
1741
a reference to the target B<Mail::IMAPClient> object (not the calling
1742
object, which is connected to the source account);
1743
 
1744
=item 2.
1745
 
1746
the message(s) to be copied, specified as either a) the message
1747
sequence number (or message UID if the UID parameter is true) of a
1748
single message, b) a reference to an array of message sequence numbers
1749
(or message UID's if the UID parameter is true) or c) the special
1750
string "ALL", which is a shortcut for the results of
1751
C<L<search>("ALL")>.
1752
 
1753
=item 3.
1754
 
1755
the folder name of a folder on the target mailbox to receive the
1756
message(s). If this argument is not supplied or if I<undef> is supplied
1757
then a folder with the same name as the currently selected folder on
1758
the calling object will be created if necessary and used. If you
1759
specify something other then I<undef> for this argument, even if it's
1760
'$imap1-E<gt>Folder' or the name of the currently selected folder, then
1761
that folder will only be used if it exists on the target object's
1762
mailbox; if it does not exist then B<migrate> will fail.
1763
 
1764
=back
1765
 
1766
The target B<Mail::IMAPClient> object should not be the same as the
1767
source. The source object is the calling object, i.e. the one whose
1768
B<migrate> method will be used. It cannot be the same object as the one
1769
specified as the target, even if you are for some reason migrating
1770
between folders on the same account (which would be silly anyway, since
1771
L<copy> can do that much more efficiently). If you try to use the same
1772
B<Mail::IMAPClient> object for both the caller and the reciever then
1773
they'll both get all screwed up and it will be your fault because I
1774
just warned you and you didn't listen.
1775
 
1776
B<migrate> will download messages from the source in chunks to minimize
1777
memory usage. The size of the chunks can be controlled by changing the
1778
source B<Mail::IMAPClient> object's the L<Buffer> parameter. The higher
1779
the L<Buffer> value, the faster the migration, but the more memory your
1780
program will require. TANSTAAFL. (See the L<Buffer> parameter and
1781
eponymous accessor method, described above under the L<"Parameters">
1782
section.)
1783
 
1784
The B<migrate> method uses Black Magic to hardwire the I/O between the
1785
two B<Mail::IMAPClient> objects in order to minimize resource
1786
consumption. If you have older scripts that used L<message_to_file> and
1787
L<append_file> to move large messages between IMAP mailboxes then you
1788
may want to try this method as a possible replacement.
1789
 
1790
=head2 move
1791
 
1792
Example:
1793
 
1794
	my $newUid = $imap->move($newFolder, $oldUid) 
1795
		or die "Could not move: $@\n";
1796
	$imap->expunge;
1797
 
1798
The B<move> method moves messages from the currently selected folder to
1799
the folder specified in the first argument to B<move>. If the L<Uid>
1800
parameter is not true, then the rest of the arguments should be either:
1801
 
1802
=over 4
1803
 
1804
=item >
1805
 
1806
a message sequence number,
1807
 
1808
=item >
1809
 
1810
a comma-separated list of message sequence numbers, or
1811
 
1812
=item >
1813
 
1814
a reference to an array of message sequence numbers.
1815
 
1816
=back
1817
 
1818
If the L<Uid> parameter is true, then the arguments should be:
1819
 
1820
=over 4
1821
 
1822
=item >
1823
 
1824
a message UID,
1825
 
1826
=item >
1827
 
1828
a comma-separated list of message UID's, or
1829
 
1830
=item >
1831
 
1832
a reference to an array of message UID's.
1833
 
1834
=back
1835
 
1836
If the target folder does not exist then it will be created.
1837
 
1838
If move is sucessful, then it returns a true value. Furthermore, if the
1839
B<Mail::IMAPClient> object is connected to a server that has the
1840
UIDPLUS capability, then the true value will be the comma-separated
1841
list of UID's for the newly copied messages. The list will be in the
1842
order in which the messages were moved. (Since B<move> uses the copy
1843
method, the messages will be moved in numerical order.)
1844
 
1845
If the move is not successful then B<move> returns C<undef>.
1846
 
1847
Note that a move really just involves copying the message to the new
1848
folder and then setting the I<\Deleted> flag. To actually delete the
1849
original message you will need to run L<expunge> (or L<close>).
1850
 
1851
=cut
1852
 
1853
=head2 namespace
1854
 
1855
Example:
1856
 
1857
	my @refs = $imap->namespace
1858
		or die "Could not namespace: $@\n";
1859
 
1860
The namespace method runs the NAMESPACE IMAP command (as defined in RFC
1861
2342). When called in a list context, it returns a list of three
1862
references. Each reference looks like this:
1863
 
1864
	[ [ $prefix_1, $separator_1 ] , 
1865
	  [ $prefix_2, $separator_2 ], 
1866
	  [ $prefix_n , $separator_n] 
1867
	]
1868
 
1869
The first reference provides a list of prefices and separator
1870
charactors for the available personal namespaces. The second reference
1871
provides a list of prefices and separator charactors for the available
1872
shared namespaces. The third reference provides a list of prefices and
1873
separator charactors for the available public namespaces.
1874
 
1875
If any of the three namespaces are unavailable on the current server
1876
then an 'undef' is returned instead of a reference. So for example if
1877
shared folders were not supported on the server but personal and public
1878
namespaces were both available (with one namespace each), the returned
1879
value might resemble this: 
1880
 
1881
	( [ "", "/" ] , undef, [ "#news", "." ] ) ;
1882
 
1883
If the B<namespace> method is called in scalar context, it returns a
1884
reference to the above-mentioned list of three references, thus
1885
creating a single structure that would pretty-print something like
1886
this:
1887
 
1888
	$VAR1 = [
1889
			[ 
1890
				[ $user_prefix_1, $user_separator_1 ] , 
1891
				[ $user_prefix_2, $user_separator_2], 
1892
				[ $user_prefix_n , $user_separator_n] 
1893
			] 	,					# or undef
1894
			[ 
1895
				[ $shared_prefix_1, $shared_separator_1 ] , 
1896
				[ $shared_prefix_2, $shared_separator_2], 
1897
				[ $shared_prefix_n , $shared_separator_n] 
1898
			] 	,					# or undef
1899
			[ 
1900
				[ $public_prefix_1, $public_separator_1 ] , 
1901
				[ $public_prefix_2, $public_separator_2], 
1902
				[ $public_prefix_n , $public_separator_n] 
1903
			] 	,					# or undef
1904
	];
1905
 
1906
Or, to look at our previous example (where shared folders are
1907
unsupported) called in scalar context:
1908
 
1909
	$VAR1 = [
1910
			[
1911
				[
1912
					"" ,
1913
					"/",
1914
				],
1915
			],
1916
 
1917
			undef, 
1918
 
1919
			[
1920
				[
1921
					"#news", 		
1922
					"." 
1923
				],
1924
			],
1925
	];
1926
 
1927
=cut
1928
 
1929
=head2 on
1930
 
1931
Example:
1932
 
1933
	my @msgs = $imap->on($Rfc2060_date) 
1934
		or warn "Could not find messages sent on $Rfc2060_date: $@\n";
1935
 
1936
The B<on> method works just like the L<since> method, below, except it
1937
returns a list of messages whose internal system dates are the same as
1938
the date supplied as the argument.
1939
 
1940
=head2 parse_headers 
1941
 
1942
Example:
1943
 
1944
	my $hashref = $imap->parse_headers($msg||@msgs, "Date", "Subject") 
1945
		or die "Could not parse_headers: $@\n";
1946
 
1947
The B<parse_headers> method accepts as arguments a message sequence
1948
number and a list of header fields. It returns a hash reference in
1949
which the keys are the header field names (without the colon) and the
1950
values are references to arrays of values. A picture would look
1951
something like this:
1952
 
1953
   $hashref = $imap->parse_headers(1,"Date","Received","Subject","To");
1954
   $hashref = {
1955
	"Date" 	 	=> [ "Thu, 09 Sep 1999 09:49:04 -0400" ]  ,
1956
        "Received"	=> [ q/
1957
	   	from mailhub ([111.11.111.111]) by mailhost.bigco.com 
1958
	   	(Netscape Messaging Server 3.6)  with ESMTP id AAA527D for 
1959
	   	<bigshot@bigco.com>; Fri, 18 Jun 1999 16:29:07 +0000
1960
	   	/, q/
1961
	   	from directory-daemon by mailhub.bigco.com (PMDF V5.2-31 #38473)
1962
 	   	id <0FDJ0010174HF7@mailhub.bigco.com> for bigshot@bigco.com
1963
 	   	(ORCPT rfc822;big.shot@bigco.com); Fri, 18 Jun 1999 16:29:05 +0000 (GMT)
1964
	   	/, q/
1965
	   	from someplace ([999.9.99.99]) by smtp-relay.bigco.com (PMDF V5.2-31 #38473) 
1966
	        with ESMTP id <0FDJ0000P74H0W@smtp-relay.bigco.com> for big.shot@bigco.com; Fri,
1967
	   	18 Jun 1999 16:29:05 +0000 (GMT)
1968
	   	/] ,
1969
	"Subject" 	=> [ qw/ Help! I've fallen and I can't get up!/ ] ,
1970
	"To"		=> [ "Big Shot <big.shot@bigco.com> ] ,
1971
	} ;
1972
 
1973
The text in the example for the "Received" array has been formated to
1974
make reading the example easier. The actual values returned are just
1975
strings of words separated by spaces and with newlines and carriage
1976
returns stripped off. The I<Received> header is probably the main
1977
reason that the B<parse_headers> method creates a hash of lists rather
1978
than a hash of values. 
1979
 
1980
If the second argument to B<parse_headers> is 'ALL' or if it is
1981
unspecified then all available headers are included in the returned
1982
hash of lists.
1983
 
1984
If you're not emotionally prepared to deal with a hash of lists then
1985
you can always call the L<fetch> method yourself with the appropriate
1986
parameters and parse the data out any way you want to. Also, in the
1987
case of headers whose contents are also reflected in the envelope, you
1988
can use the L<get_envelope> method as an alternative to
1989
L<parse_headers>.
1990
 
1991
If the L<Uid> parameter is true then the first argument will be treated
1992
as a message UID. If the first argument is a reference to an array of
1993
message sequence numbers (or UID's if L<Uid> is true), then
1994
B<parse_headers> will be run against each message in the array. In this
1995
case the return value is a hash, in which the key is the message
1996
sequence number (or UID) and the value is a reference to a hash as
1997
described above.
1998
 
1999
An example of using B<parse_headers> to print the date and subject of
2000
every message in your smut folder could look like this:
2001
 
2002
	use Mail::IMAPClient;
2003
	my $imap = Mail::IMAPClient->new( Server => $imaphost,
2004
					  User   => $login,
2005
					  Password=> $pass,
2006
					  Uid => 1,		# optional
2007
	);
2008
 
2009
	$imap->select("smut");
2010
 
2011
	for my $h (	
2012
 
2013
	 # grab the Subject and Date from every message in my (fictional!) smut folder;
2014
	 # the first argument is a reference to an array listing all messages in the folder
2015
	 # (which is what gets returned by the $imap->search("ALL") method when called in
2016
	 # scalar context) and the remaining arguments are the fields to parse out
2017
 
2018
	 # The key is the message number, which in this case we don't care about:
2019
	 values %{$imap->parse_headers( scalar($imap->search("ALL")) , "Subject", "Date")}
2020
	) {
2021
		# $h is the value of each element in the hash ref returned from parse_headers,
2022
		# and $h is also a reference to a hash.
2023
		# We'll only print the first occurance of each field because we don't expect more
2024
		# than one Date: or Subject: line per message.
2025
		 print map { "$_:\t$h->{$_}[0]\n"} keys %$h ; 
2026
	}
2027
 
2028
 
2029
=cut
2030
 
2031
=head2 recent
2032
 
2033
Example:
2034
 
2035
	my @recent = $imap->recent or warn "No recent msgs: $@\n";
2036
 
2037
The B<recent> method performs an IMAP SEARCH RECENT search against the
2038
selected folder and returns an array of sequence numbers (or UID's, if
2039
the L<Uid> parameter is true) of messages that are recent.
2040
 
2041
=cut
2042
 
2043
=head2 recent_count
2044
 
2045
Example:
2046
 
2047
	my $count = 0;
2048
	defined($count = $imap->recent_count($folder)) 
2049
		or die "Could not recent_count: $@\n";
2050
 
2051
The B<recent_count> method accepts as an argument a folder name. It
2052
returns the number of recent messages in the folder (as returned by the
2053
IMAP client command "STATUS folder RECENT"), or C<undef> in the case of an
2054
error. The B<recent_count> method was contributed by Rob Deker
2055
(deker@ikimbo.com).
2056
 
2057
=cut
2058
 
2059
=head2 rename
2060
 
2061
Example:
2062
 
2063
	$imap->rename($oldname,$nedwname) 
2064
		or die "Could not rename: $@\n";
2065
 
2066
The B<rename> method accepts two arguments: the name of an existing
2067
folder, and a new name for the folder. The existing folder will be
2068
renamed to the new name using the RENAME IMAP client command. B<rename>
2069
will return a true value if successful, or C<undef> if unsuccessful.
2070
 
2071
=cut
2072
 
2073
=head2 restore_message
2074
 
2075
Example:
2076
 
2077
	$imap->restore_message(@msgs) or die "Could not restore_message: $@\n";
2078
 
2079
The B<restore_message> method is used to undo a previous
2080
L<delete_message> operation (but not if there has been an intervening
2081
L<expunge> or L<close>). The B<IMAPClient> object must be in
2082
L<Selected> status to use the B<restore_message> method. 
2083
 
2084
The B<restore_message> method accepts a list of arguments. If the
2085
L<Uid> parameter is not set to a true value, then each item in the list
2086
should be either:
2087
 
2088
=over 4
2089
 
2090
=item >
2091
 
2092
a message sequence number,
2093
 
2094
=item >
2095
 
2096
a comma-separated list of message sequence numbers,
2097
 
2098
=item >
2099
 
2100
a reference to an array of message sequence numbers, or
2101
 
2102
=back
2103
 
2104
If the L<Uid> parameter is set to a true value, then each item in the
2105
list should be either:
2106
 
2107
=over 4
2108
 
2109
=item >
2110
 
2111
a message UID,
2112
 
2113
=item >
2114
 
2115
a comma-separated list of UID's, or
2116
 
2117
=item >
2118
 
2119
a reference to an array of message UID's.
2120
 
2121
=back
2122
 
2123
The messages identified by the sequence numbers or UID's will have
2124
their I<\Deleted> flags cleared, effectively "undeleting" the messages.
2125
B<restore_message> returns the number of messages it was able to
2126
restore. 
2127
 
2128
Note that B<restore_messages> is similar to calling
2129
C<L<unset_flag>("\Deleted",@msgs)>, except that B<restore_messages>
2130
returns a (slightly) more meaningful value. Also it's easier to type.
2131
 
2132
=cut
2133
 
2134
=head2 run
2135
 
2136
Example:
2137
 
2138
	$imap->run(@args) or die "Could not run: $@\n";
2139
 
2140
Like Perl itself, the B<Mail::IMAPClient> module is designed to make
2141
common things easy and uncommon things possible. The B<run> method is
2142
provided to make those uncommon things possible.
2143
 
2144
The B<run> method excepts one or two arguments. The first argument is a
2145
string containing an IMAP Client command, including a tag and all
2146
required arguments. The optional second argument is a string to look
2147
for that will indicate success. (The default is C</OK.*/>). The B<run>
2148
method returns an array of output lines from the command, which you are
2149
free to parse as you see fit.
2150
 
2151
The B<run> method does not do any syntax checking, other than
2152
rudimentary checking for a tag.
2153
 
2154
When B<run> processes the command, it increments the transaction count
2155
and saves the command and responses in the History buffer in the same
2156
way other commands do. However, it also creates a special entry in the
2157
History buffer named after the tag supplied in the string passed as the
2158
first argument. If you supply a numeric value as the tag then you may
2159
risk overwriting a previous transaction's entry in the History buffer.
2160
 
2161
If you want the control of B<run> but you don't want to worry about the
2162
damn tags then see L<"tag_and_run">, below.
2163
 
2164
=cut
2165
 
2166
=head2 search
2167
 
2168
Example:
2169
 
2170
	my @msgs = $imap->search(@args) or warn "search: None found\n";
2171
	if ($@) {
2172
		warn "Error in search: $@\n";
2173
	}
2174
 
2175
The B<search> method implements the SEARCH IMAP client command. Any
2176
argument supplied to B<search> is prefixed with a space and appended to
2177
the SEARCH IMAP client command. This method is another one of those
2178
situations where it will really help to have your copy of RFC2060
2179
handy, since the SEARCH IMAP client command contains a plethora of
2180
options and possible arguments. I'm not going to repeat them here. 
2181
 
2182
Remember that if your argument needs quotes around it then you must
2183
make sure that the quotes will be preserved when passing the argument.
2184
I.e. use C<qq/"$arg"/> instead of C<"$arg">. When in doubt, use the
2185
L<Quote> method.
2186
 
2187
The B<search> method returns an array containing sequence numbers of
2188
messages that passed the SEARCH IMAP client command's search criteria.
2189
If the L<Uid> parameter is true then the array will contain message
2190
UID's. If B<search> is called in scalar context then a pointer to the
2191
array will be passed, instead of the array itself. If no messages meet
2192
the criteria then B<search> returns an empty list (when in list context)
2193
or C<undef> (in scalar context).
2194
 
2195
Since a valid, successful search can legitimately return zero matches,
2196
you may wish to distinguish between a search that correctly returns 
2197
zero hits and a search that has failed for some other reason (i.e. 
2198
invalid search parameters).  Therefore, the C<$@> variable will always 
2199
be cleared before the I<SEARCH> command is issued to the server, and 
2200
will thus remain empty unless the server gives a I<BAD> or I<NO> response 
2201
to the I<SEARCH> command. 
2202
 
2203
=cut
2204
 
2205
=head2 see
2206
 
2207
Example:
2208
 
2209
	$imap->see(@msgs) or die "Could not see: $@\n";
2210
 
2211
The B<see> method accepts a list of one or more messages sequence
2212
numbers, or a single reference to an array of one or more message
2213
sequence numbers, as its argument(s). It then sets the I<\Seen> flag
2214
for those message(s). Of course, if the L<Uid> parameter is set to a
2215
true value then those message sequence numbers had better be unique
2216
message id's, but then you already knew that, didn't you?
2217
 
2218
Note that specifying C<$imap-E<gt>see(@msgs)> is just a shortcut for
2219
specifying C<$imap-E<gt>L<set_flag>("Seen",@msgs)>. 
2220
 
2221
=cut
2222
 
2223
=head2 seen
2224
 
2225
Example:
2226
 
2227
	my @seenMsgs = $imap->seen or warn "No seen msgs: $@\n";
2228
 
2229
The B<seen> method performs an IMAP SEARCH SEEN search against the
2230
selected folder and returns an array of sequence numbers of messages
2231
that have already been seen (ie their I<\Seen> flag is set). If the
2232
L<Uid> parameter is true then an array of message UID's will be
2233
returned instead. If called in scalar context than a reference to the
2234
array (rather than the array itself) will be returned.
2235
 
2236
=cut
2237
 
2238
=head2 select
2239
 
2240
Example:
2241
 
2242
	$imap->select($folder) or die "Could not select: $@\n";
2243
 
2244
The B<select> method selects a folder and changes the object's state to
2245
I<Selected>. It accepts one argument, which is the name of the folder
2246
to select.
2247
 
2248
=cut
2249
 
2250
=head2 selectable
2251
 
2252
Example:
2253
 
2254
	foreach my $f ( grep($imap->selectable($_),$imap->folders ) ) {
2255
		$imap->select($f) ;
2256
	}
2257
 
2258
The B<selectable> method accepts one value, a folder name, and returns true
2259
if the folder is selectable or false if it is not selectable.
2260
 
2261
=cut
2262
 
2263
=head2 sentbefore
2264
 
2265
Example:
2266
 
2267
	my @msgs = $imap->sentbefore($Rfc2060_date) 
2268
		or warn "Could not find any msgs sent before $Rfc2060_date: $@\n";
2269
 
2270
The B<sentbefore> method works just like L<"sentsince">, below, except it
2271
searches for messages that were sent before the date supplied as an
2272
argument to the method.
2273
 
2274
=cut
2275
 
2276
=head2 senton
2277
 
2278
Example:
2279
 
2280
	my @msgs = $imap->senton($Rfc2060_date) 
2281
		or warn "Could not find any messages sent on $Rfc2060_date: $@\n";
2282
 
2283
The B<senton> method works just like L<"sentsince">, below, except it searches
2284
for messages that were sent on the exact date supplied as an argument
2285
to the method.
2286
 
2287
=cut
2288
 
2289
=head2 sentsince
2290
 
2291
Example:
2292
 
2293
	my @msgs = $imap->sentsince($Rfc2060_date) 
2294
		or warn "Could not find any messages sent since $Rfc2060_date: $@\n";
2295
 
2296
The B<sentsince> method accepts one argument, a date in either epoch
2297
time format (seconds since 1/1/1970, or as output by L<time|perlfunc/time> 
2298
and as accepted by L<localtime|perlfunc/localtime>) 
2299
or in the I<date_text> format as defined in RFC2060 (dd-Mon-yyyy, where Mon 
2300
is the English-language three-letter abbreviation for the month). 
2301
 
2302
It searches for items in the currently selected folder for messages
2303
sent since the day whose date is provided as the argument. It uses the
2304
RFC822 I<Date:> header to determine the I<sentsince> date. (Actually,
2305
it the server that uses the I<Date:> header; this documentation just
2306
assumes that the date is coming from the I<Date:> header because that's
2307
what RFC2060 dictates.)
2308
 
2309
In the case of arguments supplied as a number of seconds, the returned
2310
result list will include items sent on or after that day, regardless of
2311
whether they arrived before the specified time on that day. The IMAP
2312
protocol does not support searches at a granularity finer than a day,
2313
so neither do I. On the other hand, the only thing I check for in a
2314
I<date_text> argument is that it matches the pattern
2315
C</\d\d-\D\D\D-\d\d\d\d/> (notice the lack of anchors), so if your
2316
server lets you add something extra to a I<date_text> string then so
2317
will B<Mail::IMAPClient>.
2318
 
2319
If you'd like, you can use the L<Rfc2060_date> method to convert from
2320
epoch time (as returned by L<time|perlfunc/time>) into an RFC2060 date
2321
specification. 
2322
 
2323
=cut
2324
 
2325
=head2 separator
2326
 
2327
Example:
2328
 
2329
	my $sepChar = $imap->separator(@args) 
2330
		or die "Could not get separator: $@\n";
2331
 
2332
The B<separator> method returns the character used as a separator
2333
character in folder hierarchies. On unix-based servers, this is often
2334
but not necessarily a forward slash (/). It accepts one argument, the
2335
name of a folder whose hierarchy's separator should be returned. If no
2336
folder name is supplied then the separator for the INBOX is returned,
2337
which probably is good enough.
2338
 
2339
If you want your programs to be portable from IMAP server brand X to
2340
IMAP server brand Y, then you should never use hard-coded separator
2341
characters to specify subfolders. (In fact, it's even more complicated
2342
than that, since some server don't allow any subfolders at all, some
2343
only allow subfolders under the "INBOX" folder, and some forbid
2344
subfolders in the inbox but allow them "next" to the inbox.
2345
Furthermore, some server implementations do not allow folders to
2346
contain both subfolders and mail messages; other servers allow this.)
2347
 
2348
=cut
2349
 
2350
=head2 set_flag
2351
 
2352
Example:
2353
 
2354
	$imap->set_flag("Seen",@msgs) 
2355
		or die "Could not set flag: $@\n";
2356
 
2357
The B<set_flag> method accepts the name of a flag as its first argument
2358
and a list of one or more messages sequence numbers, or a single
2359
reference to an array of one or more message sequence numbers, as its
2360
next argument(s). It then sets the flag specified for those message(s).
2361
Of course, if the L<Uid> parameter is set to a true value then those
2362
message sequence numbers had better be unique message id's, just as
2363
you'd expect.
2364
 
2365
Note that when specifying the flag in question, the preceding backslash
2366
(\) is entirely optional. (For you, that is. B<Mail::IMAPClient> still
2367
has remember to stick it in there before passing the command to the
2368
server if the flag is one of the reserved flags specified in RFC2060.
2369
This is in fact so important that the method checks its argument and
2370
adds the backslash when necessary, which is why you don't have to worry
2371
about it overly much.)
2372
 
2373
=cut
2374
 
2375
=head2 setacl
2376
 
2377
Example:
2378
 
2379
	$imap->setacl($folder,$userid,$authstring) 
2380
		or die "Could not set acl: $@\n";
2381
 
2382
The B<setacl> method accepts three input arguments, a folder name, a
2383
user id (or authentication identifier, to use the terminology of
2384
RFC2086), and an access rights modification string. See RFC2086 for
2385
more information. (This is somewhat experimental and its implementation
2386
may change.)
2387
 
2388
=cut
2389
 
2390
=head2 since
2391
 
2392
Example:
2393
 
2394
	my @msgs = $imap->since($date) 
2395
		or warn "Could not find any messages since $date: $@\n";
2396
 
2397
The B<since> method accepts a date in either epoch format
2398
(seconds since 1/1/1970, or as output by L<perlfunc/time> and as
2399
accepted by L<perlfunc/localtime>) or in the I<date_text> format as
2400
defined in RFC2060 (dd-Mon-yyyy, where Mon is the English-language
2401
three-letter abbreviation for the month). It searches for items in the
2402
currently selected folder for messages whose internal dates are on or
2403
after the day whose date is provided as the argument. It uses the
2404
internal system date for a message to determine if that message was
2405
sent since the given date.
2406
 
2407
In the case of arguments supplied as a number of seconds, the returned
2408
result list will include items whose internal date is on or after that
2409
day, regardless of whether they arrived before the specified time on
2410
that day. 
2411
 
2412
If B<since> is called in a list context then it will return a list of 
2413
messages meeting the I<SEARCH SINCE> criterion, or an empty list if
2414
no messages meet the criterion.
2415
 
2416
If B<since> is called in a scalar context then it will return 
2417
a reference to an array of messages meeting the I<SEARCH SINCE> 
2418
criterion, or C<undef> if no messages meet the criterion.
2419
 
2420
Since B<since> is a front-end to L<search>, some of the same rules apply.
2421
For example, the C<$@> variable will always be cleared before the I<SEARCH>
2422
command is issued to the server, and will thus remain empty unless 
2423
the server gives a I<BAD> or I<NO> response to the I<SEARCH> command.
2424
 
2425
=cut
2426
 
2427
=head2 size
2428
 
2429
Example:
2430
 
2431
	my $size = $imap->size($msgId) 
2432
		or die "Could not find size of message $msgId: $@\n";
2433
 
2434
The B<size> method accepts one input argument, a sequence number (or
2435
message UID if the L<Uid> parameter is true). It returns the size of
2436
the message in the currently selected folder with the supplied sequence
2437
number (or UID). The B<IMAPClient> object must be in a I<Selected>
2438
state in order to use this method.
2439
 
2440
=cut
2441
 
2442
=head2 sort
2443
 
2444
Example:
2445
 
2446
	my @msgs = $imap->sort(@args) ;
2447
	if ($@ ) {
2448
		warn "Error in sort: $@\n";
2449
	}
2450
 
2451
The B<sort> method is just like the L<search> method, only different.
2452
It implements the SORT extension as described in
2453
L<http://search.ietf.org/internet-drafts/draft-ietf-imapext-sort-10.txt>.
2454
It would be wise to use the L<has_capability> method to verify that the
2455
SORT capability is available on your server before trying to use the
2456
B<sort> method. If you forget to check and you're connecting to a
2457
server that doesn't have the SORT capability then B<sort> will return
2458
undef. L<LastError> will then say you are "BAD". If your server doesn't
2459
support the SORT capability then you'll have to use L<search> and then
2460
sort the results yourself.
2461
 
2462
The first argument to B<sort> is a space-delimited list of sorting
2463
criteria. The Internet Draft that describes SORT requires that this
2464
list be wrapped in parentheses, even if there is only one sort
2465
criterion. If you forget the parentheses then the B<sort> method will
2466
add them. But you have to forget both of them, or none. This isn't CMS
2467
running under VM!
2468
 
2469
The second argument is a character set to use for sorting. Different
2470
character sets use different sorting orders, so this argument is
2471
important. Since all servers must support UTF-8 and US-ASCII if they
2472
support the SORT capability at all, you can use one of those if you
2473
don't have some other preferred character set in mind.
2474
 
2475
The rest of the arguments are searching criteria, just as you would
2476
supply to the L<search> method. These are all documented in RFC2060. If
2477
you just want all of the messages in the currently selected folder
2478
returned to you in sorted order, use I<ALL> as your only search
2479
criterion.
2480
 
2481
The B<sort> method returns an array containing sequence numbers of
2482
messages that passed the SORT IMAP client command's search criteria. If
2483
the L<Uid> parameter is true then the array will contain message UID's.
2484
If B<sort> is called in scalar context then a pointer to the array will
2485
be passed, instead of the array itself. The message sequence numbers or
2486
unique identifiers are ordered according to the sort criteria
2487
specified. The sort criteria are nested in the order specified; that
2488
is, items are sorted first by the first criterion, and within the first
2489
criterion they are sorted by the second criterion, and so on.
2490
 
2491
The sort method will clear C<$@> before attempting the I<SORT>
2492
operation just as the L<search> method does.
2493
 
2494
=head2 status
2495
 
2496
Example:
2497
 
2498
	my @rawdata = $imap->status($folder,qw/(Messages)/) 
2499
		or die "Error obtaining status: $@\n";
2500
 
2501
The B<status> method accepts one argument, the name of a folder (or
2502
mailbox, to use RFC2060's terminology), and returns an array containing
2503
the results of running the IMAP STATUS client command against that
2504
folder. If additional arguments are supplied then they are appended to
2505
the IMAP STATUS client command string, separated from the rest of the
2506
string and each other with spaces.
2507
 
2508
If B<status> is not called in an array context then it returns a
2509
reference to an array rather than the array itself.
2510
 
2511
The B<status> method should not be confused with the B<Status> method
2512
(with an uppercase 'S'), which returns information about the
2513
B<IMAPClient> object. (See the section labeled L<"Status Methods">,
2514
below).
2515
 
2516
=cut
2517
 
2518
=head2 store
2519
 
2520
Example:
2521
 
2522
	$imap->store(@args) or die "Could not store: $@\n";
2523
 
2524
The B<store> method accepts a message sequence number or
2525
comma-separated list of message sequence numbers as a first argument, a
2526
message data item name, and a value for the message data item.
2527
Currently, data items are the word "FLAGS" followed by a space and a
2528
list of flags (in parens). The word "FLAGS" can be modified by
2529
prefixing it with either a "+" or a "-" (to indicate "add these flags"
2530
or "remove these flags") and by suffixing it with ".SILENT" (which
2531
reduces the amount of output from the server; very useful with large
2532
message sets). Normally you won't need to call B<store> because there
2533
are oodles of methods that will invoke store for you with the correct
2534
arguments. Furthermore, these methods are friendlier and more flexible
2535
with regards to how you specify your arguments. See for example L<see>,
2536
L<deny_seeing>, L<delete_message>, and L<restore_message>. Or L<mark>,
2537
L<unmark>, L<set_flag>, and L<unset_flag>.
2538
 
2539
=head2 subject
2540
 
2541
Example:
2542
 
2543
 
2544
	my $subject = $imap->subject($msg);
2545
 
2546
 
2547
The B<subject> method accepts one argument, a message sequence number (or a 
2548
message UID, if the I<Uid> parameter is true). The text in the "Subject" header
2549
of that message is returned (without the "Subject: " prefix). This method is
2550
a short-cut for:
2551
 
2552
	my $subject = $imap->get_header($msg, "Subject");
2553
 
2554
=head2 subscribed
2555
 
2556
Example:
2557
 
2558
	my @subscribedFolders = $imap->subscribed 
2559
		or warn "Could not find subscribed folders: $@\n";
2560
 
2561
The B<subscribed> method works like the B<folders> method, above,
2562
except that the returned list (or array reference, if called in scalar
2563
context) contains only the subscribed folders. 
2564
 
2565
Like L<folders>, you can optionally provide a prefix argument to the 
2566
B<subscribed> method.
2567
 
2568
=head2 tag_and_run
2569
 
2570
Example:
2571
 
2572
	my @output = $imap->tag_and_run(@args) 
2573
		or die "Could not tag_and_run: $@\n";
2574
 
2575
The B<tag_and_run> method accepts one or two arguments. The first
2576
argument is a string containing an IMAP Client command, without a tag
2577
but with all required arguments. The optional second argument is a
2578
string to look for that will indicate success (without pattern
2579
delimiters). The default is C<OK.*>. 
2580
 
2581
The B<tag_and_run> method will prefix your string (from the first
2582
argument) with the next transaction number and run the command. It
2583
returns an array of output lines from the command, which you are free
2584
to parse as you see fit. Using this method instead of B<run> (above)
2585
will free you from having to worry about handling the tags (and from
2586
worrying about the side affects of naming your own tags).
2587
 
2588
=cut
2589
 
2590
=head2 uidnext
2591
 
2592
Example:
2593
 
2594
	my $nextUid = $imap->uidnext($folder) or die "Could not uidnext: $@\n";
2595
 
2596
The B<uidnext> method accepts one argument, the name of a folder, and
2597
returns the numeric string that is the next available message UID for
2598
that folder.
2599
 
2600
=head2 thread
2601
 
2602
Example: 
2603
 
2604
	my $thread = $imap->thread($algorythm, $charset, @search_args ) ;
2605
 
2606
The B<thread> method accepts zero to three arguments. The first argument is the
2607
threading algorythm to use, generally either I<ORDEREDSUBJECT> or I<REFERENCES>.
2608
The second argument is the character set to use, and the third argument is the
2609
set of search arguments to use.
2610
 
2611
If the algorythm is not supplied, it defaults to I<REFERENCES> if available, or
2612
I<ORDEREDSUBJECT> if available. If neither of these is available then the 
2613
B<thread> method returns undef.
2614
 
2615
If the character set is not specified it will default to I<UTF-8>.
2616
 
2617
If the search arguments are not specified, the default is I<ALL>.
2618
 
2619
If B<thread> is called for an object connected to a server that does not support
2620
the THREADS extension then the B<thread> method will return C<undef>.
2621
 
2622
The B<threads> method will issue the I<THREAD> command as defined in 
2623
L<http://www.ietf.org/internet-drafts/draft-ietf-imapext-thread-11.txt>.
2624
It returns an array of threads. Each element in the array is either a message
2625
id or a reference to another array of (sub)threads.
2626
 
2627
If the L<Uid> parameter is set to a true value then the message id's returned 
2628
in the thread structure will be message UID's. Otherwise they will be message
2629
sequence numbers.
2630
 
2631
=head2 uidvalidity
2632
 
2633
Example:
2634
 
2635
	my $validity = $imap->uidvalidity($folder) 
2636
		or die "Could not uidvalidity: $@\n";
2637
 
2638
The B<uidvalidity> method accepts one argument, the name of a folder,
2639
and returns the numeric string that is the unique identifier validity
2640
value for the folder.
2641
 
2642
=head2 unmark
2643
 
2644
Example:
2645
 
2646
	$imap->unmark(@msgs) or die "Could not unmark: $@\n";
2647
 
2648
The B<unmark> method accepts a list of one or more messages sequence
2649
numbers, or a single reference to an array of one or more message
2650
sequence numbers, as its argument(s). It then unsets the I<\Flagged>
2651
flag for those message(s). Of course, if the L<Uid> parameter is set to
2652
a true value then those message sequence numbers should really be
2653
unique message id's.
2654
 
2655
Note that specifying C<$imap-E<gt>unmark(@msgs)> is just a shortcut for
2656
specifying C<$imap-E<gt>unset_flag("Flagged",@msgs)>. 
2657
 
2658
Note also that the I<\Flagged> flag is just one of many possible flags.
2659
This is a little confusing, but you'll have to get used to the idea
2660
that among the reserved flags specified in RFC2060 is one name
2661
I<\Flagged>. There is no specific meaning for this flag; it means
2662
whatever the mailbox owner (or delegate) wants it to mean when it
2663
is turned on.
2664
 
2665
=cut
2666
 
2667
=head2 unseen
2668
 
2669
Example:
2670
 
2671
	my @unread = $imap->unseen or warn "Could not find unseen msgs: $@\n";
2672
 
2673
The B<unseen> method performs an IMAP SEARCH UNSEEN search against the
2674
selected folder and returns an array of sequence numbers of messages
2675
that have not yet been seen (ie their I<\Seen> flag is not set). If the
2676
L<Uid> parameter is true then an array of message UID's will be
2677
returned instead. If called in scalar context than a pointer to the
2678
array (rather than the array itself) will be returned.
2679
 
2680
Note that when specifying the flag in question, the preceding backslash
2681
(\) is entirely optional.
2682
 
2683
=cut
2684
 
2685
=head2 unseen_count
2686
 
2687
Example:
2688
 
2689
	foreach my $f ($imap->folders) {
2690
		print 	"The $f folder has ",
2691
			$imap->unseen_count($f)||0, 
2692
			" unseen messages.\n";		
2693
	}
2694
 
2695
The B<unseen_count> method accepts the name of a folder as an argument
2696
and returns the number of unseen messages in that folder. If no folder
2697
argument is provided then it returns the number of unseen messages in
2698
the currently selected Folder.
2699
 
2700
=head2 unset_flag
2701
 
2702
Example:
2703
 
2704
	$imap->unset_flag("\Seen",@msgs) 
2705
		or die "Could not unset_flag: $@\n";
2706
 
2707
The B<unset_flag> method accepts the name of a flag as its first
2708
argument and a list of one or more messages sequence numbers, or a
2709
single reference to an array of one or more message sequence numbers,
2710
as its next argument(s). It then unsets the flag specified for those
2711
message(s). Of course, if the L<Uid> parameter is set to a true value
2712
then those message sequence numbers had better be unique message id's,
2713
just as you'd expect.
2714
 
2715
=cut
2716
 
2717
=head1 Other IMAP Client Commands and the Default Object Method
2718
 
2719
IMAP Client Commands not otherwise documented have been implemented via
2720
an AUTOLOAD hack and use a default method.
2721
 
2722
If a program calls a method that is not defined (or inherited) by the
2723
B<IMAPClient> module then the B<IMAPClient> module will assume that it
2724
is an IMAP client command. It will prefix the command with the next
2725
available transaction number (or tag value), and append to it the
2726
space-delimited list of arguments supplied to the unimplemented method
2727
(if any). It will then read lines of output from the imap session until
2728
it finds a line containing the strings "OK" and "Completed", and return
2729
an array containing all of the lines of output (or, if called in scalar
2730
context, an array reference). If it finds "BAD" or "NO" instead of "OK"
2731
it returns C<undef>.
2732
 
2733
Eg: 
2734
 
2735
	my @results = $imap->FOO("bar","an example","of the default");
2736
 
2737
 
2738
results in:
2739
 
2740
 
2741
	99 FOO bar an example of the default\r\n 
2742
 
2743
being sent to the IMAP server (assuming that 99 is the current
2744
transaction number).
2745
 
2746
Notice that we used an uppercase method name "FOO" so as not to
2747
conflict with future implementations of that IMAP command. If you run
2748
your script with warnings turned on (always a good idea, at least
2749
during testing), then you will receive warnings whenever you use a
2750
lowercase method name that has not been implemented. An exception to
2751
this is when you use certain common (yet unimplemented) methods that,
2752
if ever explicitly implemented, are guaranteed to behave just like the
2753
default method. To date, those methods are either documented in the
2754
section labeled L<"OBJECT METHODS">, above, or listed here:
2755
 
2756
B<Mail::IMAPClient>'s default method adds enormous flexibility and
2757
built-in extensibility but it is not psychic. It can handle almost
2758
any extension and truthfully tell you if the server successfully 
2759
performed your request. But it cannot predict how the command's
2760
output should be handled, beyond returning a true value on success
2761
and C<undef> on failure. So if you are running a command because
2762
you want the output then you may need to parse that output yourself.
2763
If you develop code that extends B<Mail::IMAPClient> in a way that
2764
you feel may be useful to others then please consider donating the
2765
code. Many of the methods in B<Mail::IMAPClient> were contributed
2766
by other programmers such as yourself. Their contributions are listed
2767
in the F<Changes> file as they occur.
2768
 
2769
=head2 copy($msg,$folder)
2770
 
2771
Copy a message from the currently selected folder in the the folder
2772
whose name is in C<$folder>
2773
 
2774
=head2 subscribe($folder)
2775
 
2776
Subscribe to a folder
2777
 
2778
B<CAUTION:> Once again, remember to quote your quotes (or use the
2779
L<Quote> method) if you want quotes to be part of the IMAP command 
2780
string. 
2781
 
2782
You can also use the default method to override the behavior of
2783
implemented IMAP methods by changing the case of the method name,
2784
preferably to all-uppercase so as not to conflict with the Class method
2785
and accessor method namespace. For example, if you don't want the
2786
L<search> method's behavior (which returns a list of message numbers)
2787
but would rather have an array of raw data returned from your L<search>
2788
operation, you can issue the following snippet:
2789
 
2790
	my @raw = $imap->SEARCH("SUBJECT","Whatever...");
2791
 
2792
which is slightly more efficient than the equivalent:
2793
 
2794
	$imap->search("SUBJECT","Whatever...");
2795
 
2796
	my @raw = $imap->Results;
2797
 
2798
Of course you probably want the search results tucked nicely into a list
2799
for you anyway, in which case you might as well use the L<search> method.
2800
 
2801
=cut
2802
 
2803
=head1 Parameters
2804
 
2805
There are several parameters that influence the behavior of an
2806
B<IMAPClient> object. Each is set by specifying a named value pair
2807
during new method invocation as follows:
2808
 
2809
	my $imap = Mail::IMAPClient->new ( parameter  => "value",
2810
			       parameter2 => "value",
2811
				...
2812
	);
2813
 
2814
Parameters can also be set after an object has been instantiated by
2815
using the parameter's eponymous accessor method like this:
2816
 
2817
	my $imap = Mail::IMAPClient->new;
2818
	   $imap->parameter( "value");
2819
	   $imap->parameter2("value");
2820
 
2821
The eponymous accessor methods can also be used without arguments to
2822
obtain the current value of the parameter as follows:
2823
 
2824
	my $imap = Mail::IMAPClient->new;
2825
           $imap->parameter( "value");
2826
           $imap->parameter2("value");
2827
 
2828
		... 	# A whole bunch of awesome perl code, 
2829
			# omitted for brevity
2830
 
2831
 
2832
	   my $forgot  = $imap->parameter;
2833
	   my $forgot2 = $imap->parameter2;
2834
 
2835
Note that in these examples I'm using 'parameter' and 'parameter2' as
2836
generic parameter names. The B<IMAPClient> object doesn't actually have
2837
parameters named 'parameter' and 'parameter2'. On the contrary, the
2838
available parameters are:
2839
 
2840
=head2 Authmechanism
2841
 
2842
Example:
2843
 
2844
		$imap->Authmechanism("CRAM-MD5");
2845
		# or
2846
		my $authmech = $imap->Authmechanism();
2847
 
2848
If specified, the I<Authmechanism> causes the specified authentication
2849
mechanism to be used whenever B<Mail::IMAPClient> would otherwise invoke
2850
B<login>. If the value specified for the I<Authmechanism> parameter is not
2851
a valid authentication mechanism for your server then you will never ever
2852
be able to log in again for the rest of your perl script, probably. So you
2853
might want to check, like this:
2854
 
2855
	my $authmech = "CRAM-MD5";
2856
	$imap->has_capability($authmech) and $imap->Authmechanism($authmech);
2857
 
2858
Of course if you know your server supports your favorite authentication 
2859
mechanism then you know, so you can then include your I<Authmechanism> 
2860
with your B<new> call, as in:
2861
 
2862
	my $imap = Mail::IMAPClient->new(
2863
			User    => $user,
2864
			Passord => $passord,
2865
			Server  => $server,
2866
			Authmechanism  => $authmech,
2867
			%etc 
2868
	);
2869
 
2870
If I<Authmechanism> is supplied but I<Authcallback> is not then you had better be
2871
supporting one of the authentication mechanisms that B<Mail::IMAPClient> supports
2872
"out of the box" (such as CRAM-MD5).
2873
 
2874
=head2 Authcallback
2875
 
2876
Example:
2877
 
2878
		$imap->Authcallback( \&callback );
2879
 
2880
 
2881
This specifies a default callback to the default authentication mechanism
2882
(see L<Authmechanism>, above). Together, these two methods replace automatic
2883
calls to login with automatic calls that look like this (sort of):
2884
 
2885
	$imap->authenticate($imap->Authmechanism,$imap->Authcallback) ;
2886
 
2887
If I<Authmechanism> is supplied but I<Authcallback> is not then you had better be
2888
supporting one of the authentication mechanisms that B<Mail::IMAPClient> supports
2889
"out of the box" (such as CRAM-MD5).
2890
 
2891
=head2 Buffer
2892
 
2893
Example:
2894
 
2895
	$Buffer = $imap->Buffer();
2896
	# or:
2897
	$imap->Buffer($new_value);
2898
 
2899
The I<Buffer> parameter sets the size of a block of I/O. It is ignored
2900
unless L<Fast_io>, below, is set to a true value (the default), or
2901
unless you are using the L<migrate> method. It's value should be the
2902
number of bytes to attempt to read in one I/O operation. The default
2903
value is 4096.
2904
 
2905
When using the L<migrate> method, you can often achieve dramatic
2906
improvements in throughput by adjusting this number upward. However,
2907
doing so also entails a memory cost, so if set too high you risk losing
2908
all the benefits of the L<migrate> method's chunking algorythm. Your
2909
program can thus terminate with an "out of memory" error and you'll
2910
have no one but yourself to blame.
2911
 
2912
Note that, as hinted above, the I<Buffer> parameter affects the
2913
behavior of the L<migrate> method regardless of whether you have
2914
L<Fast_io> turned on. Believe me, you don't want to go around migrating
2915
tons of mail without using buffered I/O! 
2916
 
2917
 
2918
=head2 Clear
2919
 
2920
Example:
2921
 
2922
	$Clear = $imap->Clear();
2923
	# or:
2924
	$imap->Clear($new_value);
2925
 
2926
The name of this parameter, for historical reasons, is somewhat
2927
misleading. It should be named I<Wrap>, because it specifies how many
2928
transactions are stored in the wrapped history buffer. But it didn't
2929
always work that way; the buffer used to actually get cleared. The name
2930
though remains the same in the interests of backwards compatibility.
2931
Also I'm too lazy to change it.
2932
 
2933
I<Clear> specifies that the object's history buffer should be wrapped
2934
after every I<n> transactions, where I<n> is the value specified for
2935
the I<Clear> parameter. Calling the eponymous B<Clear> method without
2936
an argument will return the current value of the I<Clear> parameter but
2937
will not cause clear the history buffer to wrap. 
2938
 
2939
Setting I<Clear> to 0 turns off automatic history buffer wrapping, and
2940
setting it to 1 turns off the history buffer facility (except for the
2941
last transaction, which cannot be disabled without breaking the
2942
B<IMAPClient> module). Setting I<Clear> to 0 will not cause an
2943
immediate clearing of the history buffer; setting it to 1 (or any other
2944
number) will (except of course for that inevitable last transaction). 
2945
 
2946
The default I<Clear> value is set to five in order to conserve memory.
2947
 
2948
=head2 Debug
2949
 
2950
Example:
2951
 
2952
	$Debug = $imap->Debug();
2953
	# or:
2954
	$imap->Debug($true_or_false);
2955
 
2956
Sets the debugging flag to either a true or false value. Can be
2957
supplied with the L<new> method call or separately by calling the
2958
B<Debug> object method. Use of this parameter is strongly recommended
2959
when debugging scripts and required when reporting bugs.
2960
 
2961
=head2 Debug_fh
2962
 
2963
Example:
2964
 
2965
	$Debug_fh = $imap->Debug_fh();
2966
	# or:
2967
	$imap->Debug_fh($fileHandle);
2968
 
2969
Specifies the filehandle to which debugging information should be
2970
printed. It can either a filehandle object reference or a filehandle
2971
glob. The default is to print debugging info to STDERR.
2972
 
2973
For example, you can:
2974
 
2975
	use Mail::IMAPClient;
2976
	use IO::File;
2977
	# set $user, $pass, and $server here
2978
	my $dh = IO::File->new(">debugging.output") 
2979
		or die "Can't open debugging.output: $!\n";
2980
	my $imap = Mail::IMAPClient->new(	User=>$user, Password=>$pass, 
2981
						Server=>$server, Debug=> "yes, please",
2982
						Debug_fh => $dh
2983
	);
2984
 
2985
which is the same as:
2986
 
2987
	use Mail::IMAPClient;
2988
	use IO::File;
2989
	# set $user, $pass, and $server here
2990
	my $imap = Mail::IMAPClient->new(	User	=>$user, 
2991
						Password=>$pass, 
2992
						Server	=>$server, 
2993
						Debug	=> "yes, please",
2994
						Debug_fh=> IO::File->new(">debugging.output") || 
2995
							die "Can't open debugging.output: $!\n"
2996
	);
2997
 
2998
 
2999
You can also:
3000
 
3001
	use Mail::IMAPClient;
3002
	# set $user, $pass, and $server here
3003
	open(DBG,">debugging.output") 
3004
		or die "Can't open debugging.output: $!\n";
3005
	my $imap = Mail::IMAPClient->new(	User=>$user, Password=>$pass, 
3006
						Server=>$server, Debug=> 1,
3007
						Debug_fh => *DBG
3008
	);
3009
 
3010
Specifying this parameter is not very useful unless L<Debug> is set 
3011
to a true value.
3012
 
3013
=head2 EnableServerResponseInLiteral
3014
 
3015
Example:
3016
 
3017
	$EnableServerResponseInLiteral = $imap->EnableServerResponseInLiteral();
3018
	# or:
3019
	$imap->EnableServerResponseInLiteral($new_value);
3020
 
3021
The I<EnableServerResponseInLiteral> parameter tells
3022
B<Mail::IMAPClient> to expect server responses to be embedded in
3023
literal strings. Usually literal strings contain only message data, not
3024
server responses. I have seen at least one IMAP server implementation
3025
though that includes the final <tag> OK response in the literal data.
3026
If your server does this then your script will hang whenever you try to
3027
read literal data, such as message text, or even output from the
3028
L<folders> method if some of your folders have special characters such
3029
as double quotes or sometimes spaces in the name.
3030
 
3031
I am pretty sure this behavior is not RFC2060 compliant so I am
3032
dropping it by default. In fact, I encountered the problem a long time
3033
ago when still new to IMAP and may have imagined the whole thing.
3034
However, if your scripts hang running certain methods you may want to
3035
at least try enabling this parameter by passing the eponymous method a
3036
true value. 
3037
 
3038
=head2 Fast_io
3039
 
3040
Example:
3041
 
3042
	$Fast_io = $imap->Fast_io();
3043
	# or:
3044
	$imap->Fast_io($true_or_false);
3045
 
3046
The I<Fast_io> parameter controlls whether or not your
3047
B<Mail::IMAPClient> object will attempt to use buffered (i.e. "Fast")
3048
I/O. It is turned on by default. If you turn it off you will definately
3049
slow down your program, often to a painfull degree. However, if you are
3050
experience problems you may want to try this just to see if it helps.
3051
If it does then that means you have found a bug and should report it
3052
immediately (by following the instructions in the section on
3053
L<"REPORTING BUGS">). Even if it doesn't fix the problem, testing with
3054
both I<Fast_io> turned on and with it turned off will often aid in
3055
identifying the source of the problem. (If it doesn't help you, it may
3056
help me when you report it!)
3057
 
3058
Lately there have not been any bugs associated with I<Fast_io> so this
3059
parameter may become deprecated in the future.
3060
 
3061
=head2 Folder
3062
 
3063
Example:
3064
 
3065
	$Folder = $imap->Folder();
3066
	# or:
3067
	$imap->Folder($new_value);
3068
 
3069
The I<Folder> parameter returns the name of the currently-selected
3070
folder (in case you forgot). It can also be used to set the name of the
3071
currently selected folder, which is completely unnecessary if you used
3072
the L<select> method (or L<select>'s read-only equivalent, the
3073
L<examine> method) to select it. 
3074
 
3075
Note that setting the I<Folder> parameter does not automatically select 
3076
a new folder; you use the L<select> or L<examine> object methods for that. 
3077
Generally, the I<Folder> parameter should only be queried (by using the 
3078
no-argument form of the B<Folder> method). You will only need to set the 
3079
I<Folder> parameter if you use some mysterious technique of your own for
3080
selecting a folder, which you probably won't do.
3081
 
3082
=cut
3083
 
3084
=head2 Maxtemperrors
3085
 
3086
Example:
3087
 
3088
	$Maxtemperrors = $imap->Maxtemperrors();
3089
	# or:
3090
	$imap->Maxtemperrors($new_value);
3091
 
3092
The I<Maxtemperrors> parameter specifies the number of times a write
3093
operation is allowed to fail on a "Resource Temporarily Available"
3094
error. These errors can occur from time to time if the server is too
3095
busy to empty out its read buffer (which is logically the "other end"
3096
of the client's write buffer). By default, B<Mail::IMAPClient> will
3097
retry an unlimited number of times, but you can adjust this 
3098
behavior by setting I<Maxtemperrors>. Note that after each temporary 
3099
error, the server will wait for a number of seconds equal to the number 
3100
of consecutive temporary errors times .25, so very high values for 
3101
I<Maxtemperrors> can slow you down in a big way if your "temporary 
3102
error" is not all that temporary.
3103
 
3104
You can set this parameter to "UNLIMITED" to ignore "Resource
3105
Temporarily Unavailable" errors. This is the default.
3106
 
3107
=head2 Password
3108
 
3109
Example:
3110
 
3111
	$Password = $imap->Password();
3112
	# or:
3113
	$imap->Password($new_value);
3114
 
3115
Specifies the password to use when logging into the IMAP service on the
3116
host specified in the I<Server> parameter as the user specified in the
3117
I<User> parameter. Can be supplied with the B<new> method call or
3118
separately by calling the B<Password> object method.
3119
 
3120
If I<Server>, I<User>, and I<Password> are all provided to the L<new>
3121
method, then the newly instantiated object will be connected to the
3122
host specified in I<Server> (at either the port specified in I<Port> or
3123
the default port 143) and then logged on as the user specified in the
3124
I<User> parameter (using the password provided in the I<Password>
3125
parameter). See the discussion of the L<"new"> method, below.
3126
 
3127
=head2 Peek
3128
 
3129
Example:
3130
 
3131
	$Peek = $imap->Peek();
3132
	# or:
3133
	$imap->Peek($true_or_false);
3134
 
3135
Setting I<Peek> to a true value will prevent the L<body_string>,
3136
L<message_string> and L<message_to_file> methods from automatically
3137
setting the I<\Seen> flag. Setting L<"Peek"> to 0 (zero) will force
3138
L<"body_string">, L<"message_string">, L<"message_to_file">, and
3139
L<"parse_headers"> to always set the I<\Seen> flag. 
3140
 
3141
The default is to set the seen flag whenever you fetch the body of a
3142
message but not when you just fetch the headers. Passing I<undef> to
3143
the eponymous B<Peek> method will reset the I<Peek> parameter to its
3144
pristine, default state. 
3145
 
3146
=cut
3147
 
3148
=head2 Port
3149
 
3150
Example:
3151
 
3152
	$Port = $imap->Port();
3153
	# or:
3154
	$imap->Port($new_value);
3155
 
3156
Specifies the port on which the IMAP server is listening. The default
3157
is 143, which is the standard IMAP port. Can be supplied with the
3158
L<new> method call or separately by calling the L<Port> object method.
3159
 
3160
=head2 Prewritemethod
3161
 
3162
Specifies a method to call if your authentication mechanism requires you to
3163
to do pre-write processing of the data sent to the server. If defined, then the
3164
I<Prewritemethod> parameter should contain a reference to a subroutine that 
3165
will do Special Things to data before it is sent to the IMAP server (such as
3166
encryption or signing).
3167
 
3168
This method will be called immediately prior to sending an IMAP client command
3169
to the server. Its first argument is a reference to the I<Mail::IMAPClient> object
3170
and the second argument is a string containing the command that will be sent to
3171
the server. Your I<Prewritemethod> should return a string that has been signed or
3172
encrypted or whatever; this returned string is what will actually be sent to the
3173
server.
3174
 
3175
Your I<Prewritemethod> will probably need to know more than this to do whatever it does. 
3176
It is recommended that you tuck all other pertinent information into a hash, and store a 
3177
reference to this hash somewhere where your method can get to it, possibly in the 
3178
I<Mail::IMAPClient> object itself.
3179
 
3180
Note that this method should not actually send anything over the socket connection to 
3181
the server; it merely converts data prior to sending.
3182
 
3183
If you need a I<Prewritemethod> then you probably need a L<Readmethod> as well.
3184
 
3185
=head2 Ranges
3186
 
3187
Example:
3188
 
3189
	$imap->Ranges(1);
3190
	# or:
3191
	my $search = $imap->search(@search_args);
3192
	if ( $imap->Ranges) {	# $search is a MessageSet object
3193
		print "This is my condensed search result: $search\n";
3194
		print "This is every message in the search result: ",
3195
			join(",",@$search),"\n;
3196
	}
3197
 
3198
 
3199
If set to a true value, then the L<search> method will return a 
3200
L<Mail::IMAPClient::MessageSet> object if called in a scalar context,
3201
instead of the array reference that B<fetch> normally returns when
3202
called in a scalar context. If set to zero or if undefined, then B<search>
3203
will continue to return an array reference when called in scalar context.
3204
 
3205
This parameter has no affect on the B<search> method when B<search> is called
3206
in a list context.
3207
 
3208
=head2 Readmethod
3209
 
3210
This parameter, if supplied, should contain a reference to a subroutine that will
3211
replace sysreads. The subroutine will be passed the following arguments:
3212
 
3213
=over 4
3214
 
3215
1. imap_object_ref - a reference to the current imap object
3216
 
3217
2. scalar_ref - a reference to a scalar variable into which data is read. The data
3218
place in here should be "finished data", so if you are decrypting or removing signatures
3219
then be sure to do that before you place data into this buffer.
3220
 
3221
3. read_length - the number of bytes requested to be read
3222
 
3223
4. offset - the offset into C<scalar_ref> into which data should be read. If not supplied it
3224
should default to zero.
3225
 
3226
=back
3227
 
3228
Note that this method completely replaces reads from the connection to the server, so if 
3229
you define one of these then your subroutine will have to actually do the read. It is for
3230
things like this that we have the L<Socket> parameter and eponymous accessor method.
3231
 
3232
Your I<Readmethod> will probably need to know more than this to do whatever it does. 
3233
It is recommended that you tuck all other pertinent information into a hash, and store 
3234
a reference to this hash somewhere where your method can get to it, possibly in the 
3235
I<Mail::IMAPClient> object itself.
3236
 
3237
If you need a I<Readmethod> then you probably need a L<Prewritemethod> as well.
3238
 
3239
=head2 Server
3240
 
3241
Example:
3242
 
3243
	$Server = $imap->Server();
3244
	# or:
3245
	$imap->Server($hostname);
3246
 
3247
Specifies the hostname or IP address of the host running the IMAP
3248
server. If provided as part of the L<new> method call, then the new
3249
IMAP object will automatically be connected at the time of
3250
instantiation. (See the L<new> method, below.) Can be supplied with the
3251
L<new> method call or separately by calling the B<Server> object
3252
method.
3253
 
3254
=cut
3255
 
3256
=head2 Showcredentials
3257
 
3258
Normally debugging output will mask the login credentials when the plain text
3259
login mechanism is used. Setting I<Showcredentials> to a true value will suppress
3260
this, so that you can see the string being passed back and forth during plain text
3261
login. Only set this to true when you are debugging problems with the IMAP LOGIN 
3262
command, and then turn it off right away when you're finished working on that problem.
3263
 
3264
Example:
3265
 
3266
	print "This is very risky!\n" if $imap->Showcredentials();
3267
	# or:
3268
	$imap->Showcredentials(0);	# mask credentials again
3269
 
3270
 
3271
=head2 Socket
3272
 
3273
Example:
3274
 
3275
	$Socket = $imap->Socket();
3276
	# or:
3277
	$imap->Socket($socket_fh);
3278
 
3279
The I<Socket> method can be used to obtain the socket handle of the
3280
current connection (say, to do I/O on the connection that is not
3281
otherwise supported by B<Mail::IMAPClient>) or to replace the current
3282
socket with a new handle (perhaps an SSL handle, for example). 
3283
 
3284
If you supply a socket handle yourself, either by doing something like:
3285
 
3286
	 $imap=Mail::IMAPClient->new(Socket=>$sock, User => ... );
3287
 
3288
or by doing something like:
3289
 
3290
	 $imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server => $host);
3291
	 # blah blah blah
3292
	 $imap->Socket($ssl);
3293
 
3294
then it will be up to you to establish the connection AND to
3295
authenticate, either via the L<login> method, or the fancier
3296
L<authenticate>, or, since you know so much anyway, by just doing raw
3297
I/O against the socket until you're logged in. If you do any of this
3298
then you should also set the L<State> parameter yourself to reflect the
3299
current state of the object (i.e. Connected, Authenticated, etc). 
3300
 
3301
=cut
3302
 
3303
=head2 Timeout
3304
 
3305
Example:
3306
 
3307
	$Timeout = $imap->Timeout();
3308
	# or:
3309
	$imap->Timeout($new_value);
3310
 
3311
Specifies the timeout value in seconds for reads. Specifying a true
3312
value for I<Timeout> will prevent B<Mail::IMAPClient> from blocking in
3313
a read.
3314
 
3315
Since timeouts are implemented via the perl L<select|perlfunc/select>
3316
operator, the I<Timeout> parameter may be set to a fractional number of
3317
seconds. Not supplying a I<Timeout>, or (re)setting it to zero,
3318
disables the timeout feature.
3319
 
3320
=cut
3321
 
3322
=head2 Uid
3323
 
3324
Example:
3325
 
3326
	$Uid = $imap->Uid();
3327
	# or:
3328
	$imap->Uid($true_or_false);
3329
 
3330
If L<Uid> is set to a true value (i.e. 1) then the behavior of the
3331
L<fetch>, L<search>, L<copy>, and L<store> methods (and their
3332
derivatives) is changed so that arguments that would otherwise be
3333
message sequence numbers are treated as message UID's and so that
3334
return values (in the case of the L<search> method and its derivatives)
3335
that would normally be message sequence numbers are instead message
3336
UID's.
3337
 
3338
Internally this is implemented as a switch that, if turned on, causes
3339
methods that would otherwise issue an IMAP FETCH, STORE, SEARCH, or
3340
COPY client command to instead issue UID FETCH, UID STORE, UID SEARCH,
3341
or UID COPY, respectively. The main difference between message sequence
3342
numbers and message UID's is that, according to RFC2060, UID's must not
3343
change during a session and should not change between sessions, and
3344
must never be reused. Sequence numbers do not have that same guarantee
3345
and in fact may be reused right away. 
3346
 
3347
Since foldernames also have a unique identifier (UIDVALIDITY), which is
3348
provided when the folder is L<select>ed or L<examine>d or by doing
3349
something like "$imap->status($folder,"UIDVALIDITY"), it is possible to
3350
uniquely identify every message on the server, although normally you
3351
won't need to bother.
3352
 
3353
The methods currently affected by turning on the L<Uid> flag are:
3354
 
3355
	copy 		fetch
3356
	search 		store 
3357
	message_string 	message_uid
3358
	body_string 	flags
3359
	move 		size
3360
	parse_headers	thread
3361
 
3362
Note that if for some reason you only want the L<Uid> parameter turned
3363
on for one command, then you can choose between the following two
3364
snippets, which are equivalent:
3365
 
3366
Example 1:
3367
 
3368
	$imap->Uid(1);
3369
	my @uids = $imap->search('SUBJECT',"Just a silly test"); # 
3370
	$imap->Uid(0);
3371
 
3372
Example 2:
3373
 
3374
	my @uids; 
3375
       	foreach $r ($imap->UID("SEARCH","SUBJECT","Just a silly test") {
3376
	       chomp $r;
3377
	       $r =~ s/\r$//;
3378
	       $r =~ s/^\*\s+SEARCH\s+// or next;
3379
	       push @uids, grep(/\d/,(split(/\s+/,$r)));
3380
	}
3381
 
3382
In the second example, we used the default method to issue the UID IMAP
3383
Client command, being careful to use an all-uppercase method name so as
3384
not to inadvertently call the L<Uid> accessor method. Then we parsed
3385
out the message UIDs manually, since we don't have the benefit of the
3386
built-in L<search> method doing it for us.
3387
 
3388
Please be very careful when turning the L<Uid> parameter on and off
3389
throughout a script. If you loose track of whether you've got the
3390
L<Uid> parameter turned on you might do something sad, like deleting
3391
the wrong message. Remember, like all eponymous accessor methods, the
3392
B<Uid> method without arguments will return the current value for the
3393
L<Uid> parameter, so do yourself a favor and check. The safest approach
3394
is probably to turn it on at the beginning (or just let it default to
3395
being on) and then leave it on. (Remember that leaving it turned off
3396
can lead to problems if changes to a folder's contents cause
3397
resequencing.) 
3398
 
3399
By default, the L<Uid> parameter is turned on.
3400
 
3401
=head2 User
3402
 
3403
Example:
3404
 
3405
	$User = $imap->User();
3406
	# or:
3407
	$imap->User($userid);
3408
 
3409
Specifies the userid to use when logging into the IMAP service. Can be
3410
supplied with the L<new> method call or separately by calling the
3411
B<User> object method.
3412
 
3413
Parameters can be set during L<new> method invocation by passing named
3414
parameter/value pairs to the method, or later by calling the
3415
parameter's eponymous object method.
3416
 
3417
=head2 Ssl
3418
 
3419
Example: 
3420
 
3421
	$is_ssl_active = $imap->Ssl();
3422
	# or:
3423
	$imap->Ssl($activate_ssl);
3424
 
3425
Specifies whether a connection should be established using a SSL (cyphered)
3426
channel or via a regular clear TCP connection. Of course, setting this
3427
parameter makes sense only before the connection is established.
3428
 
3429
Please note that this parameter was specifically added for the Debian 
3430
packaging. If you are developing software to be deployed over different 
3431
machines, we suggest you not to use it - or to specify your users to install
3432
this patch. You can get it at Debian's bug tracking system at
3433
L<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=111960>, or at CPAN's
3434
L<http://rt.cpan.org/NoAuth/Bug.html?id=9256>.
3435
 
3436
=cut
3437
 
3438
 
3439
=head1 Status Methods
3440
 
3441
There are several object methods that return the status of the object.
3442
They can be used at any time to check the status of an B<IMAPClient>
3443
object, but are particularly useful for determining the cause of
3444
failure when a connection and login are attempted as part of a single
3445
L<new> method invocation. The status methods are:
3446
 
3447
=head2 Escaped_results
3448
 
3449
Example:
3450
	my @results = $imap->Escaped_results ;
3451
 
3452
The B<Escaped_results> method is almost identical to the B<History>
3453
method. Unlike the B<History> method, however, server output
3454
transmitted literally will be wrapped in double quotes, with all of the
3455
parentheses, double quotes, backslashes, newlines, and carrage returns
3456
escaped. If called in a scalar context, B<Escaped_results> returns an
3457
array reference rather than an array.
3458
 
3459
B<Escaped_results> is useful if you are retrieving output and
3460
processing it manually, and you are depending on the above special
3461
characters to delimit the data. It is not useful when retrieving
3462
message contents; use B<message_string> or B<body_string> for that.
3463
 
3464
=head2 History
3465
 
3466
Example:
3467
 
3468
	my @history = $imap->History;
3469
 
3470
The B<History> method is almost identical to the L<Results> method.
3471
Unlike the L<Results> method, however, the IMAP command that was issued
3472
to create the results being returned is not included in the returned
3473
results. If called in a scalar context, B<History> returns an array
3474
reference rather than an array.
3475
 
3476
=head2 IsUnconnected
3477
 
3478
returns a true value if the object is currently in an L<Unconnected>
3479
state.
3480
 
3481
=head2 IsConnected
3482
 
3483
returns a true value if the object is currently in either a
3484
L<Connected>, L<Authenticated>, or L<Selected> state.
3485
 
3486
=head2 IsAuthenticated
3487
 
3488
returns a true value if the object is currently in either an
3489
L<Authenticated> or L<Selected> state.
3490
 
3491
=head2 IsSelected
3492
 
3493
returns a true value if the object is currently in a L<Selected> state.
3494
 
3495
=head2 LastError
3496
 
3497
Internally B<LastError> is implemented just like a parameter (as
3498
described in L<"Parameters">, above). There is a I<LastError> attribute
3499
and an eponymous accessor method which returns the I<LastError> text
3500
string describing the last error condition encountered by the server. 
3501
 
3502
Note that some errors are more serious than others, so I<LastError>'s
3503
value is only meaningful if you encounter an error condition that you
3504
don't like. For example, if you use the L<exists> method to see if a
3505
folder exists and the folder does not exist, then an error message will
3506
be recorded in I<LastError> even though this is not a particularly
3507
serious error. On the other hand, if you didn't use L<exists> and just
3508
tried to L<select> a non-existing folder, then L<select> would return
3509
C<undef> after setting I<LastError> to something like C<NO SELECT
3510
failed: Can't open mailbox "mailbox": no such mailbox>. At this point
3511
it would be useful to print out the contents of I<LastError> as you
3512
L<die|perlfunc/die>.
3513
 
3514
=head2 LastIMAPCommand
3515
 
3516
New in version 2.0.4, B<LastIMAPCommand> returns the exact IMAP command
3517
string to be sent to the server. Useful mainly in constructing error
3518
messages when L<LastError> just isn't enough.
3519
 
3520
=head2 Report
3521
 
3522
The B<Report> method returns an array containing a history of the IMAP
3523
session up to the point that B<Report> was called. It is primarily
3524
meant to assist in debugging but can also be used to retrieve raw
3525
output for manual parsing. The value of the L<Clear> parameter controls
3526
how many transactions are in the report. (See the discussion of
3527
L<Clear> in L<"Parameters">, above.)
3528
 
3529
=cut
3530
 
3531
=head2 Results
3532
 
3533
The B<Results> method returns an array containing the results of one
3534
IMAP client command. It accepts one argument, the transaction number of
3535
the command whose results are to be returned. If transaction number is
3536
unspecified then B<Results> returns the results of the last IMAP client
3537
command issued. If called in a scalar context, B<Results> returns an
3538
array reference rather than an array.
3539
 
3540
=cut
3541
 
3542
=head2 State 
3543
 
3544
The B<State> method returns a numerical value that indicates the
3545
current status of the B<IMAPClient> object. If invoked with an
3546
argument, it will set the object's state to that value. If invoked
3547
without an argument, it behaves just like L<Status>, below. 
3548
 
3549
Normally you will not have to invoke this function. An exception is if
3550
you are bypassing the B<Mail::IMAPClient> module's L<connect> and/or
3551
L<login> modules to set up your own connection (say, for example, over
3552
a secure socket), in which case you must manually do what the
3553
L<connect> and L<login> methods would otherwise do for you.
3554
 
3555
=head2 Status 
3556
 
3557
The B<Status> method returns a numerical value that indicates the
3558
current status of the B<IMAPClient> object. (Not to be confused with
3559
the L<status> method, all lower-case, which is the implementation of
3560
the I<STATUS> IMAP client command.)
3561
 
3562
=head2 Transaction 
3563
 
3564
The B<Transaction> method returns the tag value (or transaction number)
3565
of the last IMAP client command.
3566
 
3567
=head1 Undocumented Methods and Subroutines
3568
 
3569
There are two types of undocumented subroutines and methods. The first
3570
are methods that are not documented because they don't exist, even
3571
though they work just fine. Some of my favorite B<Mail::IMAPClient>
3572
methods don't exist but I use them all the time anyway. You can too,
3573
assuming you have your copy of RFC2060 and its extension RFC's handy.
3574
(By the way, you do have them handy because I gave them to you. They're
3575
bundled with the B<Mail::IMAPClient> distribution in the F<docs/>
3576
subdirectory.) You should feel free to use any of these undocumented
3577
methods.
3578
 
3579
These undocumented methods all use what this document refers to as the
3580
"default method". See L<Other IMAP Client Commands and the Default
3581
Object Method>, above, for more information on the default method.
3582
 
3583
There are also some undocumented methods and subroutines that actually
3584
do exist. Don't use these! If they aren't documented it's for a reason.
3585
They are either experimental, or intended for use by other
3586
B<Mail::IMAPClient> methods only, or deprecated, or broken, or all or
3587
none of the above. In no cases can you write programs that use these
3588
methods and assume that these programs will work with the next version
3589
of B<Mail::IMAPClient>. I never try to make these undocumented methods
3590
and subroutines backwards compatible because they aren't part of the
3591
documented API. 
3592
 
3593
Occasionally I will add a method and forget to document it; in that
3594
case it's a bug and you should report it. (See L<"REPORTING BUGS">,
3595
below.) It is sometimes hard to tell the difference; if in doubt you
3596
may submit a bug report and see what happens! However, don't bothering
3597
submitting bug reports for missing documentation for any method or
3598
subroutine that begins with an underscore (_) character. These methods
3599
are always private and will never be part of the documented interface. 
3600
 
3601
=head1 REPORTING BUGS
3602
 
3603
Please feel free to e-mail the author at C<bug-Mail-IMAPClient@rt.cpan.org>
3604
if you encounter any strange behaviors. Don't worry about hurting my 
3605
feelings or sounding like a whiner or anything like that; 
3606
if there's a problem with this module you'll be doing me a favor by
3607
reporting it.  However, I probably won't be able to do much about it if 
3608
you don't include enough information, so please read and follow these
3609
instructions carefully.
3610
 
3611
When reporting a bug, please be sure to include the following:
3612
 
3613
- As much information about your environment as possible. I especially
3614
need to know which version of Mail::IMAPClient you are running and the
3615
type/version of IMAP server to which you are connecting. Your OS and
3616
perl verions would be helpful too.
3617
 
3618
- As detailed a description of the problem as possible. (What are you
3619
doing? What happens? Have you found a work-around?)
3620
 
3621
- An example script that demonstrates the problem (preferably with as
3622
few lines of code as possible!) and which calls the Mail::IMAPClient's
3623
L<new> method with the L<Debug> parameter set to "1". (If this generates
3624
a ridiculous amount of output and you're sure you know where the problem
3625
is, you can create your object with debugging turned off and then 
3626
turn it on later, just before you issue the commands that recreate the 
3627
problem. On the other hand, if you can do this you can probably also 
3628
reduce the program rather than reducing the output, and this would be 
3629
the best way to go under most circumstances.)
3630
 
3631
- Output from the example script when it's running with the Debug
3632
parameter turned on. You can edit the output to remove (or preferably
3633
to "X" out) sensitive data, such as hostnames, user names, and
3634
passwords, but PLEASE do not remove the text that identifies the TYPE
3635
of IMAP server to which you are connecting. Note that in most versions
3636
of B<Mail::IMAPClient>, debugging does not print out the user or
3637
password from the login command line. However, if you use some other
3638
means of authenticating then you may need to edit the debugging output
3639
with an eye to security.
3640
 
3641
- If something worked in a previous release and doesn't work now,
3642
please tell me which release did work. You don't have to test every
3643
intervening release; just let me know it worked in version x but
3644
doesn't work in version (x+n) or whatever.
3645
 
3646
- Don't be surprised if I come back asking for a trace of the problem.
3647
To provide this, you should create a file called I<.perldb> in your
3648
current working directory and include the following line of text in
3649
that file:
3650
 
3651
C<&parse_options("NonStop=1 LineInfo=mail_imapclient_db.out");>
3652
 
3653
For your debugging convenience, a sample .perldb file, which was
3654
randomly assigned the name F<sample.perldb>, is provided in the
3655
distribution.
3656
 
3657
Next, without changing your working directory, debug the example script
3658
like this: C<perl -d example_script.pl [ args ]>
3659
 
3660
Note that in these examples, the script that demonstrates your problem
3661
is named "example_script.pl" and the trace output will be saved in
3662
"mail_imapclient_db.out". You should either change these values to suit
3663
your needs, or change your needs to suit these values.
3664
 
3665
Bug reports should be mailed to: 
3666
 
3667
	bug-Mail-IMAPClient@rt.cpan.org
3668
 
3669
Please remember to place a SHORT description of the problem in the subject
3670
of the message. Please try to be a bit specific; things like "Bug
3671
in Mail::IMAPClient" or "Computer Problem" won't exactly expedite things
3672
on my end.
3673
 
3674
=head1 REPORTING THINGS THAT ARE NOT BUGS
3675
 
3676
If you have suggestions for extending this functionality of this module, or
3677
if you have a question and you can't find an answer in any of the 
3678
documentation (including the RFC's, which are included in this distribution
3679
for a reason), then you can e-mail me at the following address:
3680
 
3681
	DJKERNEN@cpan.org
3682
 
3683
Please note that this address is for questions, suggestions, and other comments
3684
about B<Mail::IMAPClient>. It's not for reporting bugs, it's not for general 
3685
correspondence, and it's especially not for selling porn, mortgages, Viagra, 
3686
penis enlargment pills, DVD copying software, or anything else.
3687
 
3688
=head1 AUTHOR
3689
 
3690
	David J. Kernen
3691
	The Kernen Consulting Group, Inc
3692
	DJKERNEN@cpan.org
3693
 
3694
=cut
3695
 
3696
=head1 COPYRIGHT
3697
 
3698
   Copyright 1999, 2000, 2001, 2002 The Kernen Group, Inc.
3699
   All rights reserved.
3700
 
3701
This program is free software; you can redistribute it and/or modify it
3702
under the terms of either:
3703
 
3704
=over 4
3705
 
3706
=item a) the "Artistic License" which comes with this Kit, or
3707
 
3708
=item b) the GNU General Public License as published by the Free Software 
3709
Foundation; either version 1, or (at your option) any later version.
3710
 
3711
=back
3712
 
3713
This program is distributed in the hope that it will be useful, but
3714
WITHOUT ANY WARRANTY; without even the implied warranty of
3715
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU
3716
General Public License or the Artistic License for more details. All your
3717
base are belong to us.
3718
 
3719
=cut
3720
 
3721
my $not_void = 0;	# This is a documentation-only file!