From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/56436 Path: main.gmane.org!not-for-mail From: prj@po.cwru.edu (Paul Jarc) Newsgroups: gmane.emacs.gnus.general Subject: Re: nnmaildir and info flags Date: Wed, 25 Feb 2004 15:43:06 -0500 Organization: What did you have in mind? A short, blunt, human pyramid? Sender: ding-owner@lists.math.uh.edu Message-ID: References: <87fzg0dj0n.fsf@server.crasseux.com> <87vfov2a05.fsf@server.crasseux.com> <87znbojjtx.fsf@server.crasseux.com> <20040225201530.GA9635@speedy.schwinge.homeip.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1077741855 11371 80.91.224.253 (25 Feb 2004 20:44:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 25 Feb 2004 20:44:15 +0000 (UTC) Original-X-From: ding-owner+M4977@lists.math.uh.edu Wed Feb 25 21:44:04 2004 Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Aw5sy-0005DZ-00 for ; Wed, 25 Feb 2004 21:44:04 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 1Aw5sI-0001XG-00; Wed, 25 Feb 2004 14:43:22 -0600 Original-Received: from justine.libertine.org ([66.139.78.221] ident=postfix) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 1Aw5s7-0001WF-00 for ding@lists.math.uh.edu; Wed, 25 Feb 2004 14:43:11 -0600 Original-Received: from mirapoint1.tis.cwru.edu (mirapoint1.TIS.CWRU.Edu [129.22.104.46]) by justine.libertine.org (Postfix) with ESMTP id 8F2323A0043 for ; Wed, 25 Feb 2004 14:43:09 -0600 (CST) Original-Received: from multivac.cwru.edu (multivac.ITS.CWRU.Edu [129.22.114.26]) by mirapoint1.tis.cwru.edu (MOS 3.4.3-CR) with SMTP id ATZ48114; Wed, 25 Feb 2004 15:43:07 -0500 (EST) Original-Received: (qmail 11944 invoked by uid 500); 25 Feb 2004 20:43:29 -0000 Original-To: ding@gnus.org In-Reply-To: <20040225201530.GA9635@speedy.schwinge.homeip.net> (Thomas Schwinge's message of "Wed, 25 Feb 2004 21:15:30 +0100") Mail-Copies-To: nobody Mail-Followup-To: ding@gnus.org Original-Lines: 16 User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:56436 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:56436 --=-=-= Thomas Schwinge wrote: > It needs some tiny midifications to get it working: See the attached > patch. Oops. Thanks for the fixes. > Since this is the first time I wrote something in perl, I'd be glad if > someone with perl experience - Paul :-) - could have a look at it. It looks ok, although I'm not a big fan of non-tail recursion, so I made some changes. paul --=-=-= Content-Type: application/x-perl Content-Disposition: attachment; filename=marksync #!/usr/local/bin/perl -w use strict; use IO::Handle; use IO::File; use Errno; my @mapping= ( [qw(D .)], [qw(F tick)], [qw(P forward)], [qw(R reply)], [qw(S read)], [qw(T expire)], ); sub die_usage() { die("usage: marksync {--f2m|--m2f} nnmaildir-directory"); } sub die_err(@) { die('unable to ', @_, ': ', $!, "\n"); } sub die_open($ ) { die_err('open ', $_[0]); } sub die_link($$) { die_err('link ', $_[0], ' to ', $_[1]); } sub die_mkdir($ ) { die_err('mkdir ', $_[0]); } @ARGV==2 or die_usage(); my $mode=$ARGV[0]; $mode eq '--f2m' or $mode eq '--m2f' or die_usage(); sub file_exists() { return ($! != Errno::ENOENT); } sub do_create($ ) { my ($path)=@_; my $idx=0; for (;;) { substr($path, $idx)=~m:^(/*):; $idx+=length($1); $idx=index($path, '/', $idx); last if $idx<0; my $dir=substr($path, 0, $idx); mkdir($dir) or $!==Errno::EEXIST or die_mkdir($dir); } my $file=IO::File->new(); $file->open($path, O_WRONLY|O_CREAT, 0600) or die_open($path); $file->close(); } sub do_rename($$) { rename($_[0], $_[1]) or die_err('rename ', $_[0], ' to ', $_[1]); } sub listdir($$) { my ($dirpath, $fullpath)=@_; my $dir=IO::Handle->new(); opendir($dir, $dirpath) or die_open($ARGV[1]); my @files=readdir($dir); closedir($dir); @files=grep(/[^.]/, @files); if ($fullpath) { @files=map($dirpath.'/'.$_, @files); } return @files; } my $dir=$ARGV[1]; $dir=~s:/*\z::; foreach my $maildir (listdir($dir, 1)) { my $cur=$maildir.'/cur'; foreach my $msg (listdir($cur, 0)) { my $info_idx=index($msg, ':'); my $uniq=substr($msg, 0, $info_idx); my $info=substr($msg, $info_idx); if ($info!~/^:2,/) { next; } if ($mode eq '--m2f') { # Update the maildir flags my $new_flags=''; foreach my $map (@mapping) { my ($flag, $mark)=@$map; my $markpath=$maildir.'/.nnmaildir/marks/'.$mark.'/'.$uniq; if ($mark eq '.') # This maildir flag has no corresponding Gnus mark; # just preserve it if it's there. { if (index($info, $flag)>=0) { $new_flags.=$flag; } } elsif (stat($markpath)) { $new_flags.=$flag; } elsif (file_exists()) { die_err('stat ', $markpath); } } my $new_info=':2,'.$new_flags; if ($info ne $new_info) { do_rename($cur.'/'.$msg, $cur.'/'.$uniq.$new_info); } } else { # --f2m; Update the Gnus marks foreach my $map (@mapping) { my ($flag, $mark)=@$map; if ($mark eq '.') { next; } my $markdir=$maildir.'/.nnmaildir/marks/'.$mark; my $markpath=$markdir.'/'.$uniq; if (index($info, $flag)>=0) { my $linkpath=$markdir.'/:'; if (link($linkpath, $markpath) or $!==Errno::EEXIST) { next; } if (not file_exists()) { do_create($linkpath); } elsif ($!==Errno::EMLINK) { do_create($linkpath.'{new}'); do_rename($linkpath.'{new}', $linkpath); } else { die_link($linkpath, $markpath); } link($linkpath, $markpath) or $!==Errno::EEXIST or die_link($linkpath, $markpath); } else { if (unlink($markpath)<0 and file_exists()) { die_err('unlink ', $markpath); } } } } } } --=-=-=--