使用下面的代码我得到了MIME消息的所有部分, 但我的要求是在一个多部分体内计算部分, 有人可以帮忙吗?
void testFunc() {
GMimeStream* stream;
GMimeParser* parser;
GMimeMessage* msg;
GMimeObject* root = NULL;
stream = g_mime_stream_fs_new(fd); // Fd is the email file
parser = g_mime_parser_new_with_stream(stream);
g_object_unref(stream);
msg = g_mime_parser_construct_message(parser);
g_object_unref(parser);
if (msg) {
root = g_mime_message_get_mime_part(msg);
int part_count=0;
scan_part(root, &scan_data, &part_count);
}
}
static void scan_part(GMimeObject *part, struct scan_part_data *scan_data, int *part_count) {
gboolean is_multipart = GMIME_IS_MULTIPART(part);
if (is_multipart) {
GMimeMultipart* mpart = GMIME_MULTIPART(part);
int count = g_mime_multipart_get_count(mpart);
int i;
for (i = 0; i < count; i++) {
GMimeObject* subpart = g_mime_multipart_get_part(mpart, i);
scan_part(subpart, scan_data, part_count);
return;
}
} else if (GMIME_IS_MESSAGE_PART(part)) {
GMimeMessage* msg = g_mime_message_part_get_message(GMIME_MESSAGE_PART(part));
GMimeObject* subpart = g_mime_message_get_mime_part(msg);
scan_part(subpart, scan_data, part_count);
return;
}
gboolean is_part = GMIME_IS_PART(part);
if (is_part || is_multipart) {
(*part_count)++;
// some code;
}
}
答案 0 :(得分:2)
要获得单个多部分的计数,请执行以下操作:
int count = g_mime_multipart_get_count (multipart);
答案 1 :(得分:0)
我得到了我的问题的答案,
static void scan_part(GMimeObject *part, struct scan_part_data *scan_data, int *part_count) {
gboolean is_multipart = GMIME_IS_MULTIPART(part);
if (is_multipart) {
GMimeMultipart* mpart = GMIME_MULTIPART(part);
int count = g_mime_multipart_get_count(mpart);
+++ (*part_count)++;
int i;
for (i = 0; i < count; i++) {
GMimeObject* subpart = g_mime_multipart_get_part(mpart, i);
scan_part(subpart, scan_data, part_count);
return;
}
} else if (GMIME_IS_MESSAGE_PART(part)) {
GMimeMessage* msg = g_mime_message_part_get_message(GMIME_MESSAGE_PART(part));
GMimeObject* subpart = g_mime_message_get_mime_part(msg);
scan_part(subpart, scan_data, part_count);
return;
}
gboolean is_part = GMIME_IS_PART(part);
if (is_part || is_multipart) {
--- (*part_count)++;
// some code;
}
}