summaryrefslogtreecommitdiff
path: root/bin/movemymail
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-12-07 10:39:00 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-12-07 17:46:56 -0700
commit64a3111fdb7956500a1970c004338e9ee254351a (patch)
tree3b90bb5d87faf51a4721e12adabb150e5b794e0b /bin/movemymail
parent3240f48f78ecf1f557a10a6a2090553b441b39e1 (diff)
downloaddotfiles-64a3111fdb7956500a1970c004338e9ee254351a.tar.gz
replace 'offline' script
Diffstat (limited to 'bin/movemymail')
-rwxr-xr-xbin/movemymail15
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/movemymail b/bin/movemymail
index b80a5f1b..68eb0ca6 100755
--- a/bin/movemymail
+++ b/bin/movemymail
@@ -7,6 +7,7 @@ use autodie ":all";
use Fcntl qw(LOCK_EX LOCK_NB);
use Net::Domain "hostfqdn";
+use LWP::Simple qw($ua get);
# Ensure only one copy of this script is ever running, and then we assume that
# mbsync isn't already running either, as always invoked via this script.
@@ -20,8 +21,18 @@ open my $df, "-|", "df", "-kP", $root;
<$df>, my @df_fields = split " ", <$df>;
$df_fields[3] > 1048576 or die "free space low; no movemymail\n";
-system [0, 1], "offline";
-$? >> 8 == 0 and die "we're offline; cannot further sync mail\n";
+# See also LWP::UserAgent::is_online() and LWP::Online.
+# We could check more than one website, and try each more than once, in case
+# there are temporary failures.
+#
+# We match page content using get(), rather than just calling head(), so that
+# we don't consider WiFi portal login pages to indicate connectivity.
+$ua->timeout(10);
+my $result = get "http://www.msftncsi.com/ncsi.txt";
+unless ($result and $result eq "Microsoft NCSI") {
+ grep $_ eq "--accept-offline", @ARGV
+ ? exit : die "we're offline; cannot further sync mail\n"
+}
system "postqueue", "-f";
eval { system "mbsync", "fastmail" };