# Copyright (c) 2001 Jeff Keegan (jkeegan@keegan.org) # $Id: mail.itcl,v 1.4 2005/08/08 00:50:50 davidlallen Exp $ # # Mail module by Jeff Keegan, http://www.keegan.org/jeff # # History: # First version, July 24, 2001 # July 24, 2001: Version 1.0 # July 28, 2001: Version 1.1 # Allow viewing/deleting of existing emails # Jan 4, 2006 : Version 1.2 # Allow for missing PreTivoCentral MFS section # # Send Message changed event after reading a message. 23Feb03 13:21 proc action_mail {chan path env} { if {[string index $path 0] == "/"} { set path [string range $path 1 end] } puts $chan [html_start "TiVo Mail"] puts $chan [html_table_start "" "TiVo Mail" "COLSPAN=2"] puts $chan [tr "" [td [html_link "/newmail" "Create New Mail"]]] puts $chan [tr "" [td [html_link "/listmail" "View/Delete Existing Mail"]]] puts $chan [html_table_end] puts $chan [html_end] } proc action_listmail {chan path env} { global db global images set showdeleted "" eval $env puts $chan [html_start "List TiVo Mail"] foreach section {PreTivoCentral MessageBoard} { if {$section == "PreTivoCentral"} { puts $chan [html_table_start "" "" ""] puts $chan [tr "" [th "COLSPAN=3" "Pre-TiVo Central"]] } elseif {$section == "MessageBoard"} { puts $chan [html_table_start "" "" ""] puts $chan [tr "" [th "COLSPAN=3" "Message Board"]] } catch [ ForeachMfsFileTrans fsid name type "/MessageItem/$section" "" 20 { set msg [db $db openid $fsid] set deleted [dbobj $msg get Deleted] if {$deleted != 1 || $showdeleted != ""} { set from [dbobj $msg get From] set subject [dbobj $msg get Subject] set subject [strim $subject] if {$subject == ""} { set subject "No Subject" } set body [dbobj $msg get Body] set dateread [dbobj $msg get DateRead] set tmpimgstr "" if {$dateread != ""} { append tmpimgstr [img "alt=\"\"" [lindex $images 1]] } set date [dbobj $msg get DateGenerated] set time [dbobj $msg get TimeGenerated] set seconds [expr $date * 86400 + $time] if {$::lang == "en"} { set daystr [nth_sup [ftime $seconds "%e"]] set datestr [ftime $seconds "%a $daystr %b %Y"] } else { set datestr [ftime $seconds "%1m/%1d"] } puts $chan [tr "" [td $tmpimgstr] [td "nowrap" $datestr] [td [html_link "/viewmail/$fsid" "$subject"]] ] } } ] puts $chan [html_table_end] } puts $chan [html_end] } proc action_newmail {chan path env} { set expirevals "1 2 4 7 14 31 5475" set expirelabels "{in 1 day} {in 2 days} {in 4 days} {in 1 week} {in 2 weeks} {in 1 month} {never}" set priorityvals "3 2 1" set prioritylabs "Low Medium High" set destvals "1 2" set destlabs "{Message Board} {Pre-TiVo Central}" puts $chan [html_start "Create TiVo Mail"] puts $chan [html_form_start "POST" "/sendmail"] puts $chan [html_table_start "" "Enter new email message" "COLSPAN=2"] puts $chan [tr "" [td "Priority:"] [td "" [html_form_select "priority" $priorityvals $prioritylabs "2"]]] puts $chan [tr "" [td "Destination:"] [td "" [html_form_select "destination" $destvals $destlabs "1"]]] puts $chan [tr "" [td "Expire:"] [td "" [html_form_select "expire" $expirevals $expirelabels "14"]]] puts $chan [tr "" [td "Subject:"] [td [html_form_text 1 65 "subject" ""]]] puts $chan [tr "" [td "From:"] [td [html_form_text 1 65 "from" ""]]] puts $chan [tr "" [td "Body:"] [td [html_form_text 15 65 "body" ""]]] puts $chan [html_table_end] puts $chan [html_form_input "submit" "submit" "Send Mail"] puts $chan [html_form_end] puts $chan [html_end] } proc action_sendmail {chan path env} { global db eval $env set now [clock seconds] set date [expr $now / 86400] set time [expr $now % 86400] set expire [expr ($now / 86400) + $expire] RetryTransaction { set obj [db $db create MessageItem] dbobj $obj set DateGenerated $date dbobj $obj set TimeGenerated $time dbobj $obj set ExpirationDate $expire dbobj $obj set From $from dbobj $obj set Subject $subject dbobj $obj set Body $body dbobj $obj set FromId $Inc::MSG_SRC_INDIV dbobj $obj set Priority $priority dbobj $obj set Destination $destination } # Supress events for versions >=6 -- rbautch if {$::version < 6} { event send $TmkEvent::EVT_DATA_CHANGED $TmkDataChanged::MESSAGES 0 } puts $chan [html_start "Mail 'Sent'"] puts $chan "Mail 'Sent'" puts $chan [html_end] } proc action_viewmail {chan id env} { global db if {[string index $id 0] == "/"} { set id [string range $id 1 end] } set now [clock seconds] set nowdate [expr $now / 86400] set nowtime [expr $now % 86400] RetryTransaction { set msg [db $db openid $id] set from [htmlEncode [dbobj $msg get From]] set subject [htmlEncode [dbobj $msg get Subject]] set body [htmlEncode [dbobj $msg get Body]] set date [dbobj $msg get DateGenerated] set time [dbobj $msg get TimeGenerated] set seconds [expr $date * 86400 + $time] if {$::lang == "en"} { set daystr [nth_sup [ftime $seconds "%e"]] set datestr [ftime $seconds "%a $daystr %b %Y"] } else { set datestr [ftime $seconds "%1m/%1d"] } set expdate [dbobj $msg get ExpirationDate] set expsecs [expr $expdate * 86400] if {$::lang == "en"} { set daystr [nth_sup [ftime $expsecs "%e"]] set expdatestr [ftime $expsecs "%a $daystr %b %Y"] } else { set expdatestr [ftime $expsecs "%1m/%1d"] } set deleted [dbobj $msg get Deleted] dbobj $msg set DateRead $nowdate dbobj $msg set TimeRead $nowtime } #LJ # Supress events for versions >=6 -- rbautch if {$::version < 6} { event send $TmkEvent::EVT_DATA_CHANGED $TmkDataChanged::MESSAGES 0 } puts $chan [html_start "View TiVo Mail"] puts $chan [html_table_start "" "" ""] puts $chan [tr "" [td "WIDTH='1%'" "Subject:"] [td $subject]] puts $chan [tr "" [td "WIDTH='1%'" "From:"] [td $from]] puts $chan [tr "" [td "WIDTH='1%'" "Date:"] [td $datestr]] puts $chan [tr "" [td "WIDTH='1%'" "Expire:"] [td $expdatestr]] puts $chan [tr "" [td "COLSPAN=2" "$body"]] puts $chan [html_table_end] set actionstr "" append actionstr [tr "" [td [html_link "/deletemail/$id" "Delete Message"]]] append actionstr "\n" if {$deleted != 1} { puts $chan [html_table_start "" "" ""] puts $chan [tr "" [th "Actions"]] puts $chan $actionstr puts -nonewline $chan [html_table_end] puts $chan "

