Re: [gmime-devel] What's the preferred way to retrieve message body?



On 01/22/2010 02:45 PM, Dirk-Jan C. Binnema wrote:
>>>>>> "Jeffrey" == Jeffrey Stedfast <fejj novell com> writes:
>>>>>>             
>     Jeffrey> Junping Zhang wrote:
>     >> 
>     >> Thanks a lot for the explanation!
>     >> 
>     >> > The problem with g_mime_message_get_body() is that it made a lot of
>     >> > assumptions about the structure of the message (meaning it was pretty
>     >> > naive). Because of this, it wouldn't properly work on all messages.
>     >> 
>     >> As Dirk mentioned in the earlier post, the body is obvious in 99% of
>     >> cases.  I would say that you can define the body part with a given
>     >> email. I like the new API, but when you have time, if you can list the
>     >> cases where body can't be clearly defined, it will be good
>     >> information. Off hand, I can iterate the following (that's probably
>     >> outside of that 99% :)):
>     >> 
>
> <snip>
>
>     Jeffrey> Part of the problem is that some mailers might split the body into
>     Jeffrey> multiple text parts (for various reasons, such as trying to be fancy
>     Jeffrey> about embedding images between paragraphs of text or whatever else w/o
>     Jeffrey> resorting to using text/html).
>
> Getting the body of a message is a rather common operation though, so I think
> it would make sense to put the various heuristics in GMime. I think most GMime
> users would need something like it, and it would help them a lot, even if it's
> 'only' a 99% solution.
>
> Maybe express the difficulties in the name (e.g.,
> 'g_mime_message_guess_body').
>
> One additional parameter would be the preferred mime-type -- sometimes, html
> is preferred, and sometimes plain text. If we cannot find the preferred type,
> we might need to opt for the other. And then there are messages that have
> something totally different as body... e.g,., a PDF.
>
> Anyway, a 99% solution would be a good start. Jeffrey, would you be interested
> in this? If you would add a basic g_mime_message_guess_body, in a couple of
> iterations we could improve the heuristics to be at least as good as just
> about any mail reader -- and they usually don't have much trouble guessing the
> right body part.
>   

I'll consider doing it (the question gets asked a lot). I think I like
your idea of naming it guess_body() which makes it a bit more clear that
it really is only a guess. I think I'd also make it return the GMimePart
(or a GMimeObject) that represented the body rather than returning a
string buffer. If it returned a GMimeObject, I could just make it return
the multipart/alternative as a whole and let the caller sort out which
part it wants to use from that. Of course, then there'd have to be a way
to deal with encrypted parts... and multipart/related parts.

Jeff



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]