#!/p/kd/fdc/solaris9ssl/wermit + #!/p/kd/fdc/mm-pop/wermit + # Tue Dec 6 12:10:23 2005 # # Updated Thu Mar 27 12:02:00 2008 # . do logging # . don't exit upon connection failure if password is not wrong # Updated Fri Aug 22 14:47:32 2008 # . Add timestamps to session log # Updated Sat Oct 3 14:37:42 2009 # . Copy .mm-newmail to .mm-newmail-backup in case MM says that # the mail file is corrupt and deletes it. # # mailcheck (alias mch) # # To enable debugging, run it like this: # # DEBUG=1 mch # # Cunix new-mail checker for use with MM. # Checks POP server for new mail every 5 minutes. # # Directions: start this script in its own window and enter your password # when requested (you only have to do this once). Let the script run until # you're ready to go home, then interrupt the script with Ctrl-C and log out. # # If new mail is present, it is moved from the POP server to ~/.mm-newmail # and a beeping message is printed. The next time MM is activated it will # read in the new mail. Note: This script is just the looping wrapper for # another script, pop.ksc, that does the real work. # # The initial test releases of these scripts are rather verbose. # For now, the scripts run only in the foreground. # # Frank da Cruz, CUIT, fdc@columbia.edu, Nov-Dec 2005 local \%w \%f \%m \%p logging logfile .logging = 0 .logfile := \fpathname(~)mch.log .logging = 1 .\%w = -1 # Log channel .\%f = 0 # Failure count .\%p = 0 # Pass count .total = 0 # Message count .debug = 0 if def \$(DEBUG) .debug := \$(DEBUG) local ON_CTRLC def ON_CTRLC { # Ctrl-C trap echo \m(name) INTERRUPTED... logwrite END - PASSES=\%p OK=\%m FAILED=\%f EMAILS=\m(total) echo "\%0: END - SESSIONS=\%p OK=\%m FAILED=\%f" exit 0 } def LOGWRITE { # Write a log record if \m(logging) { fopen /append \%w \m(logfile) if fail { echo "LOG OPEN failed: \m(logfile) errno=\v(errno) - \f_errmsg()" .logging = 0 } if \f_status(\%w) { fwrite /line \%w \v(timestamp): \%* if fail echo "\%0: FWRITE \%w FAILED - \f_errmsg()" fclose \%w if fail { echo \%0: Problem with log file \m(logfile) on channel \%w file status } } else { echo \%0: Problem with log file \m(logfile) on channel \%w file status } } } .host = pop.columbia.edu:995 # Old server if exist ~/.cyrustt { # Cyrus (new) server .host = mail.columbia.edu:995 } .sleep ::= 5*60 # Check interval = 5 minutes .mypath := \fstripx(\%0,/) # Directory where this script lives while not def pass { # Get password (once) askq /echo:* pass "\$(USER)'s Password: " } .dest := \fpathname(~/.mm-newmail) # Destination file for new mail .date := 0 # Creation date of new mail file .\%m = 0 # Pass count logwrite BEGIN \v(user) # Start log while true { # New-mail getting loop incr \%p # Count pass .\%n = 0 take \m(mypath)/pop.ksc \m(host) \m(dest) \m(pass) # Run the POP script if fail { # Bad increment \%f # Count a failure echo "********" if not \%n echo "\v(timestamp): POP connect or login failure" else echo "\v(timestamp): POP connect failure (\%f/\%p)" echo "********" logwrite FAILED - \m(failmessage) if not \%m exit 1 # Don't loop if password was wrong } else { incr \%m # Count a good password echo "--------" if exist \m(dest) { # Show results .prev := \m(date) .date := \fdate(\m(dest)) if eq "\m(prev)" "\m(date)" echo MAIL WAITING: else echo \{7}NEW MAIL:\{7} grep /nopage "^From " \m(dest) copy \m(dest) \m(dest)-backup # In case mm can't deal with it } echo \v(time) - SLEEP \m(sleep)... echo "--------" logwrite OK - Messages: \m(messages) increment total messages } sleep \m(sleep) # Sleep and then loop again if kbhit clear keyboard-buffer # Clear out any typing } ; Local Variables: ; comment-column:40 ; comment-start:"# " ; End: