<HTML>
<HEAD><TITLE>Mail Message</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>Mail Message</H2>

<!--- A message number must be passed in the URL --->
<CFPARAM NAME="URL.MsgNum" TYPE="numeric">
<CFPARAM NAME="URL.Delete" TYPE="boolean" DEFAULT="No">

<!--- If we don't have a username/password --->
<!--- send user to main CheckMail.cfm page --->
<CFIF IsDefined("SESSION.Mail.GetMessages") EQ "No">
  <CFLOCATION URL="CheckMail.cfm">
</CFIF>

<!--- If the user is trying to delete the message --->
<CFIF URL.Delete>
  <!--- Contact POP Server and delete the message --->
  <CFPOP
    ACTION="Delete"
    MESSAGENUMBER="#URL.MsgNum#"
    SERVER="#SESSION.Mail.POPServer#"
    USERNAME="#SESSION.Mail.Username#"
    PASSWORD="#SESSION.Mail.Password#">

  <!--- Send user back to main "Check Mail" page --->    
  <CFLOCATION URL="CheckMail.cfm?Refresh=Yes">


<!--- If not deleting, retrieve and show the message --->
<CFELSE>

  <!--- Contact POP Server and retrieve the message --->
  <CFPOP
    ACTION="GetAll"
    NAME="GetMsg"
    MESSAGENUMBER="#URL.MsgNum#"
    SERVER="#SESSION.Mail.POPServer#"
    USERNAME="#SESSION.Mail.Username#"
    PASSWORD="#SESSION.Mail.Password#">
    
  <CFSET MsgDate = ParseDateTime(GetMsg.Date, "POP")>  
  
  <!--- If message was not retrieved from POP server --->  
  <CFIF GetMsg.RecordCount NEQ 1>
    <CFTHROW 
      MESSAGE="Message could not be retrieved."
      DETAIL="Perhaps the message has already been deleted.">
  </CFIF>  
  
  <!--- We will provide a link to Delete message --->
  <CFSET DeleteURL = "#CGI.SCRIPT_NAME#?MsgNum=#MsgNum#&Delete=Yes">
    
  <!--- Display message in a simple table format --->  
  <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3">
    <CFOUTPUT>
      <TR>
        <TH BGCOLOR="Wheat" ALIGN="left" NOWRAP>
          Message #URL.MsgNum# of #SESSION.Mail.GetMessages.RecordCount#
        </TH>
        <TD ALIGN="right" BGCOLOR="beige">
          <!--- Provide "Back" button, if appropriate --->    
          <CFIF URL.MsgNum GT 1>
            <A HREF="CheckMailMsg.cfm?MsgNum=#Val(URL.MsgNum - 1)#">
              <IMG SRC="../images/BrowseBack.gif" 
                WIDTH="40" HEIGHT="16" ALT="Back" BORDER="0"></A>
          </CFIF>
          <!--- Provide "Next" button, if appropriate --->
          <CFIF URL.MsgNum LT SESSION.Mail.GetMessages.RecordCount>
            <A HREF="CheckMailMsg.cfm?MsgNum=#Val(URL.MsgNum + 1)#">
              <IMG SRC="../images/BrowseNext.gif" 
                WIDTH="40" HEIGHT="16" ALT="Next" BORDER="0"></A>
          </CFIF>
        </TD>
      </TR>
      <TR>
        <TH ALIGN="right">From:</TH>
        <TD>#HTMLEditFormat(GetMsg.From)#</TD>
      </TR>
      <CFIF GetMsg.CC NEQ "">
      <TR>
        <TH ALIGN="right">CC:</TH>
        <TD>#HTMLEditFormat(GetMsg.CC)#</TD>
      </TR>
      </CFIF>
      <TR>
        <TH ALIGN="right">Date:</TH>
        <TD>#DateFormat(MsgDate)# #TimeFormat(MsgDate)#</TD>
      </TR>
      <TR>
        <TH ALIGN="right">Subject:</TH>
        <TD>#GetMsg.Subject#</TD>
      </TR>
      <TR>
        <TD BGCOLOR="Beige" COLSPAN="2">
          <STRONG>Message:</STRONG><BR>
          
          <CFIF GetMsg.Header contains "Content-Type: text/html">
            #GetMsg.Body# 
          <CFELSE>
            #HTMLCodeFormat(GetMsg.Body)#
          </CFIF>
        </TD>
      </TR>
    </CFOUTPUT>
  </TABLE>  

  <CFOUTPUT>  
    <!--- Provide link back to list of messages --->
    <STRONG><A HREF="CheckMail.cfm">Back To Message List</A></STRONG><BR>
    <!--- Provide link to Delete message --->
    <A HREF="#DeleteURL#">Delete Message</A><BR>
    <!--- "Log Out" link to discard SESSION.Mail info --->
    <A HREF="CheckMail.cfm?Logout=Yes">Log Out</A><BR>
  </CFOUTPUT>
</CFIF>

</BODY>
</HTML>

