login about faq

Hello all using VB6, ActiveX, how to select last 50 (newest) message headers, if I have 4000 messages? THanks.

asked Oct 23 '13 at 04:23

Trebam's gravatar image

Trebam
16337


If the Chilkat IMAP reference documentation is perused, it will be discovered that there are two ways of fetching email from an IMAP server -- by UID or by sequence number.

The UID itself does not imply any ordering, but it uniquely identifies an email. Sets of UID's can be obtained via Search on various criteria -- but this provides no way of getting the most recent N emails. (It might provide a way of getting all emails that are less than one week old, but not a pre-determined result set size.)

A sequence number, however, implies an ordering to the emails in a mailbox. The first email to be inserted in the mailbox is at sequence number 1, the 2nd at 2, etc. If the 1st email is deleted, then what was previously the email at sequence number 2 now becomes the email at sequence number 1.

After selecting a mailbox, the Chilkat.Imap.NumMessages property contains the number of messages in the mailbox. (This is stated in the reference documentation.) If there are 100 emails in the mailbox, and you wish to download the 50 newest, and the oldest email is at sequence number 1, then you would download emails from sequence number 51 to 100. The reference documentation can be quickly reviewed to see what methods are available for downloading by sequence number. You'll find several options -- you may download them individually or altogether in a set by specifying the starting sequence number and a count.

link

answered Oct 23 '13 at 09:53

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Yes. You should pass a starting sequence number and a count to FetchSequenceHeaders. If you want to fetch the last 50 emails, assuming the Inbox has more than 50 emails, you would do this:

cnt = imap.NumMessages
bundle = imap.FetchSequence cnt-49, 50
Remember: The 2nd argument is the count of the number of emails you wish to fetch. Also remember that the 1st email is at sequence number 1. For example, if there are exactly 50 emails in Inbox, then you can see that subtracting 49 is correct because 50 - 49 = 1. The starting sequence number would be 1 and you'd be fetching 50 emails.

link

answered Oct 23 '13 at 16:37

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Thank you for your answer.

when I try this:

cnt = imap.NumMessages

bundle = imap.FetchSequenceHeaders cnt-50, cnt

bundle is empty

What is wrong here?

Thanks

link

answered Oct 23 '13 at 10:59

Trebam's gravatar image

Trebam
16337

edited Oct 23 '13 at 10:59

The LastErrorText property is ALWAYS the first place to look to find out why any method call failed, or did not behave as expected (even if the method call returns a success status).

(Oct 23 '13 at 11:01) chilkat ♦♦

OK sorry, I'm new user :( here is LastErrorText, after I call:

cnt = imap.NumMessages
bundle = imap.FetchSequenceHeaders cnt-50, cnt

ChilkatLog: FetchSequenceHeaders: DllDate: Aug 15 2013 ChilkatVersion: 9.4.1.42 UnlockPrefix: xxxxxxx Username: xxxxxx Architecture: Little Endian; 32-bit Language: ActiveX VerboseLogging: 0 Failed to find OK line in response. Failed to fetch sequence range of summaries --FetchSequenceHeaders --ChilkatLog

cnt have value 4100

Thanks!

link

answered Oct 23 '13 at 12:33

Trebam's gravatar image

Trebam
16337

edited Oct 23 '13 at 12:49

Enter code and lastErrorText inside html <pre> / </pre> tags to make them readable.

(Oct 23 '13 at 12:46) chilkat ♦♦

OK I entered "pre" tags. Looks like something is wrong with OK line?

(Oct 23 '13 at 13:21) Trebam

This code works OK:

cnt = imap.NumMessages
bundle = imap.FetchSequence cnt-50, cnt
but it is too slow ... 25 seconds to display 50 messages.

same code but using FetchSequenceHeaders, produces this error (used verboseLogging):

ChilkatLog:
  FetchSequenceHeaders:
    DllDate: Aug 15 2013
    ChilkatVersion: 9.4.1.42
    UnlockPrefix: xxx
    Username: xxx
    Architecture: Little Endian; 32-bit
    Language: ActiveX
    VerboseLogging: 1
    ImapCmdSent: aaad FETCH 4388:8825 (UID FLAGS RFC822.SIZE BODYSTRUCTURE BODY.PEEK[HEADER])
    getCompleteResponse2:
      rcvUntilMatchStringQP: 

  dbReceived0: 
  startIdx: 0
  dbReceived: aaad BAD Error in IMAP command FETCH: Invalid messageset

  Found match string.
  ImapCmdResp: aaad BAD Error in IMAP command FETCH: Invalid messageset
--getCompleteResponse2
msg: aaad BAD Error in IMAP command FETCH: Invalid messageset

Failed to find OK line in response.
Failed to fetch sequence range of summaries

--FetchSequenceHeaders --ChilkatLog

Any idea why?

Thanks.

link

answered Oct 23 '13 at 15:07

Trebam's gravatar image

Trebam
16337

edited Oct 23 '13 at 15:13

Of course, it working perfect now.

Thanks a lot.

link

answered Oct 23 '13 at 17:23

Trebam's gravatar image

Trebam
16337

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×175
×5

Asked: Oct 23 '13 at 04:23

Seen: 3,043 times

Last updated: Oct 23 '13 at 17:23

powered by OSQA