Getting mail_fetch_body to work - IMAP

This is a discussion on Getting mail_fetch_body to work - IMAP ; Hi, I'm trying to get c-client's mail_fetch_body to work in order to return the first x bytes of the message body. When I call char *text=mail_fetch_body(stream,number,"",&length,FT_PEEK); text contains the whole message (including header). But whenever I try to specify a ...

+ Reply to Thread
Results 1 to 9 of 9

Getting mail_fetch_body to work

  1. Default Getting mail_fetch_body to work

    Hi,

    I'm trying to get c-client's mail_fetch_body to work in order to return
    the first x bytes of the message body. When I call

    char *text=mail_fetch_body(stream,number,"",&length,FT_PEEK);

    text contains the whole message (including header). But whenever I try
    to specify a section, an empty string (not NULL) is returned. I tried
    for example:

    char *text=mail_fetch_body(stream,number,"<0.500>",&length,FT_PEEK);
    char *text=mail_fetch_body(stream,number,"TEXT<0.500>",&length,FT_PEEK);
    char *text=mail_fetch_body(stream,number,"[TEXT]",&length,FT_PEEK);

    I tried many other section strings, but none worked. What am I doing wrong?

    --
    Sebastian Schuberth

  2. Default Re: Getting mail_fetch_body to work

    On Thu, 8 Jul 2004, Sebastian Schuberth wrote:
    > But whenever I try to
    > specify a section, an empty string (not NULL) is returned. I tried for
    > example:
    > char *text=mail_fetch_body(stream,number,"<0.500>",&length,FT_PEEK);
    > char *text=mail_fetch_body(stream,number,"TEXT<0.500>",&length,FT_PEEK);
    > char *text=mail_fetch_body(stream,number,"[TEXT]",&length,FT_PEEK);


    The "section" argument to mail_fetch_body() is what RFC 3501 calls a
    "section-part". You can't use an RFC 3501 "section-text"; that's what
    those separate mail_fetch_body(), mail_fetch_header(), mail_fetch_text(),
    and mail_fetch_mime() functions do. You most definitely can not use a
    partial specifier (which isn't part of a RFC 3501 section at all!).

    To do partial fetches you must use mail_partial_body() and/or
    mail_partial_text(), which in turn means that you have to arm a mailgets_t
    function prior to the call (and disarm it afterwards).

    -- Mark --

    http://staff.washington.edu/mrc
    Science does not emerge from voting, party politics, or public debate.
    Si vis pacem, para bellum.

  3. Default Re: Getting mail_fetch_body to work

    > To do partial fetches you must use mail_partial_body() and/or
    > mail_partial_text(), which in turn means that you have to arm a
    > mailgets_t function prior to the call (and disarm it afterwards).


    FYI: I'm trying to emulate the functionality of POP3's TOP command. So I
    came up with this:

    char* mailgets(readfn_t f,void* stream,unsigned long size,GETS_DATA* md) {
    char *buffer=new char[size];
    f(stream,size,buffer);
    return buffer;
    }

    bool WINAPI TPluginProtocol::RetrieveTop(const int MsgNum,int
    LineCount,char** pDest) {
    // ...

    mail_parameters(stream,SET_GETS,mailgets);
    length=mail_partial_text(stream,number,NIL,0,500,FT_PEEK);
    mail_parameters(stream,SET_GETS,NIL);

    // ...
    }

    This is where i'm stuck. Questions:
    - How do I obtain the bytes read as "mail_partial_text()" only returns a
    long (the number of bytes read, I guess)?
    - Do I need to make "buffer" global in order to access the bytes read
    and be able to free it?

    Thanks for your help!

    BTW: Isn't there any more up-to-date documentation than "internal.txt"?
    (I mean documentation, not example source code :-)

    --
    Sebastian Schuberth

  4. Default Re: Getting mail_fetch_body to work

    On Fri, 9 Jul 2004, Sebastian Schuberth wrote:
    > This is where i'm stuck. Questions:
    > - How do I obtain the bytes read


    That's the job of your mailgets_t callback routine.

    > as "mail_partial_text()" only returns a long
    > (the number of bytes read, I guess)?


    mail_partial_text() returns a T vs. NIL success/fail indication.

    > - Do I need to make "buffer" global in order to access the bytes read and be
    > able to free it?


    The GETS_DATA holds a lot of interesting pieces of data for your
    mailgets_t callback routine to use. Among other things, it holds the open
    MAILSTREAM, which has convenient members such as sparep which you can
    stash data.

    > BTW: Isn't there any more up-to-date documentation than "internal.txt"? (I
    > mean documentation, not example source code :-)


    No, there isn't. It would be a major (expensive) undertaking, and there
    doesn't seem to be all that many people who would benefit from it.

    -- Mark --

    http://staff.washington.edu/mrc
    Science does not emerge from voting, party politics, or public debate.
    Si vis pacem, para bellum.

  5. Default Re: Getting mail_fetch_body to work

    >> - Do I need to make "buffer" global in order to access the bytes read
    >> and be able to free it?

    >
    > The GETS_DATA holds a lot of interesting pieces of data for your
    > mailgets_t callback routine to use. Among other things, it holds the
    > open MAILSTREAM, which has convenient members such as sparep which you
    > can stash data.


    Thanks, I got it working now. One slightly OT question: What is the
    difference between "mail_partial_text" and "mail_partial_body"? In my
    test, both deliver the same strings. Which one should I use if I want to
    get the pure hand-written contents of a mail?

    --
    Sebastian Schuberth

  6. Default Re: Getting mail_fetch_body to work

    On Fri, 9 Jul 2004, Sebastian Schuberth wrote:
    > Thanks, I got it working now. One slightly OT question: What is the
    > difference between "mail_partial_text" and "mail_partial_body"? In my test,
    > both deliver the same strings.


    mail_partial_text() and mail_partial_body() are ****ogous to
    mail_fetch_text() and mail_fetch_body().

    A "text" fetch is without regard to MIME, and only can be done to sections
    that refer to a message (either top level or a MESSAGE/RFC822). It refers
    to the entire text of the message (the part after the delimiting CRLFCRLF
    at the end of the header).

    A "body" fetch is a MIME body part fetch.

    For a non-multipart message only, a text fetch and a body fetch of section
    "1" return the same string.

    > Which one should I use if I want to get the
    > pure hand-written contents of a mail?


    I have no idea what you mean by "pure hand-written contents of a mail."

    -- Mark --

    http://staff.washington.edu/mrc
    Science does not emerge from voting, party politics, or public debate.
    Si vis pacem, para bellum.

  7. Default Re: Getting mail_fetch_body to work

    >> Which one should I use if I want to get the pure hand-written contents
    >> of a mail?

    >
    > I have no idea what you mean by "pure hand-written contents of a mail."


    :-) Your answer to my previous question already also answered this
    question. Thanks again.

    --
    Sebastian Schuberth

  8. Default Re: Getting mail_fetch_body to work

    >> Thanks, I got it working now. One slightly OT question: What is the
    >> difference between "mail_partial_text" and "mail_partial_body"? In my
    >> test, both deliver the same strings.


    [...]

    > A "text" fetch is without regard to MIME, and only can be done to
    > sections that refer to a message (either top level or a
    > MESSAGE/RFC822). It refers to the entire text of the message (the part
    > after the delimiting CRLFCRLF at the end of the header).


    Hmm, as mentioned above, it basically works. But from time to time I'm
    getting exceptions whehn trying to preview messages. Can you see any
    misuse of the way c-client is intended to work in this code:

    char* mailgets(readfn_t f,void* stream,unsigned long size,GETS_DATA* md) {
    md->stream->sparep=new char[size+1];
    char *buffer=static_cast<char*>(md->stream->sparep);
    f(stream,size,buffer);
    buffer[size]='\0';
    return buffer;
    }

    bool WINAPI TPluginProtocol::RetrieveTop(const int MsgNum,int
    LineCount,char** pDest) {
    // ...

    char *header=mail_fetch_header(stream,number,NIL,NIL,NIL,FT_PEEK);
    length=strlen(header);

    // Assume an average number of bytes per line and get the body contents.
    mail_parameters(stream,SET_GETS,mailgets);
    bool
    result=(mail_partial_body(stream,number,NIL,0,LineCount*50,FT_PEEK)!=NIL);
    mail_parameters(stream,SET_GETS,NIL);
    if (!result) return false;

    char *string=static_cast<char*>(stream->sparep);

    *pDest=new char[length+strlen(string)+1];
    if (*pDest) {
    strcpy(*pDest,header);
    strcpy(*pDest+length,string);
    result=(**pDest!='\0');
    }

    delete string;
    stream->sparep=NIL;

    // ...
    }

    --
    Sebastian Schuberth

  9. Default Re: Getting mail_fetch_body to work

    I'm sorry, I can't help you debug your code, especially not code written
    in C++ (*not* my favorite language). I will comment that you probably
    shouldn't put the string itself on the sparep, but rather a SIZEDTEXT
    holding both the string and its size. In general, you should return the
    string and its size instead of assuming null termination; SIZEDTEXT is
    convenient but you can just have a char* and a ulong pair.

    -- Mark --

    http://staff.washington.edu/mrc
    Science does not emerge from voting, party politics, or public debate.
    Si vis pacem, para bellum.

+ Reply to Thread

Similar Threads

  1. assambly don't work but aplication windows work. why?
    By Application Development in forum Sharepoint
    Replies: 0
    Last Post: 12-05-2007, 07:43 AM
  2. Replies: 0
    Last Post: 10-31-2007, 04:45 AM
  3. Replies: 0
    Last Post: 10-29-2007, 03:10 PM
  4. how does nlb work?
    By Application Development in forum Sharepoint
    Replies: 3
    Last Post: 08-10-2007, 08:28 AM
  5. VDQ : how does Lcc: actually work?
    By Application Development in forum Pine
    Replies: 1
    Last Post: 12-20-2004, 01:57 PM