-
Notifications
You must be signed in to change notification settings - Fork 10
/
index2maildir.pl
executable file
·59 lines (48 loc) · 1.17 KB
/
index2maildir.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env perl
# Use like: doveadm dump dovecot.index|index2maildir.pl ~/Maildir-test
# Mainly useful for debugging other peoples' index file problems
use strict;
my $uidv = 0;
my $nextuid = 0;
my $dir = $ARGV[0];
if ($dir eq "") {
die "Give dest maildir directory as parameter";
}
die "$dir already exists" if (-e $dir);
while (<STDIN>) {
if (/^uid validity .* = (\d+) /) {
$uidv = $1;
} elsif (/^next uid .* = (.*)$/) {
$nextuid = $1;
} else {
last if (/^-- RECORDS:/);
}
}
if ($uidv == 0 || $nextuid == 0) {
die "Give index dump output in stdin";
}
mkdir $dir || die "Can't create $dir";
mkdir "$dir/tmp";
mkdir "$dir/new";
mkdir "$dir/cur";
my $f;
open $f, ">$dir/dovecot-uidlist" || die "Can't create uidlist";
print $f "3 V$uidv N$nextuid\n";
while (<STDIN>) {
if (/^RECORD: .*uid=(\d+), flags=(.*)$/) {
my $uid = $1;
my $flags = $2;
my $fname = "u$uid";
print $f "$uid :$fname\n";
my ($mf, $destdir);
if ($flags =~ /Recent/) {
$destdir = "$dir/new";
} else {
$destdir = "$dir/cur";
}
open $mf, ">$destdir/$fname";
close $mf;
}
}
close $f;
print "Converted index input to Maildir in $dir\n";