summaryrefslogtreecommitdiff
path: root/bin/expand-annex-mboxes
blob: ecce1002c09464d7164e5ead1795c760365e9c30 (plain)
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
#!/usr/bin/perl

use 5.028;
use strict;
use warnings;
use lib "$ENV{HOME}/src/dotfiles/perl5";

use Fcntl qw(LOCK_EX LOCK_NB);
use File::Path qw(make_path);
use File::Spec::Functions qw(catfile splitpath);
use Local::Homedir::Mail qw(expand_mbox);

# CONFIG

our $mboxes   = "$ENV{HOME}/annex/mail";
our $expanded = "$ENV{HOME}/.fmail/annex";

# CODE

# flock ourselves to ensure that only one copy of this script is ever
# running
exit 0 unless flock DATA, LOCK_EX|LOCK_NB;
die "no movemymail\n" if -e "$ENV{HOME}/.nomovemymail";

make_path($expanded);
open my $touch_fh, '>', "$expanded/.duplicity-ignore";
close $touch_fh;

foreach my $mbox (glob "$mboxes/*.gz") {
    # $mbox might be a dangling symlink on this machine
    next unless -e $mbox;

    my (undef, undef, $name) = splitpath($mbox);
    $name =~ s/\.gz$//;
    expand_mbox($mbox, catfile($expanded, $name));
}

# needed for above flock to work (__DATA__ would also work)
__END__