[patch] Re: Fix the logic for updating maildir flags.

Nicolas Sebrecht nicolas.s-dev at laposte.net
Sat Jan 26 16:41:08 GMT 2013


I believe it was never reviewed/merged. Somewhat old but resending it.

On Tue, Dec 20, 2011 at 01:45:21PM -0500, Rafael Ávila de Espíndola wrote:
> This patch fixes the logic for updating maildir flags.
> 
> I noticed this failing when offlineimap and dovecot accessed the same
> directory.
> Dovecot adds lowercase flags for keywords the IMAP clients sends it, so
> I had a
> file that was named like
> 
>     ....:2,a
> 
> With the old logic, infostr would be set to infomatch.group(1) which was
> ':2,a'.
> We would then remove the '2,[A-Z]*' leaving only the 'a'. leaving us in
> the end
> with a new file named
> 
>     .....:a2,....
> 
> If the old flags were in [A-Z], we should completly strip them. I looks like
> the code intent was to merge them. That is what this change implements. We
> convert the old flags into a set and merge that with the incoming flags.
> 
> After this change, the above case produces a file named
> 
>     .......:2,...a
> 
> Cheers,
> Rafael

> diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
> index df5dd2e..90d9164 100644
> --- a/offlineimap/folder/Maildir.py
> +++ b/offlineimap/folder/Maildir.py
> @@ -274,13 +274,14 @@ class MaildirFolder(BaseFolder):
>          else:
>              dir_prefix = 'new'
>  
> -        infostr = self.infosep
>          infomatch = re.search('(' + self.infosep + '.*)$', newname)
>          if infomatch:                   # If the info string is present..
> -            infostr = infomatch.group(1)
> +            oldinfo = infomatch.group(1) # of the form :2,...
> +            oldflags = set(oldinfo[3:])
> +            flags |= oldflags
>              newname = newname.split(self.infosep)[0] # Strip off the info string.
> -        infostr = re.sub('2,[A-Z]*', '', infostr)
> -        infostr += '2,' + ''.join(sorted(flags))
> +        infostr = self.infosep + '2,'
> +        infostr += ''.join(sorted(flags))
>          newname += infostr
>          
>          newfilename = os.path.join(dir_prefix, newname)

-- 
Nicolas Sebrecht
-------------- next part --------------
A non-text attachment was scrubbed...
Name: update_flags.patch
Type: text/x-diff
Size: 995 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/offlineimap-project/attachments/20130126/1e163261/attachment-0002.patch>


More information about the OfflineIMAP-project mailing list