summaryrefslogtreecommitdiff
path: root/bin/annexfmail
blob: b18008fec3b457f6d66aa044c96602393ed45159 (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
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl

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

use Local::Homedir::Mail qw(archive_to_mbox);
use File::Spec::Functions qw(catfile);
use POSIX qw(strftime);

# CONFIG

our $maildirs        = "$ENV{HOME}/.fmail";
our $mboxes          = "$ENV{HOME}/annex/mail";
our $expanded_mboxes = "$ENV{HOME}/.fmail/annex";
our %names = (inbox => 'archive', sent => 'sent', lists => 'lists');
our @annex_sync_remotes = qw(origin cloud);

# CODE

# might use Proc::Find from CPAN instead of this
system "pgrep -u $ENV{USER} mbsync";
die "mbsync is running" if $? == 0;

die "no source!"         unless -d $maildirs;
die "no dest!"           unless -d $mboxes;
die "no expansion dest!" unless -d $expanded_mboxes;

system "movemymail";
system "touch $ENV{HOME}/.nomovemymail";

my $suffix = lc strftime("-%b-%Y", localtime);
my @gzipped_mboxes;
foreach my $name (keys %names) {
    my $target = $names{$name} . $suffix;
    archive_to_mbox(
        catfile($maildirs,        $name),
        catfile($mboxes,          $target),
        catfile($expanded_mboxes, $target));
    push @gzipped_mboxes, $target . ".gz";
}

chdir $mboxes;
system "git annex add @gzipped_mboxes";
system "git annex sync @annex_sync_remotes -C .";

unlink "$ENV{HOME}/.nomovemymail";
system "notmuch new";