" } puts $chan [html_end] } proc action_deletemail {chan id env} { global db if {[string index $id 0] == "/"} { set id [string range $id 1 end] } puts $chan [html_start "Confirm Mail Delete"] RetryTransaction { set msg [db $db openid $id] set from [htmlEncode [dbobj $msg get From]] set from [string trim $from "{}"] set subject [htmlEncode [dbobj $msg get Subject]] set subject [string trim $subject "{}"] set body [htmlEncode [dbobj $msg get Body]] set date [dbobj $msg get DateGenerated] set time [dbobj $msg get TimeGenerated] } set seconds [expr $date * 86400 + $time] if {$::lang == "en"} { set daystr [nth_sup [ftime $seconds "%e"]] set datestr [ftime $seconds "%a $daystr %b %Y"] } else { set datestr [ftime $seconds "%1m/%1d"] } puts $chan "Delete message from \"$from\" entitled \"$subject\", sent on \"$datestr\"?\n"; puts $chan "

" puts $chan [html_link "/dodeletemail/$id" "Yes"] puts $chan "     " puts $chan "No" puts $chan [html_end] } proc action_dodeletemail {chan id env} { global db if {[string index $id 0] == "/"} { set id [string range $id 1 end] } set now [clock seconds] set date [expr $now / 86400] set time [expr $now % 86400] RetryTransaction { set msg [db $db openid $id] dbobj $msg set Deleted 1 dbobj $msg set DateRead $date dbobj $msg set TimeRead $time } # Supress events for versions >=6 -- rbautch if {$::version < 6} { event send $TmkEvent::EVT_DATA_CHANGED $TmkDataChanged::MESSAGES 0 } puts $chan [html_start "Mail Deleted"] puts $chan "Mail Deleted" puts $chan "

" puts $chan [html_link "/listmail" "Back to View Mail"] puts $chan [html_end] } register_module "mail" "Mail" "Create/view/delete TiVo mail messages"