const gchar * libbalsa_message_body_charset(LibBalsaMessageBody * body) { const gchar *charset; if (!body) return NULL; if (body->charset) /* This overrides all! Important for non * us-ascii messages over IMAP. */ return body->charset; if (GMIME_IS_PART(body->mime_part)) { GMimeContentType *type; type = g_mime_object_get_content_type(body->mime_part); return g_mime_content_type_get_parameter(type, "charset"); } charset = libbalsa_message_body_charset(body->parts); if (charset) return charset; return libbalsa_message_body_charset(body->next); }
QNetworkReply* MailNetworkManager::makeReply(const QNetworkRequest& req, GMimeObject* content) { auto ctype = g_mime_object_get_content_type(content); char *mtstr = g_mime_content_type_to_string(ctype); QString mediaType = QString::fromUtf8(mtstr); g_free(mtstr); const char *enc = g_mime_content_type_get_parameter(ctype, "charset"); if (enc != NULL) { mediaType += "; charset=\""; mediaType += QString::fromUtf8(enc); mediaType += "\""; } g_return_val_if_fail(GMIME_IS_PART(content), NULL); GMimeStream *stream = g_mime_stream_mem_new(); GMimeDataWrapper *wrapper = g_mime_part_get_content_object(GMIME_PART(content)); g_mime_data_wrapper_write_to_stream(wrapper, stream); GByteArray *bytes = g_mime_stream_mem_get_byte_array(GMIME_STREAM_MEM(stream)); QByteArray buffer((const char*) bytes->data, bytes->len); g_object_unref(stream); qDebug() <<"making reply of length" <<buffer.size() <<"and type" <<mediaType; return StaticHTTPReply::ok(req, buffer, mediaType); }
static void display_part(GMimeObject *part, const GMimeContentType *ct) { GMimeStream *ostream, *fstream; GMimeFilter *basic; GMimeDataWrapper *content; GMimeFilter *charset, *html; GMimePartEncodingType encoding; encoding = g_mime_part_get_encoding(GMIME_PART(part)); fstream = g_mime_stream_file_new(stdout); ostream = g_mime_stream_filter_new_with_stream(fstream); g_mime_stream_unref(fstream); /* Encoding filter, always on */ if (charset = g_mime_filter_charset_new(g_mime_content_type_get_parameter(ct, "charset"), "utf-8")) { g_mime_stream_filter_add(GMIME_STREAM_FILTER(ostream), charset); g_object_unref(charset); } if (g_mime_content_type_is_type(ct, "text", "plain")) { if (text_only == 0) { html = g_mime_filter_html_new ( GMIME_FILTER_HTML_CONVERT_SPACES | GMIME_FILTER_HTML_CONVERT_URLS | GMIME_FILTER_HTML_MARK_CITATION | GMIME_FILTER_HTML_CITE, 0); g_mime_stream_filter_add(GMIME_STREAM_FILTER(ostream), html); g_object_unref(html); } content = g_mime_part_get_content_object(GMIME_PART(part)); g_mime_data_wrapper_write_to_stream(content, ostream); g_mime_stream_flush(ostream); g_object_unref(content); // GMimeFilterBasic (base64, quopri) // GMimeFilterCharset // GMimeFilterHTML // GMimeFilterEnriched (text/enriched, text/rtf) } else if (g_mime_content_type_is_type(ct, "text", "html")) { content = g_mime_part_get_content_object(GMIME_PART(part)); g_mime_data_wrapper_write_to_stream(content, ostream); g_mime_stream_flush(ostream); g_object_unref(content); } else if (strcmp(ct->type, "image") == 0) { display_image(part); } }