summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.hornet1
-rwxr-xr-xbin/mbsyncloop46
-rw-r--r--config/imapnotify/tozt.conf8
3 files changed, 44 insertions, 11 deletions
diff --git a/Makefile.hornet b/Makefile.hornet
index 2963fe4..29ef1e8 100644
--- a/Makefile.hornet
+++ b/Makefile.hornet
@@ -6,6 +6,7 @@ INSTALL := \
.config/i3/signal-workspace.json \
.config/i3/terminal-workspace.json \
.config/i3status/config \
+ .config/imapnotify/tozt.conf \
.config/msmtp/config \
.config/perspektiv/config.toml \
.mbsyncrc \
diff --git a/bin/mbsyncloop b/bin/mbsyncloop
index a00dc59..b96ddae 100755
--- a/bin/mbsyncloop
+++ b/bin/mbsyncloop
@@ -32,22 +32,46 @@ if (!$pid) {
exit;
}
+open my $goimapnotify, '-|', "sh", "-c", "goimapnotify --conf ~/.config/imapnotify/tozt.conf 2>&1" or die;
+
my $last_all = 0;
while (1) {
my $now = time;
-
- my $channel;
- if ($now - $last_all > 15 * 60) {
- $channel = "all";
+ if (($now - $last_all) >= 14 * 60) {
+ sync("all");
+ $last_all = $now;
}
- else {
- $channel = "priority";
+ if (idle(15 * 60 - (time - $now))) {
+ sync("priority");
}
+}
- my $status = system("mbsync -c ~/.mbsyncloop $channel");
- if ($status == 0 && $channel eq "all") {
- $last_all = $now;
+sub sync {
+ my ($channel) = @_;
+ warn "syncing $channel";
+ while (1) {
+ my $status = system("mbsync -c ~/.mbsyncloop $channel");
+ if (!$status) {
+ system("notmuch new | grep -v '^No new mail\.\$'");
+ last;
+ }
+ sleep 5;
+ }
+ warn "done syncing $channel";
+}
+
+sub idle {
+ my ($max_delay) = @_;
+ my $rin = '';
+ vec($rin, fileno($goimapnotify), 1) = 1;
+ my $ready = select(my $rout = $rin, undef, undef, $max_delay);
+ if ($ready) {
+ while (1) {
+ my $ready = select(my $rout = $rin, undef, undef, 0.01);
+ last unless $ready;
+ sysread $goimapnotify, my $data, 4096;
+ }
+ return 1;
}
- system("notmuch new | grep -v '^No new mail\.\$'");
- sleep 60 - (time - $now);
+ return 0;
}
diff --git a/config/imapnotify/tozt.conf b/config/imapnotify/tozt.conf
new file mode 100644
index 0000000..77d35dd
--- /dev/null
+++ b/config/imapnotify/tozt.conf
@@ -0,0 +1,8 @@
+{
+ "host": "mail.tozt.net",
+ "port": 993,
+ "tls": true,
+ "username": "doy@tozt.net",
+ "passwordCmd": "rbw get mail.tozt.net doy@tozt.net",
+ "boxes": [ "INBOX", "personal" ]
+}