-
Notifications
You must be signed in to change notification settings - Fork 0
/
offlineimap_helper
executable file
·55 lines (36 loc) · 1.16 KB
/
offlineimap_helper
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
50
51
52
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Expect;
# This is based on hourly cron runs. If you run it shorter, modify
# accordingly.
my $TIMEOUT_MINUTES = 50;
# This is based on backing up a single account. If that's not what
# you're doing, you will likely get a false failure.
my $OFFLINEIMAP_DONE = " *** Finished account";
my $OFFLINEIMAP = "offlineimap";
my $timeout_seconds = $TIMEOUT_MINUTES * 60;
$Expect::Log_Stdout = 0;
my $exp = Expect->spawn($OFFLINEIMAP) || die "Can't spawn ${OFFLINEIMAP}";
my $ret = $exp->expect($timeout_seconds, $OFFLINEIMAP_DONE);
# If the pattern didn't match, it will time out, either because it's
# stuck, or because it errored. Either way, print a message, followed
# by everything we captured
if (!defined($ret)) {
print qq^
OfflineIMAP encountered an error. If it was stuck, I'm about to kill
it. If not, it exited on its own, but unssucessfully. Regardless, here
is the output it had when I gave up on it:
====
^;
print $exp->before();
print "====\n";
}
# else, print nothing
# gracefully it, regardless of state
$exp->soft_close();
# give it a minute
sleep(60);
# force close
$exp->hard_close();