Re: [gmime-devel] gmime-devel-list Digest, Vol 76, Issue 4



Thank you for the prompt response.

My apologies. I thought I had included that snippet of code. To print the encoding I use:

    GMimeContentEncoding encoding =
        g_mime_part_get_content_encoding(part);
    const char* encoding_as_string =
        g_mime_content_encoding_to_string(encoding);

    cout << indent << "- content encoding: ";
    if (encoding_as_string)
        cout << encoding_as_string;
    else
        cout << "NULL";
    cout << endl;              

As for the content_description, I was expecting "text/plain" and "text/html". If this is the wrong field to get this discrimination, which field would be correct?

Related to that (but lower priority), how do I get the "multipart/alternative;" field from the multipart? the content type from the top level part returned by g_mime_message_get_mime_part(message)?

TIA.



On Tuesday, July 18, 2017 1:12 PM, "gmime-devel-list-request gnome org" <gmime-devel-list-request gnome org> wrote:


Send gmime-devel-list mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of gmime-devel-list digest..."


Today's Topics:

  1. Re:  part data is always NULL (Jeffrey Stedfast)


----------------------------------------------------------------------

Message: 1
Date: Tue, 18 Jul 2017 12:33:49 +0000
From: Jeffrey Stedfast <jestedfa microsoft com>
Subject: Re: [gmime-devel] part data is always NULL
Content-Type: text/plain; charset="utf-8"

Maybe I?m missing something but what exactly do you expect the Content-Description string to contain if not NULL?

Also I don?t see where your code prints the ?content encoding? so I have no idea how you are getting that value, but will point out the following method signature:

GMimeContentEncoding g_mime_part_get_content_encoding (GMimePart *mime_part);

GMimeContentENcoding is an enum, not a string, and the default value (i.e. when no encoding is specified) is `0`, so if you try to print `0` as a string, it?s NULL.

Hope that helps,

Jeff

From: gmime-devel-list <gmime-devel-list-bounces gnome org> on behalf of Yuval Peduel via gmime-devel-list <gmime-devel-list gnome org>
Reply-To: Yuval Peduel <ypeduel yahoo-inc com>
Date: Monday, July 17, 2017 at 8:12 PM
Subject: [gmime-devel] part data is always NULL

My apologies if this has been covered but I couldn't find a way of doing an effective search in the archives.

I'm new to GMIME so I wrote a small test program to parse and print out the MIME structure of emails.

When I get to a part, I try to get the content description and the content encoding. The char* returned by the corresponding functions is always NULL.

I'm running the code on Mac OSX Sierra

The relevant portion of the raw message is:

Subject: test message
To: yuval peduel <ypeduel yahoo-inc com>
Content-Type: multipart/alternative; boundary="94eb2c043cb48bca710554265079"
Content-Length: 328

--94eb2c043cb48bca710554265079
Content-Type: text/plain; charset="UTF-8"

I'm expecting this message to have two MIME sections

--94eb2c043cb48bca710554265079
Content-Type: text/html; charset="UTF-8"

<div dir="ltr">I'm expecting this message to have two MIME sections<div><br></div></div>

--94eb2c043cb48bca710554265079--

The code fragments that I think are relevant are:

    GMimeMessage* message = g_mime_parser_construct_message(parser, NULL);
    /* unref the parser since we no longer need it */
    g_object_unref (parser);

    error = process_gmime_message(message, params);


int process_gmime_message(GMimeMessage* message,
                          po::variables_map &params) {
    int error = 0;

    GMimeObject * mime_part = g_mime_message_get_mime_part(message);

    cout << "In process_gmime_message, the top level part is ";
    if      (GMIME_IS_MESSAGE_PART(mime_part)) {
        cout << " recognized as MESSAGE_PART\n";
    } else if (GMIME_IS_MULTIPART(mime_part)) {
        cout << " recognized as MULTI_PART ";
        GMimeMultipart* multipart = (GMimeMultipart *)mime_part;
        int part_count = g_mime_multipart_get_count(multipart);
        cout << "with " << part_count << " contained parts\n";
        process_mime_multipart(multipart, 0);
    } else if (GMIME_IS_PART(mime_part)) {
        cout << " recognized as PART\n";
        process_mime_part((GMimePart *)mime_part, 0);
    } else
        cout << " not recognized as part\n";

    return error;
}

void process_mime_multipart(GMimeMultipart* multipart, int level) {

    cout << "process_mime_multipart called" << endl;
    if (multipart == NULL) {
        cout << "ERROR: NULL part" << endl;
        return;
    }

    string indent = "  ";
    for (int depth = 0; depth < level; ++depth)
        indent += "  ";

    cout << indent << "mime multi-part:" << endl;
    int count = g_mime_multipart_get_count(multipart);

    for (int ndx = 0; ndx < count; ++ndx) {
        GMimeObject* mime_part = g_mime_multipart_get_part(multipart, ndx);

        if (GMIME_IS_MESSAGE_PART(mime_part)) {
            cout << " recognized as MESSAGE_PART\n";
        } else if (GMIME_IS_MULTIPART(mime_part)) {
            cout << " recognized as MULTI_PART ";
            GMimeMultipart* multipart = (GMimeMultipart *)mime_part;
            int part_count = g_mime_multipart_get_count(multipart);
            cout << "with " << part_count << " contained parts\n";
            process_mime_multipart(multipart, level+1);
        } else if (GMIME_IS_PART(mime_part)) {
            cout << " recognized as PART\n";
            process_mime_part((GMimePart *)mime_part, level+1);
        } else
            cout << " not recognized as part\n";
    }
}

void process_mime_part(GMimePart *part, int level) {

    cout << "process_mime_part called" << endl;
    if (part == NULL) {
        cout << "ERROR: NULL part" << endl;
        return;
    }

    string indent = "  ";
    for (int depth = 0; depth < level; ++depth)
        indent += "  ";

    cout << indent << "mime part:" << endl;

    const char* description =
        g_mime_part_get_content_description(part);
    cout << indent << "- content description: ";
    if (description)
        cout << description;
    else
        cout << "NULL";
    cout << endl;

My output looks like:

In process_gmime_message, the top level part is  recognized as MULTI_PART with 2 contained parts
process_mime_multipart called
  mime multi-part:
recognized as PART
process_mime_part called
      mime part:
      - content description: NULL
      - content encoding: NULL
recognized as PART
process_mime_part called
      mime part:
      - content description: NULL
      - content encoding: NULL

which seems to be saying that I'm recognizing the two MIME parts, just not getting the relevant data.

Suggestions? Questions whose answers will help you help me?

TIA.



-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

Subject: Digest Footer

_______________________________________________
gmime-devel-list mailing list


------------------------------

End of gmime-devel-list Digest, Vol 76, Issue 4
***********************************************




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