PDA

View Full Version : How to sort and paging


bmwmpower
08-22-2006, 11:35 AM
I have code for retrieve emails from server by pop3 components so this is my code
The problem is how I can sort this emails by date and also make paging for this email (10 emails per page)


Code

<%

'On Error resume next

Server.ScriptTimeOut = 90000

function Subst (strValue, strOldValue, strNewValue)
intLoc = InStr(strValue, strOldValue)
While intLoc > 0
if intLoc > 1 then
if intLoc = Len(strValue) then
strValue = Left(strValue, intLoc-1) & strNewValue
else
strValue = Left(strValue, intLoc -1) & strNewValue & Right(strValue, Len(strValue)-(intLoc-Len(strOldValue)+1))
end if
else
strValue = strNewValue & Right(strValue, Len(strValue)-1)
end if
intLoc = InStr(strValue, strOldValue)
Wend
Subst = strValue
end function

function FixUpItems (strItem)
if strItem <> "" then
strItem = Subst(strItem, "<", "&lt;")
strItem = Subst(strItem, ">", "&gt;")
FixUpItems = strItem
else
FixUpItems = "<br>"
end if
end function

function FixDateItems (strItem)
xDate=Split(strItem, " ", -1, 1)
FixDateItems = xDate(1) &" "& xDate(2) & " " & xDate(3) & " "& xDate(4)
'FixDateItems =strItem
end function

rem ******************************************
rem * Shows a form for the user to fill in
rem * host, uid and pwd.
rem ******************************************
sub ShowPopForm (strHostName, strUser, strPassword)
Response.Write "<table border=0>"
Response.Write "<form action=""webmail2.asp"" method=post>"
Response.Write "<tr><td>Enter POP3 Mail Host:<td><input type=text size=45 name=host value=""" & strHostName & """>"
Response.Write "<tr><td>Enter POP3 User Name:<td><input type=text size=45 name=uid value=""" & strUser & """>"
Response.Write "<tr><td>Enter POP3 Password:<td><input type=password size=45 name=pwd value=""" & strPassword & """>"
Response.Write "<input type=""Submit"">"
Response.Write "</form>"
Response.Write "</table>"

end sub

rem ******************************************
rem * Get the list of all message headers and
rem * display the info to the client
rem ******************************************
sub ShowMessageList (strHost, strUid, strPwd)

Set Mailer = Server.CreateObject("POP3svg.Mailer")
Mailer.RemoteHost = strHost
Mailer.UserName = strUid
Mailer.Password = strPwd
Response.Write "<h1>" & Mailer.UserName & "</h2>"
rem ******************************************
rem * GetPopHeaders will automatically open
rem * the connection, grab the POP header
rem * information and return a variant array
rem * consisting of strings:
rem * Msg No, Subject, Date, From, Sender, To,
rem * Reply-to, and Size
rem * the more mail you have the longer it
rem * takes to pull this information
rem ******************************************
if Mailer.GetPopHeaders then
' Response.Write "<br>Found " & Mailer.MessageCount & " messages on server.<p>" & VbCrLf
Response.Write "<table border=1 width=""90%"">" & VbCrLf
Response.Write "<tr>" & VbCrLf
Response.Write "<td><b>" & "Msg " & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "Subject" & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "Date" & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "From" & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "Size" & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "Status" & "<b></td>" & VbCrLf
Response.Write "<td><b>" & "Delete" & "<b></td>" & VbCrLf
Response.Write "</tr>" & VbCrLf

varArray = Mailer.MessageInfo
if VarType(varArray) <> vbNull And IsEmpty(varArray) <> True then
ArrayLimit = UBound(varArray)
For I = 0 to ArrayLimit
strStatus = varArray(I)(8)
if (strStatus = "R") then
strStatus = "<b>read</b>"
strRowColor = "#ffffff"
elseif (strStatus = "U") then
strStatus = "<b>Unread</b>"
strRowColor = "#efefef"
end if
Response.Write "<tr bgColor="& strRowColor &" >"
strMsgNo = Trim(varArray(I)(0))
rem the random number is to prevent the browser from thinking that the
rem page is cached when you try and delete the same message number
Randomize
intRndNo = Int(500 * Rnd)
Response.Write "<td align=Center>" & strMsgNo & "</td>"
strSubject = varArray(I)(1)
if strSubject = "" then strSubject = "(No Subject)"
Response.Write "<td align=left>" & "<a href=readMessage.asp?msgno=" & strMsgNo & "&rndno=" & intRndNo & ">" & FixUpItems (strSubject) & "</a></td>" & VbCrLf
Response.Write "<td align=left>" & FixDateItems(varArray(I)(2)) & "</td>" & VbCrLf
Response.Write "<td align=left>" & FixUpItems (varArray(I)(3)) & "</td>" & VbCrLf
Response.Write "<td align=left>" & varArray(I)(7) & "</td>"
Response.Write "<td align=left>" & strStatus & "</td>"
Response.Write "<td align=left>" & "<a href=webmail2.asp?deletemsg=" & strMsgNo & "&rndno=" & intRndNo & ">Delete</a></td>"
Response.Write "</tr>" & Chr(10) & Chr(13)
Next
else
Response.Write "<tr><td colspan=10 align=center><b>No messages on server</b></tr>"
end if
Response.Write "</table><center><p><br>"
' Response.Write "<a href=""webmail2.asp?rndno=" & intRndNo & """>Refresh</a></center>"
Response.Write "<a href=""webmail2.asp"">Refresh</a></center>"
else
Response.Write "<p>Connection Failure. Check your mailhost, username and password."
end if
Response.Write "</blockquote>"
end sub

