Conversion mailbox - maildir

Conversion mailbox - maildir - Divers - Linux et OS Alternatifs

Marsh Posté le 18-12-2003 à 17:39:01    

Salut !
 
Le pb est le suivant : on a tout un tas de mailboxes à covnertir en maildir.
 
je suppose qu'un utilitaire existe pr cela, mais devant le flot d'informations délivrées par google je 'nai rien pu trouver de très pertinent...
 
merci d'avance pr votre aide :)

Reply

Marsh Posté le 18-12-2003 à 17:39:01   

Reply

Marsh Posté le 18-12-2003 à 18:10:12    

perfectmailbox ?  

Code :
  1. #!/usr/bin/perl
  2. # "Simple but Perfect" mbox to Maildir converter v0.1
  3. # by Philip Mak <pmak@aaanime.net>
  4. # Usage: perfect_maildir ~/Maildir < mbox
  5. # Simple  - only converts one mbox (can use script in one-liners)
  6. # Perfect - message Flags/X-Flags are converted; "^>From ." line is unescaped
  7. # I wrote this script after being unsatisfied with existing mbox to
  8. # maildir converters. By making it "Simple", code complexity is kept
  9. # low thus making it easy to program and debug. At the same time,
  10. # since it only converts one mbox at a time, it is perfect for use in
  11. # a shell ``for'' loop (for example).
  12. # As for being "Perfect", to the best of my knowledge this script does
  13. # the conversion correctly in all cases; it will translate "Status"
  14. # and "X-Status" fields into maildir info, and it correctly detects
  15. # where messages begin and end. (This is only version 0.1 so I may
  16. # have messed something up though. Please send me feedback!)
  17. # NOTE: The MUA ``mutt'' has a bug/feature where in the message index,
  18. # it claims that all maildir messages have 0 lines unless they have a
  19. # "Lines:" header set. perfect_maildir does not attempt to add the
  20. # "Lines:" header; you may want to reconfigure ``mutt' to display byte
  21. # size instead of lines instead by adding the following line to your
  22. # ~/.muttrc file:
  23. #
  24. # set index_format="%4C %Z %{%b %d} %-15.15L (%4c) %s"
  25. # check for valid arguments
  26. my ($maildir) = @ARGV;
  27. if (!$maildir) {
  28.   print STDERR "Usage: perfect_maildir ~/Maildir < mbox\n";
  29.     exit 1;
  30.     }
  31.     # check for writable maildir
  32.     unless (-w "$maildir/cur" ) {
  33.       print STDERR "Cannot write to $maildir/cur\n";
  34.         exit 1;
  35. }
  36. unless (-w "$maildir/new" ) {
  37.   print STDERR "Cannot write to $maildir/new\n";
  38.     exit 1;
  39.     }
  40.     my $num = 0;
  41.     my $time = time;
  42.     repeat:
  43.     # read header
  44.     my $headers = '';
  45.     my $flags = '';
  46.     my $subject = '';
  47.     while (my $line = <STDIN> ) {
  48.       # detect end of headers
  49.         last if $line eq "\n";
  50.    # strip "From" line from header
  51.      $headers .= $line unless $line =~ /^From ./;
  52.        # detect flags
  53.          $flags .= $1 if $line =~ /^Status: ([A-Z]+)/;
  54.     $flags .= $1 if $line =~ /^X-Status: ([A-Z]+)/;
  55.       $subject = $1 if $line =~ /^Subject: (.*)$/;
  56.       }
  57.       $num++;
  58.       # open output file
  59.       my $file;
  60.       if ($flags =~ /O/) {
  61.         $file = "$maildir/cur/$time.$num.$ENV{HOSTNAME}";
  62.           my $extra = '';
  63.      $extra .= 'F' if $flags =~ /F/; # flagged
  64.        $extra .= 'R' if $flags =~ /A/; # replied
  65.          $extra .= 'S' if $flags =~ /R/; # seen
  66.            $extra .= 'T' if $flags =~ /D/; # trashed
  67.       $file .= ":2,$extra" if $extra;
  68.       } else {
  69.         $file = "$maildir/new/$time.$num.$ENV{HOSTNAME}";
  70.         }
  71.         # filter out the "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA" message
  72.         $file = '/dev/null' if ($num == 1 and $subject eq "DON'T DELETE THIS MESSAGE -- FOLDER
  73.         INTERNAL DATA" );
  74.         open(FILE, ">$file" );
  75.         print FILE "$headers\n";
  76.         while (my $line = <STDIN> ) {
  77.           # detect end of message
  78.             last if $line =~ /^From ./;
  79.        # unescape "From"
  80.          $line =~ s/^>From (.)/From $1/;
  81.            print FILE $line;
  82.            }
  83.            close(FILE);
  84.            goto repeat unless eof(STDIN);
  85.            my $elapsed = time - $time;
  86.            print "Inserted $num messages into maildir $maildir in $elapsed seconds\n";


Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed