login about faq

Is there a Function i can use in IMAP to get all mails where the UID is greater then a given UID? Or how can i write a logic that i don't have to download all the Mails(Header) from Server and compare all the UID's localy? And how can i do the same Functionality in POP3??

I wanna use this in Android

THX Howard

asked Dec 14 '15 at 08:05

Howard's gravatar image

Howard
156


Thanks Howard,

I see now. In this case, you should consider the possibility that the IMAP server is at fault. You can see the exact command and response -- the IMAP server should not have responded with a UID smaller than 79.

I don't understand why people consider servers infallible. Maybe this particular server has a bug. If not, then the question is "How do I correctly construct the IMAP SEARCH criteria?" Chilkat simply passes the SEARCH criteria string (provided by the application) directly into the SEARCH command. If your app passes "poodle doodle 123" to the Search method, then you would see in the log:

ImapCmdSent: aad UID SEARCH poodle doodle 123
So the question is: Is the criteria "UID 79:*" the correct criteria string for requesting all UIDs at 79 and above? To answer that, you have to go to RFC 3501. The grammar for the SEARCH command is this horrible mess:
search          = "SEARCH" [SP "CHARSET" SP astring] 1*(SP search-key)
                    ; CHARSET argument to MUST be registered with IANA

search-key = "ALL" / "ANSWERED" / "BCC" SP astring / "BEFORE" SP date / "BODY" SP astring / "CC" SP astring / "DELETED" / "FLAGGED" / "FROM" SP astring / "KEYWORD" SP flag-keyword / "NEW" / "OLD" / "ON" SP date / "RECENT" / "SEEN" / "SINCE" SP date / "SUBJECT" SP astring / "TEXT" SP astring / "TO" SP astring / "UNANSWERED" / "UNDELETED" / "UNFLAGGED" / "UNKEYWORD" SP flag-keyword / "UNSEEN" / ; Above this line were in [IMAP2] "DRAFT" / "HEADER" SP header-fld-name SP astring / "LARGER" SP number / "NOT" SP search-key / "OR" SP search-key SP search-key / "SENTBEFORE" SP date / "SENTON" SP date / "SENTSINCE" SP date / "SMALLER" SP number / "UID" SP sequence-set / "UNDRAFT" / sequence-set / "(" search-key (SP search-key) ")"

We want the "UID" criteria, so we need to know exact what the heck a "sequence-set" is...
sequence-set    = (seq-number / seq-range) ("," sequence-set)
                    ; set of seq-number values, regardless of order.
                    ; Servers MAY coalesce overlaps and/or execute the
                    ; sequence in any order.
                    ; Example: a message sequence number set of
                    ; 2,4:7,9,12: for a mailbox with 15 messages is
                    ; equivalent to 2,4,5,6,7,9,12,13,14,15
                    ; Example: a message sequence number set of :4,5:7
                    ; for a mailbox with 10 messages is equivalent to
                    ; 10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
                    ; overlap coalesced to be 4,5,6,7,8,9,10.
A seq-range is this:
seq-range       = seq-number ":" seq-number
                    ; two seq-number values and all values between
                    ; these two regardless of order.
                    ; Example: 2:4 and 4:2 are equivalent and indicate
                    ; values 2, 3, and 4.
                    ; Example: a unique identifier sequence range of
                    ; 3291:* includes the UID of the last message in
                    ; the mailbox, even if that value is less than 3291.
And according to this your SEARCH criteria string is correct and valid, and therefore the IMAP server must be at fault.

link

answered Jan 20 at 09:58

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Jan 20 at 09:58

That's a really good point to consider when working with servers - they may be doing things wrong. Just as you should validate all data passed from a client when you are developing server software, it should be considered best practice to validate all data returned from a server when you are programming client software!

(Jan 20 at 10:04) jpbro ♦

okay i see. so if you said my SEARCH criteria string is right ... and you said Chilkat is right... what i absolutely believe!! Then only the Server can be wrong.. okay i get it. BUT (always :-D ) i check this with a local Exchange Server in my Company... okay this could have a wrong setup... but now i also check my Google Account... and surprise surprise the same issue.. :-)

so that means: may the IMAP Protocol is doing things wrong :-D

(Jan 20 at 10:15) Howard

Thanks Howard,

Chilkat passes the raw search criteria to the server, and gets a response -- so the only way Chilkat can be defective is if it's not sending the command that was asked to be sent. So Chilkat is OK in this respect.

If the server is behaving correctly, then it can only be that our understanding of how to form the correct search criteria is incorrect. After re-reading the RFC specification, I think I see the issue and our misunderstanding:

; Example: a unique identifier sequence range of
; 3291:* includes the UID of the last message in
; the mailbox, even if that value is less than 3291.
Notice the clause "even if that value is less than 3291". So the search criteria "UID 79:*" returns all UIDs 79 and above INCLUDING the very last UID regardless of its value. (Ughh!) So it must mean that 78 was the last email in the mailbox. A program would need to understand that the message set returned might contain a single UID that is less than 79.

link

answered Jan 20 at 10:36

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Jan 20 at 10:36

OOOKAY... i SEEE... :-) ... i discussed that with my coworker... he is working on a iOS App und he uses mailcore to communicate with the IMAP Servers... (but i like chilkat!! ) ... in Mailcore this misunderstanding with the old mail is hidden because mailcore is not giving back this last old mail... just an Feature Idea for Chilkat :-)

(Jan 20 at 11:07) Howard

okay... i found an old chilkat postfor IMAP here

to get the newest Mails i have to save the last fetched MailID and then you can call something like this:

imap.Search("UID " + (yourlastID + 1) + ":*", 1)

but i have NO Idea how i can do this with POP3

link

answered Dec 21 '15 at 12:17

Howard's gravatar image

Howard
156

OKAY... i now think i need Professional Help from Chilkat Team :-)

after working a while with the Solution from above now i don't get again the right number of new mails :-( If i have NO new Mails on a Mailbox i get back 1 "new" Mail but this is just the Mail with the highest UUID... not really a NEW Mail. Ma Last UUID was 78 and i get back this Mail:

ChilkatLog:
  Search(2ms):
    DllDate: Oct 27 2015
    ChilkatVersion: 9.5.0.53
    UnlockPrefix: *********
    Architecture: Little Endian; 32-bit
    Language: Android Java
    VerboseLogging: 1
    Component successfully unlocked using purchased unlock code.
    criteria: UID 79:*
    criteriaUtf8QP: UID 79:*
    connectedTo: *********
    selectedMailbox: INBOX
    bUid: 1
    Command: aaad UID SEARCH UID 79:*
    ImapCmdSent: aaad UID SEARCH UID 79:*
    getCompleteResponse(2ms):
      ImapCmdResp: * SEARCH 78
      ImapCmdResp: aaad OK SEARCH completed.
    --getCompleteResponse
    numMessages: 1
    Success.
  --Search
--ChilkatLog

BUT ... if the MailBox has really a NEW Mail i got THIS back (a Mail with UUID 85)

ChilkatLog:
  Search(2ms):
    DllDate: Oct 27 2015
    ChilkatVersion: 9.5.0.53
    UnlockPrefix: ********
    Architecture: Little Endian; 32-bit
    Language: Android Java
    VerboseLogging: 1
    Component successfully unlocked using purchased unlock code.
    criteria: UID 79:*
    criteriaUtf8QP: UID 79:*
    connectedTo: ********
    selectedMailbox: INBOX
    bUid: 1
    Command: aaad UID SEARCH UID 79:*
    ImapCmdSent: aaad UID SEARCH UID 79:*
    getCompleteResponse(2ms):
      ImapCmdResp: * SEARCH 85
      ImapCmdResp: aaad OK SEARCH completed.
    --getCompleteResponse
    numMessages: 1
    Success.
  --Search
--ChilkatLog

what i have to do to get only NEW Mails and get nothing if i have no new Mails in the Mailbox?? Or is this not possible??

THX

link

answered Jan 18 at 05:43

Howard's gravatar image

Howard
156

