Problem with IMAPTalk and arrays
am 05.05.2006 06:17:34 von jbermudes
I'm writing a program to retrieve messages from an IMAP server and it
is almost done, all I need left is to be able to tell if a message has
been read or not.
According to the IMAPTalk API:
(http://cpan.uwinnipeg.ca/htdocs/Mail-IMAPTalk/Mail/IMAPTalk .html#fetch_results),
the data structure returned by this call:
my $Res = $IMAP->fetch('1:*', '(flags rfc822.size uid)');
will look like this:
$Res = {
1 => {
'uid' => 1952,
'flags' => [ '\\recent', '\\seen' ],
'rfc822.size' => 1150
},
2 => {
'uid' => 1958,
'flags' => [ '\\recent' ],
'rfc822.size' => 110
}
};
He notes that the bracketed lists have become array references.
By doing the following, I can extract the UID of the i-th message:
$MsgExtra = $IMAP->fetch($i, '(flags uid)')->{$i};
How can I check if the i-th message has been read?
Thanks!!
Re: Problem with IMAPTalk and arrays
am 05.05.2006 18:43:50 von nobull67
jbermudes@gmail.com wrote:
> I'm writing a program to retrieve messages from an IMAP server and it
> is almost done, all I need left is to be able to tell if a message has
> been read or not.
>
> According to the IMAPTalk API:
> (http://cpan.uwinnipeg.ca/htdocs/Mail-IMAPTalk/Mail/IMAPTalk .html#fetch_results),
>
> the data structure returned by this call:
>
> my $Res = $IMAP->fetch('1:*', '(flags rfc822.size uid)');
>
> will look like this:
>
> $Res = {
> 1 => {
> 'uid' => 1952,
> 'flags' => [ '\\recent', '\\seen' ],
> 'rfc822.size' => 1150
> },
> 2 => {
> 'uid' => 1958,
> 'flags' => [ '\\recent' ],
> 'rfc822.size' => 110
> }
> };
>
> He notes that the bracketed lists have become array references.
>
> By doing the following, I can extract the UID of the i-th message:
>
> $MsgExtra = $IMAP->fetch($i, '(flags uid)')->{$i};
>
> How can I check if the i-th message has been read?
I have no familiarity with the module you are using but you appear to
be saying you have something like...
$MsgExtra = {
'uid' => 1952,
'flags' => [ '\\recent', '\\seen' ],
};
....and you want to detect the '\\seen'.
print "read\n" if grep { $_ eq '\\seen' } @{$MsgExtra->{flags}};
Note if the flags field is really a set (not a list) it would have been
better for the module to have converted it into a hash. rather than an
array.
$Res = {
1 => {
'uid' => 1952,
'flags' => { '\\recent' => 1, '\\seen' => 1 },
'rfc822.size' => 1150
},
2 => {
'uid' => 1958,
'flags' => { '\\recent' => 1 },
'rfc822.size' => 110
}
};
Then you could have simply said:
print "read\n" if $MsgExtra->{flags}{'\\seen'};