IMAP new mail notification utility with IDLE support and Notification Center (OS X) and DBus (others) notifications

on mac os, use growl by default and if the password for an account is not set, try to retrieve it from the keychain

+26 -2
+26 -2
imapbiff.pl
··· 36 36 # %config = ( 37 37 # "server.name.here" => { 38 38 # "username" => "example", 39 + # # on mac os, leave "password" key undefined and imapbiff will 40 + # # retrieve it from your keychain 39 41 # "password" => "password", 40 42 # "ssl" => 1, 41 43 # "folders" => [ "INBOX", "mailbox2", "mailbox3.whatever" ], ··· 72 74 # seconds to allow a folder check to take 73 75 $socktimeout = 10; 74 76 75 - # use dbus notifications by default 76 - $notify = "dbus"; 77 + # use growl on mac os by default, otherwise use dbus 78 + if ($^O eq "darwin") { 79 + $notify = "growl"; 80 + } else { 81 + $notify = "dbus"; 82 + } 77 83 78 84 # read the user's config 79 85 my $configdat; ··· 121 127 foreach my $server (keys %config) { 122 128 foreach my $folder (@{$config{$server}{"folders"}}) { 123 129 $config{$server}{"seen"}{$folder} = (); 130 + } 131 + 132 + # on mac os, retrieve any unset passwords from the keychain 133 + if ($^O eq "darwin" && $config{$server}{"password"} eq "") { 134 + open(SEC, "security find-internet-password -g -a '" 135 + . $config{$server}{"username"} . "' -s '" . $server . "' " 136 + . "2>&1 |") || die "can't run security: " . $!; 137 + while (chop(my $line = <SEC>)) { 138 + if ($line =~ /^password: "(.+)"$/) { 139 + $config{$server}{"password"} = $1; 140 + } 141 + } 142 + 143 + if ($config{$server}{"password"} eq "") { 144 + die "no password set in config and couldn't find password for \"" 145 + . $config{$server}{"username"} . "\" on \"" . $server . "\" " 146 + . "in keychain"; 147 + } 124 148 } 125 149 126 150 imap_connect($server);