libcyrus and the imap proto

John Alton Tamplin jtampli at sph.emory.edu
Thu Feb 27 09:53:57 EST 2003


Patrick Welche wrote:

>Overall I see that you send commands to the imap server using imclient_send,
>the last argument of which is essentially the text of the imap command.
>You register callbacks based on keyword, so that when the server sends you
>a reply, the function registered gets called. I suspect I am getting confused
>between "tagged" and "untagged". The following is fine, and I think that
>
>. capability                       <- sent with imclient_send
>* CAPABILITY IMAP4 IMAP4rev1 ...   -> untagged? capability response
>                                      picked up by callback based on
>                                      keyword "CAPABILITY"
>. OK Completed                     -> tagged? ok response picked up by
>                                      imclient_send's finishproc
>
>
>but now for the problem
>
>. examine inbox                    <- sent with imclient_send
>* FLAGS (\Answered \Flagged ...    -> untaged flags response, callback_flags
>* OK [PERMANENTFLAGS ()]           -> untagged ok response, callback_ok
>* 13 EXISTS             ********* What about these two?
>* 1 RECENT              ********* untagged responses with no keyword?
>* OK [UNSEEN 13]                   -> untagged ok response, callback_ok
>* OK [UIDVALIDITY 1043953684]      -> untagged ok response, callback_ok
>* OK [UIDNEXT 15]                  -> untagged ok response, callback_ok
>. OK [READ-ONLY] Completed         -> tagged? ok response picked up by
>                                      imclient_send's finishproc
>
>same for eg
>. fetch 1 (internaldate)
>* 1 FETCH (INTERNALDATE "30-Jan-2003 19:23:41 +0000")
>. OK Completed
>
>How can I see the result of fetch?
>  
>
I have not used the C library, but the perl interface is similar so I 
suspect this approach will work for you.  What I did was add a callback 
with an empty string for a trigger.  The callback gets called on every 
line, and you can parse it as you please.

        $imap->addcallback({-trigger=>'',-callback=>sub {
                my %a=@_;

                if($a{-text}=~ /RFC822\.SIZE\s+(\d+)/i) {
                        $totmsg++;
                        $totbytes+=$1;
                        if($1>100000) {
                                $largemsg++;
                                $largebytes+=$1;
                        }
                        $largest=$1 if($1>$largest);
                }
        }});
        ($rc,$text)=$imap->send('','','FETCH 1:* RFC822.SIZE',$mbx);


-- 
John A. Tamplin                               Unix System Administrator
Emory University, School of Public Health     +1 404/727-9931







More information about the Info-cyrus mailing list