Fwd: How to get MAILMIME_DISCRETE_TYPE_TEXT in UTF-8?

"DINH Viêt Hoà" <[email protected]> Mon, 12 Nov 2007 17:03:50 +0100
Newsgroups gmane.mail.libetpan.user
Message-ID <[email protected]>
On Nov 12, 2007 4:02 PM, Stanislaw T. Findeisen
<[email protected]> wrote:
> Hello,
>
> I want to parse MIME message and read texts stored in its
> MAILMIME_DISCRETE_TYPE_TEXT subparts.
>
> I think I already know how to find those parts --- so this is not a
> problem. The question is how to read the texts when I already got a
> pointer to this structure:
>
>      struct mailmime_data {
>          int dt_type;
>          int dt_encoding;
>          int dt_encoded;
>          union {
>              struct {
>                  const char * dt_data;
>                  size_t dt_length;
>              } dt_text;
>              char * dt_filename;
>          } dt_data;
>      };
>
> The questions are:
>
> (1) In case of MAILMIME_DISCRETE_TYPE_TEXT, is dt_data a 0-terminated
> string of length equal to dt_length?

dt_data is not supposed to be a 0-terminated string.

> (2) How to get the text (dt_data) DECODED, namely in UTF-8? Are there
> any helper functions for this?

You can find some interesting API in mailmime_content.h
encoded or decoded refers to base64 or quoted-printable (or other) encoding.
http://dinh.viet.hoa.free.fr/wiki/index.php?title=Mailmime_Parsing_Messages#mailmime_parse.28.29

For charset encoding (which can be found in the header), you can refer
to libetpan/src/data-types/charconv.h:

int charconv(const char * tocode, const char * fromcode,
    const char * str, size_t length,
    char ** result);

int charconv_buffer(const char * tocode, const char * fromcode,
                    const char * str, size_t length,
                    char ** result, size_t * result_len);

See charset_decode() for reference:
http://libetpan.svn.sourceforge.net/viewvc/libetpan/etpanX/trunk/src/backend/etpan-message-fetcher.c?revision=57&view=markup

> (3) What are the usage scenarios when dt_type can be MAILMIME_DATA_FILE?

That's when you are building your MIME structure yourself using files.

--
DINH Viêt Hoà

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/