MAIL CHECKER
Author Jon Visick
File Name MailCheck.powerpro
Requirements Mail plugin, Event plugin, PowerPro 3.7+
Assumptions
  1. & is the "expression follows" character
  2. As written, the script assumes that item #13 on a bar named DeskIcons has an icon that should change when mail is received. Icons for empty mailbox, checking mail and mail received are in an icon library.
Variables
  1. MailServer = POP server name (e.g. mail.yourhost.com) or IP address
  2. MailUser = POP account user name
  3. MailPass = POP account password
  4. ILib = Path to icon library
  5. MsgCount = number of messages at last check
Description: A script to check a POP server and announce the arrival of new mail by changing the icon on a bar and playing a sound. Modified from Alan Campbell's sample script included with the Mail plugin.
Notes:
How to use this script:
  1. Create a bar with a button that will show the state of the POP3 mailbox (e.g., a button that runs the mail program)
  2. Find or create icons for empty mailbox, mailbox with mail and mail being checked or server not available
  3. Create a timer which runs the MailCheck script at the desired interval. For example, set timer c Running, Down and AutoStart with a 1-minute Reset time and the Reset command set to *Script RunFile MailCheck.txt. (Alternatively, a bar could have a button that runs the MailCheck script on demand.)

; Set parameters for Mail plugin
mail.error_dialog_off()
mail.use_long_vars()
mail.returns_values()

; Set directory for icon library (could be done in a startup script)
ILib="C:\Program Files\PowerPro\Icons\IconLibrary.icl"

; If not already set, set server parameters
If (MailServer == "") do
    MailServer = "[server name]"
    MailUser = "[user name]"
    MailPass = "[password]"
Endif

; Start connecting to account (done in the background using Alan's
; threaded option in Mail plugin). Set an event as a timer to check
; for connection every 2 seconds for 1 minute before timing out.
; Show the "checking" icon while connecting is in process.

mail.connect_to_accnt_threaded(MailServer, MailUser, MailPass)
ev_connect_mail = event.create(2,30,".MailCheck@OnEvent")
Format Item item 13 list "DeskIcons" iconfile &(ILib) iconnum 200
quit

@OnEvent
; Every 2 seconds, event comes here to see if connection has been
; made--if not, it waits another time cycle
If (mail.check_connected ge 0) do
    .MailCheck@DoMail
Endif
Quit

@DoMail
; Once the connection is made, come here to check for messages, etc.

; Shut down the timer event
If (event.exists(ev_connect_mail))
    event.destroy(ev_connect_mail)

; Set the timeout for getting messages
mail.set_timeout(4000)

; See if there are new messages and disconnect
ml_no_msgs = mail.get_no_msgs
mail.disconnect()

If (ml_no_msgs gt 0) do
    ; If there are any messages, change to the appropriate icon
    Format Item item 13 list "DeskIcons" iconfile &(ILib) iconnum 202

    If (MsgCount eq "" or (ml_no_msgs gt MsgCount)) do
        ;If there are additional messages since last time (>MsgCount)
        ;or there were no messages before, then play a sound
        do(SoundDir++"message.wav","")
    Endif
Else
    *Format Item item 13 list "Desk icons" iconfile &(ILib) iconnum 201
Endif

; Assign MsgCount variable to keep track of current number of messages
Assign MsgCount ml_no_msgs
mail.unload()
Quit