jstedfast / gmime

A C/C++ MIME creation and parser library with support for S/MIME, PGP, and Unix mbox spools.
GNU Lesser General Public License v2.1
111 stars 36 forks source link

Text part type #127

Closed feddoa closed 1 year ago

feddoa commented 1 year ago

I am working on antispam project with gmime lib. I need to get text/plain and text/html parts from message, i've done it with this code:

if (GMIME_IS_TEXT_PART(part))
        {
            //TEXT_PART
            std::string str_text_body = g_mime_text_part_get_text((GMimeTextPart*)part);
            p_str_data->append(str_text_body);
            return;
        }

I cant realize how to detect which type this text part is(text/plain or text/html) I thought there is something like g_mime_text_part_get_type but I`ve found this function with empty args list. I would be glad if u give an advice

jstedfast commented 1 year ago

The following code snippet is the correct way to check for this:

GMimeContentType *content_type;

content_type = g_mime_object_get_content_type ((GMimeObject *) part);
if (g_mime_content_type_is_mime_type (content_type, "text", "plain")) {
    // this is text/plain
} else if (g_mime_content_type_is_type (content_type, "text", "html")) {
    // this is text/html
} else if (g_mime_content_type_is_type (content_type, "text", "*")) {
    // this matches all text mime-types
}
feddoa commented 1 year ago

Thank you!