Do not QP-encode CRLFs when content type is text.
This commit is contained in:
parent
de659db112
commit
86f0a63802
@ -363,6 +363,7 @@ libvmimetest_sources = [
|
||||
# ============================== Parser ==============================
|
||||
'tests/parser/attachmentHelperTest.cpp',
|
||||
'tests/parser/bodyPartTest.cpp',
|
||||
'tests/parser/bodyTest.cpp',
|
||||
'tests/parser/charsetTest.cpp',
|
||||
'tests/parser/charsetFilteredOutputStreamTest.cpp',
|
||||
'tests/parser/datetimeTest.cpp',
|
||||
|
@ -494,7 +494,10 @@ void body::generateImpl
|
||||
else
|
||||
{
|
||||
// Generate the contents
|
||||
m_contents->generate(os, getEncoding(), ctx.getMaxLineLength());
|
||||
ref <contentHandler> contents = m_contents->clone();
|
||||
contents->setContentTypeHint(getContentType());
|
||||
|
||||
contents->generate(os, getEncoding(), ctx.getMaxLineLength());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,4 +102,16 @@ bool emptyContentHandler::isBuffered() const
|
||||
}
|
||||
|
||||
|
||||
void emptyContentHandler::setContentTypeHint(const mediaType& type)
|
||||
{
|
||||
m_contentType = type;
|
||||
}
|
||||
|
||||
|
||||
const mediaType emptyContentHandler::getContentTypeHint() const
|
||||
{
|
||||
return m_contentType;
|
||||
}
|
||||
|
||||
|
||||
} // vmime
|
||||
|
@ -90,6 +90,8 @@ void IMAPMessagePartContentHandler::generate
|
||||
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
theEncoder->encode(tempIn, os);
|
||||
}
|
||||
// No encoding to perform
|
||||
@ -110,6 +112,7 @@ void IMAPMessagePartContentHandler::generate
|
||||
// Encode temporary buffer to output stream
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
utility::inputStreamStringAdapter is(oss.str());
|
||||
|
||||
@ -188,6 +191,18 @@ bool IMAPMessagePartContentHandler::isBuffered() const
|
||||
}
|
||||
|
||||
|
||||
void IMAPMessagePartContentHandler::setContentTypeHint(const mediaType& type)
|
||||
{
|
||||
m_contentType = type;
|
||||
}
|
||||
|
||||
|
||||
const mediaType IMAPMessagePartContentHandler::getContentTypeHint() const
|
||||
{
|
||||
return m_contentType;
|
||||
}
|
||||
|
||||
|
||||
} // imap
|
||||
} // net
|
||||
} // vmime
|
||||
|
@ -52,7 +52,7 @@ streamContentHandler::~streamContentHandler()
|
||||
|
||||
|
||||
streamContentHandler::streamContentHandler(const streamContentHandler& cts)
|
||||
: contentHandler(), m_encoding(cts.m_encoding),
|
||||
: contentHandler(), m_encoding(cts.m_encoding), m_contentType(cts.m_contentType),
|
||||
m_stream(cts.m_stream), m_length(cts.m_length)
|
||||
{
|
||||
}
|
||||
@ -66,6 +66,7 @@ ref <contentHandler> streamContentHandler::clone() const
|
||||
|
||||
streamContentHandler& streamContentHandler::operator=(const streamContentHandler& cts)
|
||||
{
|
||||
m_contentType = cts.m_contentType;
|
||||
m_encoding = cts.m_encoding;
|
||||
|
||||
m_stream = cts.m_stream;
|
||||
@ -103,6 +104,7 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
m_stream->reset(); // may not work...
|
||||
|
||||
@ -129,6 +131,7 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
|
||||
{
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
m_stream->reset(); // may not work...
|
||||
|
||||
@ -216,4 +219,16 @@ bool streamContentHandler::isBuffered() const
|
||||
}
|
||||
|
||||
|
||||
void streamContentHandler::setContentTypeHint(const mediaType& type)
|
||||
{
|
||||
m_contentType = type;
|
||||
}
|
||||
|
||||
|
||||
const mediaType streamContentHandler::getContentTypeHint() const
|
||||
{
|
||||
return m_contentType;
|
||||
}
|
||||
|
||||
|
||||
} // vmime
|
||||
|
@ -44,7 +44,8 @@ stringContentHandler::stringContentHandler(const string& buffer, const vmime::en
|
||||
|
||||
|
||||
stringContentHandler::stringContentHandler(const stringContentHandler& cts)
|
||||
: contentHandler(), m_encoding(cts.m_encoding), m_string(cts.m_string)
|
||||
: contentHandler(), m_contentType(cts.m_contentType),
|
||||
m_encoding(cts.m_encoding), m_string(cts.m_string)
|
||||
{
|
||||
}
|
||||
|
||||
@ -75,6 +76,7 @@ ref <contentHandler> stringContentHandler::clone() const
|
||||
|
||||
stringContentHandler& stringContentHandler::operator=(const stringContentHandler& cts)
|
||||
{
|
||||
m_contentType = cts.m_contentType;
|
||||
m_encoding = cts.m_encoding;
|
||||
m_string = cts.m_string;
|
||||
|
||||
@ -127,6 +129,7 @@ void stringContentHandler::generate(utility::outputStream& os,
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
utility::inputStreamStringProxyAdapter in(m_string);
|
||||
|
||||
@ -151,6 +154,7 @@ void stringContentHandler::generate(utility::outputStream& os,
|
||||
{
|
||||
ref <utility::encoder::encoder> theEncoder = enc.getEncoder();
|
||||
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
|
||||
theEncoder->getProperties()["text"] = (m_contentType.getType() == mediaTypes::TEXT);
|
||||
|
||||
utility::inputStreamStringProxyAdapter in(m_string);
|
||||
|
||||
@ -217,4 +221,16 @@ bool stringContentHandler::isBuffered() const
|
||||
}
|
||||
|
||||
|
||||
void stringContentHandler::setContentTypeHint(const mediaType& type)
|
||||
{
|
||||
m_contentType = type;
|
||||
}
|
||||
|
||||
|
||||
const mediaType stringContentHandler::getContentTypeHint() const
|
||||
{
|
||||
return m_contentType;
|
||||
}
|
||||
|
||||
|
||||
} // vmime
|
||||
|
66
tests/parser/bodyTest.cpp
Normal file
66
tests/parser/bodyTest.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "tests/testUtils.hpp"
|
||||
|
||||
|
||||
VMIME_TEST_SUITE_BEGIN(bodyTest)
|
||||
|
||||
VMIME_TEST_LIST_BEGIN
|
||||
VMIME_TEST(testGenerate_Text)
|
||||
VMIME_TEST(testGenerate_NonText)
|
||||
VMIME_TEST_LIST_END
|
||||
|
||||
|
||||
void testGenerate_Text()
|
||||
{
|
||||
// RFC-2015: [Quoted-Printable encoding] A line break in a text body,
|
||||
// represented as a CRLF sequence in the text canonical form, must be
|
||||
// represented by a line break which is also a CRLF sequence, in the
|
||||
// Quoted-Printable encoding
|
||||
|
||||
vmime::bodyPart p;
|
||||
p.getBody()->setContents(vmime::create <vmime::stringContentHandler>
|
||||
("Foo éé\r\né bar\r\nbaz"), vmime::mediaType("text", "plain"),
|
||||
vmime::charset("utf-8"), vmime::encoding("quoted-printable"));
|
||||
|
||||
VASSERT_EQ("generate",
|
||||
"Foo =C3=A9=C3=A9\r\n"
|
||||
"=C3=A9 bar\r\n"
|
||||
"baz",
|
||||
p.getBody()->generate());
|
||||
}
|
||||
|
||||
void testGenerate_NonText()
|
||||
{
|
||||
vmime::bodyPart p;
|
||||
p.getBody()->setContents(vmime::create <vmime::stringContentHandler>
|
||||
("Binary\xfa\xfb\r\ndata\r\n\r\n\xfc"), vmime::mediaType("application", "octet-stream"),
|
||||
vmime::charset("utf-8"), vmime::encoding("quoted-printable"));
|
||||
|
||||
VASSERT_EQ("generate",
|
||||
"Binary=FA=FB=0D=0Adata=0D=0A=0D=0A=FC",
|
||||
p.getBody()->generate());
|
||||
}
|
||||
|
||||
VMIME_TEST_SUITE_END
|
@ -32,6 +32,7 @@
|
||||
#include "vmime/utility/smartPtr.hpp"
|
||||
#include "vmime/utility/progressListener.hpp"
|
||||
#include "vmime/encoding.hpp"
|
||||
#include "vmime/mediaType.hpp"
|
||||
|
||||
|
||||
namespace vmime
|
||||
@ -118,6 +119,18 @@ public:
|
||||
* if not (ie. streamed data from socket)
|
||||
*/
|
||||
virtual bool isBuffered() const = 0;
|
||||
|
||||
/** Gives a hint about the kind of data managed by this object.
|
||||
*
|
||||
* @param type content media type
|
||||
*/
|
||||
virtual void setContentTypeHint(const mediaType& type) = 0;
|
||||
|
||||
/** Returns a hint about the kind of data managed by this object.
|
||||
*
|
||||
* @return type content media type
|
||||
*/
|
||||
virtual const mediaType getContentTypeHint() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -54,6 +54,13 @@ public:
|
||||
bool isEmpty() const;
|
||||
|
||||
bool isBuffered() const;
|
||||
|
||||
void setContentTypeHint(const mediaType& type);
|
||||
const mediaType getContentTypeHint() const;
|
||||
|
||||
private:
|
||||
|
||||
mediaType m_contentType;
|
||||
};
|
||||
|
||||
|
||||
|
@ -63,12 +63,16 @@ public:
|
||||
|
||||
bool isBuffered() const;
|
||||
|
||||
void setContentTypeHint(const mediaType& type);
|
||||
const mediaType getContentTypeHint() const;
|
||||
|
||||
private:
|
||||
|
||||
weak_ref <IMAPMessage> m_message;
|
||||
weak_ref <part> m_part;
|
||||
|
||||
vmime::encoding m_encoding;
|
||||
vmime::mediaType m_contentType;
|
||||
};
|
||||
|
||||
|
||||
|
@ -99,8 +99,13 @@ public:
|
||||
|
||||
bool isBuffered() const;
|
||||
|
||||
void setContentTypeHint(const mediaType& type);
|
||||
const mediaType getContentTypeHint() const;
|
||||
|
||||
private:
|
||||
|
||||
mediaType m_contentType;
|
||||
|
||||
// Equals to NO_ENCODING if data is not encoded, otherwise this
|
||||
// specifies the encoding that have been used to encode the data.
|
||||
vmime::encoding m_encoding;
|
||||
|
@ -79,8 +79,13 @@ public:
|
||||
|
||||
bool isBuffered() const;
|
||||
|
||||
void setContentTypeHint(const mediaType& type);
|
||||
const mediaType getContentTypeHint() const;
|
||||
|
||||
private:
|
||||
|
||||
mediaType m_contentType;
|
||||
|
||||
// Equals to NO_ENCODING if data is not encoded, otherwise this
|
||||
// specifies the encoding that have been used to encode the data.
|
||||
vmime::encoding m_encoding;
|
||||
|
Loading…
Reference in New Issue
Block a user