Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET IMAP

 AfterLogic Forum : MailBee.NET IMAP
Subject Topic: How to get new messages? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Mhd
Newbie
Newbie


Joined: 18 February 2008
Location: United Kingdom
Online Status: Offline
Posts: 38
Posted: 01 March 2008 at 7:11am | IP Logged Quote Mhd

Hi, do someone have a sample script to download new messages?

Regards.
Back to Top View Mhd's Profile Search for other posts by Mhd
 
Mhd
Newbie
Newbie


Joined: 18 February 2008
Location: United Kingdom
Online Status: Offline
Posts: 38
Posted: 01 March 2008 at 1:57pm | IP Logged Quote Mhd

Forget it, I did it.
Back to Top View Mhd's Profile Search for other posts by Mhd
 
Mhd
Newbie
Newbie


Joined: 18 February 2008
Location: United Kingdom
Online Status: Offline
Posts: 38
Posted: 03 March 2008 at 8:52am | IP Logged Quote Mhd

Hi again, I think I'm doing something wrong in retreiving the new messages, Here is my code:
imp.SelectFolder("Inbox")

Dim objMsg As MailBee.Mime.MailMessage, arrNew, I, J

arrNew = imp.Search(True, "unseen", "")
If imp.MessageCount > 0 Then
                Dim objAtt As MailBee.Mime.AttachmentCollection
For I = 1 To (arrNew.count - 1)

objMsg = imp.DownloadEntireMessage(arrNew(I), False)
                     'objMsg.
                     ' Make all header values be automatically HTML-encoded. Alternatively,
                     ' we could use Server.HtmlEncode when writing values into HTML.
                     objMsg.Parser.HeadersAsHtml = True

                     ' Tell MailBee to generate HTML body from plain-text
                     ' if the HTML body was missing in the e-mail.
                     objMsg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml
                     objMsg.Parser.PlainToHtmlOptions = PlainToHtmlConvertOptions.UriToLink

                     MsgBox("Subject: " & objMsg.Subject & _
                       objMsg.BodyPlainText)

                     If objMsg.HasAttachments Then
                          objAtt = objMsg.Attachments
                     End If
                    
                Next

-----------------
It give me an error in the index of the message in the DownloadEntireMessage, what I'm doing wrong?!

Regards.
Back to Top View Mhd's Profile Search for other posts by Mhd
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 04 March 2008 at 12:59am | IP Logged Quote Andrew

You are getting this error because each iteration decreases number of unread messages in the mailbox and after reading several messages, the index counter will be out of unread messages range.

Try to change the following statement:

Code:
For I = 1 To (arrNew.count - 1)


to:

Code:
For I = (arrNew.count - 1) To 1 Step -1


Also, we recommend you to use message UIDs (unique identifiers) instead of indexes. Working with UIDs, you'd never face such issue because they never shift or suddenly change.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
Mhd
Newbie
Newbie


Joined: 18 February 2008
Location: United Kingdom
Online Status: Offline
Posts: 38
Posted: 04 March 2008 at 7:14am | IP Logged Quote Mhd

I still get the same problem, how can I use message UIDs instead of indexes?
Back to Top View Mhd's Profile Search for other posts by Mhd
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 05 March 2008 at 1:38am | IP Logged Quote Andrew

In the sample you provided, Imap.Search already returns a collection of UIDs (the first parameter is True):

Code:
arrNew = imp.Search(True, "unseen", "")


but Imap.DownloadEntireMessage expects a message index (the 2nd parameter is False):

Code:
objMsg = imp.DownloadEntireMessage(arrNew(I), False)


That's why you get the issue. Although IMAP UIDs are numeric values, they cannot be used as indexes. Change the second parameter of DownloadEntireMessage to True.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
Mhd
Newbie
Newbie


Joined: 18 February 2008
Location: United Kingdom
Online Status: Offline
Posts: 38
Posted: 05 March 2008 at 6:50am | IP Logged Quote Mhd

thanks
Back to Top View Mhd's Profile Search for other posts by Mhd
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide