summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-03-19 23:41:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-03-20 15:01:21 -0700
commit9a3c37c21e9a1502a7b98705617cc4d5adeeeff1 (patch)
treefafe26b455fbde90aa38dc7b94ab2b9379bb73d0 /scripts
parent4fd9b0282d7289ea993eefa22d497617a7dd5333 (diff)
downloaddotfiles-9a3c37c21e9a1502a7b98705617cc4d5adeeeff1.tar.gz
rename annexfmail out of PATH
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mail/archive-fmail-to-annex49
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/mail/archive-fmail-to-annex b/scripts/mail/archive-fmail-to-annex
new file mode 100755
index 00000000..b18008fe
--- /dev/null
+++ b/scripts/mail/archive-fmail-to-annex
@@ -0,0 +1,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";