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 ¶ms) {
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.