summaryrefslogtreecommitdiffstats
path: root/.local/bin
diff options
context:
space:
mode:
authorjoe <rbo@gmx.us>2025-10-03 17:22:39 +0200
committerjoe <rbo@gmx.us>2025-10-03 17:22:39 +0200
commitb8b4e874e59b556d20b554d9119e8f5be8c0ef80 (patch)
tree5be182d4d5ca124c72768c5adf25cbb96bae1d18 /.local/bin
parentsubtlerain told me to delete this - he was right (diff)
downloaddotfiles-bsd-b8b4e874e59b556d20b554d9119e8f5be8c0ef80.tar.gz
dotfiles-bsd-b8b4e874e59b556d20b554d9119e8f5be8c0ef80.tar.bz2
dotfiles-bsd-b8b4e874e59b556d20b554d9119e8f5be8c0ef80.tar.xz
dotfiles-bsd-b8b4e874e59b556d20b554d9119e8f5be8c0ef80.tar.zst
dotfiles-bsd-b8b4e874e59b556d20b554d9119e8f5be8c0ef80.zip
Diffstat (limited to '')
-rwxr-xr-x.local/bin/fetch_mail84
1 files changed, 51 insertions, 33 deletions
diff --git a/.local/bin/fetch_mail b/.local/bin/fetch_mail
index b466432..743d027 100755
--- a/.local/bin/fetch_mail
+++ b/.local/bin/fetch_mail
@@ -2,12 +2,22 @@
use strict;
use warnings;
-use threads;
use Fcntl;
use Env qw(HOME);
use constant MC_FILE_PATH => '/tmp/mc_';
+sub test_gpg
+{
+ my $ret;
+
+ $ret = system("echo test | gpg2 --sign --batch --no-tty --pinentry-mode error -o /dev/null >/dev/null 2>&1");
+ if ($ret != 0) {
+ notify(" gpg locked | can't fetch mails");
+ }
+ return $ret;
+}
+
sub notify
{
my ($str) = @_;
@@ -27,7 +37,7 @@ sub get_new_mail
system('killall mbsync >/dev/null 2>&1');
$ret = system('mbsync', $acc);
- if ($ret != 0) {
+ if ($ret != 0) {
notify(" $acc: failed to sync mails");
}
return;
@@ -61,31 +71,29 @@ sub fetch_thread
{
my ($acc) = @_;
- # my $pre_count = -1;
- # my $mc_file = MC_FILE_PATH . $acc;
- # my $fh;
- # if (-f $mc_file) {
- # open($fh, '+<', $mc_file) or die $!;
- # $pre_count = <$fh>;
- # } else {
- # open($fh, '+>', $mc_file) or die $!;
- # $pre_count = -1;
- # }
- # # if ($pre_count == -1) {
- # # $pre_count = count_new_mails($_, $maildir);
- # # }
- # get_new_mail($acc);
- # my $post_count = count_new_mails($acc);
- # if ($post_count > $pre_count && $post_count > 0) {
- # my $notify_str = ' ' . $acc . ': ' . $post_count . ' new mail';
- # $notify_str .= ($post_count > 1 ? "s\n" : "\n");
- # notify($notify_str)
- # }
- # seek($fh, 0, 0);
- # print $fh "$post_count";
- # close($fh);
- print "hey $acc\n";
- threads->detach();
+ my $pre_count = -1;
+ my $mc_file = MC_FILE_PATH . $acc;
+ my $fh;
+ if (-f $mc_file) {
+ open($fh, '+<', $mc_file) or die $!;
+ $pre_count = <$fh>;
+ } else {
+ open($fh, '+>', $mc_file) or die $!;
+ $pre_count = -1;
+ }
+ # if ($pre_count == -1) {
+ # $pre_count = count_new_mails($_, $maildir);
+ # }
+ get_new_mail($acc);
+ my $post_count = count_new_mails($acc);
+ if ($post_count > $pre_count && $post_count > 0) {
+ my $notify_str = ' ' . $acc . ': ' . $post_count . ' new mail';
+ $notify_str .= ($post_count > 1 ? "s\n" : "\n");
+ notify($notify_str)
+ }
+ seek($fh, 0, 0);
+ print $fh "$post_count";
+ close($fh);
return;
}
@@ -94,14 +102,24 @@ sub fetch_mail
$ENV{'MAIL'} = $HOME . '/.local/share/mail';
$ENV{'GNUPGHOME'} = $HOME . '/.local/share/gnupg';
$ENV{'PASSWORD_STORE_DIR'} = $HOME . '/.local/share/pass';
- my @threads;
+ my @pids;
+ my $ret;
- # test gpg
+ $ret = test_gpg();
+ if ($ret != 0) {
+ return;
+ }
my @accs = get_all_accounts();
- push(@threads, threads->new(\&fetch_thread, $_)) for (@accs);
- # $_->join() for (@threads);
- print "done\n";
- # notify($notify_str) if (length($notify_str) > $og_length);
+ for (@accs) {
+ my $pid = fork();
+ if (not $pid) {
+ fetch_thread($_);
+ return;
+ }
+ push(@pids, $pid);
+
+ }
+ while (wait() != -1) {}
return;
}