#!/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";