aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/header.cpp7
-rw-r--r--tests/parser/headerTest.cpp19
-rw-r--r--vmime/header.hpp8
3 files changed, 34 insertions, 0 deletions
diff --git a/src/header.cpp b/src/header.cpp
index 663eb8df..6543a302 100644
--- a/src/header.cpp
+++ b/src/header.cpp
@@ -276,6 +276,13 @@ void header::removeField(const size_t pos)
}
+void header::replaceField(ref <headerField> field, ref <headerField> newField)
+{
+ insertFieldBefore(field, newField);
+ removeField(field);
+}
+
+
void header::removeAllFields()
{
m_fields.clear();
diff --git a/tests/parser/headerTest.cpp b/tests/parser/headerTest.cpp
index d096b28c..47bd0ebe 100644
--- a/tests/parser/headerTest.cpp
+++ b/tests/parser/headerTest.cpp
@@ -43,6 +43,8 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testInsertFieldAfter1)
VMIME_TEST(testInsertFieldAfter2)
+ VMIME_TEST(testReplaceField)
+
VMIME_TEST(testRemoveField1)
VMIME_TEST(testRemoveField2)
@@ -192,6 +194,23 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
}
+ // replaceField
+ void testReplaceField()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nB: b\r\nC: c\r\n");
+
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("Z", "z");
+ hdr.replaceField(hdr.getField("B"), hf);
+
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "Z: z", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ }
+
// removeField
void testRemoveField1()
{
diff --git a/vmime/header.hpp b/vmime/header.hpp
index fcbd09e8..6f5bf6d7 100644
--- a/vmime/header.hpp
+++ b/vmime/header.hpp
@@ -170,6 +170,14 @@ public:
*/
void removeField(const size_t pos);
+ /** Replaces a field with another field.
+ *
+ * @param field field to be replaced
+ * @param newField field to replace with
+ * @throw exceptions::no_such_field if the field is not in the list
+ */
+ void replaceField(ref <headerField> field, ref <headerField> newField);
+
/** Remove all fields from the list.
*/
void removeAllFields();