summaryrefslogtreecommitdiff
path: root/bin/annexfmail
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2019-10-12 10:08:29 -0700
committerSean Whitton <spwhitton@spwhitton.name>2019-10-12 10:08:29 -0700
commit4da59bbfa8125df00dedfe978340b830af168a63 (patch)
tree93f5624b8208bc12e7970931eaaa848ae87323bd /bin/annexfmail
parent126d69613da453e8d8914587e32a708f532ecbfd (diff)
downloaddotfiles-4da59bbfa8125df00dedfe978340b830af168a63.tar.gz
rewrite annexfmail not to use archivemail
archivemail has not been ported to python3
Diffstat (limited to 'bin/annexfmail')
-rwxr-xr-xbin/annexfmail124
1 files changed, 49 insertions, 75 deletions
diff --git a/bin/annexfmail b/bin/annexfmail
index 493e7527..4f0c685b 100755
--- a/bin/annexfmail
+++ b/bin/annexfmail
@@ -1,75 +1,49 @@
-#!/bin/bash
-
-. $HOME/.shenv
-. $HOME/lib/tputfs.sh
-
-set -e
-
-# 1. turn off mbsync for a bit
-
-if pgrep mbsync >/dev/null; then
- echo "annexfmail: mbsync is running so I can't disable it" >&2
- exit 1
-fi
-
-movemymail
-touch ~/.nomovemymail
-
-# 2. set constants
-
-OUTPUT=$HOME/lib/annex/doc/mail
-INPUT=$HOME/.fmail
-
-# set the archive suffix ourselves because we don't want the archive
-# ending with -jan-2014 to be added to after the end of January, so
-# that it may be safely archived into the annex
-suffix=$(date +-%b-%Y | sed 's/\(.*\)/\L\1/')
-
-# 3. safety check to be sure we don't overwrite anything
-
-if [ -e "$OUTPUT/archive${suffix}.gz" ] \
- || [ -e "$OUTPUT/sent${suffix}.gz" ] \
- || [ -e "$OUTPUT/feeds${suffix}.gz" ] \
- || [ -e "$OUTPUT/lists${suffix}.gz" ]; then
- echo "annexfmail: looks like you've already made an archive recently" >&2
- echo "annexfmail: to avoid issues with git-annex, wait until next month"
- exit 1
-fi
-
-# 4. now do the archiving run
-
-archivemail \
- --days=31 \
- --output-dir=$OUTPUT \
- --preserve-unread \
- --archive-name=archive${suffix} \
- $INPUT/inbox
-
-archivemail \
- --days=31 \
- --output-dir=$OUTPUT \
- --preserve-unread \
- --archive-name=sent${suffix} \
- $INPUT/sent
-
-archivemail \
- --days=31 \
- --output-dir=$OUTPUT \
- --preserve-unread \
- --archive-name=feeds${suffix} \
- $INPUT/feeds
-
-archivemail \
- --days=31 \
- --output-dir=$OUTPUT \
- --preserve-unread \
- --archive-name=lists${suffix} \
- $INPUT/lists
-
-# cd $OUTPUT
-# git annex add archive${suffix}.gz sent${suffix}.gz debian${suffix}.gz feeds${suffix}.gz
-
-#mv "$HOME/.mbsyncrc~" "$HOME/.mbsyncrc"
-
-status now commit and sync ~/lib/annex
-status and rm ~/.nomovemymail
+#!/usr/bin/perl
+
+use 5.028;
+use strict;
+use warnings;
+use lib "$ENV{HOME}/lib/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}/lib/annex/doc/mail";
+our $expanded_mboxes = "$ENV{HOME}/.fmail/annex";
+our %names
+ = (inbox => 'archive', sent => 'sent', feeds => 'feeds', lists => 'lists');
+our @annex_sync_remotes = qw(origin athena);
+
+# 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";