From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/56377 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: Thu, 12 Feb 2004 18:23:35 -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> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1076628324 16939 80.91.224.253 (12 Feb 2004 23:25:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 12 Feb 2004 23:25:24 +0000 (UTC) Cc: ding@gnus.org Original-X-From: ding-owner+M4917@lists.math.uh.edu Fri Feb 13 00:25:14 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 1ArQCn-00026D-00 for ; Fri, 13 Feb 2004 00:25:13 +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 1ArQBi-0003J9-00; Thu, 12 Feb 2004 17:24:06 -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 1ArQBd-0003J4-00 for ding@lists.math.uh.edu; Thu, 12 Feb 2004 17:24:01 -0600 Original-Received: from mirapoint1.tis.cwru.edu (mirapoint1.TIS.CWRU.Edu [129.22.104.46]) by justine.libertine.org (Postfix) with ESMTP id B590B3A00B3 for ; Thu, 12 Feb 2004 17:24:00 -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 ASL41999; Thu, 12 Feb 2004 18:23:37 -0500 (EST) Original-Received: (qmail 5720 invoked by uid 500); 12 Feb 2004 23:23:58 -0000 Original-To: Bijan Soleymani In-Reply-To: <87znbojjtx.fsf@server.crasseux.com> (Bijan Soleymani's message of "Thu, 12 Feb 2004 12:20:26 -0500") Mail-Copies-To: nobody Mail-Followup-To: Bijan Soleymani , ding@gnus.org Original-Lines: 19 User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:56377 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:56377 --=-=-= Bijan Soleymani wrote: > Ok here's the same script with the errors fixed I got motivated and wrote a similar script, though I haven't tested it. It covers all the marks and flags that exist in common. It has two modes: --f2m takes the information from the maildir flags and copies it to the Gnus mark storage; you can run this after using mutt/IMAP/whatever and before you start Gnus. --m2f copies information in the other direction, for use after you've run Gnus and are going to use mutt/IMAP/whatever. Better not run it in either mode while Gnus is running. The second argument is your nnmaildir server directory, containing your maildirs. 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: gnus_maildir_sync {--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]); } @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 $file=IO::File->new(); $file->open($_[0], O_WRONLY|O_CREAT, 0600) or die_open($_[0]); $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=''; if (index($info, 'D')>=0) { $new_flags.='D'; } 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()) { create_file($linkpath); } elsif ($!==Errno::EMLINK) { create_file($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); } } } } } } --=-=-=--