rem ******************************************
rem * Shows the text for one specific message
rem ******************************************
sub ShowMessage(strHost, strUid, strPwd, strMsgNo)
Response.Write "<h2>Message #" & strMsgNo & " follows:</h2><pre>"

Set Mailer = Server.CreateObject("POP3svg.Mailer")


rem ******************************************
rem * Make sure that you've got the following
rem * directory set up. Also, note that
rem * if you retrieve message number 1 it
rem * will be saved as c:\temp\1.txt
rem * ** DEMO WARNING **
rem * For MULTIUSER use you'll need to point
rem * the base directories to a user specific
rem * directory to keep users from walking
rem * on top of each other.
rem ******************************************

strMailBaseDir = server.mappath("temp")

Mailer.MailDirectory = strMailBaseDir

Mailer.RemoteHost = strHost
Mailer.UserName = strUid
Mailer.Password = strPwd
Mailer.OpenPop3
' Mailer.Pop3Log = server.mappath("webmail/pop3log.txt")

rem We could do multiple retrieves here but this demo only shows the
rem selected message.

Mailer.Retrieve strMsgNo

rem Mailer.RetrieveToFile strMsgNo, "TestMsg.txt"
Mailer.ClosePop3

Response.Write "<table border=1 width=""90%"">" & VbCrLf

' Response.Write "<tr><td width=""20%"" align=right><b>" & "Msg ID:" & "<b></td><td>" & FixUpItems(Mailer.MessageID) & "</td></tr>" & VbCrLf

Response.Write "<tr><td width=""20%"" align=right><b>" & "Date:" & "<b></td><td>" & Mailer.Date & "</td></tr>" & VbCrLf
Response.Write "<tr><td width=""20%"" align=right><b>" & "Subject:" & "<b></td><td>" & FixUpItems(Mailer.Subject) & "</td></tr>" & VbCrLf
Response.Write "<tr><td width=""20%"" align=right><b>" & "From:" & "<b></td><td>" & Mailer.FromName & " &lt;" & Mailer.FromAddress & "&gt;</td></tr>" & VbCrLf

rem *******************************************
rem You can also access any field in the header
rem using Mailer.GetHeaderField(FieldName)
rem *******************************************
strTemp = Mailer.GetHeaderField("Reply-To")
if strTemp <> "" then
Response.Write "<tr><td width=""20%"" align=right><b>" & "Reply-To:" & "<b></td><td>" & FixUpItems(strTemp) & "</td></tr>" & VbCrLf
end if

strTemp = Mailer.Recipients
if strTemp <> "" then
Response.Write "<tr><td width=""20%"" align=right><b>" & "To:" & "<b></td><td>" & FixUpItems(strTemp) & "</td></tr>" & VbCrLf
end if

strTemp = Mailer.CC
if strTemp <> "" then
Response.Write "<tr><td width=""20%"" align=right><b>" & "CC:" & "<b></td><td>" & FixUpItems(strTemp) & "</td></tr>" & VbCrLf
end if

