Skip Menu |
 

This queue is for tickets about the Net-IMAP-Simple CPAN distribution.

Report information
The Basics
Id: 59330
Status: rejected
Priority: 0/
Queue: Net-IMAP-Simple

People
Owner: Nobody in particular
Requestors: hawkexploretalent [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: possible bug in _process_flags()
Date: Tue, 13 Jul 2010 15:15:05 -0700
To: bug-Net-IMAP-Simple [...] rt.cpan.org
From: Hawk ExploreTalent <hawkexploretalent [...] gmail.com>
Download (untitled) / with headers
text/plain 2.1k
Greetings Mr. Miller (or whoever is maintaining this package), I'm working on a project to migrate email from one server to another using IMAP. In my loop, my Perl script reads messages one at a time from the source server and checks to see if the message is on the target server (just the headers). If the message isn't found on the target server, then the message flags are pulled and the message is copied to the target server. During the operation which reads the message flags from the source server, I get an error like this: GLOB(0xa34030)2010-07-13 13:57:31 unable to get flags for source msg #2: warning unknown return string (id=174): ) There are two messages in this box, and all works well if I don't pull the flags. However, I'm trying to maintain the seen/unseen nature of each message so that the script can be run as many times as necessary to get all the email migrated over and keep the read/unread state of each message. In the source code for Net::IMAP::Simple.pl, the sub _process_flags calls shift for $self as the first action (from @_ presumably), but $self is never passed to _process_flags when it's called from elsewhere, such as from the sub msg_flags. Is this right? -Hawk sub _process_flags { my $self = shift; return grep { m/^\\\w+\z/ } map { split m/\s+/, $_ } @_; } sub msg_flags { my ( $self, $number ) = @_; my @flags; $self->{_waserr} = 1; # assume something went wrong. # _send_cmd] 15 FETCH 12 (FLAGS)\r\n # _process_cmd] * 12 FETCH (FLAGS (\Seen))\r\n # _cmd_ok] * 12 FETCH (FLAGS (\Seen))\r\n # _seterrstr] warning unknown return string (id=15): * 12 FETCH (FLAGS (\Seen))\r\n # _process_cmd] 15 OK Success\r\n return $self->_process_cmd( cmd => [ FETCH => qq[$number (FLAGS)] ], final => sub { return if $self->{_waserr}; wantarray ? @flags : "@flags"; }, process => sub { if( $_[0] =~ m/\* $number FETCH \(FLAGS \(([^()]+?)\)\)/i ) { @flags = $self->_process_flags($1); delete $self->{_waserr}; } }, ); }
Subject: Re: [rt.cpan.org #59330] possible bug in _process_flags()
Date: Tue, 13 Jul 2010 19:26:24 -0400
To: bug-Net-IMAP-Simple [...] rt.cpan.org
From: Paul Miller <jettero [...] cpan.org>
Download (untitled) / with headers
text/plain 2.1k
On Tue, Jul 13, 2010 at 6:15 PM, Hawk ExploreTalent via RT <bug-Net-IMAP-Simple@rt.cpan.org> wrote: Show quoted text
> Greetings Mr. Miller (or whoever is maintaining this package),
It's me!! Show quoted text
> I'm working on a project to migrate email from one server to another using > IMAP.  In my loop, my Perl script reads messages one at a time from the > source server and checks to see if the message is on the target server (just > the headers).
I do this too. my @flags = $server1->msg_flags($msg_number); my $msg = $server1->get($msg_number); # many boring things $server2->put( ux => $msg, @flags ); Show quoted text
> GLOB(0xa34030)2010-07-13 13:57:31 unable to get flags for source msg #2: > warning unknown return string (id=174): )
I'm not totally sure what's going on here. If it's possible, please paste the relevant log lines (just the relevant ones please) into the ticket. I inherited this module in a state that generates a great deal of spurious warnings and errors that ... apparently don't affect behavior. I constructed quite a few tests -- by no means complete, but quite a few -- to ensure that most things work correctly, but I haven't really spent any energy hunting down those errors. They seem to be part of it's correct functioning. That said, if you're not getting the flags you expect, I want to dig into it lickety split!! Show quoted text
> In the source code for Net::IMAP::Simple.pl, the sub _process_flags calls > shift for $self as the first action (from @_ presumably), but $self is never > passed to _process_flags when it's called from elsewhere, such as from the > sub msg_flags.  Is this right?
It's probably right. I didn't look very carefully, but it seems to work and didn't look wrong to me. Check the "perldoc perlboot" pages for details on this... but basically: ClassName->afunction("arg"); $instance->afunction("arg"); afunction("arg"); sub afunction { my ($self, $arg) = @_; # ("ClassName", "arg") for a class, # ($instance, "arg") for instance. # ("arg", undef) for the naked function call } -- If riding in an airplane is flying, then riding in a boat is swimming. 115 jumps, 47.9 minutes of freefall, 91.6 freefall miles.
Subject: Re: [rt.cpan.org #59330] possible bug in _process_flags()
Date: Tue, 13 Jul 2010 17:43:10 -0700
To: bug-Net-IMAP-Simple [...] rt.cpan.org
From: Hawk ExploreTalent <hawkexploretalent [...] gmail.com>
Download (untitled) / with headers
text/plain 11.7k

Message body is not shown because it is too large.

Download (untitled) / with headers
text/html 13.8k

Message body is not shown because it is too large.

I'm glad I thought to check RT today. I didn't receive an email from RT either due to the size of the message (which it seems to object to) or due to spam filtering. Who knows. On Tue Jul 13 20:43:22 2010, hawkexploretalent@gmail.com wrote: Show quoted text
> Okay... I'm going round and round here with this thing. It > seems if I query message flags, then things go wierd. If I > skip the flags, all messages which were read are marked "seen" > (which is not what I want), and all messages which are copied > to the new server are marked "unseen" or "new" or "unread", and > this is not what I want unless it was marked that way in the > original server.
I think I'm seeing in the log file you attached that you actually set seen explicitly. The log formatting is a little messed up though. Perhaps you could send an email to me directly with the log file and sources attached? Perhaps not the whole program, but preferably a smallish example that produces the problem? -- If riding in an airplane is flying, then riding in a boat is swimming. 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.
Download (untitled) / with headers
text/plain 455b
Hrm, actually, I was not looking at a flag change command. It was an illusion. But I can say that ... RFC3501 (under the FETCH command) says that messages are \Seen once you FETCH them: Show quoted text
> The \Seen flag is implicitly set; if this causes the flags to > change, they SHOULD be included as part of the FETCH responses.
-- If riding in an airplane is flying, then riding in a boat is swimming. 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.
Subject: Re: [rt.cpan.org #59330] possible bug in _process_flags()
Date: Tue, 20 Jul 2010 17:10:51 -0700
To: bug-Net-IMAP-Simple [...] rt.cpan.org
From: Hawk ExploreTalent <hawkexploretalent [...] gmail.com>
Download (untitled) / with headers
text/plain 1.1k
Dear Paul, Don't know what the issue was with the Flags, but it definitely didn't work with Net::IMAP::Simple. I switched to Net::IMAP::Client and, with a few tweaks, all is well. I tweaked the timeout, and added an examine sub (instead of select), and now I can migrate thousands of email accounts with one command. The script checks the target server to see if the message is already there before appending it, so I can run it as many times as necessary to keep the target server up-to-date before we switch DNS. Thanks again for your help. I hope you figure it out some day. -Hawk On Thu, Jul 15, 2010 at 8:40 AM, Paul Miller via RT <bug-Net-IMAP-Simple@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=59330 > > > Hrm, actually, I was not looking at a flag change command.  It was an > illusion.  But I can say that ...  RFC3501 (under the FETCH command) says > that messages are \Seen once you FETCH them: >
>> The \Seen flag is implicitly set; if this causes the flags to >> change, they SHOULD be included as part of the FETCH responses.
> > > -- > If riding in an airplane is flying, then riding in a boat is swimming. > 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles. > >
Download (untitled) / with headers
text/plain 662b
I'm glad you got everything working. In my mind, there's no bug here. It's definitely doing what it's supposed to. When you get the body of a message the client is supposed to mark the message \Seen, which may not be the same as "read" but it is still correct to set the flag. If that's not what you want, then you'd have to manually set it back yourself. I did describe a work around (using msg_flags()) but if IMAP::Client is easier, then it seems you're all set either way. I'm closing this, replies will re-open it. -- If riding in an airplane is flying, then riding in a boat is swimming. 116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.