| Author |  | 
      
        | XAvinashX Newbie
 
  
 
 Joined: 17 April 2007
 Location: United States
 Online Status: Offline
 Posts: 7
 | 
          i havent been able to solve this problem yet. please can someone help me with a sample script to show me how to retrive new messages first then the later ones...
           | Posted: 06 June 2007 at 6:25pm | IP Logged |   |  
           | 
 |  
 plz plz
 
 i tried using this but it still shows the later messages first then the new ones..
 
 <%
 Dim objIMAP4, objMsg, arrNew, I
 Set objIMAP4 = Server.CreateObject("MailBee.IMAP4")
 objIMAP4.LicenseKey = "xxxxxxxxx"
 objIMAP4.ServerName = "xxxxx.com"
 objIMAP4.UserName = "xxxx"
 objIMAP4.Password = "xxxx"
 
 If objIMAP4.Connect Then
 
 objIMAP4.SelectMailbox "xxxx"
 
 arrNew = objIMAP4.Search(True, "new")
 
 For I = LBound(arrNew) To UBound(arrNew)
 
 Unique-ID
 Set objMsg = objIMAP4.RetrieveSingleMessage(arrNew(I), True)
 
 Response.Write _
 "From: " & Server.HTMLEncode(objMsg.FromAddr) & "<br>" & _
 "To: " & Server.HTMLEncode(objMsg.ToAddr) & "<br>" & _
 "Subject: " & Server.HTMLEncode(objMsg.Subject) & "<br>" & _
 "Date: " & objMsg.GetDateFromString(objMsg.Date) & "<br><br>" & _
 objMsg.BodyText
 Next
 
 objIMAP4.Disconnect
 End If
 %>
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          "NEW" is a combination of "UNSEEN" and "RECENT" flags. If you connect to a mailbox in read/write mode where some messages have "RECENT" flag set, download no messages, and then disconnect from the mailbox, "RECENT" flag will be reset for all the messages. Instead of "NEW", please try to use "UNSEEN" flag which is reset once the message gets downloaded.
           | Posted: 07 June 2007 at 12:08am | IP Logged |   |  
           | 
 |  
 Try to replace the following line of your code:
 
 
 
| Code: 
 
    
    | 
      
       | arrNew = objIMAP4.Search(True, "new") |  |  |  
 with:
 
 
 
| Code: 
 
    
    | 
      
       | arrNew = objIMAP4.Search(True, "UNSEEN") |  |  |  
 
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | XAvinashX Newbie
 
  
 
 Joined: 17 April 2007
 Location: United States
 Online Status: Offline
 Posts: 7
 | 
          i tried using "UNSEEN", it dosent show any messages. it only shows me the messages if i use "all"
           | Posted: 07 June 2007 at 8:15pm | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | XAvinashX Newbie
 
  
 
 Joined: 17 April 2007
 Location: United States
 Online Status: Offline
 Posts: 7
 | 
          
           | Posted: 07 June 2007 at 8:16pm | IP Logged |   |  
           | 
 |  
| XAvinashX wrote: 
 
    
    | 
      
       | i tried using "UNSEEN", it dosent show any messages. it only shows me the messages if i use "all" |  |  |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | XAvinashX Newbie
 
  
 
 Joined: 17 April 2007
 Location: United States
 Online Status: Offline
 Posts: 7
 | 
          this is my actual code that i am using.
           | Posted: 07 June 2007 at 8:22pm | IP Logged |   |  
           | 
 |  please if you can modify this and show me how i can list new messages first.
 
 <%
 Dim objIMAP4, objEnvelopes, arrUIDs, objMsg, myDate, myString
 Set objIMAP4 = CreateObject("MailBee.IMAP4")
 objIMAP4.LicenseKey = "xxxx"
 objIMAP4.ServerName = "xxxx"
 objIMAP4.UserName = "xxxx"
 objIMAP4.Password = "xxxx"
 If objIMAP4.Connect Then
 If objIMAP4.SelectMailbox("xxxx") Then
 arrUIDs = objIMAP4.Search(True)
 Set objEnvelopes = objIMAP4.RetrieveEnvelopes(1, objIMAP4.MessageCount, False)
 SetLocale("en-us")
 Set Msg = CreateObject("MailBee.Message")
 %>
 <%
 For I = 1 To objEnvelopes.Count
 myDate = msg.GetDateFromString(objEnvelopes(I).Date, False)
 myString = FormatDateTime(myDate, 2)
 %>
 <%= objEnvelopes(I).FromAddr %>
 <a href="ee.asp?uid=<%= arrUIDs(I) %>"><%= objEnvelopes(I).Subject %></a>
 <%= myString %>
 <%
 Next
 End If
 End If
 %>
 <%
 objIMAP4.Disconnect
 objEnvelopes.Disconnect
 Msg.Disconnect
 %>
 
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Andrew AfterLogic Support
 
  
 
 Joined: 28 April 2006
 Location: United States
 Online Status: Offline
 Posts: 1189
 | 
          We tested the following sample with our IMAP server:
           | Posted: 07 June 2007 at 11:21pm | IP Logged |   |  
           | 
 |  
 
 
| Code: 
 
    
    | 
      
       | <% Dim objIMAP4, objMsg, arrNew, I
 Set objIMAP4 = Server.CreateObject("MailBee.IMAP4")
 objIMAP4.LicenseKey = "xxxxxxxxx"
 objIMAP4.ServerName = "xxxxx.com"
 objIMAP4.UserName = "xxxx"
 objIMAP4.Password = "xxxx"
 
 If objIMAP4.Connect Then
 
 objIMAP4.SelectMailbox "xxxx"
 
 arrNew = objIMAP4.Search(True, "Unseen")
 
 For I = LBound(arrNew) To UBound(arrNew)
 
 Unique-ID
 Set objMsg = objIMAP4.RetrieveSingleMessage(arrNew(I), True)
 
 Response.Write _
 "From: " & Server.HTMLEncode(objMsg.FromAddr) & "<br>" & _
 "To: " & Server.HTMLEncode(objMsg.ToAddr) & "<br>" & _
 "Subject: " & Server.HTMLEncode(objMsg.Subject) & "<br>" & _
 "Date: " & objMsg.GetDateFromString(objMsg.Date) & "<br><br>" & _
 objMsg.BodyText
 Next
 
 objIMAP4.Disconnect
 End If
 %>
 |  |  |  
 And found it works fine, i.e. shows only new messages which have not been downloaded yet.
 
 We executed this sample first time, it displayed no messages because Inbox had no new messages. Then, we sent a couple of messages to the test account and executed the sample again, it displayed these new messages only. Third execution displayed no messages because Inbox had no new messages again.
 
 In the actual code you provided, you're downloading all messages, not new:
 
 
 
| Code: 
 
    
    | 
      
       | Set objEnvelopes = objIMAP4.RetrieveEnvelopes(1, objIMAP4.MessageCount, False) |  |  |  
 The following lines are incorrect and unnecessary:
 
 
 
| Code: 
 
    
    | 
      
       | objEnvelopes.Disconnect Msg.Disconnect
 |  |  |  
 
 Best regards,
 Andrew
 | 
       
        | Back to Top |     | 
       
       
        |  |