<!--- 
  Filename: CheckMail.cfm
  Author:   Nate Weiss (NMW)
  Purpose:  Creates a very simple POP client
--->

<HTML>
<HEAD><TITLE>Check Your Mail</TITLE></HEAD>
<BODY>

<!--- Simple CSS-based formatting styles --->
<STYLE>
  BODY {font-family:sans-serif;font-size:12px}
  TH   {font-size:12px;background:navy;color:white}
  TD   {font-size:12px;background:lightgrey;color:navy}
</STYLE>
<H2>Check Your Mail</H2>

<!--- If user is logging out, --->  
<!--- or if user is submitting a different username/password --->
<CFIF IsDefined("URL.Logout") OR IsDefined("FORM.POPServer")>
  <CFSET StructDelete(SESSION, "Mail")>
</CFIF>

<!--- If we don't have a username/password --->
<CFIF NOT IsDefined("SESSION.Mail")>
  <!--- Show "mail server login" form --->
  <CFINCLUDE TEMPLATE="CheckMailLogin.cfm">
</CFIF>


<!--- If we need to contact server for list of messages --->
<!--- (if just logged in, or if clicked "Refresh" link) --->
<CFIF NOT IsDefined("SESSION.Mail.GetMessages") OR IsDefined("URL.Refresh")>
  <!--- Flush page output buffer --->
  <CFFLUSH>

  <!--- Contact POP Server and retieve messages --->
  <CFPOP
    ACTION="GetHeaderOnly"
    NAME="SESSION.Mail.GetMessages"
    SERVER="#SESSION.Mail.POPServer#"
    USERNAME="#SESSION.Mail.Username#"
    PASSWORD="#SESSION.Mail.Password#"
    MAXROWS="50">
</CFIF>  

  
<!--- If no messages were retrieved... --->
<CFIF SESSION.Mail.GetMessages.RecordCount EQ 0>
  <P>You have no mail messages at this time.<BR>
  
<!--- If messages were retrieved... --->  
<CFELSE>
  <!--- Display Messages in HTML Table Format --->  
  <TABLE BORDER="0" CELLSPACING="2" CELLSPACING="2" COLS="3" WIDTH="550">
    <!--- Column Headings for Table --->
    <TR>
      <TH WIDTH="100">Date Sent</TH>
      <TH WIDTH="200">From</TH>
      <TH WIDTH="200">Subject</TH>
    </TR>
    <!--- Display info about each message in a table row --->
    <CFOUTPUT QUERY="SESSION.Mail.GetMessages">
      <!--- Parse Date from the "date" mail header --->
      <CFSET MsgDate = ParseDateTime(Date, "POP")>
      <!--- Let user click on Subject to read full message --->
      <CFSET LinkURL = "CheckMailMsg.cfm?MsgNum=#MessageNumber#">

      <TR VALIGN="baseline">
        <!--- Show parsed Date and Time for message--->
        <TD>
          <STRONG>#DateFormat(MsgDate)#</STRONG><BR>
          #TimeFormat(MsgDate)# #ReplyTo#
        </TD>
        <!--- Show "From" address, escaping brackets --->
        <TD>#HTMLEditFormat(From)#</TD>
        <TD><STRONG><A HREF="#LinkURL#">#Subject#</A></STRONG></TD>
      </TR>  
    </CFOUTPUT>
  </TABLE>
  
  <!--- "Refresh" link to get new list of messages  --->
  <STRONG><A HREF="CheckMail.cfm?Refresh=Yes">Refresh Message List</A></STRONG><BR>
  <!--- "Log Out" link to discard SESSION.Mail info --->
  <A HREF="CheckMail.cfm?Logout=Yes">Log Out</A><BR>
</CFIF>


</BODY>
</HTML>