2 # Mail notifier plugin for fubar. Creates a sunken button which changes
3 # color when there is new mail and executes $CONFIGDIR/mail when pressed
6 set image [image create bitmap -background white -foreground black \
7 -data {#define mailfg_width 24
8 #define mailfg_height 12
9 static unsigned char mailfg_bits[] = {
10 0xff, 0xff, 0xff, 0x0d, 0x00, 0xb0, 0x71, 0x00, 0x8e, 0x81, 0x83, 0x81,
11 0x01, 0x7c, 0x80, 0x01, 0x7e, 0x80, 0x81, 0x81, 0x83, 0x71, 0x00, 0x8c,
12 0x0d, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
13 } -maskdata {#define mailbgd_width 24
14 #define mailbgd_height 12
15 static unsigned char mailbgd_bits[] = {
16 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
17 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
18 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
20 button .mail -relief sunken -bd 1 -image $image -width 32\
21 -command { exec $CONFIGDIR/mail &}
22 set mailDefBg [.mail cget -bg]
25 # procedure to be invoked each minute
27 proc ::mail::checkMbox {} {
29 return [expr {[file atime $mailpath]<[file mtime $mailpath]}]
32 proc ::mail::checkMailDir {} {
34 return [llength [glob -nocomplain $mailpath/new/*]]
41 set f [open "|$::RunCmd($imap(host)) $imap(command) 2>/dev/null" r+]
42 fconfigure $f -buffering line -blocking no
43 fileevent $f readable "::mail::imapRead $f"
45 vwait ::mail::imapnewmail
56 if {$imapstate == 1 && [regexp -nocase ready $line]} {
57 puts $f "1 EXAMINE INBOX"
59 } elseif {$imapstate ==2} {
60 if {[string match "1 *" $line]} {
63 } elseif {[regexp {^\*[[:space:]]+([[:digit:]]+)[[:space:]]+RECENT} $line match new]} {
69 proc ::mail::check {args} {
73 .mail configure -bg red
75 .mail configure -bg $mailDefBg
83 # Find out mailbox type
85 if {[file exists $::CONFIGDIR/imapmail]} {
86 set f [open $::CONFIGDIR/imapmail]
87 catch {array set imap [read $f]}
88 if {[info exists imap(host)]&&[info exists imap(command)]&&
89 [info exists ::RunCmd($imap(host))]} {
90 set checkcmd checkImap
92 tk_messageBox -title error -type ok -message "Incorrect syntax of imapmail file"
95 set tryboxes [list /var/mail/$::env(LOGNAME) /var/spool/mail/$::env(LOGNAME) ~/Maildir]
97 if {[info exists ::env(MAIL)]} {
98 set tryboxes [concat [list $::env(MAIL)] $tryboxes]
101 foreach box $tryboxes {
102 if {[file exists $box]} {
104 if {[file isdirectory $box]&&[file isdirectory $box/new]} {
105 set checkcmd checkMailDir
107 set checkcmd checkMbox
113 if {[info exists checkcmd]} {
114 pack .mail -side right -padx 10
115 notifier ::mail::check