# $self->fetch($set, $flags, [$callback])
# Issue an UID FETCH command with the given UID $set, $flags, and
# optional $callback.
-sub fetch($$$$) {
+sub fetch($$$;&) {
my ($self, $set, $flags, $callback) = @_;
$self->_send("UID FETCH $set $flags", $callback);
}
}
-# $self->slurp([$cmd, $callback])
+# $self->slurp([$callback, $cmd])
# See if the server has sent some unprocessed data; try to as many
# lines as possible, process them, and return the number of lines
# read.
# This is mostly useful when waiting for notifications while no
# command is progress, cf. RFC 2177 (IDLE) or RFC 5465 (NOTIFY).
-sub slurp($;$$) {
- my ($self, $cmd, $callback) = @_;
+sub slurp($;&$) {
+ my ($self, $callback, $cmd) = @_;
my $ssl = $self->{_SSL};
my $read = 0;
return $read if $r == 0; # nothing more to read
}
my $x = $self->_getline();
- $self->_resp($x, $cmd, undef, $callback);
+ $self->_resp($x, $callback, $cmd);
$read++;
}
}
# when the callback $stopwhen returns true.
# Return false if the timeout was reached, and true if IDLE was
# stopped due the callback.
-sub idle($$$) {
+sub idle($;$&) {
my ($self, $timeout, $stopwhen) = @_;
$timeout //= 1740; # 29 mins
+ my $callback = sub() {$timeout = -1 if $stopwhen->()};
$self->fail("Server did not advertise IDLE (RFC 2177) capability.")
unless $self->_capable('IDLE');
$self->_cmd_flush();
for (; $timeout > 0; $timeout--) {
- $self->slurp('IDLE', sub() {$timeout = -1 if $stopwhen->()});
+ $self->slurp($callback, 'IDLE');
sleep 1 if $timeout > 0;
}
}
-# $self->pull_new_messages($callback, $attrs, @ignore)
+# $self->pull_new_messages($attrs, $callback, @ignore)
# FETCH new messages since the UIDNEXT found in the persistent cache
# (or 1 in no such UIDNEXT is found), and process each response on the
# fly with the callback.
# Finally, update the UIDNEXT from the persistent cache to the value
# found in the internal cache.
# /!\ Use pull_updates afterwards to udpate the HIGHESTMODSEQ!
-sub pull_new_messages($$$@) {
+sub pull_new_messages($$&@) {
my $self = shift;
my $attrs = shift;
my $callback = shift;
# provided, is used to process each untagged response. $command and
# $set can further limit the set of responses to apply the callback
# to.
-sub _recv($$;$&$) {
+sub _recv($$;&$$) {
my ($self, $tag, $callback, $cmd, $set) = @_;
my $r;
last;
}
else {
- $self->_resp($x, $cmd, $set, $callback);
+ $self->_resp($x, $callback, $cmd, $set);
}
}
return \@envelope;
}
-# $self->_resp($buf, [$cmd, $set, $callback] )
+# $self->_resp($buf, [$callback, $cmd, $set] )
# Parse an untagged response line or a continuation request line.
# (The trailing CRLF must be removed.) The internal cache is
# automatically updated when needed.
# If a command and callback are given, the callback is be executed
# for each (parsed) responses associated with the command.
-sub _resp($$;$$$) {
+sub _resp($$;&$$) {
my $self = shift;
local $_ = shift;
+ my $callback = shift;
my $cmd = shift;
my $set = shift;
- my $callback = shift;
my $cache = $self->{_CACHE}->{$self->{_SELECTED}} if defined $self->{_SELECTED};
if (s/\A\* //) {