From da3511816ac2a4a01617e4baee3aaf075f93fdcd Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Sun, 9 Mar 2003 11:05:00 +0100 Subject: [PATCH] - change the use of $ENV{HOSTNAME} by `hostname` - Put the flag "S" if status is "O" (used by uw-imap/pop) - write to /dev/null if $header is empty (avoid null messages) - don't increment $num if message is going to be written to /dev/null... (null message or "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA" message) --- CHANGES | 11 +++++++++ perfect_maildir.pl | 66 +++++++++++++++++++++++++----------------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/CHANGES b/CHANGES index 32cf35f..5cd5ada 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,14 @@ +v0.2 Sun Mar 9 11:05:56 CET 2003 + +Emmanuel Lacour + +- change the use of $ENV{HOSTNAME} by `hostname` +- Put the flag "S" if status is "O" (used by uw-imap/pop) +- write to /dev/null if $header is empty (avoid null messages) +- don't increment $num if message is going to be written to /dev/null... + (null message or "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA" + message) + v0.1 Tue, 25 Dec 2001 02:16:15 -0800 Philip Mak diff --git a/perfect_maildir.pl b/perfect_maildir.pl index 5f5d13e..eed9be0 100755 --- a/perfect_maildir.pl +++ b/perfect_maildir.pl @@ -1,35 +1,29 @@ #!/usr/bin/perl -# "Simple but Perfect" mbox to Maildir converter v0.1 -# by Philip Mak - -# Usage: perfect_maildir ~/Maildir < mbox - -# Simple - only converts one mbox (can use script in one-liners) -# Perfect - message Flags/X-Flags are converted; "^>From ." line is unescaped - -# I wrote this script after being unsatisfied with existing mbox to -# maildir converters. By making it "Simple", code complexity is kept -# low thus making it easy to program and debug. At the same time, -# since it only converts one mbox at a time, it is perfect for use in -# a shell `for'' loop (for example). - -# As for being "Perfect", to the best of my knowledge this script does -# the conversion correctly in all cases; it will translate "Status" -# and "X-Status" fields into maildir info, and it correctly detects -# where messages begin and end. (This is only version 0.1 so I may -# have messed something up though. Please send me feedback!) - -# NOTE: The MUA `mutt'' has a bug/feature where in the message index, -# it claims that all maildir messages have 0 lines unless they have a -# "Lines:" header set. perfect_maildir does not attempt to add the -# "Lines:" header; you may want to reconfigure `mutt' to display byte -# size instead of lines instead by adding the following line to your -# ~/.muttrc file: -# -# set index_format="%4C %Z %{%b %d} %-15.15L (%4c) %s" +# "Simple but Perfect" mbox to Maildir converter v0.2 +# Copyright (C) 2001-2003 Philip Mak +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Get the hostname + +my $hostname = `hostname`; +chomp ($hostname); # check for valid arguments + my ($maildir) = @ARGV; if (!$maildir) { print STDERR "Usage: perfect_maildir ~/Maildir < mbox\n"; @@ -67,25 +61,28 @@ while (my $line = ) { $flags .= $1 if $line =~ /^X-Status: ([A-Z]+)/; $subject = $1 if $line =~ /^Subject: (.*)$/; } + $num++; # open output file my $file; if ($flags =~ /O/) { - $file = "$maildir/cur/$time.$num.$ENV{HOSTNAME}"; + $file = "$maildir/cur/$time.$num.$hostname"; my $extra = ''; $extra .= 'F' if $flags =~ /F/; # flagged $extra .= 'R' if $flags =~ /A/; # replied - $extra .= 'S' if $flags =~ /R/; # seen + $extra .= 'S' if (($flags =~ /R/) || ($flags =~ /O/)); # seen $extra .= 'T' if $flags =~ /D/; # trashed $file .= ":2,$extra" if $extra; } else { - $file = "$maildir/new/$time.$num.$ENV{HOSTNAME}"; + $file = "$maildir/new/$time.$num.$hostname"; } -# filter out the "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA" message -$file = '/dev/null' if ($num == 1 and $subject eq "DON'T DELETE THIS MESSAGE -- FOLDER -INTERNAL DATA"); +# filter out the "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA" message or the message doesn't exists +if (($num == 1 and $subject eq "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA") || (!$headers)) { + $file = '/dev/null'; + $num--; +} open(FILE, ">$file"); print FILE "$headers\n"; @@ -99,7 +96,6 @@ while (my $line = ) { print FILE $line; } close(FILE); - goto repeat unless eof(STDIN); my $elapsed = time - $time; -- 2.11.0