Couple of things first - Is this for POP3 or IMAP that you are trying to get unread messages? If POP3, then according to this document: http://www.example-code.com/vb6/pop3_unread.asp POP3 doesn't support getting unread messages:

"The POP3 protocol does not provide the ability to ask the server which emails are "unread". Furthermore, a pure POP3 server does not even keep this information."

However, you may be able to "fudge" it using the provided example code at that link.

For IMAP - having you tried using the Search metghod with the NEW criteria as described in the reference documentation for the Search method?

Lastly, remember that this is a user-user help forum, not an official support channel, so if you need "professional" support you should use the official support email address if you have an active support license (or if not, you should consider purchasing one). More information on Chilkat support is available here: https://www.chilkatsoft.com/support.asp

link

answered Jan 18 at 10:27

jpbro's gravatar image

jpbro ♦
1.1k2618

okay first of all thanks for your answer.

second: sorry for making things not so clear that i'm talking in my last Post about IMAP. You could see this on the LogFiles i posted above but i should be more clear.!!

When we talking about IMAP the things are not that easy like you describe. In my case i never get a Mail with the "Recent flag" so i can't use the Search Method with the "NEW criteria". But what i do NOW is just to ignore the Fetched Mail if the UUID is the same like my LAST UUID in my local DB. I was hoping there is another way...

I thought this Forum is also Supported by Chilkat and u also see a lot of Answers from them. Also i think other User may are interested on things like i ask... that's why i use this Forum. And btw. i HAVE a License :-D

But thanks again for your Answer

link

answered Jan 20 at 05:06

Howard's gravatar image

Howard
156

OK, I wasn't sure since the initial post mentioned trying to use functionality similar to IMAP with POP3, so I thought there might be some confusion regarding what library classes you should be using.

My first thought is that it might be a bug in the library that has already been fixed - you are using 9.5.0.53 which is slightly out of date, so it might be worth trying the latest release and see if the problem persists.

If it is still an issue in the latest version, it's probably worth reporting directly to Chilkat at the support email address, but perhaps you could use this temporary workaround - when you get your result you can quickly compare the UID of the message to your stored most-recent UID. If they match then ignore the returned result, otherwise do your normal processing against it.

link

answered Jan 20 at 09:11

jpbro's gravatar image

jpbro ♦
1.1k2618

This part of the LastErrorText is showing both the exact command and response:

    Command: aaad UID SEARCH UID 79:
    ImapCmdSent: aaad UID SEARCH UID 79:
    getCompleteResponse(2ms):
      ImapCmdResp: * SEARCH 85
      ImapCmdResp: aaad OK SEARCH completed.
    --getCompleteResponse
    numMessages: 1

Your program asks for all UID's from 79 onward, and the IMAP server responds with one UID: 85.

This is undeniable proof that only one email exists (in that particular mailbox) with a UID greater than 79. There's no bug in Chilkat here because the command and response can be clearly seen.

If you expected more emails in the response, then somehow your expectation was wrong -- there truly are no more emails having UIDs >= 79 other than the single email with UID 85.

link

answered Jan 20 at 09:29

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

thanks for your response!

You are right but your example is the Log from the Case where ONE new Mail was at the Server. I also didn't say is's a Chilkat Bug. And i did not expect more than this one new Mail.

BUT :-D

if you look at the First Log you find this:

Command: aaad UID SEARCH UID 79:*
    ImapCmdSent: aaad UID SEARCH UID 79:*
    getCompleteResponse(2ms):
      ImapCmdResp: * SEARCH 78
      ImapCmdResp: aaad OK SEARCH completed.
    --getCompleteResponse
    numMessages: 1

but this is really NOT what i expected. I thought the response is NO Mail. I ask for all UID's from 79 onward but get the Mail with UID 78. This response i get if there is NO new Mail on the Server...

link

answered Jan 20 at 09:41

Howard's gravatar image

Howard
156

edited Jan 20 at 09:43

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
×60
×45

Asked: Dec 14 '15 at 08:05

Seen: 1,161 times

Last updated: Jan 20 at 11:07

powered by OSQA