Skip Menu |

This queue is for tickets about the Mail-Box CPAN distribution.

Report information
The Basics
Id: 40198
Status: resolved
Priority: 0/
Queue: Mail-Box

People
Owner: Nobody in particular
Requestors: fschlich [...] cis.fu-berlin.de
Cc:
AdminCc:

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



Subject: $manager->moveMessage should not delete msg if source==destination
justification for severity: unintentional data loss can occur without any kind of error or warning! a call to $manager-moveMessage should check whether the message(s) to be moved might already be in the destination folder (only), and not flag them as deleted in their source folder, as is currently done, which results in them being deleted altogether, ie unintentional loss of these messages. Scenario: I'm working with whole threads over two folders ('new' and 'seen'), which at one point I might decide to archive (move to a third place) or postpone (move to 'seen'). But messages which already were in 'seen' are not postponed, they are lost! As far as I can see, there's no straightforward way to find out which folder a message is in, so I could skip the moveMessage? As a workaround, I'm using a temporary folder, but this shouldn't be necessary really...
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Wed, 22 Oct 2008 23:19:31 +0200
To: Florian via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Florian via RT (bug-Mail-Box@rt.cpan.org) [081020 15:56]: Show quoted text
> Subject: $manager->moveMessage should not delete msg if source==destination > a call to $manager-moveMessage should check whether the message(s) to be > moved might already be in the destination folder (only), and not flag > them as deleted in their source folder, as is currently done, which > results in them being deleted altogether, ie unintentional loss of these > messages.
This only happens if keep_dups is false (default), I thing. If you open folders with ->new(keep_dups => 1) then the new one will not be deleted automatically. But I think your problem is common and should therefore be solved in the library. Somewhere in Mail::Box::Manager, copyMessage(). I have to think about it. Show quoted text
> As far as I can see, there's no straightforward way to find out which > folder a message is in, so I could skip the moveMessage? As a > workaround, I'm using a temporary folder, but this shouldn't be > necessary really...
Quite simple if($msg1->folder==$msg2->folder) -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Wed, 22 Oct 2008 23:38:09 +0200
To: Florian via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Florian via RT (bug-Mail-Box@rt.cpan.org) [081020 15:56]: Show quoted text
> Subject: $manager->moveMessage should not delete msg if source==destination
What about this: Mail::Box::Manager::copyMessages() replace: my @coerced = ref $folder ? map {$_->copyTo($folder, share => $args{share})} @messages : $self->appendMessages(@messages, %args, folder => $folder); # hidden option, do not use it: it's designed to optimize moveMessage if($args{_delete}) { $_->label(deleted => 1) foreach @messages; } by: unless(ref $folder) { my @c = $self->appendMessages(@messages, %args, folder => $folder); $_->label(deleted => 1) for @messages; return @c; } my @coerced; foreach my $msg (@messages) { if($msg->folder==$folder) # ignore move to same folder { push @coerced, $msg; next; } push @coerced, $msg->copyTo($folder, share => $args{share}); $msg->label(deleted => 1) if $args{_delete}; } @coerced; ***UNTESTED*** (maybe you have time to expiriment with this) -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Thu, 23 Oct 2008 22:35:06 +0200
To: Mark Overmeer via RT <bug-Mail-Box [...] rt.cpan.org>
From: Florian Schlichting <fschlich [...] CIS.FU-Berlin.DE>
Hi, first, thanks for your quick reply and help. Is rt.cpan.org the preferred way to report bugs and problems? That is, would you want me to report the issue with dummy messages and threadStart() that I tried to post to the mailing list but never made it through moderation to RT? On Wed, Oct 22, 2008 at 05:19:47PM -0400, Mark Overmeer via RT wrote: Show quoted text
Show quoted text
> This only happens if keep_dups is false (default), I thing. If you > open folders with ->new(keep_dups => 1) then the new one will not > be deleted automatically.
I didn't test that, but in general I wouldn't want two messages with the same Message-ID in the same folder anyway... Show quoted text
> > As far as I can see, there's no straightforward way to find out which > > folder a message is in, so I could skip the moveMessage? As a > > workaround, I'm using a temporary folder, but this shouldn't be > > necessary really...
> > Quite simple if($msg1->folder==$msg2->folder)
Hmm, I thought I had seen something like that, but couldn't find anything when I was looking for it. I would have expected some mention in the documentation for Mail::Message or Mail::Box::Manager, but never looked into Mail::Box::Message, as that's deeply into the magic workings of Mail::Box! At the top of Mail/Box/Message.pod it even reads "If you access the knowledge of a message, then read Mail::Message"... Do you think it could be mentioned in Mail::Message? (talking about documentation, how about spelling out the options for Mail::Box::nrMessages() -- once I had discovered it also counts the deleted messages it was easy to find out why, but I never would have noticed had I not been testing your patch) NB: the above equation (in the incarnation you suggested for Mail::Box::Manager::copyMessages()) failed on me with "Operation `==': no method found", but worked ok when replacing '==' with 'eq'. Show quoted text
> What about this: > > Mail::Box::Manager::copyMessages() replace: > > my @coerced > = ref $folder > ? map {$_->copyTo($folder, share => $args{share})} @messages > : $self->appendMessages(@messages, %args, folder => $folder); > > # hidden option, do not use it: it's designed to optimize moveMessage > if($args{_delete}) > { $_->label(deleted => 1) foreach @messages; > }
I've had perfect results with a slightly modfied replacement (udiff): unless(ref $folder) { my @c = $self->appendMessages(@messages, %args, folder => $folder); - $_->label(deleted => 1) for @messages; + if($args{_delete}) + { $_->label(deleted => 1) for @messages; + } return @c; } my @coerced; foreach my $msg (@messages) - { if($msg->folder==$folder) # ignore move to same folder + { if($msg->folder eq $folder) # ignore move to same folder { push @coerced, $msg; next; } push @coerced, $msg->copyTo($folder, share => $args{share}); $msg->label(deleted => 1) if $args{_delete}; } @coerced; warm regards, Florian
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Fri, 24 Oct 2008 11:02:31 +0200
To: Florian via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Florian via RT (bug-Mail-Box@rt.cpan.org) [081023 20:35]: Show quoted text
> Queue: Mail-Box > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40198 > > > first, thanks for your quick reply and help. Is rt.cpan.org the > preferred way to report bugs and problems? That is, would you want me to > report the issue with dummy messages and threadStart() that I tried to > post to the mailing list but never made it through moderation to RT?
The mailinglist attracted hundreds of spam a day. I just had it closed with close to 10,000 waiting in de moderation list. Yes, please in RT. Show quoted text
> On Wed, Oct 22, 2008 at 05:19:47PM -0400, Mark Overmeer via RT wrote: >
> > This only happens if keep_dups is false (default), I thing. If you > > open folders with ->new(keep_dups => 1) then the new one will not > > be deleted automatically.
> > I didn't test that, but in general I wouldn't want two messages with the > same Message-ID in the same folder anyway...
Yes, that's why the default is set to this. However, it bites us in this case. Show quoted text
> > Quite simple if($msg1->folder==$msg2->folder)
> > Hmm, I thought I had seen something like that, but couldn't find > anything when I was looking for it. I would have expected some mention > in the documentation for Mail::Message or Mail::Box::Manager, but never > looked into Mail::Box::Message, as that's deeply into the magic workings > of Mail::Box! At the top of Mail/Box/Message.pod it even reads "If you > access the knowledge of a message, then read Mail::Message"... Do you > think it could be mentioned in Mail::Message?
A Mail::Message is a message without location, without box... so it cannot have a folder method. The first level to document this is the Mail::Box::Message extension of it. With over 1000 methods, it is already difficult to have things documented at least on one spot. MailBox has over 50k lines of pod, but that is never enough!! only the most important features get a special treatment on being mentioned more than once. However... your hint could get a spot in Mail::Box-Index or such. Suggestions welcome. If you say: "I want to see whether a message is in the same folder as some other message", then it actually extremely close to the above code. Show quoted text
> (talking about documentation, how about spelling out the options for > Mail::Box::nrMessages() -- once I had discovered it also counts the > deleted messages it was easy to find out why, but I never would have > noticed had I not been testing your patch)
Contributions welcome Show quoted text
> NB: the above equation (in the incarnation you suggested for > Mail::Box::Manager::copyMessages()) failed on me with "Operation `==': > no method found", but worked ok when replacing '==' with 'eq'.
oh, yes... it is folder name comparison. Your improved patch applied to 2.085. -- Thanks for the effort, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Fri, 24 Oct 2008 15:29:48 +0200
To: Mark Overmeer via RT <bug-Mail-Box [...] rt.cpan.org>
From: Florian Schlichting <fschlich [...] CIS.FU-Berlin.DE>
Show quoted text
> never enough!! only the most important features get a special treatment > on being mentioned more than once. However... your hint could get a > spot in Mail::Box-Index or such. Suggestions welcome.
it's difficult indeed... Taking up your suggestion, all I could think of is this: --- Box-Index.pod.org 2008-10-24 14:26:02.505048755 +0200 +++ Box-Index.pod 2008-10-24 14:42:16.839767611 +0200 @@ -151,10 +151,11 @@ <li>Searching folders (Mail::Box::Search) <ul> <li>scan header and body (Mail::Box::Search::Grep) <li>check for spam (Mail::Box::Search::SpamAssassin) </ul> + <li>Managing messages in folders (Mail::Box::Message) </ul> <li><strong><a name="ftypes">Folder types</a></strong> Show quoted text
> > (talking about documentation, how about spelling out the options for > > Mail::Box::nrMessages() -- once I had discovered it also counts the > > deleted messages it was easy to find out why, but I never would have > > noticed had I not been testing your patch)
> > Contributions welcome
I was simply thinking: --- Box.pod.org 2008-10-24 14:52:23.469638239 +0200 +++ Box.pod 2008-10-24 14:52:51.553982543 +0200 @@ -1083,7 +1083,7 @@ =back -$obj-E<gt>B<nrMessages>(OPTIONS) +$obj-E<gt>B<nrMessages>(['ALL',RANGE,'ACTIVE','DELETED',LABEL,!LABEL,FILTER]) =over 4 the thing is that this line is present in quite a few files, so should be changed in many places: Box/Net.pod Box/Dir.pod Box/MH.pod Box/File.pod Box/Mbox.pod Box/Dbx.pod Box/IMAP4.pod Box/Maildir.pod Box/POP3.pod But I'm going to propose a somewhat larger change for Mail::Box, returning only active messages as default: --- Box.pod.org 2008-10-24 14:52:23.469638239 +0200 +++ Box.pod 2008-10-24 15:26:07.022731891 +0200 @@ -1083,12 +1083,13 @@ =back -$obj-E<gt>B<nrMessages>(OPTIONS) +$obj-E<gt>B<nrMessages>(['ALL',RANGE,'ACTIVE','DELETED',LABEL,!LABEL,FILTER]) =over 4 -Simply calls L<messages()|Mail::Box/"The messages"> in scalar context to return a count instead -of the messages itself. Some people seem to understand this better. +Simply calls L<messages('ACTIVE')|Mail::Box/"The messages"> in scalar context +to return a count of active (not deleted) messages instead of the messages +themselves. Some people seem to understand this better. =back --- Box.pm.org 2008-10-24 15:23:13.223844391 +0200 +++ Box.pm 2008-10-24 15:03:10.709803071 +0200 @@ -548,7 +548,7 @@ } -sub nrMessages(@) { scalar shift->messages(@_) } +sub nrMessages(@) { scalar shift->messages(@_ ? @_ : 'ACTIVE') } Show quoted text
> Your improved patch applied to 2.085.
thanks a lot! Florian
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Sat, 25 Oct 2008 16:15:58 +0200
To: Florian via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Florian via RT (bug-Mail-Box@rt.cpan.org) [081024 14:07]: Show quoted text
> Queue: Mail-Box > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40198 > > > + <li>Managing messages in folders (Mail::Box::Message)
ok Show quoted text
> > > (talking about documentation, how about spelling out the options for > > > Mail::Box::nrMessages() -- once I had discovered it also counts the > > > deleted messages it was easy to find out why, but I never would have > > > noticed had I not been testing your patch)
I am against it: it carries the same options as messages(), so when those change, I have to be aware that the nrMessages() has to change as well. Besides: I have to copy the explenation examples as well... Let's just add: The OPTIONS are passed (to explained in) M<messages()>. Show quoted text
> -$obj-E<gt>B<nrMessages>(OPTIONS) > +$obj-E<gt>B<nrMessages>(['ALL',RANGE,'ACTIVE','DELETED',LABEL,!LABEL,FILTER]) > > the thing is that this line is present in quite a few files, so should > be changed in many places:
I generate my POD with OODoc, so: write once... copy many. Show quoted text
> -sub nrMessages(@) { scalar shift->messages(@_) } > +sub nrMessages(@) { scalar shift->messages(@_ ? @_ : 'ACTIVE') }
This would be a dangerous change: an interface breaking one. Sorry, not useful enough to apply that change. Just say $folder->nrMessages('ACTIVE') (other submission will be processed asap... my little son want to get out of bed now) -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Mon, 27 Oct 2008 14:12:27 +0100
To: Mark Overmeer via RT <bug-Mail-Box [...] rt.cpan.org>
From: Florian Schlichting <fschlich [...] CIS.FU-Berlin.DE>
Show quoted text
> > > > (talking about documentation, how about spelling out the options for > > > > Mail::Box::nrMessages() -- once I had discovered it also counts the > > > > deleted messages it was easy to find out why, but I never would have > > > > noticed had I not been testing your patch)
> > I am against it: it carries the same options as messages(), so when those > change, I have to be aware that the nrMessages() has to change as well. > Besides: I have to copy the explenation examples as well... > > Let's just add: > The OPTIONS are passed (to explained in) M<messages()>.
hmm, that's pretty evident already, I'd say; the problem in my view is that people don't go and look up what messages() does, and just expect that nrMessages() is so simple it will return the right number... Perhaps what's needed is a warning added to the explanation, along the lines of "Note that nrMessages() will default to returning a count of C<ALL> messages in the folder, including both C<ACTIVE> and C<DELETED>." That way, the pitfall is apparent even to people in a hurry, and then they can go and read more under messages() if need be. Show quoted text
> > -sub nrMessages(@) { scalar shift->messages(@_) } > > +sub nrMessages(@) { scalar shift->messages(@_ ? @_ : 'ACTIVE') }
> > This would be a dangerous change: an interface breaking one. Sorry,
Mail::Box being as big and popular as it is, you're probably very right here... Thanks for your quick response, and for caring so well for such a big and important module! Show quoted text
> (other submission will be processed asap... my little son want to > get out of bed now)
:-) Florian
Subject: Re: [rt.cpan.org #40198] $manager->moveMessage should not delete msg if source==destination
Date: Mon, 27 Oct 2008 14:28:42 +0100
To: Florian via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Florian via RT (bug-Mail-Box@rt.cpan.org) [081027 13:12]: Show quoted text
> Queue: Mail-Box > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40198 > > > Perhaps what's needed is a warning added to the explanation, along the > lines of "Note that nrMessages() will default to returning a count of > C<ALL> messages in the folder, including both C<ACTIVE> and C<DELETED>."
This is a style I like. Accepted. -- MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Fix released in 2.085