void GetHeader(GMimeMessage* pMessage) { GMimeHeaderList *list=NULL; GMimeHeaderIter iter; const char * name,*value; if(NULL==(list=g_mime_object_get_header_list(GMIME_OBJECT(pMessage)))) printf("[log]:\tfailed to get header list\n"); if(!g_mime_header_list_get_iter(list,&iter)) printf("[log]:\tfailed to get header list iter!\n"); #if __DEBUG printf("\n[log]\t Output Headers =====>>>>>\n\n"); #endif for(;;) { name=g_mime_header_iter_get_name(&iter); value=g_mime_header_iter_get_value(&iter); #if __DEBUG printf("%s:\t %s\n", name, value); #endif if (!g_mime_header_iter_next(&iter)) { break;/* code */ } } }
static GSList *gmime_fields_to_nameval(GMimeObject *part) { GMimeHeaderList *headers = g_mime_object_get_header_list(part); GMimeHeaderIter *iter = g_mime_header_iter_new(); GSList *fields = NULL; if (g_mime_header_list_get_iter(headers, iter)) { do { fields = sipe_utils_nameval_add(fields, g_mime_header_iter_get_name(iter), g_mime_header_iter_get_value(iter)); } while (g_mime_header_iter_next(iter)); } g_mime_header_iter_free(iter); return fields; }
static void test_disposition_sync (void) { GMimeContentDisposition *disposition; const char *raw_value, *value; GMimeHeaderList *headers; GMimeParamList *params; GMimeObject *object; GMimeHeader *header; GMimePart *part; object = (GMimeObject *) (part = g_mime_part_new ()); headers = g_mime_object_get_header_list (object); testsuite_check ("content-disposition synchronization"); try { g_mime_object_set_disposition (object, "attachment"); /* first, check that the current Content-Disposition header * value is "application/octet-stream" as expected */ if (!(value = g_mime_object_get_header (object, "Content-Disposition"))) throw (exception_new ("initial content-disposition header was unexpectedly null")); if (strcmp ("attachment", value) != 0) throw (exception_new ("initial content-disposition header had unexpected value: %s", value)); header = g_mime_header_list_get_header (headers, "Content-Disposition"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("initial content-disposition raw_value was unexpectedly null")); if (strcmp (" attachment\n", raw_value) != 0) throw (exception_new ("initial content-disposition raw_value had unexpected value: %s", raw_value)); /* now change the content-disposition's disposition */ disposition = g_mime_object_get_content_disposition (object); g_mime_content_disposition_set_disposition (disposition, "inline"); if (!(value = g_mime_object_get_header (object, "Content-Disposition"))) throw (exception_new ("content-disposition header was unexpectedly null after changing type")); if (strcmp ("inline", value) != 0) throw (exception_new ("content-disposition header had unexpected value after changing type")); header = g_mime_header_list_get_header (headers, "Content-Disposition"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-disposition raw_value was unexpectedly null after changing type")); if (strcmp (" inline\n", raw_value) != 0) throw (exception_new ("content-disposition raw_value had unexpected value after changing type: %s", raw_value)); /* now change the content-disposition's parameters by setting a param */ g_mime_content_disposition_set_parameter (disposition, "filename", "hello.txt"); if (!(value = g_mime_object_get_header (object, "Content-Disposition"))) throw (exception_new ("content-disposition header was unexpectedly null after setting a param")); if (strcmp ("inline; filename=hello.txt", value) != 0) throw (exception_new ("content-disposition header had unexpected value after setting a param")); header = g_mime_header_list_get_header (headers, "Content-Disposition"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-disposition raw_value was unexpectedly null after setting a param")); if (strcmp (" inline; filename=hello.txt\n", raw_value) != 0) throw (exception_new ("content-disposition raw_value had unexpected value after setting a param: %s", raw_value)); /* now change the content-disposition's parameters by clearing the params */ params = g_mime_content_disposition_get_parameters (disposition); g_mime_param_list_clear (params); if (!(value = g_mime_object_get_header (object, "Content-Disposition"))) throw (exception_new ("content-disposition header was unexpectedly null after clearing params")); if (strcmp ("inline", value) != 0) throw (exception_new ("content-disposition header had unexpected value after clearing params")); header = g_mime_header_list_get_header (headers, "Content-Disposition"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-disposition raw_value was unexpectedly null after clearing params")); if (strcmp (" inline\n", raw_value) != 0) throw (exception_new ("content-disposition raw_value had unexpected value after clearing params: %s", raw_value)); /* let's try this in reverse... set the header value and make sure GMimeContentDisposition gets updated */ header = g_mime_header_list_get_header_at (headers, 1); g_mime_header_set_value (header, NULL, "attachment; filename=xyz", NULL); disposition = g_mime_object_get_content_disposition (object); if (!g_mime_content_disposition_is_attachment (disposition)) throw (exception_new ("GMimeContentDisposition object was not updated")); header = g_mime_header_list_get_header (headers, "Content-Disposition"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-disposition raw_value was unexpectedly null after setting value")); if (strcmp (" attachment; filename=xyz\n", raw_value) != 0) throw (exception_new ("content-disposition raw_value had unexpected value after setting value: %s", raw_value)); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("content-disposition header not synchronized: %s", ex->message); } finally; g_object_unref (part); }
static void test_content_type_sync (void) { const char *raw_value, *value; GMimeHeaderList *headers; GMimeContentType *type; GMimeParamList *params; GMimeObject *object; GMimeHeader *header; GMimePart *part; object = (GMimeObject *) (part = g_mime_part_new ()); headers = g_mime_object_get_header_list (object); testsuite_check ("content-type synchronization"); try { /* first, check that the current Content-Type header * value is "application/octet-stream" as expected */ if (!(value = g_mime_object_get_header (object, "Content-Type"))) throw (exception_new ("initial content-type header was unexpectedly null")); if (strcmp ("application/octet-stream", value) != 0) throw (exception_new ("initial content-type header had unexpected value: %s", value)); /* now change the content-type's media type... */ type = g_mime_object_get_content_type (object); g_mime_content_type_set_media_type (type, "text"); if (!(value = g_mime_object_get_header (object, "Content-Type"))) throw (exception_new ("content-type header was unexpectedly null after changing type")); if (strcmp ("text/octet-stream", value) != 0) throw (exception_new ("content-type header had unexpected value after changing type")); header = g_mime_header_list_get_header (headers, "Content-Type"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-type raw_value was unexpectedly null after changing type")); if (strcmp (" text/octet-stream\n", raw_value) != 0) throw (exception_new ("content-type raw_value had unexpected value after changing type")); /* now change the content-type's media subtype... */ g_mime_content_type_set_media_subtype (type, "plain"); if (!(value = g_mime_object_get_header (object, "Content-Type"))) throw (exception_new ("content-type header was unexpectedly null after changing subtype")); if (strcmp ("text/plain", value) != 0) throw (exception_new ("content-type header had unexpected value after changing subtype")); header = g_mime_header_list_get_header (headers, "Content-Type"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-type raw_value was unexpectedly null after changing subtype")); if (strcmp (" text/plain\n", raw_value) != 0) throw (exception_new ("content-type raw_value had unexpected value after changing subtype")); /* now change the content-type's parameters by setting a param */ g_mime_content_type_set_parameter (type, "format", "flowed"); if (!(value = g_mime_object_get_header (object, "Content-Type"))) throw (exception_new ("content-type header was unexpectedly null after setting a param")); if (strcmp ("text/plain; format=flowed", value) != 0) throw (exception_new ("content-type header had unexpected value after setting a param")); header = g_mime_header_list_get_header (headers, "Content-Type"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-type raw_value was unexpectedly null after setting a param")); if (strcmp (" text/plain; format=flowed\n", raw_value) != 0) throw (exception_new ("content-type raw_value had unexpected value after setting a param")); /* now change the content-type's parameters by clearing the params */ params = g_mime_content_type_get_parameters (type); g_mime_param_list_clear (params); if (!(value = g_mime_object_get_header (object, "Content-Type"))) throw (exception_new ("content-type header was unexpectedly null after clearing params")); if (strcmp ("text/plain", value) != 0) throw (exception_new ("content-type header had unexpected value after clearing params")); header = g_mime_header_list_get_header (headers, "Content-Type"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-type raw_value was unexpectedly null after clearing params")); if (strcmp (" text/plain\n", raw_value) != 0) throw (exception_new ("content-type raw_value had unexpected value after clearing params")); /* let's try this in reverse... set the header value and make sure GMimeContentType gets updated */ header = g_mime_header_list_get_header_at (headers, 0); g_mime_header_set_value (header, NULL, "text/html; charset=utf-8", NULL); type = g_mime_object_get_content_type (object); if (!g_mime_content_type_is_type (type, "text", "html")) throw (exception_new ("GMimeContentType object was not updated")); header = g_mime_header_list_get_header (headers, "Content-Type"); if (!(raw_value = g_mime_header_get_raw_value (header))) throw (exception_new ("content-type raw_value was unexpectedly null after setting value")); if (strcmp (" text/html; charset=utf-8\n", raw_value) != 0) throw (exception_new ("content-type raw_value had unexpected value after setting value")); testsuite_check_passed (); } catch (ex) { testsuite_check_failed ("content-type header not synchronized: %s", ex->message); } finally; g_object_unref (part); }