normalize header names to lower case v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 06 Feb 2021 20:32:26 +0100
branchv_0
changeset 5 a3794fe5ea4b
parent 4 dd8ff58fb29b
child 6 47b677177365
normalize header names to lower case
src/XMLDocumentConstructor.h
--- a/src/XMLDocumentConstructor.h	Sat Feb 06 20:24:55 2021 +0100
+++ b/src/XMLDocumentConstructor.h	Sat Feb 06 20:32:26 2021 +0100
@@ -55,6 +55,12 @@
 		return contentType.getType() + "/" + contentType.getSubType();
 	}
 
+	std::string toLowerCase(const std::string& value) {
+		std::string result = value;
+		std::transform(result.begin(), result.end(), result.begin(), ::tolower);
+		return result;
+	}
+
 	std::string fetchBody(std::shared_ptr<vmime::body> body) {
 		std::stringstream result;
 		vmime::utility::outputStreamAdapter resultAdapter(result);
@@ -121,9 +127,7 @@
 
 		for (std::shared_ptr<vmime::headerField> mimeField : m.getHeader()->getFieldList()) {
 			// TODO: Are names always ASCII and subset of UTF-8?
-			// TODO: Convert header names to lower case? (they should be case insensitive)
-			xmlpp::Element* field = headers->add_child(nameCodec.encode(mimeField->getName()));
-
+			xmlpp::Element* field = headers->add_child(toLowerCase(nameCodec.encode(mimeField->getName())));
 
 			if (auto value = mimeField->getValue<vmime::text>()) {
 				field->add_child_text(value->getConvertedText(ch));