Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: wjhns117 [...] hardakers.net
Cc:
AdminCc:

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



Subject: Mail::Box::Maildir::Message information lossage
The current maildir message module doesn't respect all the possible flags in use by various applications. Certain applications (dovecot being a prime example) stores extra flags at the end in lower-case for application specific purposes. If you use Mail::Box utilities to open maildir folders created by applications like dovecot then upon close it renames the files and all the extra markings get lost (which in my case, is really really bad though fortunately they were mostly expiration marks that I can at least recreate moderately easily). The fix attached is actually to simply save and remember all lowercase flags and then apply them later during save time. (I actually find it odd that when I pass access => 'r' to the top level Mail::Box manager it renames the files in the first place, but that's a different issue). Ideally, I actually think it would be safer to remember all unknown tags not just the lower case ones. But I wasn't sure how accepted that would be (and will cause performance loss because of the need to resort flags later). So the attached patch just deals with unknown lowercase flags.
Subject: fix.patch
--- Message.pm 2008-12-11 03:05:40.000000000 -0800 +++ /users/hardaker/f/x/tmp/h/Mail-Box-2.081/lib/Mail/Box/Maildir/Message.pm 2009-01-06 09:02:35.000000000 -0800 @@ -24,10 +23,15 @@ return $newname if defined $oldname && $oldname eq $newname; my ($id, $semantics, $flags) - = $newname =~ m!(.*?)(?:\:([12])\,([A-Z]*))! + = $newname =~ m!(.*?)(?:\:([12])\,([A-Za-z]*))! ? ($1, $2, $3) : ($newname, '',''); + # IMAP and other clients use lowercase flags to store application tags + ($self->{'lcflags'}) = ($flags =~ m/([a-z]+)/); + $self->{'lcflags'} ||= ''; # avoid undef warnings later + $flags =~ s/[a-z]+//; + my %flags; $flags{$_}++ foreach split //, $flags; @@ -89,7 +93,8 @@ . ($labels->{passed} ? 'P' : '') . ($labels->{replied} ? 'R' : '') . ($labels->{seen} ? 'S' : '') - . ($labels->{deleted} ? 'T' : ''); + . ($labels->{deleted} ? 'T' : '') + . $self->{'lcflags'}; my $newset = $labels->{accepted} ? 'cur' : 'new'; if($set ne $newset)
Subject: Re: [rt.cpan.org #42182] Mail::Box::Maildir::Message information lossage
Date: Wed, 7 Jan 2009 09:23:27 +0100
To: Wes Hardaker via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Wes Hardaker via RT (bug-Mail-Box@rt.cpan.org) [090106 17:20]: Show quoted text
> Tue Jan 06 12:20:09 2009: Request 42182 was acted upon. > Transaction: Ticket created by HARDAKER > Queue: Mail-Box > Subject: Mail::Box::Maildir::Message information lossage > > The current maildir message module doesn't respect all the possible > flags in use by various applications.
MailBox attempts to provide an abstract interface, hiding differences in message storage between folder types as good as possible. This means that it interprets flags into conditions which can be tested with nicely named methods or readable parameters: if($msg->deleted) # T flag if($msg->label('seen') # all other flags When you move a message from a Maildir folder into an Mbox folder, these flags get automatically written in the other convension. No-one ever told me that there are other flags for Maildir, so that is the only reason the list is limited. Show quoted text
> Ideally, I actually think it would be safer to remember all unknown tags > not just the lower case ones. But I wasn't sure how accepted that would > be (and will cause performance loss because of the need to resort flags > later). So the attached patch just deals with unknown lowercase flags.
Just because I do not handle all flags I do not understand, I do get extra information from you which helps me improve the module, so other people. Probably I should have produced a warning message when unknown flags appear. That would have saved you some work. Could you compose a list of missing flags and a clear word for their meaning is each case? I'll add that for the next release. Mbox additionally defines 'old' (folder has been opened, but the message was not read) and 'flagged' (something like 'selected' to be involved in some upcoming action). MH adds 'current'. Maybe some of the flags need a hook with an existing method. For instance, $msg->reply() will automatically set the 'replied' flag on the message. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Grr... send this via mail a week ago, but it took a week to bounce... Submitting this through the web-tracker instead. Show quoted text
>> The current maildir message module doesn't respect all the possible >> flags in use by various applications.
Show quoted text
MOv> MailBox attempts to provide an abstract interface, hiding differences MOv> in message storage between folder types as good as possible.
I think that's the right approach wherever possible. By the way, I think it's a fantastic module so don't get me wrong about it because I'm reporting one issue... I love the module! Show quoted text
MOv> When you move a message from a Maildir folder into an Mbox folder,
these Show quoted text
MOv> flags get automatically written in the other convension.
Right, and I do think that's the right thing to do. However, I do think that holding on to unknown flags is probably a good idea too. The user would have to realize that transferring from one box type to another may be lossy when unknown flags are being used (and a simple statement to that effect in the CAVEATS section would suffice). Show quoted text
MOv> No-one ever told me that there are other flags for Maildir, so that is MOv> the only reason the list is limited.
Well, maildir is interesting since it's not a "standard" in most ways. I don't know its history, but it *feels* like a storage format that started in one application and sort of grew into many more. There are a standard set of flags which are documented on various web pages (for example) and coming up with that list isn't hard. You're already handling them all :-) What's interesting is that because there isn't a specification, it doesn't really prevent applications from adding their own since there isn't a statement anywhere saying "don't do that". Show quoted text
MOv> Probably I should have produced a warning message when unknown MOv> flags appear. That would have saved you some work.
That would have been nice, but I need to save them completely. I have a script that is simply scanning a bunch of mail boxes and showing me the new messages in them. I have about 70 incoming mail nnmaildir in-boxes that are served by an imap server. I don't want to open them all to see that most of the messages aren't important, so I have a script that uses your module and just summarizes them for me. The script looks straight into the maildir folders themselves to avoid the imap interface. The problem was that when the script ran, it renamed all the files dropping the extra flags that the imap server assigned to the message files. The imap server in question is "dovecot" which stores special imap tags as lowercase maildir flags. So a maildir message file may have an "a" flag on it, and then there is another mapping file that dovecot has in the top level maildir directory for the folder (IE, the one containing the "cur" and "new" ... folders) called "dovecot-keywords". In there we have something like: 0 gnus-expire 1 gnus-forward 2 gnus-save The 0 in this case is what is mapped to the maildir 'a' flag. Now, I don't know *why* dovecot took this approach to do things but it did. Probably for speed purposes as an imap client searching for the 'gnus-expire' tag can simply do a quick search for any files containing the 'a' flag. Show quoted text
MOv> Could you compose a list of missing flags and a clear word for their MOv> meaning is each case? I'll add that for the next release.
The above shows that the lowercase flags are being used without a specific meaning... IE, they're application specific (in my case dovecot). I have no idea if other applications are doing similar odd things. My suggestion is just that the perl module tries to keep them if it can (IE, it's not doing something through a lossy process like converting from one box type to another)
Subject: Re: [rt.cpan.org #42182] Mail::Box::Maildir::Message information lossage
Date: Thu, 15 Jan 2009 11:31:40 +0100
To: Wes Hardaker via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Wes Hardaker via RT (bug-Mail-Box@rt.cpan.org) [090113 18:38]: Show quoted text
> Queue: Mail-Box > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=42182 > >
>>> The current maildir message module doesn't respect all the possible >>> flags in use by various applications.
>
> MOv> MailBox attempts to provide an abstract interface, hiding differences > MOv> in message storage between folder types as good as possible.
> > I think that's the right approach wherever possible. By the way, I > think it's a fantastic module so don't get me wrong about it because I'm > reporting one issue... I love the module!
I handle bug-reports (for all my modules) on daily basis... and am always glad when I receive them: the best way to improve the quality of the code. Show quoted text
> MOv> When you move a message from a Maildir folder into an Mbox folder,
> these flags get automatically written in the other convension. > > Right, and I do think that's the right thing to do. However, I do think > that holding on to unknown flags is probably a good idea too. The user > would have to realize that transferring from one box type to another may > be lossy when unknown flags are being used (and a simple statement to > that effect in the CAVEATS section would suffice).
I have added a "BE WARNED" text to Mail::Box::Manager::moveMessage() and Mail::Box::addMessage() which is the usual method where message type coercions are made. Show quoted text
> MOv> Probably I should have produced a warning message when unknown > MOv> flags appear. That would have saved you some work.
> > My suggestion is just that the perl module tries to keep them if it can > (IE, it's not doing something through a lossy process like converting > from one box type to another)
You convinced me. Please test the attached pre-release. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Download Mail-Box-2.087.tar.gz
application/x-gunzip 585.2k

Message body not shown because it is not plain text.

fixed in 2.087
On Tue Feb 03 06:43:53 2009, MARKOV wrote: Show quoted text
> fixed in 2.087
So... I appologize for the delay. I've been both sick (for a month!) and away on a work trip. I'm just getting caught up again from all of that. I was all set to write you a happy "it's fixed" note, but it turns out that something is still wrong and I lost all the flags in a folder again after checking out the most recent version. I'm not sure why, as glancing at the code it looks like it should work. Oh wait... there it is. You see that the flags it's picking are still matching only the upper-case ones? If you check my original patch, it modifies the regex to add a-z to the [] match. Yep. I just made that change to the 2.087 code and it no longer drops my lower case flags.
I am stupid (and overloaded). Fixed in 2.090