Response.Write "<tr><td width=""20%"" align=right><b>" & "Attachments:" & "<b></td><td>" & Mailer.AttachmentCount & "</td></tr>" & VbCrLf
Response.Write "</table></br>" & VbCrLf
Response.Write Mailer.BodyText & VbCrLf

if Mailer.AttachmentCount > 0 then
Response.Write "<hr></pre>" & VbCrLf

'Response.Write "Attachments will be save to " & Mailer.MailDirectory
' Response.Write "<p>In a normal Web app you'll probably want to save these files "
' Response.Write "off to a directory accessible to the Web server, create the following "
' Response.Write "list of files as links, and allow the user to download specific file "
' Response.Write "attachments. You'll have to invent a scheme where the files are erased "
' Response.Write "(on session end would be a logical place)<p>"
Response.Write "<table border=1 >" & VbCrLf
Response.Write "<tr><td>Attachment</td>"
'Response.Write " <td>ContentType</td>"
Response.Write "<td>FileName</td>"
Response.Write " <td>FileSize</td></tr>" & VbCrLf
For intCount = 1 to Mailer.AttachmentCount
if Mailer.GetAttachmentInfo (intCount) then
Response.Write "<tr><td>" & intCount & "</td>"
' Response.Write "<td>" & Mailer.AttContentType & "</td>"
Response.Write "<td><a href=temp/"& Mailer.AttFileName & ">" & Mailer.AttFileName & "</a></td><td>" & Mailer.AttFileSize & "</td></tr>" & VbCrLf
Mailer.SaveAttachment (intCount)
end if
Next
Response.Write "</table>" & VbCrLf
end if

rem *******
rem NOTE that the physical file is our message # - 1 & ".txt"
rem *******
rem strFileName = strMailBaseDir & strMsgNo-1 & ".txt"
rem Set FileObject = CreateObject("Scripting.FileSystemObject")
rem Set MsgFile = FileObject.OpenTextFile(strFileName, 1, False, True)
rem Do While MsgFile.AtEndOfStream <> True
rem strMsgLine = MsgFile.ReadLine
rem Response.Write strMsgLine & "<br>"
rem Loop
rem MsgFile.Close
rem Response.Write "</pre>"
rem Response.Write "<h2>" & strFileName & "</h2>"

rem Erase the temporary file
rem Mailer.EraseFile(strFileName)
end sub

rem ******************************************
rem * DELETE the message PERMANENTLY from the
rem * server
rem ******************************************
sub DeleteMessage (strHost, strUid, strPwd, strMsgNo)
Response.Write "<b>Deleting Message #" & strMsgNo & " From Server</b><p>"
Set Mailer = Server.CreateObject("POP3svg.Mailer")

Mailer.RemoteHost = strHost
Mailer.UserName = strUid
Mailer.Password = strPwd
Mailer.OpenPop3

rem We could do multiple deletes here but this demo only does 1. You must
rem close the server at this point or our message numbers in
rem ShowMessageList won't be correct.

Mailer.Delete strMsgNo
Mailer.ClosePop3

ShowMessageList strHost, strUid, strPwd
end sub

sub SavePOPVars
Session("host") = Request.Form("host")
Session("uid") = Request.Form("uid")
Session("pwd") = Request.Form("pwd")
end sub


rem ******************************************
rem * Main code begins here
rem ******************************************

if Request.ServerVariables("REQUEST_METHOD") = "POST" then
SavePOPVars
end if

strHost = Session("host")
strUid = Session("uid")
strPwd = Session("pwd")
strMsgNo = Request.QueryString("msgno")
strDeleteNo = Request.QueryString("deletemsg")

rem We can log pop3 responses to a file by assigning Object.Pop3Log
rem This is for DEBUG use only
rem eg. Mailer.Pop3Log = server.mappath("webmail/pop3log.txt")
rem DO NOT use in a multi-user situation with the SAME file name

if (strUid = "") or (strPwd = "") or (strHost = "") then
ShowPopForm strHost, strUid, strPwd
else
if (strMsgNo <> "") then
ShowMessage strHost, strUid, strPwd, strMsgNo
else
if (strDeleteNo <> "") then
DeleteMessage strHost, strUid, strPwd, strDeleteNo
else
ShowMessageList strHost, strUid, strPwd
end if
end if
end if

%>

any one can help me
how i can sort and paging this messages !!!! ????