This file is part of MXE.
See index.html for further information.
Commits from master branch of git://github.com/kisli/vmime
rebased onto version 0.9.1 tarball files.
From 17ff5157ffdc749f60b8285f84e64ac5e06d4283 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Tue, 16 Nov 2010 13:28:05 +0000
Subject: [PATCH 01/42] Started version 0.9.2.
diff --git a/ChangeLog b/ChangeLog
index 871d055..8fdcdb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,12 @@
+VERSION 0.9.2svn
+================
+
+2010-11-16 Vincent Richard
+
+ * Started version 0.9.2.
+
+
VERSION 0.9.1
=============
diff --git a/SConstruct b/SConstruct
index fb01edf..55f9223 100644
--- a/SConstruct
+++ b/SConstruct
@@ -29,7 +29,7 @@ import string
# Package version number
packageVersionMajor = 0
packageVersionMinor = 9
-packageVersionMicro = 1
+packageVersionMicro = 2
# API version number (libtool)
#
--
1.7.10.4
From c12ee2b267b9dcfd092a298dfd9a8eec81ab3a0b Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Tue, 30 Nov 2010 14:57:03 +0000
Subject: [PATCH 02/42] Initialize and delete object.
diff --git a/vmime/net/imap/IMAPParser.hpp b/vmime/net/imap/IMAPParser.hpp
index 0f3e9ec..d71c3ca 100644
--- a/vmime/net/imap/IMAPParser.hpp
+++ b/vmime/net/imap/IMAPParser.hpp
@@ -3823,7 +3823,9 @@ public:
msg_att_item()
: m_date_time(NULL), m_number(NULL), m_envelope(NULL),
- m_uniqueid(NULL), m_nstring(NULL), m_body(NULL), m_flag_list(NULL)
+ m_uniqueid(NULL), m_nstring(NULL), m_body(NULL), m_flag_list(NULL),
+ m_section(NULL)
+
{
}
@@ -3836,6 +3838,7 @@ public:
delete (m_nstring);
delete (m_body);
delete (m_flag_list);
+ delete (m_section);
}
void go(IMAPParser& parser, string& line, string::size_type* currentPos)
--
1.7.10.4
From fd277afe87485c9d3377964794b76006c6d36a56 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Wed, 8 Dec 2010 08:52:54 +0000
Subject: [PATCH 03/42] No extra space between ':' and '<' in MAIL FROM and
RCPT TO. Wait for server response after QUIT and
before closing connection.
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp
index 204daae..d9fb7b8 100644
--- a/src/net/smtp/SMTPTransport.cpp
+++ b/src/net/smtp/SMTPTransport.cpp
@@ -516,6 +516,7 @@ void SMTPTransport::internalDisconnect()
try
{
sendRequest("QUIT");
+ readResponse();
}
catch (exception&)
{
@@ -565,7 +566,7 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients
// Emit the "MAIL" command
ref resp;
- sendRequest("MAIL FROM: <" + expeditor.getEmail() + ">");
+ sendRequest("MAIL FROM:<" + expeditor.getEmail() + ">");
if ((resp = readResponse())->getCode() != 250)
{
@@ -578,7 +579,7 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients
{
const mailbox& mbox = *recipients.getMailboxAt(i);
- sendRequest("RCPT TO: <" + mbox.getEmail() + ">");
+ sendRequest("RCPT TO:<" + mbox.getEmail() + ">");
if ((resp = readResponse())->getCode() != 250)
{
--
1.7.10.4
From d64da50e879c0e480d2e65c43e3b903c3e80101f Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 10 Dec 2010 16:24:06 +0000
Subject: [PATCH 04/42] Fixed unit test after bug fix.
diff --git a/tests/net/smtp/SMTPTransportTest.cpp b/tests/net/smtp/SMTPTransportTest.cpp
index 5015552..6552f9e 100644
--- a/tests/net/smtp/SMTPTransportTest.cpp
+++ b/tests/net/smtp/SMTPTransportTest.cpp
@@ -165,7 +165,7 @@ public:
}
else if (cmd == "MAIL")
{
- VASSERT_EQ("MAIL", std::string("MAIL FROM: "), line);
+ VASSERT_EQ("MAIL", std::string("MAIL FROM:"), line);
localSend("250 OK\r\n");
}
--
1.7.10.4
From 130d0aabda2a9988913ad201390796775dc16a65 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 10 Dec 2010 16:54:38 +0000
Subject: [PATCH 05/42] Fixed boundary parsing (thanks to John van der Kamp,
Zarafa).
diff --git a/src/body.cpp b/src/body.cpp
index 13dff6b..738d3e7 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -127,10 +127,30 @@ void body::parse(const string& buffer, const string::size_type position,
const string boundarySep("--" + boundary);
string::size_type partStart = position;
- string::size_type pos = buffer.find(boundarySep, position);
+ string::size_type pos = position;
bool lastPart = false;
+ while (pos != string::npos && pos < end)
+ {
+ pos = buffer.find(boundarySep, pos);
+
+ if (pos == string::npos ||
+ ((pos == 0 || buffer[pos - 1] == '\n') &&
+ (buffer[pos + boundarySep.length()] == '\r' ||
+ buffer[pos + boundarySep.length()] == '\n' ||
+ buffer[pos + boundarySep.length()] == '-'
+ )
+ )
+ )
+ {
+ break;
+ }
+
+ // boundary not a beginning of line, or just a prefix of another, continue the search.
+ pos++;
+ }
+
if (pos != string::npos && pos < end)
{
m_prologText = string(buffer.begin() + position, buffer.begin() + pos);
@@ -181,7 +201,26 @@ void body::parse(const string& buffer, const string::size_type position,
}
partStart = pos;
- pos = buffer.find(boundarySep, partStart);
+
+ while (pos != string::npos && pos < end)
+ {
+ pos = buffer.find(boundarySep, pos);
+
+ if (pos == string::npos ||
+ ((pos == 0 || buffer[pos - 1] == '\n') &&
+ (buffer[pos + boundarySep.length()] == '\r' ||
+ buffer[pos + boundarySep.length()] == '\n' ||
+ buffer[pos + boundarySep.length()] == '-'
+ )
+ )
+ )
+ {
+ break;
+ }
+
+ // boundary not a beginning of line, or just a prefix of another, continue the search.
+ pos++;
+ }
}
m_contents = vmime::create ();
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index 12c4f74..df2bf85 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -84,7 +84,7 @@ VMIME_TEST_SUITE_BEGIN
vmime::string str =
"Content-Type: multipart/mixed; boundary=\"MY-BOUNDARY\""
"\r\n\r\n"
- "--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1"
+ "--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1\r\n"
"--MY-BOUNDARY\r\nHEADER2\r\n\r\nBODY2";
vmime::bodyPart p;
--
1.7.10.4
From c63f37c888798f0e7e99aa03afda16445a72b7b2 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 21 Jan 2011 15:28:06 +0000
Subject: [PATCH 06/42] Fixed possible infinite loop (thanks to John van der
Kamp, Zarafa).
diff --git a/src/word.cpp b/src/word.cpp
index db720dc..1c1c1a6 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -386,7 +386,7 @@ void word::generate(utility::outputStream& os, const string::size_type maxLineLe
maxRunLength = std::max(maxRunLength, curRunLength);
- if (maxRunLength >= maxLineLength - 3)
+ if (((flags & text::FORCE_NO_ENCODING) == 0) && maxRunLength >= maxLineLength - 3)
{
// Generate with encoding forced
generate(os, maxLineLength, curLinePos, newLinePos, flags | text::FORCE_ENCODING, state);
diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp
index b84f376..746ac94 100644
--- a/tests/parser/textTest.cpp
+++ b/tests/parser/textTest.cpp
@@ -52,6 +52,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testWhitespaceMBox)
VMIME_TEST(testFoldingAscii)
+ VMIME_TEST(testForcedNonEncoding)
VMIME_TEST_LIST_END
@@ -442,5 +443,15 @@ VMIME_TEST_SUITE_BEGIN
" =?us-ascii?Q?9012345678901234567890123456789?=", w.generate(50));
}
+ void testForcedNonEncoding()
+ {
+ // Testing long unbreakable and unencodable header
+ vmime::relay r;
+ r.parse(" from User (Ee9GMqZQ8t7IQwftfAFHd2KyScCYRrFSJ50tKEoXv2bVCG4HcPU80GGWiFabAvG77FekpGgF1h@[127.0.0.1]) by servername.hostname.com\n\t"
+ "with esmtp id 1NGTS9-2C0sqG0; Fri, 4 Dec 2009 09:23:49 +0100");
+
+ VASSERT_EQ("received.long", "from User\r\n (Ee9GMqZQ8t7IQwftfAFHd2KyScCYRrFSJ50tKEoXv2bVCG4HcPU80GGWiFabAvG77FekpGgF1h@[127.0.0.1])\r\n by servername.hostname.com with esmtp id 1NGTS9-2C0sqG0; Fri, 4 Dec 2009\r\n 09:23:49 +0100", r.generate(78));
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From 1fafad8f913e700b350e6915de8be710fc2d1ced Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 28 Jan 2011 12:11:08 +0000
Subject: [PATCH 07/42] Fixed possible read to invalid memory location (thanks
to Alexander Konovalov).
diff --git a/src/word.cpp b/src/word.cpp
index 1c1c1a6..fa08d33 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -460,7 +460,7 @@ void word::generate(utility::outputStream& os, const string::size_type maxLineLe
os << string(curLineStart, p);
- if (parserHelpers::isSpace(*(p - 1)))
+ if (p != m_buffer.begin() && parserHelpers::isSpace(*(p - 1)))
state->lastCharIsSpace = true;
else
state->lastCharIsSpace = false;
--
1.7.10.4
From 73298423f695d7c4441d44619e4b7f9de75f566e Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Wed, 9 Mar 2011 18:03:31 +0000
Subject: [PATCH 08/42] Fixed bug #3174903. Fixed word parsing when buffer
does not end with NL. Fixed 'no encoding' when
forced.
diff --git a/src/body.cpp b/src/body.cpp
index 738d3e7..8596833 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -153,7 +153,10 @@ void body::parse(const string& buffer, const string::size_type position,
if (pos != string::npos && pos < end)
{
- m_prologText = string(buffer.begin() + position, buffer.begin() + pos);
+ vmime::text text;
+ text.parse(buffer, position, pos);
+
+ m_prologText = text.getWholeBuffer();
}
for (int index = 0 ; !lastPart && (pos != string::npos) && (pos < end) ; ++index)
@@ -246,7 +249,10 @@ void body::parse(const string& buffer, const string::size_type position,
// Treat remaining text as epilog
else if (partStart < end)
{
- m_epilogText = string(buffer.begin() + partStart, buffer.begin() + end);
+ vmime::text text;
+ text.parse(buffer, partStart, end);
+
+ m_epilogText = text.getWholeBuffer();
}
}
// Treat the contents as 'simple' data
@@ -333,7 +339,7 @@ void body::generate(utility::outputStream& os, const string::size_type maxLineLe
if (!prologText.empty())
{
- text prolog(word(prologText, getCharset()));
+ text prolog(prologText, vmime::charset("us-ascii"));
prolog.encodeAndFold(os, maxLineLength, 0,
NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);
@@ -356,7 +362,7 @@ void body::generate(utility::outputStream& os, const string::size_type maxLineLe
if (!epilogText.empty())
{
- text epilog(word(epilogText, getCharset()));
+ text epilog(epilogText, vmime::charset("us-ascii"));
epilog.encodeAndFold(os, maxLineLength, 0,
NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);
diff --git a/src/word.cpp b/src/word.cpp
index fa08d33..aeaa737 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -102,7 +102,9 @@ ref word::parseNext(const string& buffer, const string::size_type positio
++pos;
unencoded += buffer.substr(startPos, endPos - startPos);
- unencoded += ' ';
+
+ if (pos != end) // ignore white-spaces at end
+ unencoded += ' ';
startPos = pos;
continue;
@@ -191,14 +193,15 @@ ref word::parseNext(const string& buffer, const string::size_type positio
++pos;
}
- // Treat unencoded text at the end of the buffer
- if (end != startPos)
- {
- if (startPos != pos && !isFirst && prevIsEncoded)
- unencoded += whiteSpaces;
+ if (startPos != end && !isFirst && prevIsEncoded)
+ unencoded += whiteSpaces;
+ if (startPos != end)
unencoded += buffer.substr(startPos, end - startPos);
+ // Treat unencoded text at the end of the buffer
+ if (!unencoded.empty())
+ {
ref w = vmime::create (unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, end);
@@ -337,12 +340,14 @@ void word::generate(utility::outputStream& os, const string::size_type maxLineLe
state = &defaultGeneratorState;
// Find out if encoding is forced or required by contents + charset
- bool encodingNeeded = (flags & text::FORCE_ENCODING) != 0;
+ bool encodingNeeded = false;
- if (encodingNeeded == false)
- encodingNeeded = wordEncoder::isEncodingNeeded(m_buffer, m_charset);
- else if ((flags & text::FORCE_NO_ENCODING) != 0)
+ if ((flags & text::FORCE_NO_ENCODING) != 0)
encodingNeeded = false;
+ else if ((flags & text::FORCE_ENCODING) != 0)
+ encodingNeeded = true;
+ else // auto-detect
+ encodingNeeded = wordEncoder::isEncodingNeeded(m_buffer, m_charset);
// If possible and requested (with flag), quote the buffer (no folding is performed).
// Quoting is possible if and only if:
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index df2bf85..b129913 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -34,6 +34,8 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testParse)
VMIME_TEST(testGenerate)
VMIME_TEST(testParseMissingLastBoundary)
+ VMIME_TEST(testPrologEpilog)
+ VMIME_TEST(testPrologEncoding)
VMIME_TEST_LIST_END
@@ -105,5 +107,79 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("1", "Foo: bar\r\n\r\nBaz", p1.generate());
}
+ void testPrologEpilog()
+ {
+ const char testMail[] =
+ "To: test@vmime.org\r\n"
+ "From: test@vmime.org\r\n"
+ "Subject: Prolog and epilog test\r\n"
+ "Content-Type: multipart/mixed; \r\n"
+ " boundary=\"=_boundary\"\r\n"
+ "\r\n"
+ "Prolog text\r\n"
+ "--=_boundary\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "Part1\r\n"
+ "--=_boundary--\r\n"
+ "Epilog text";
+
+ vmime::bodyPart part;
+ part.parse(testMail);
+
+ VASSERT_EQ("prolog", "Prolog text", part.getBody()->getPrologText());
+ VASSERT_EQ("epilog", "Epilog text", part.getBody()->getEpilogText());
+ }
+
+ // Test for bug fix: prolog should not be encoded
+ // http://sourceforge.net/tracker/?func=detail&atid=525568&aid=3174903&group_id=69724
+ void testPrologEncoding()
+ {
+ const char testmail[] =
+ "To: test@vmime.org\r\n"
+ "From: test@vmime.org\r\n"
+ "Subject: Prolog encoding test\r\n"
+ "Content-Type: multipart/mixed; \r\n"
+ " boundary=\"=_+ZWjySayKqSf2CyrfnNpaAcO6-G1HpoXdHZ4YyswAWqEY39Q\"\r\n"
+ "\r\n"
+ "This is a multi-part message in MIME format. Your mail reader does not\r\n"
+ "understand MIME message format.\r\n"
+ "--=_+ZWjySayKqSf2CyrfnNpaAcO6-G1HpoXdHZ4YyswAWqEY39Q\r\n"
+ "Content-Type: text/html; charset=windows-1251\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "=DD=F2=EE =F2=E5=EA=F1=F2=EE=E2=E0=FF =F7=E0=F1=F2=FC =F1=EB=EE=E6=ED=EE=E3=\r\n"
+ "=EE =F1=EE=EE=E1=F9=E5=ED=E8=FF\r\n"
+ "--=_+ZWjySayKqSf2CyrfnNpaAcO6-G1HpoXdHZ4YyswAWqEY39Q\r\n"
+ "Content-Type: application/octet-stream; charset=windows-1251\r\n"
+ "Content-Disposition: attachment; filename=FNS.zip\r\n"
+ "Content-Transfer-Encoding: base64\r\n"
+ "\r\n"
+ "UEsDBB...snap...EEAAAAAA==\r\n"
+ "--=_+ZWjySayKqSf2CyrfnNpaAcO6-G1HpoXdHZ4YyswAWqEY39Q--\r\n"
+ "Epilog text";
+
+ vmime::ref msg = vmime::create();
+
+ std::string istr(testmail);
+
+ std::string ostr;
+ vmime::utility::outputStreamStringAdapter out(ostr);
+
+ for (int i = 0 ; i < 10 ; ++i)
+ {
+ ostr.clear();
+
+ msg->parse(istr);
+ msg->generate(out);
+
+ istr = ostr;
+ }
+
+ VASSERT_EQ("prolog", "This is a multi-part message in MIME format. Your mail reader"
+ " does not understand MIME message format.", msg->getBody()->getPrologText());
+ VASSERT_EQ("epilog", "Epilog text", msg->getBody()->getEpilogText());
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From 5f5757b9d4bb0febb1e2183578eb91e801a08038 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 27 Mar 2011 11:26:55 +0000
Subject: [PATCH 09/42] Allow static linking in mingw-cross-env. Added 'iconv'
and uses 'ws2_32' instead of 'winsock32' (#3213487).
diff --git a/SConstruct b/SConstruct
index 55f9223..177f5b4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1089,7 +1089,7 @@ def generateAutotools(target, source, env):
vmime_pc_in.write("Description: " + packageDescription + "\n")
vmime_pc_in.write("Version: @VERSION@\n")
vmime_pc_in.write("Requires: @GSASL_REQUIRED@\n")
- vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
+ vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
#vmime_pc_in.write("Cflags: -I${includedir}/@GENERIC_VERSIONED_LIBRARY_NAME@\n")
vmime_pc_in.write("Cflags: -I${includedir}/ @LIBGNUTLS_CFLAGS@\n")
vmime_pc_in.close()
@@ -1709,7 +1709,7 @@ fi
# -- Link with Winsock (Windows)
if test "x$VMIME_DETECT_PLATFORM" = "xwindows"; then
- VMIME_ADDITIONAL_PC_LIBS="$VMIME_ADDITIONAL_PC_LIBS -lwsock32"
+ VMIME_ADDITIONAL_PC_LIBS="$VMIME_ADDITIONAL_PC_LIBS -lws2_32"
fi
# -- getaddrinfo (POSIX)
--
1.7.10.4
From 2b48b4a68ce3e9b9b1a3f485123af5938a568324 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 31 Mar 2011 19:13:03 +0000
Subject: [PATCH 10/42] Flush stateful data from iconv (thanks to John van der
Kamp, Zarafa).
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp
index 38b9e5e..2135788 100644
--- a/src/charsetConverter.cpp
+++ b/src/charsetConverter.cpp
@@ -119,6 +119,7 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream&
size_t inPos = 0;
bool prevIsInvalid = false;
+ bool breakAfterNext = false;
while (true)
{
@@ -126,11 +127,12 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream&
size_t inLength = static_cast (in.read(inBuffer + inPos, sizeof(inBuffer) - inPos) + inPos);
size_t outLength = sizeof(outBuffer);
- const char* inPtr = inBuffer;
+ const char* inPtr = breakAfterNext ? NULL : inBuffer;
+ size_t *ptrLength = breakAfterNext ? NULL : &inLength;
char* outPtr = outBuffer;
// Convert input bytes
- if (iconv(cd, ICONV_HACK(&inPtr), &inLength,
+ if (iconv(cd, ICONV_HACK(&inPtr), ptrLength,
&outPtr, &outLength) == static_cast (-1))
{
// Illegal input sequence or input sequence has no equivalent
@@ -170,9 +172,12 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream&
prevIsInvalid = false;
}
- // Check for end of data
- if (in.eof() && inPos == 0)
+ if (breakAfterNext)
break;
+
+ // Check for end of data, loop again to flush stateful data from iconv
+ if (in.eof() && inPos == 0)
+ breakAfterNext = true;
}
}
diff --git a/tests/parser/charsetTest.cpp b/tests/parser/charsetTest.cpp
index 8ad71d7..54a09a7 100644
--- a/tests/parser/charsetTest.cpp
+++ b/tests/parser/charsetTest.cpp
@@ -100,6 +100,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testFilterValid1)
VMIME_TEST(testFilterValid2)
VMIME_TEST(testFilterValid3)
+ VMIME_TEST(testEncodingHebrew1255)
// Test invalid input
VMIME_TEST(testFilterInvalid1)
@@ -227,6 +228,15 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("1", toHex(expectedOut), toHex(actualOut));
}
+ void testEncodingHebrew1255()
+ {
+ // hewbrew string in windows-1255 charset
+ const char data[] = "\xe9\xf9\xf7\xf8\xe9\xf9\xf8\xf7\xe9\xe9\xf9";
+ vmime::word w = vmime::word(data, "windows-1255");
+ vmime::string encoded = w.generate();
+ // less than 60% ascii, base64 received
+ VASSERT_EQ("1", "=?windows-1255?B?6fn3+On5+Pfp6fk=?=", encoded);
+ }
// Conversion to hexadecimal for easier debugging
static const vmime::string toHex(const vmime::string str)
--
1.7.10.4
From 8d2e039c5201e144ff08e2ff7cf9efe77fe4b3d0 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 10 Jun 2011 19:39:09 +0000
Subject: [PATCH 11/42] Requested email change.
diff --git a/AUTHORS b/AUTHORS
index 20a0181..bbddb30 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -21,7 +21,7 @@ AUTHORS file.
- Rafael Fernandez
- Xin Li
- Benjamin Biron
- - Bertrand Benoit
+ - Bertrand Benoit
- Tim Teulings
- Georg Sauthoff
- Pierre Thierry (patches for STL algorithms)
--
1.7.10.4
From cc6317f28ae0b61fea36e1bc78b09dc8300579f8 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Tue, 14 Jun 2011 18:37:54 +0000
Subject: [PATCH 12/42] Fixed compilation issue following namespace change.
diff --git a/examples/example7.cpp b/examples/example7.cpp
index 1ddb3d0..243b1da 100644
--- a/examples/example7.cpp
+++ b/examples/example7.cpp
@@ -43,18 +43,18 @@ int main()
vmime::platform::setHandler();
// Enumerate encoders
- vmime::encoderFactory* ef = vmime::encoderFactory::getInstance();
+ vmime::utility::encoder::encoderFactory* ef = vmime::utility::encoder::encoderFactory::getInstance();
std::cout << "Available encoders:" << std::endl;
for (int i = 0 ; i < ef->getEncoderCount() ; ++i)
{
- vmime::ref
+ vmime::ref
enc = ef->getEncoderAt(i);
std::cout << " * " << enc->getName() << std::endl;
- vmime::ref e = enc->create();
+ vmime::ref e = enc->create();
std::vector props = e->getAvailableProperties();
--
1.7.10.4
From a916d12d44ac43fc8e4729e0a91f4d6243f29a11 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 19 Jun 2011 17:51:33 +0000
Subject: [PATCH 13/42] Fixed parsing of an attachment filename that is
between 66 and 76 characters long (Zarafa).
diff --git a/src/parameter.cpp b/src/parameter.cpp
index 91a7e5c..f59d5ab 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -281,7 +281,8 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
bool needQuoting = false;
string::size_type valueLength = 0;
- for (string::size_type i = 0 ; (i < value.length()) && (pos + valueLength < maxLineLength - 4) ; ++i, ++valueLength)
+ // Use worst-case length name.length()+2 for 'name=' part of line
+ for (string::size_type i = 0 ; (i < value.length()) && (pos + name.length() + 2 + valueLength < maxLineLength - 4) ; ++i, ++valueLength)
{
switch (value[i])
{
--
1.7.10.4
From 9735165c57000a6368e91ce8852206a20930c1ca Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 19 Jun 2011 18:08:12 +0000
Subject: [PATCH 14/42] Correctly generate attachment names which are long and
have high characters for Outlook Express (Zarafa).
diff --git a/src/parameter.cpp b/src/parameter.cpp
index f59d5ab..d757e1b 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -268,17 +268,19 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
// value is to be generated.
// A stream for a temporary storage
- std::ostringstream sevenBitBuffer;
+ std::string sevenBitBuffer;
+ utility::outputStreamStringAdapter sevenBitStream(sevenBitBuffer);
string::size_type pos = curLinePos;
if (pos + name.length() + 10 + value.length() > maxLineLength)
{
- sevenBitBuffer << NEW_LINE_SEQUENCE;
+ sevenBitStream << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
bool needQuoting = false;
+ bool needQuotedPrintable = false;
string::size_type valueLength = 0;
// Use worst-case length name.length()+2 for 'name=' part of line
@@ -308,6 +310,16 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
needQuoting = true;
break;
+
+ default:
+
+ if (!parserHelpers::isAscii(value[i]))
+ {
+ needQuotedPrintable = true;
+ needQuoting = true;
+ }
+
+ break;
}
}
@@ -315,12 +327,12 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
if (needQuoting)
{
- sevenBitBuffer << name << "=\"";
+ sevenBitStream << name << "=\"";
pos += name.length() + 2;
}
else
{
- sevenBitBuffer << name << "=";
+ sevenBitStream << name << "=";
pos += name.length() + 1;
}
@@ -332,29 +344,43 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
const bool alwaysEncode = m_value.getCharset().getRecommendedEncoding(recommendedEnc);
bool extended = alwaysEncode;
- for (string::size_type i = 0 ; (i < value.length()) && (pos < maxLineLength - 4) ; ++i)
+ if (needQuotedPrintable)
{
- const char_t c = value[i];
-
- if (/* needQuoting && */ (c == '"' || c == '\\')) // 'needQuoting' is implicit
- {
- sevenBitBuffer << '\\' << value[i]; // escape 'x' with '\x'
- pos += 2;
- }
- else if (parserHelpers::isAscii(c))
- {
- sevenBitBuffer << value[i];
- ++pos;
- }
- else
+ // Send the name in quoted-printable, so outlook express et.al.
+ // will understand the real filename
+ size_t oldLen = sevenBitBuffer.length();
+ m_value.generate(sevenBitStream);
+ pos += sevenBitBuffer.length() - oldLen;
+ extended = true; // also send with RFC-2231 encoding
+ }
+ else
+ {
+ // Do not chop off this value, but just add the complete name as one header line.
+ for (string::size_type i = 0 ; i < value.length() ; ++i)
{
- extended = true;
+ const char_t c = value[i];
+
+ if (/* needQuoting && */ (c == '"' || c == '\\')) // 'needQuoting' is implicit
+ {
+ sevenBitStream << '\\' << value[i]; // escape 'x' with '\x'
+ pos += 2;
+ }
+ else if (parserHelpers::isAscii(c))
+ {
+ sevenBitStream << value[i];
+ ++pos;
+ }
+ else
+ {
+ extended = true;
+ }
}
- }
+
+ } // !needQuotedPrintable
if (needQuoting)
{
- sevenBitBuffer << '"';
+ sevenBitStream << '"';
++pos;
}
@@ -532,7 +558,7 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
// "7bit/us-ascii" will suffice in this case.
// Output what has been stored in temporary buffer so far
- os << sevenBitBuffer.str();
+ os << sevenBitBuffer;
}
#endif // !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
--
1.7.10.4
From 8d69ad6849d8d6b211674942157f2af8bcd51c26 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 19 Jun 2011 18:16:49 +0000
Subject: [PATCH 15/42] Alias for UTF-7 charset.
diff --git a/src/charset.cpp b/src/charset.cpp
index e043186..0fda450 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -45,6 +45,9 @@ charset::charset()
charset::charset(const string& name)
: m_name(name)
{
+ // If we receive this rfc-1642 valid MIME charset, convert it to something usefull for iconv
+ if (utility::stringUtils::isStringEqualNoCase(m_name, "unicode-1-1-utf-7"))
+ m_name = "utf-7";
}
@@ -60,6 +63,10 @@ void charset::parse(const string& buffer, const string::size_type position,
m_name = utility::stringUtils::trim
(string(buffer.begin() + position, buffer.begin() + end));
+ // If we parsed this rfc-1642 valid MIME charset, convert it to something usefull for iconv
+ if (utility::stringUtils::isStringEqualNoCase(m_name, "unicode-1-1-utf-7"))
+ m_name = "utf-7";
+
setParsedBounds(position, end);
if (newPosition)
--
1.7.10.4
From ccd95daf9cdd7171fc2027afa5d0ad80b0475ded Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 19 Jun 2011 18:39:35 +0000
Subject: [PATCH 16/42] Fixed messageBuilder to accept an empty mailbox group
in 'To:' field, to allow for undisclosed-recipients
(Zarafa).
diff --git a/src/messageBuilder.cpp b/src/messageBuilder.cpp
index 870d59e..3597b3a 100644
--- a/src/messageBuilder.cpp
+++ b/src/messageBuilder.cpp
@@ -51,17 +51,15 @@ ref messageBuilder::construct() const
// Generate the header fields
msg->getHeader()->Subject()->setValue(m_subject);
- if (m_from.isEmpty())
- throw exceptions::no_expeditor();
-
- if ((m_to.isEmpty() || m_to.getAddressAt(0)->isEmpty()) &&
+ if (((m_to.isEmpty()) || (m_to.getAddressAt(0)->isEmpty() && !m_to.getAddressAt(0)->isGroup())) &&
(m_cc.isEmpty() || m_cc.getAddressAt(0)->isEmpty()) &&
(m_bcc.isEmpty() || m_bcc.getAddressAt(0)->isEmpty()))
{
throw exceptions::no_recipient();
}
- msg->getHeader()->From()->setValue(m_from);
+ if (!m_from.isEmpty())
+ msg->getHeader()->From()->setValue(m_from);
if (!m_to.isEmpty())
msg->getHeader()->To()->setValue(m_to);
--
1.7.10.4
From 583e25bcdee132e53e0792cd8f0d8e535cabb743 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 19 Jun 2011 18:49:55 +0000
Subject: [PATCH 17/42] Added support for mailboxes that specify an (encoded)
full name with an empty email address, set by a <>
marker (Zarafa).
diff --git a/src/mailbox.cpp b/src/mailbox.cpp
index 5cb0139..fea7479 100644
--- a/src/mailbox.cpp
+++ b/src/mailbox.cpp
@@ -88,6 +88,7 @@ void mailbox::parse(const string& buffer, const string::size_type position,
// Temporary buffers for extracted name and address
string name;
string address;
+ bool hadBrackets = false;
while (p < pend)
{
@@ -283,6 +284,7 @@ void mailbox::parse(const string& buffer, const string::size_type position,
}
else if (*p == '>')
{
+ hadBrackets = true;
break;
}
else if (!parserHelpers::isSpace(*p))
@@ -309,7 +311,7 @@ void mailbox::parse(const string& buffer, const string::size_type position,
// Swap name and address when no address was found
// (email address is mandatory, whereas name is optional).
- if (address.empty() && !name.empty())
+ if (address.empty() && !name.empty() && !hadBrackets)
{
m_email.clear();
m_email.reserve(name.size());
diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp
index 8411daa..9ebadca 100644
--- a/tests/parser/mailboxTest.cpp
+++ b/tests/parser/mailboxTest.cpp
@@ -32,6 +32,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testParse)
+ VMIME_TEST(testEmptyEmailAddress)
VMIME_TEST_LIST_END
@@ -113,5 +114,19 @@ VMIME_TEST_SUITE_BEGIN
}
}
+ void testEmptyEmailAddress()
+ {
+ vmime::addressList addrList;
+ addrList.parse("\"Full Name\" <>");
+
+ VASSERT_EQ("count", 1, addrList.getAddressCount());
+ VASSERT_EQ("!group", false, addrList.getAddressAt(0)->isGroup());
+
+ vmime::ref mbox = addrList.getAddressAt(0).dynamicCast ();
+
+ VASSERT_EQ("name", "Full Name", mbox->getName());
+ VASSERT_EQ("email", "", mbox->getEmail());
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From 461b92f84d5c16b297d33610fcd89fc7ca5a161a Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 24 Jun 2011 15:46:23 +0000
Subject: [PATCH 18/42] Added missing libs in pkg-config file.
diff --git a/SConstruct b/SConstruct
index 177f5b4..37c0ac6 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1089,7 +1089,7 @@ def generateAutotools(target, source, env):
vmime_pc_in.write("Description: " + packageDescription + "\n")
vmime_pc_in.write("Version: @VERSION@\n")
vmime_pc_in.write("Requires: @GSASL_REQUIRED@\n")
- vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
+ vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
#vmime_pc_in.write("Cflags: -I${includedir}/@GENERIC_VERSIONED_LIBRARY_NAME@\n")
vmime_pc_in.write("Cflags: -I${includedir}/ @LIBGNUTLS_CFLAGS@\n")
vmime_pc_in.close()
--
1.7.10.4
From 2b2c0abd02a17ccff7d49e266b9854f4ea47f8e4 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sat, 25 Jun 2011 17:07:53 +0000
Subject: [PATCH 19/42] Fixed parsing of empty body parts (thanks to John van
der Kamp, from Zarafa).
diff --git a/src/body.cpp b/src/body.cpp
index 8596833..9d7d57f 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -197,6 +197,11 @@ void body::parse(const string& buffer, const string::size_type position,
{
ref part = vmime::create ();
+ // End before start may happen on empty bodyparts (directly
+ // successive boundaries without even a line-break)
+ if (partEnd < partStart)
+ std::swap(partStart, partEnd);
+
part->parse(buffer, partStart, partEnd, NULL);
part->m_parent = m_part;
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index b129913..075b8f9 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -36,6 +36,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testParseMissingLastBoundary)
VMIME_TEST(testPrologEpilog)
VMIME_TEST(testPrologEncoding)
+ VMIME_TEST(testSuccessiveBoundaries)
VMIME_TEST_LIST_END
@@ -181,5 +182,23 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("epilog", "Epilog text", msg->getBody()->getEpilogText());
}
+ void testSuccessiveBoundaries()
+ {
+ vmime::string str =
+ "Content-Type: multipart/mixed; boundary=\"MY-BOUNDARY\""
+ "\r\n\r\n"
+ "--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1\r\n"
+ "--MY-BOUNDARY\r\n"
+ "--MY-BOUNDARY--\r\n";
+
+ vmime::bodyPart p;
+ p.parse(str);
+
+ VASSERT_EQ("count", 2, p.getBody()->getPartCount());
+
+ VASSERT_EQ("part1-body", "BODY1", extractContents(p.getBody()->getPartAt(0)->getBody()->getContents()));
+ VASSERT_EQ("part2-body", "", extractContents(p.getBody()->getPartAt(1)->getBody()->getContents()));
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From 2648d744da0e2e744c7959999ac513c3016072b4 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 26 Jun 2011 08:19:11 +0000
Subject: [PATCH 20/42] Use gnutls_priority_set_direct() instead of GNUTLS
deprecated functions.
diff --git a/SConstruct b/SConstruct
index 37c0ac6..01ad3f3 100644
--- a/SConstruct
+++ b/SConstruct
@@ -816,6 +816,7 @@ else:
config_hpp.write('// -- TLS/SSL support\n')
if env['with_tls'] == 'yes':
config_hpp.write('#define VMIME_HAVE_TLS_SUPPORT 1\n')
+ config_hpp.write('#define HAVE_GNUTLS_PRIORITY_FUNCS 1\n')
else:
config_hpp.write('#define VMIME_HAVE_TLS_SUPPORT 0\n')
@@ -1626,11 +1627,42 @@ if test "x$conf_tls" = "xyes"; then
else
AC_MSG_ERROR(can't find an usable version of GNU TLS library)
fi
+
+ # -- check for gnutls_priority_set_direct() function
+ if test "x$have_gnutls" = "xyes"; then
+ AC_MSG_CHECKING(for gnutls_priority_set_direct)
+
+ LIBS_save="$LIBS"
+ LIBS="$LIBS $LIBGNUTLS_LIBS"
+ CPPFLAGS_save="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $LIBGNUTLS_CFLAGS"
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ],
+ [gnutls_session s; gnutls_priority_set_direct(s, NULL, NULL);])],
+ [have_gnutls_priority_funcs=yes],
+ [have_gnutls_priority_funcs=no])
+
+ CPPFLAGS="$CPPFLAGS_save"
+ LIBS="$LIBS_save"
+
+ AC_MSG_RESULT([$have_gnutls_priority_funcs])
+
+ if test "x$have_gnutls_priority_funcs" = "xyes"; then
+ AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, true)
+ HAVE_GNUTLS_PRIORITY_FUNCS=1
+ else
+ AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, false)
+ HAVE_GNUTLS_PRIORITY_FUNCS=0
+ fi
+ fi
else
AM_CONDITIONAL(VMIME_HAVE_TLS_SUPPORT, false)
VMIME_HAVE_TLS_SUPPORT=0
fi
+AC_SUBST(LIBGNUTLS_CFLAGS)
+AC_SUBST(LIBGNUTLS_LIBS)
+
# ** platform handlers
VMIME_BUILTIN_PLATFORMS=''
@@ -1919,6 +1951,7 @@ typedef unsigned ${VMIME_TYPE_INT32} vmime_uint32;
#define VMIME_HAVE_SASL_SUPPORT ${VMIME_HAVE_SASL_SUPPORT}
// -- TLS support
#define VMIME_HAVE_TLS_SUPPORT ${VMIME_HAVE_TLS_SUPPORT}
+#define HAVE_GNUTLS_PRIORITY_FUNCS ${HAVE_GNUTLS_PRIORITY_FUNCS}
// -- Messaging support
#define VMIME_HAVE_MESSAGING_FEATURES ${VMIME_HAVE_MESSAGING_FEATURES}
""")
diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
index 010c007..af73a05 100644
--- a/src/net/tls/TLSSession.cpp
+++ b/src/net/tls/TLSSession.cpp
@@ -123,6 +123,21 @@ TLSSession::TLSSession(ref cv)
// Sets some default priority on the ciphers, key exchange methods,
// macs and compression methods.
+#if HAVE_GNUTLS_PRIORITY_FUNCS
+
+ if ((res = gnutls_priority_set_direct
+ (*m_gnutlsSession, "NORMAL:%SSL3_RECORD_VERSION", NULL)) != 0)
+ {
+ if ((res = gnutls_priority_set_direct
+ (*m_gnutlsSession, "NORMAL", NULL)) != 0)
+ {
+ throwTLSException
+ ("gnutls_priority_set_direct", res);
+ }
+ }
+
+#else // !HAVE_GNUTLS_PRIORITY_FUNCS
+
gnutls_set_default_priority(*m_gnutlsSession);
// Sets the priority on the certificate types supported by gnutls.
@@ -197,6 +212,8 @@ TLSSession::TLSSession(ref cv)
gnutls_compression_set_priority(*m_gnutlsSession, compressionPriority);
+#endif // !HAVE_GNUTLS_PRIORITY_FUNCS
+
// Initialize credentials
gnutls_credentials_set(*m_gnutlsSession,
GNUTLS_CRD_ANON, g_gnutlsGlobal.anonCred);
--
1.7.10.4
From 1060121ffd4315c3158ffc001040f4f705514e7a Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 26 Jun 2011 12:47:25 +0000
Subject: [PATCH 21/42] Fixed encoding of whitespace. Fixed old test case.
diff --git a/src/text.cpp b/src/text.cpp
index 2454456..66c3b35 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -320,12 +320,6 @@ void text::createFromString(const string& in, const charset& ch)
}
else
{
- if (count)
- {
- ref w = getWordAt(getWordCount() - 1);
- w->getBuffer() += ' ';
- }
-
appendWord(vmime::create
(chunk, charset(charsets::US_ASCII)));
diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp
index 746ac94..43ec836 100644
--- a/tests/parser/textTest.cpp
+++ b/tests/parser/textTest.cpp
@@ -53,6 +53,8 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testFoldingAscii)
VMIME_TEST(testForcedNonEncoding)
+
+ VMIME_TEST(testBugFix20110511)
VMIME_TEST_LIST_END
@@ -149,7 +151,7 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("2.1", 3, t2.getWordCount());
VASSERT_EQ("2.2", "some ASCII characters and special chars: ", t2.getWordAt(0)->getBuffer());
VASSERT_EQ("2.3", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(0)->getCharset());
- VASSERT_EQ("2.4", "\xf1\xf2\xf3\xf4 ", t2.getWordAt(1)->getBuffer());
+ VASSERT_EQ("2.4", "\xf1\xf2\xf3\xf4", t2.getWordAt(1)->getBuffer());
VASSERT_EQ("2.5", c2, t2.getWordAt(1)->getCharset());
VASSERT_EQ("2.6", "and then more ASCII chars.", t2.getWordAt(2)->getBuffer());
VASSERT_EQ("2.7", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(2)->getCharset());
@@ -453,5 +455,43 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("received.long", "from User\r\n (Ee9GMqZQ8t7IQwftfAFHd2KyScCYRrFSJ50tKEoXv2bVCG4HcPU80GGWiFabAvG77FekpGgF1h@[127.0.0.1])\r\n by servername.hostname.com with esmtp id 1NGTS9-2C0sqG0; Fri, 4 Dec 2009\r\n 09:23:49 +0100", r.generate(78));
}
+ void testBugFix20110511()
+ {
+ /*
+
+ Using the latest version of vmime (0.9.1), encoding the following string: Jean
+ Gwenaël Dutourd will result in:
+ Jean =?utf-8?Q?Gwena=C3=ABl_?= Dutourd
+ However, decoding this will result in Jean Gwenaël Dutourd (notice two spaces
+ between the last 2 words). The encoder adds a _ after the second word, but
+ since the last word is not encoded, the space between them is not ignored, and
+ is decoded into an additional space.
+
+ See: http://sourceforge.net/projects/vmime/forums/forum/237357/topic/4531365
+
+ */
+
+ const std::string DECODED_TEXT = "Jean Gwenaël Dutourd";
+ const std::string ENCODED_TEXT = "Jean =?utf-8?Q?Gwena=C3=ABl?= Dutourd";
+
+ // Encode
+ VASSERT_EQ("encode", ENCODED_TEXT,
+ vmime::text::newFromString(DECODED_TEXT, vmime::charset("utf-8"))->generate());
+
+ // Decode
+ vmime::text t;
+ t.parse(ENCODED_TEXT);
+
+ // -- words
+ std::ostringstream oss; oss << t;
+ VASSERT_EQ("decode1",
+ "[text: [[word: charset=us-ascii, buffer=Jean ],"
+ "[word: charset=utf-8, buffer=Gwenaël],"
+ "[word: charset=us-ascii, buffer= Dutourd]]]", oss.str());
+
+ // -- getWholeBuffer
+ VASSERT_EQ("decode2", DECODED_TEXT, t.getWholeBuffer());
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From dc6dc039fc0edccf4630894fa6ed8cd4bf3bb3ce Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sat, 20 Aug 2011 06:35:06 +0000
Subject: [PATCH 22/42] Use gnutls_strerror() for reporting errors.
diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
index af73a05..7426a73 100644
--- a/src/net/tls/TLSSession.cpp
+++ b/src/net/tls/TLSSession.cpp
@@ -41,6 +41,9 @@
//#define GNUTLS_DEBUG 1
+#include
+#include
+
#if VMIME_DEBUG && GNUTLS_DEBUG
#include
#endif // VMIME_DEBUG && GNUTLS_DEBUG
@@ -257,119 +260,14 @@ ref TLSSession::getCertificateVerifier()
void TLSSession::throwTLSException(const string& fname, const int code)
{
- string msg = fname + "() returned ";
-
-#define ERROR(x) \
- case x: msg += #x; break;
-
- switch (code)
- {
- ERROR(GNUTLS_E_SUCCESS)
- ERROR(GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM)
- ERROR(GNUTLS_E_UNKNOWN_CIPHER_TYPE)
- ERROR(GNUTLS_E_LARGE_PACKET)
- ERROR(GNUTLS_E_UNSUPPORTED_VERSION_PACKET)
- ERROR(GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
- ERROR(GNUTLS_E_INVALID_SESSION)
- ERROR(GNUTLS_E_FATAL_ALERT_RECEIVED)
- ERROR(GNUTLS_E_UNEXPECTED_PACKET)
- ERROR(GNUTLS_E_WARNING_ALERT_RECEIVED)
- ERROR(GNUTLS_E_ERROR_IN_FINISHED_PACKET)
- ERROR(GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET)
- ERROR(GNUTLS_E_UNKNOWN_CIPHER_SUITE)
- ERROR(GNUTLS_E_UNWANTED_ALGORITHM)
- ERROR(GNUTLS_E_MPI_SCAN_FAILED)
- ERROR(GNUTLS_E_DECRYPTION_FAILED)
- ERROR(GNUTLS_E_MEMORY_ERROR)
- ERROR(GNUTLS_E_DECOMPRESSION_FAILED)
- ERROR(GNUTLS_E_COMPRESSION_FAILED)
- ERROR(GNUTLS_E_AGAIN)
- ERROR(GNUTLS_E_EXPIRED)
- ERROR(GNUTLS_E_DB_ERROR)
- ERROR(GNUTLS_E_SRP_PWD_ERROR)
- ERROR(GNUTLS_E_INSUFFICIENT_CREDENTIALS)
- ERROR(GNUTLS_E_HASH_FAILED)
- ERROR(GNUTLS_E_BASE64_DECODING_ERROR)
- ERROR(GNUTLS_E_MPI_PRINT_FAILED)
- ERROR(GNUTLS_E_REHANDSHAKE)
- ERROR(GNUTLS_E_GOT_APPLICATION_DATA)
- ERROR(GNUTLS_E_RECORD_LIMIT_REACHED)
- ERROR(GNUTLS_E_ENCRYPTION_FAILED)
- ERROR(GNUTLS_E_PK_ENCRYPTION_FAILED)
- ERROR(GNUTLS_E_PK_DECRYPTION_FAILED)
- ERROR(GNUTLS_E_PK_SIGN_FAILED)
- ERROR(GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION)
- ERROR(GNUTLS_E_KEY_USAGE_VIOLATION)
- ERROR(GNUTLS_E_NO_CERTIFICATE_FOUND)
- ERROR(GNUTLS_E_INVALID_REQUEST)
- ERROR(GNUTLS_E_SHORT_MEMORY_BUFFER)
- ERROR(GNUTLS_E_INTERRUPTED)
- ERROR(GNUTLS_E_PUSH_ERROR)
- ERROR(GNUTLS_E_PULL_ERROR)
- ERROR(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER)
- ERROR(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
- ERROR(GNUTLS_E_PKCS1_WRONG_PAD)
- ERROR(GNUTLS_E_RECEIVED_ILLEGAL_EXTENSION)
- ERROR(GNUTLS_E_INTERNAL_ERROR)
- ERROR(GNUTLS_E_DH_PRIME_UNACCEPTABLE)
- ERROR(GNUTLS_E_FILE_ERROR)
- ERROR(GNUTLS_E_TOO_MANY_EMPTY_PACKETS)
- ERROR(GNUTLS_E_UNKNOWN_PK_ALGORITHM)
- ERROR(GNUTLS_E_INIT_LIBEXTRA)
- ERROR(GNUTLS_E_LIBRARY_VERSION_MISMATCH)
- ERROR(GNUTLS_E_NO_TEMPORARY_RSA_PARAMS)
- ERROR(GNUTLS_E_LZO_INIT_FAILED)
- ERROR(GNUTLS_E_NO_COMPRESSION_ALGORITHMS)
- ERROR(GNUTLS_E_NO_CIPHER_SUITES)
- ERROR(GNUTLS_E_OPENPGP_GETKEY_FAILED)
- ERROR(GNUTLS_E_PK_SIG_VERIFY_FAILED)
- ERROR(GNUTLS_E_ILLEGAL_SRP_USERNAME)
- ERROR(GNUTLS_E_SRP_PWD_PARSING_ERROR)
- ERROR(GNUTLS_E_NO_TEMPORARY_DH_PARAMS)
- ERROR(GNUTLS_E_ASN1_ELEMENT_NOT_FOUND)
- ERROR(GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND)
- ERROR(GNUTLS_E_ASN1_DER_ERROR)
- ERROR(GNUTLS_E_ASN1_VALUE_NOT_FOUND)
- ERROR(GNUTLS_E_ASN1_GENERIC_ERROR)
- ERROR(GNUTLS_E_ASN1_VALUE_NOT_VALID)
- ERROR(GNUTLS_E_ASN1_TAG_ERROR)
- ERROR(GNUTLS_E_ASN1_TAG_IMPLICIT)
- ERROR(GNUTLS_E_ASN1_TYPE_ANY_ERROR)
- ERROR(GNUTLS_E_ASN1_SYNTAX_ERROR)
- ERROR(GNUTLS_E_ASN1_DER_OVERFLOW)
- //ERROR(GNUTLS_E_OPENPGP_TRUSTDB_VERSION_UNSUPPORTED)
- ERROR(GNUTLS_E_OPENPGP_UID_REVOKED)
- ERROR(GNUTLS_E_CERTIFICATE_ERROR)
- //ERROR(GNUTLS_E_X509_CERTIFICATE_ERROR)
- ERROR(GNUTLS_E_CERTIFICATE_KEY_MISMATCH)
- ERROR(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE)
- ERROR(GNUTLS_E_X509_UNKNOWN_SAN)
- ERROR(GNUTLS_E_OPENPGP_FINGERPRINT_UNSUPPORTED)
- ERROR(GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE)
- ERROR(GNUTLS_E_UNKNOWN_HASH_ALGORITHM)
- ERROR(GNUTLS_E_UNKNOWN_PKCS_CONTENT_TYPE)
- ERROR(GNUTLS_E_UNKNOWN_PKCS_BAG_TYPE)
- ERROR(GNUTLS_E_INVALID_PASSWORD)
- ERROR(GNUTLS_E_MAC_VERIFY_FAILED)
- ERROR(GNUTLS_E_CONSTRAINT_ERROR)
- ERROR(GNUTLS_E_BASE64_ENCODING_ERROR)
- ERROR(GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY)
- //ERROR(GNUTLS_E_INCOMPATIBLE_CRYPTO_LIBRARY)
- ERROR(GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY)
- ERROR(GNUTLS_E_OPENPGP_KEYRING_ERROR)
- ERROR(GNUTLS_E_X509_UNSUPPORTED_OID)
- //ERROR(GNUTLS_E_RANDOM_FAILED)
- ERROR(GNUTLS_E_UNIMPLEMENTED_FEATURE)
-
- default:
-
- msg += "unknown error";
- break;
- }
+ std::ostringstream msg;
-#undef ERROR
+ msg << fname + "() returned code ";
+ msg << std::hex << code;
+ msg << ": ";
+ msg << gnutls_strerror(code);
- throw exceptions::tls_exception(msg);
+ throw exceptions::tls_exception(msg.str());
}
--
1.7.10.4
From 7ea6fc3737ef36407e1c90f3aa05f89a39bdefb7 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 21 Aug 2011 08:55:46 +0000
Subject: [PATCH 23/42] Removed dependency on gcrypt for gnutls version >=
2.12.
diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
index 7426a73..d3f6d49 100644
--- a/src/net/tls/TLSSession.cpp
+++ b/src/net/tls/TLSSession.cpp
@@ -26,9 +26,17 @@
#include "vmime/config.hpp"
+// Dependency on gcrypt is not needed since GNU TLS version 2.12.
+// See here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=638651
+#if GNUTLS_VERSION_NUMBER <= 0x020b00
+# define VMIME_GNUTLS_NEEDS_GCRYPT 1
+#endif
+
#if VMIME_HAVE_PTHREAD
# include
-# include
+# if VMIME_GNUTLS_NEEDS_GCRYPT
+# include
+# endif
# include
#endif // VMIME_HAVE_PTHREAD
@@ -49,7 +57,7 @@
#endif // VMIME_DEBUG && GNUTLS_DEBUG
-#if VMIME_HAVE_PTHREAD && defined(GCRY_THREAD_OPTION_PTHREAD_IMPL)
+#if VMIME_HAVE_PTHREAD && VMIME_GNUTLS_NEEDS_GCRYPT && defined(GCRY_THREAD_OPTION_PTHREAD_IMPL)
extern "C"
{
GCRY_THREAD_OPTION_PTHREAD_IMPL;
@@ -70,7 +78,9 @@ struct TLSGlobal
TLSGlobal()
{
#if VMIME_HAVE_PTHREAD && defined(GCRY_THREAD_OPTION_PTHREAD_IMPL)
+ #if VMIME_GNUTLS_NEEDS_GCRYPT
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+ #endif // VMIME_GNUTLS_NEEDS_GCRYPT
#endif // VMIME_HAVE_PTHREAD && defined(GCRY_THREAD_OPTION_PTHREAD_IMPL
gnutls_global_init();
--
1.7.10.4
From f21c55be642b166a2f0518ace2b179bed3916b23 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sun, 21 Aug 2011 09:04:46 +0000
Subject: [PATCH 24/42] Fixed HAVE_GNUTLS_PRIORITY_FUNCS never defined when
configured with no TLS support.
diff --git a/SConstruct b/SConstruct
index 01ad3f3..11e884b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1654,10 +1654,16 @@ if test "x$conf_tls" = "xyes"; then
AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, false)
HAVE_GNUTLS_PRIORITY_FUNCS=0
fi
+ else
+ AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, false)
+ HAVE_GNUTLS_PRIORITY_FUNCS=0
fi
else
AM_CONDITIONAL(VMIME_HAVE_TLS_SUPPORT, false)
VMIME_HAVE_TLS_SUPPORT=0
+
+ AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, false)
+ HAVE_GNUTLS_PRIORITY_FUNCS=0
fi
AC_SUBST(LIBGNUTLS_CFLAGS)
--
1.7.10.4
From d4e66226a696745adafa1767210580f8fbb7ae00 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Tue, 15 Nov 2011 11:40:42 +0000
Subject: [PATCH 25/42] GNU TLS 3 has no 'extra' (thanks to mabrand).
diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
index d3f6d49..cb50acc 100644
--- a/src/net/tls/TLSSession.cpp
+++ b/src/net/tls/TLSSession.cpp
@@ -22,7 +22,9 @@
//
#include
+#if GNUTLS_VERSION_NUMBER < 0x030000
#include
+#endif
#include "vmime/config.hpp"
--
1.7.10.4
From bacbe512e406d22f6acc83597fcdfc2d624cf82b Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Tue, 15 Nov 2011 11:46:07 +0000
Subject: [PATCH 26/42] Set Diffie-Hellman prime size (bug SF#3434852).
diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
index cb50acc..0606808 100644
--- a/src/net/tls/TLSSession.cpp
+++ b/src/net/tls/TLSSession.cpp
@@ -139,6 +139,7 @@ TLSSession::TLSSession(ref cv)
// Sets some default priority on the ciphers, key exchange methods,
// macs and compression methods.
#if HAVE_GNUTLS_PRIORITY_FUNCS
+ gnutls_dh_set_prime_bits(*m_gnutlsSession, 128);
if ((res = gnutls_priority_set_direct
(*m_gnutlsSession, "NORMAL:%SSL3_RECORD_VERSION", NULL)) != 0)
--
1.7.10.4
From 6574b60a303c5d864e840aa23959656bb2803485 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 22 Dec 2011 08:51:28 +0000
Subject: [PATCH 27/42] Updated coding conventions.
diff --git a/HACKING b/HACKING
index 4f35a53..f51d738 100644
--- a/HACKING
+++ b/HACKING
@@ -1,10 +1,10 @@
-This file contains coding guidelines for VMime. You should follow these
-guidelines if you want to contribute to VMime. It guarantees some minimal
-quality of the code.
+This file contains coding guidelines for VMime. You should follow them
+if you want to contribute to VMime. The rules below are not guidelines
+or recommendations, but strict rules.
-1. General guidelines
+1. General rules
1.1. Language
1.2. Unit tests
1.3. CVS
@@ -18,19 +18,22 @@ quality of the code.
2.5. Line length
2.6. Spaces and parentheses
2.7. End-of-line character
+ 2.8. Short functions
+ 2.9. Limit Variable Scope
3. Naming conventions
3.1. Classes
3.2. Variables/parameters/member variables
3.3. Member variables
3.4. Files
3.5. Namespaces
+ 3.6. Constants
4. Comments
5. Miscellaneous
-1. General guidelines
-=====================
+1. General rules
+================
1.1. Language
-------------
@@ -50,7 +53,7 @@ When you fix a bug, also add a new test case to ensure the bug will not
happen anymore.
-1.3. CVS
+1.3. SVN
--------
Each commit MUST be done with a message ('-m' flag) that briefly describes what
@@ -154,7 +157,11 @@ Except when body spans over multiple lines:
2.5. Line length
----------------
-Line length should not exceed 80 characters.
+Each line of text should not exceed 80 characters.
+
+Exception: if a comment line contains an example command or a literal URL
+longer than 100 characters, that line may be longer than 100 characters
+for ease of cut and paste.
2.6. Spaces and parentheses
@@ -193,6 +200,30 @@ Configure your editor to use "\n" (UNIX convention) for end-of-line sequence,
and not "\r\n" (Windows), nor "\n\r", nor any other combination.
+2.8. Short functions
+--------------------
+
+To the extent that it is feasible, functions should be kept small and focused.
+It is, however, recognized that long functions are sometimes appropriate, so no
+hard limit is placed on method length. If a function exceeds 40 lines or so,
+think about whether it can be broken up without harming the structure of the
+program.
+
+
+2.9. Limit Variable Scope
+-------------------------
+
+The scope of local variables should be kept to a minimum. By doing so, you
+increase the readability and maintainability of your code and reduce the
+likelihood of error. Each variable should be declared in the innermost block
+that encloses all uses of the variable.
+
+Local variables should be declared at the point they are first used. Nearly
+every local variable declaration should contain an initializer. If you don't
+yet have enough information to initialize a variable sensibly, you should
+postpone the declaration until you do.
+
+
3. Naming conventions
=====================
@@ -255,6 +286,12 @@ Implementation files must be placed in 'src/' directory.
Namespaces are named exactly like variables.
+3.6. Constants
+--------------
+
+Constants are ALL_CAPS_WITH_UNDERSCORES.
+
+
4. Comments
===========
--
1.7.10.4
From 130e5223dea0af2f8d9d01cca7845be4e1a08d13 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 11:46:39 +0200
Subject: [PATCH 28/42] Added function to retrieve sequence numbers of
messages whose UID is greater or equal than a
specified UID (thanks to Zahi Mashael).
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 0122d21..50a2f2b 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -1772,6 +1772,62 @@ void IMAPFolder::status(int& count, int& unseen)
}
+std::vector IMAPFolder::getMessageNumbersStartingOnUID(const message::uid& uid)
+{
+ std::vector v;
+
+ std::ostringstream command;
+ command.imbue(std::locale::classic());
+
+ command << "SEARCH UID " << uid;
+
+ // Send the request
+ m_connection->send(true, command.str(), true);
+
+ // Get the response
+ utility::auto_ptr resp(m_connection->readResponse());
+
+ if (resp->isBad() ||
+ resp->response_done()->response_tagged()->resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
+ {
+ throw exceptions::command_error("SEARCH",
+ m_connection->getParser()->lastLine(), "bad response");
+ }
+
+ const std::vector & respDataList = resp->continue_req_or_response_data();
+
+ for (std::vector ::const_iterator
+ it = respDataList.begin() ; it != respDataList.end() ; ++it)
+ {
+ if ((*it)->response_data() == NULL)
+ {
+ throw exceptions::command_error("SEARCH",
+ m_connection->getParser()->lastLine(), "invalid response");
+ }
+
+ const IMAPParser::mailbox_data* mailboxData =
+ (*it)->response_data()->mailbox_data();
+
+ // We are only interested in responses of type "SEARCH"
+ if (mailboxData == NULL ||
+ mailboxData->type() != IMAPParser::mailbox_data::SEARCH)
+ {
+ continue;
+ }
+
+ for (std::vector ::const_iterator
+ it = mailboxData->search_nz_number_list().begin() ;
+ it != mailboxData->search_nz_number_list().end();
+ ++it)
+ {
+ v.push_back((*it)->value());
+ }
+ }
+
+ return v;
+}
+
+
} // imap
} // net
} // vmime
diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp
index dd680c9..d11ae3b 100644
--- a/src/net/maildir/maildirFolder.cpp
+++ b/src/net/maildir/maildirFolder.cpp
@@ -1363,6 +1363,12 @@ const utility::file::path maildirFolder::getMessageFSPath(const int number) cons
}
+std::vector maildirFolder::getMessageNumbersStartingOnUID(const message::uid& /* uid */)
+{
+ throw exceptions::operation_not_supported();
+}
+
+
} // maildir
} // net
} // vmime
diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp
index d5fc687..e085609 100644
--- a/src/net/pop3/POP3Folder.cpp
+++ b/src/net/pop3/POP3Folder.cpp
@@ -843,6 +843,12 @@ void POP3Folder::expunge()
}
+std::vector POP3Folder::getMessageNumbersStartingOnUID(const message::uid& /* uid */)
+{
+ throw exceptions::operation_not_supported();
+}
+
+
} // pop3
} // net
} // vmime
diff --git a/vmime/net/folder.hpp b/vmime/net/folder.hpp
index b20e9c9..df9cbaf 100644
--- a/vmime/net/folder.hpp
+++ b/vmime/net/folder.hpp
@@ -383,6 +383,13 @@ public:
*/
virtual int getFetchCapabilities() const = 0;
+ /** Return the sequence numbers of messages whose UID equal or greater than uid
+ *
+ * @param uid the uid of the first message
+ * @throw net_exception if an error occurs
+ */
+ virtual std::vector getMessageNumbersStartingOnUID(const message::uid& uid) = 0;
+
// Event listeners
void addMessageChangedListener(events::messageChangedListener* l);
void removeMessageChangedListener(events::messageChangedListener* l);
diff --git a/vmime/net/imap/IMAPFolder.hpp b/vmime/net/imap/IMAPFolder.hpp
index dec3878..cc52596 100644
--- a/vmime/net/imap/IMAPFolder.hpp
+++ b/vmime/net/imap/IMAPFolder.hpp
@@ -120,6 +120,8 @@ public:
int getFetchCapabilities() const;
+ std::vector getMessageNumbersStartingOnUID(const message::uid& uid);
+
private:
void registerMessage(IMAPMessage* msg);
diff --git a/vmime/net/maildir/maildirFolder.hpp b/vmime/net/maildir/maildirFolder.hpp
index 7474b1a..68b5b89 100644
--- a/vmime/net/maildir/maildirFolder.hpp
+++ b/vmime/net/maildir/maildirFolder.hpp
@@ -121,6 +121,8 @@ public:
int getFetchCapabilities() const;
+ std::vector getMessageNumbersStartingOnUID(const message::uid& uid);
+
private:
void scanFolder();
diff --git a/vmime/net/pop3/POP3Folder.hpp b/vmime/net/pop3/POP3Folder.hpp
index abaa8eb..c482908 100644
--- a/vmime/net/pop3/POP3Folder.hpp
+++ b/vmime/net/pop3/POP3Folder.hpp
@@ -119,6 +119,8 @@ public:
int getFetchCapabilities() const;
+ std::vector getMessageNumbersStartingOnUID(const message::uid& uid);
+
private:
void registerMessage(POP3Message* msg);
--
1.7.10.4
From 3f1a565b8b532f0d11a13d3f6d763b00c8ce625b Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 11:55:07 +0200
Subject: [PATCH 29/42] Added .gitignore.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..44e03a8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*.o
+*.swp
+build/
+
+/libvmime.a
+/vmime.pc
+/vmime/config.hpp
+
+# SConstruct
+.sconsign.dblite
+/options.cache
--
1.7.10.4
From 5937bcda0fac9cb80d0cecbaa663ecdfe2839c09 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 12:08:01 +0200
Subject: [PATCH 30/42] Added check before dereferencing.
diff --git a/vmime/utility/smartPtr.hpp b/vmime/utility/smartPtr.hpp
index c448632..df63685 100644
--- a/vmime/utility/smartPtr.hpp
+++ b/vmime/utility/smartPtr.hpp
@@ -338,7 +338,9 @@ protected:
{
if (m_ptr)
{
- m_ptr->getRefManager()->releaseStrong();
+ if (m_ptr->getRefManager())
+ m_ptr->getRefManager()->releaseStrong();
+
m_ptr = 0;
}
}
--
1.7.10.4
From b0d74ce63ea9563ef4b218bce2497bd668dfad29 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 12:34:51 +0200
Subject: [PATCH 31/42] Updated README.
diff --git a/README b/README
index 6921cea..7db9175 100644
--- a/README
+++ b/README
@@ -1,2 +1,30 @@
-TODO
+VMime is a powerful C++ class library for working with RFC-822 and MIME messages
+and Internet messaging services like IMAP, POP or SMTP.
+
+With VMime you can parse, generate and modify messages, and also connect to store
+and transport services to receive or send messages over the Internet. The library
+offers all the features to build a complete mail client.
+
+Key Features
+------------
+
+* it is free software! GNU GPL license (Commercial licenses available!)
+* fully RFC-compliant implementation
+* object-oriented and modular design
+* very easy-to-use (intuitive design)
+* well documented code
+* very high reliability
+* maximum portability
+
+Features Overview
+-----------------
+
+* RFC-2822 and multipart messages
+* aggregate documents and embedded objects
+* 8-bit MIME and encoded word extensions
+* full support for attachments
+* POP3, IMAP, SMTP, maildir and sendmail
+* SSL/TLS security layer and X.509 certificates (using GNU TLS)
+* SASL authentication (using GNU SASL)
+
--
1.7.10.4
From 350fada21a4f11c2f633a3cde1f2195efefe7e32 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 22:10:54 +0200
Subject: [PATCH 32/42] Added test: Ensure '7bit' encoding is used when body
is 7-bit only.
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index 075b8f9..e1d47a3 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -37,6 +37,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testPrologEpilog)
VMIME_TEST(testPrologEncoding)
VMIME_TEST(testSuccessiveBoundaries)
+ VMIME_TEST(testGenerate7bit)
VMIME_TEST_LIST_END
@@ -200,5 +201,18 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("part2-body", "", extractContents(p.getBody()->getPartAt(1)->getBody()->getContents()));
}
+ /** Ensure '7bit' encoding is used when body is 7-bit only. */
+ void testGenerate7bit()
+ {
+ vmime::ref p1 = vmime::create ();
+ p1->setText(vmime::create ("Part1 is US-ASCII only."));
+
+ vmime::ref msg = vmime::create ();
+ p1->generateIn(msg, msg);
+
+ vmime::ref header1 = msg->getBody()->getPartAt(0)->getHeader();
+ VASSERT_EQ("1", "7bit", header1->ContentTransferEncoding()->getValue()->generate());
+ }
+
VMIME_TEST_SUITE_END
--
1.7.10.4
From 6c877ea41a2e408df61ac6f988c3bae7e0821141 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 22:29:32 +0200
Subject: [PATCH 33/42] Added tests for Quoted-Printable encoding.
diff --git a/tests/utility/encoderTest.cpp b/tests/utility/encoderTest.cpp
index f2d42b6..b2d6bc8 100644
--- a/tests/utility/encoderTest.cpp
+++ b/tests/utility/encoderTest.cpp
@@ -33,6 +33,8 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST_LIST_BEGIN
VMIME_TEST(testBase64)
VMIME_TEST(testQuotedPrintable)
+ VMIME_TEST(testQuotedPrintable_SoftLineBreaks)
+ VMIME_TEST(testQuotedPrintable_CRLF)
VMIME_TEST(testQuotedPrintable_RFC2047)
VMIME_TEST_LIST_END
@@ -288,6 +290,35 @@ VMIME_TEST_SUITE_BEGIN
}
}
+ /** Tests Soft Line Breaks (RFC-2047/6.7(5). */
+ void testQuotedPrintable_SoftLineBreaks()
+ {
+ VASSERT_EQ("1", "Now's the time=\r\n"
+ " for all folk =\r\n"
+ "to come to the=\r\n"
+ " aid of their =\r\n"
+ "country.",
+ encode("quoted-printable", "Now's the time for all folk "
+ "to come to the aid of their country.", 15));
+ }
+
+ /** In text mode, ensure line breaks in QP-encoded text are represented
+ * by a CRLF sequence, as per RFC-2047/6.7(4). */
+ void testQuotedPrintable_CRLF()
+ {
+ vmime::propertySet encProps;
+
+ // in "text" mode
+ encProps["text"] = true;
+ VASSERT_EQ("text", "line1\r\nline2",
+ encode("quoted-printable", "line1\r\nline2", 80, encProps));
+
+ // in "binary" mode
+ encProps["text"] = false;
+ VASSERT_EQ("binary", "line1=0D=0Aline2",
+ encode("quoted-printable", "line1\r\nline2", 80, encProps));
+ }
+
void testQuotedPrintable_RFC2047()
{
/*
--
1.7.10.4
From e88f062ab58654aee3cf45f94e8a5dd6c1256279 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Thu, 5 Apr 2012 23:15:04 +0200
Subject: [PATCH 34/42] Fixed wrong encoding of line breaks in QP-encoded text
(issue #7).
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 0919d44..b4e79db 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -34,19 +34,28 @@ namespace vmime
encoding::encoding()
- : m_name(encodingTypes::SEVEN_BIT)
+ : m_name(encodingTypes::SEVEN_BIT),
+ m_usage(USAGE_UNKNOWN)
{
}
encoding::encoding(const string& name)
- : m_name(utility::stringUtils::toLower(name))
+ : m_name(utility::stringUtils::toLower(name)),
+ m_usage(USAGE_UNKNOWN)
+{
+}
+
+
+encoding::encoding(const string& name, const EncodingUsage usage)
+ : m_name(utility::stringUtils::toLower(name)),
+ m_usage(usage)
{
}
encoding::encoding(const encoding& enc)
- : headerFieldValue(), m_name(enc.m_name)
+ : headerFieldValue(), m_name(enc.m_name), m_usage(enc.m_usage)
{
}
@@ -54,6 +63,8 @@ encoding::encoding(const encoding& enc)
void encoding::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
+ m_usage = USAGE_UNKNOWN;
+
m_name = utility::stringUtils::toLower(utility::stringUtils::trim
(utility::stringUtils::unquote(utility::stringUtils::trim
(string(buffer.begin() + position, buffer.begin() + end)))));
@@ -80,7 +91,14 @@ void encoding::generate(utility::outputStream& os, const string::size_type /* ma
ref encoding::getEncoder() const
{
- return (utility::encoder::encoderFactory::getInstance()->create(generate()));
+ ref encoder =
+ utility::encoder::encoderFactory::getInstance()->create(generate());
+
+ // FIXME: this should not be here (move me into QP encoder instead?)
+ if (m_usage == USAGE_TEXT && m_name == encodingTypes::QUOTED_PRINTABLE)
+ encoder->getProperties()["text"] = true;
+
+ return encoder;
}
@@ -94,6 +112,7 @@ encoding& encoding::operator=(const encoding& other)
encoding& encoding::operator=(const string& name)
{
m_name = utility::stringUtils::toLower(name);
+ m_usage = USAGE_UNKNOWN;
return (*this);
}
@@ -167,6 +186,8 @@ const encoding encoding::decideImpl
const encoding encoding::decide
(ref data, const EncodingUsage usage)
{
+ encoding enc;
+
if (usage == USAGE_TEXT && data->isBuffered() &&
data->getLength() > 0 && data->getLength() < 32768)
{
@@ -177,12 +198,16 @@ const encoding encoding::decide
data->extract(os);
os.flush();
- return decideImpl(buffer.begin(), buffer.end());
+ enc = decideImpl(buffer.begin(), buffer.end());
}
else
{
- return encoding(encodingTypes::BASE64);
+ enc = encoding(encodingTypes::BASE64);
}
+
+ enc.setUsage(usage);
+
+ return enc;
}
@@ -194,7 +219,10 @@ const encoding encoding::decide(ref data,
encoding recEncoding;
if (chset.getRecommendedEncoding(recEncoding))
+ {
+ recEncoding.setUsage(usage);
return recEncoding;
+ }
}
return decide(data, usage);
@@ -227,6 +255,18 @@ void encoding::setName(const string& name)
}
+encoding::EncodingUsage encoding::getUsage() const
+{
+ return m_usage;
+}
+
+
+void encoding::setUsage(const EncodingUsage usage)
+{
+ m_usage = usage;
+}
+
+
const std::vector [ > encoding::getChildComponents() const
{
return std::vector ][ >();
diff --git a/src/utility/encoder/qpEncoder.cpp b/src/utility/encoder/qpEncoder.cpp
index aa95022..ab8db2e 100644
--- a/src/utility/encoder/qpEncoder.cpp
+++ b/src/utility/encoder/qpEncoder.cpp
@@ -292,14 +292,15 @@ utility::stream::size_type qpEncoder::encode(utility::inputStream& in,
case 13: // CR
case 10: // LF
{
- // Text mode (where using CRLF or LF or ... does not
- // care for a new line...)
- if (text)
+ // RFC-2045/6.7(4)
+
+ // Text data
+ if (text && !rfc2047)
{
outBuffer[outBufferPos++] = c;
++curCol;
}
- // Binary mode (where CR and LF bytes are important!)
+ // Binary data
else
{
QP_ENCODE_HEX(c);
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index e1d47a3..9d51262 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -38,6 +38,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testPrologEncoding)
VMIME_TEST(testSuccessiveBoundaries)
VMIME_TEST(testGenerate7bit)
+ VMIME_TEST(testTextUsageForQPEncoding)
VMIME_TEST_LIST_END
@@ -214,5 +215,28 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("1", "7bit", header1->ContentTransferEncoding()->getValue()->generate());
}
+ void testTextUsageForQPEncoding()
+ {
+ vmime::ref part = vmime::create ();
+ part->setText(vmime::create ("Part1-line1\r\nPart1-line2\r\n\x89"));
+
+ vmime::ref msg = vmime::create ();
+ part->generateIn(msg, msg);
+
+ vmime::ref body = msg->getBody()->getPartAt(0)->getBody();
+ vmime::ref header = msg->getBody()->getPartAt(0)->getHeader();
+
+ std::ostringstream oss;
+ vmime::utility::outputStreamAdapter os(oss);
+ body->generate(os, 80);
+
+ VASSERT_EQ("1", "quoted-printable", header->ContentTransferEncoding()->getValue()->generate());
+
+ // This should *NOT* be:
+ // Part1-line1=0D=0APart1-line2=0D=0A=89
+ VASSERT_EQ("2", "Part1-line1\r\nPart1-line2\r\n=89", oss.str());
+ }
+
+
VMIME_TEST_SUITE_END
diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp
index ba78081..42f5246 100644
--- a/vmime/encoding.hpp
+++ b/vmime/encoding.hpp
@@ -47,6 +47,7 @@ public:
enum EncodingUsage
{
+ USAGE_UNKNOWN,
USAGE_TEXT, /**< Use for body text. */
USAGE_BINARY_DATA /**< Use for attachment, image... */
};
@@ -54,6 +55,7 @@ public:
encoding();
explicit encoding(const string& name);
+ encoding(const string& name, const EncodingUsage usage);
encoding(const encoding& enc);
public:
@@ -72,6 +74,19 @@ public:
*/
void setName(const string& name);
+ /** Return the type of contents this encoding is used for.
+ * See the EncodingUsage enum.
+ */
+ EncodingUsage getUsage() const;
+
+ /** Set the type of contents this encoding is used for.
+ * See the EncodingUsage enum.
+ *
+ * @param usage type of contents
+ */
+ void setUsage(const EncodingUsage usage);
+
+
encoding& operator=(const encoding& other);
encoding& operator=(const string& name);
@@ -113,6 +128,7 @@ public:
private:
string m_name;
+ EncodingUsage m_usage;
/** Decide which encoding to use based on the specified data.
*
--
1.7.10.4
From ea77bdba96588345090e3de81d9d6af116edeeb5 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Fri, 6 Apr 2012 22:26:18 +0200
Subject: [PATCH 35/42] Fixed memory leak.
diff --git a/src/net/tls/TLSSocket.cpp b/src/net/tls/TLSSocket.cpp
index dab0338..3cccc1e 100644
--- a/src/net/tls/TLSSocket.cpp
+++ b/src/net/tls/TLSSocket.cpp
@@ -50,6 +50,12 @@ TLSSocket::TLSSocket(ref session, ref sok)
TLSSocket::~TLSSocket()
{
+ if (m_ex)
+ {
+ delete m_ex;
+ m_ex = NULL;
+ }
+
try
{
disconnect();
--
1.7.10.4
From 440d491fd6da134fcb5f19416743e8f2044556bf Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Sat, 14 Apr 2012 13:46:05 +0200
Subject: [PATCH 36/42] Split stream.hpp/.cpp into multiple source files.
diff --git a/SConstruct b/SConstruct
index 11e884b..ea5c4eb 100644
--- a/SConstruct
+++ b/SConstruct
@@ -144,6 +144,20 @@ libvmime_sources = [
'utility/smartPtr.cpp', 'utility/smartPtr.hpp',
'utility/smartPtrInt.cpp', 'utility/smartPtrInt.hpp',
'utility/stream.cpp', 'utility/stream.hpp',
+ 'utility/streamUtils.cpp', 'utility/streamUtils.hpp',
+ 'utility/filteredStream.cpp', 'utility/filteredStream.hpp',
+ 'utility/inputStream.cpp', 'utility/inputStream.hpp',
+ 'utility/inputStreamAdapter.cpp', 'utility/inputStreamAdapter.hpp',
+ 'utility/inputStreamByteBufferAdapter.cpp', 'utility/inputStreamByteBufferAdapter.hpp',
+ 'utility/inputStreamPointerAdapter.cpp', 'utility/inputStreamPointerAdapter.hpp',
+ 'utility/inputStreamSocketAdapter.cpp', 'utility/inputStreamSocketAdapter.hpp',
+ 'utility/inputStreamStringAdapter.cpp', 'utility/inputStreamStringAdapter.hpp',
+ 'utility/inputStreamStringProxyAdapter.cpp', 'utility/inputStreamStringProxyAdapter.hpp',
+ 'utility/outputStream.cpp', 'utility/outputStream.hpp',
+ 'utility/outputStreamAdapter.cpp', 'utility/outputStreamAdapter.hpp',
+ 'utility/outputStreamByteArrayAdapter.cpp', 'utility/outputStreamByteArrayAdapter.hpp',
+ 'utility/outputStreamSocketAdapter.cpp', 'utility/outputStreamSocketAdapter.hpp',
+ 'utility/outputStreamStringAdapter.cpp', 'utility/outputStreamStringAdapter.hpp',
'utility/stringProxy.cpp', 'utility/stringProxy.hpp',
'utility/stringUtils.cpp', 'utility/stringUtils.hpp',
'utility/url.cpp', 'utility/url.hpp',
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp
index 2135788..cf75bdd 100644
--- a/src/charsetConverter.cpp
+++ b/src/charsetConverter.cpp
@@ -23,6 +23,8 @@
#include "vmime/charsetConverter.hpp"
#include "vmime/exception.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
extern "C"
diff --git a/src/component.cpp b/src/component.cpp
index fbf677b..139cf66 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -23,6 +23,7 @@
#include "vmime/component.hpp"
#include "vmime/base.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
#include
diff --git a/src/encoding.cpp b/src/encoding.cpp
index b4e79db..5d99ab6 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -24,6 +24,7 @@
#include "vmime/encoding.hpp"
#include "vmime/contentHandler.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
#include "vmime/utility/encoder/encoderFactory.hpp"
#include
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index da7c4b7..cb23cd0 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -28,6 +28,7 @@
#include "vmime/exception.hpp"
#include "vmime/streamContentHandler.hpp"
+#include "vmime/utility/inputStreamPointerAdapter.hpp"
#include "vmime/contentDispositionField.hpp"
diff --git a/src/generatedMessageAttachment.cpp b/src/generatedMessageAttachment.cpp
index e9bd1a6..443a9d3 100644
--- a/src/generatedMessageAttachment.cpp
+++ b/src/generatedMessageAttachment.cpp
@@ -23,6 +23,8 @@
#include "vmime/generatedMessageAttachment.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp
index c845b57..98524af 100644
--- a/src/htmlTextPart.cpp
+++ b/src/htmlTextPart.cpp
@@ -31,6 +31,8 @@
#include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp
index b419b85..1dd7ff3 100644
--- a/src/mdn/MDNHelper.cpp
+++ b/src/mdn/MDNHelper.cpp
@@ -31,6 +31,8 @@
#include "vmime/path.hpp"
#include "vmime/dateTime.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/mdn/receivedMDNInfos.cpp b/src/mdn/receivedMDNInfos.cpp
index cff211c..f97a58d 100644
--- a/src/mdn/receivedMDNInfos.cpp
+++ b/src/mdn/receivedMDNInfos.cpp
@@ -23,6 +23,8 @@
#include "vmime/mdn/receivedMDNInfos.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/message.cpp b/src/message.cpp
index 6f4b046..1b4f086 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -24,6 +24,8 @@
#include "vmime/message.hpp"
#include "vmime/options.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 50a2f2b..81bf386 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -34,6 +34,8 @@
#include "vmime/exception.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include
#include
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index bc661ed..702d5f2 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -31,6 +31,8 @@
#include "vmime/net/imap/IMAPPart.hpp"
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include
#include
#include
diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp
index 4e6ba97..85c6ec2 100644
--- a/src/net/imap/IMAPMessagePartContentHandler.cpp
+++ b/src/net/imap/IMAPMessagePartContentHandler.cpp
@@ -23,6 +23,9 @@
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp
index d11ae3b..8c4b275 100644
--- a/src/net/maildir/maildirFolder.cpp
+++ b/src/net/maildir/maildirFolder.cpp
@@ -35,6 +35,9 @@
#include "vmime/exception.hpp"
#include "vmime/platform.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp
index 51cd1ba..4ab75e7 100644
--- a/src/net/maildir/maildirMessage.cpp
+++ b/src/net/maildir/maildirMessage.cpp
@@ -31,6 +31,8 @@
#include "vmime/exception.hpp"
#include "vmime/platform.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp
index 50f4f87..69ef004 100644
--- a/src/net/pop3/POP3Message.cpp
+++ b/src/net/pop3/POP3Message.cpp
@@ -25,6 +25,8 @@
#include "vmime/net/pop3/POP3Folder.hpp"
#include "vmime/net/pop3/POP3Store.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include
diff --git a/src/net/pop3/POP3Store.cpp b/src/net/pop3/POP3Store.cpp
index 9d554c6..793112a 100644
--- a/src/net/pop3/POP3Store.cpp
+++ b/src/net/pop3/POP3Store.cpp
@@ -30,6 +30,7 @@
#include "vmime/security/digest/messageDigestFactory.hpp"
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/inputStreamSocketAdapter.hpp"
#include "vmime/net/defaultConnectionInfos.hpp"
diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp
index 53ff0d1..e7762cc 100644
--- a/src/net/sendmail/sendmailTransport.cpp
+++ b/src/net/sendmail/sendmailTransport.cpp
@@ -32,6 +32,8 @@
#include "vmime/utility/childProcess.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
#include "vmime/net/defaultConnectionInfos.hpp"
#include "vmime/config.hpp"
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp
index d9fb7b8..bbbea75 100644
--- a/src/net/smtp/SMTPTransport.cpp
+++ b/src/net/smtp/SMTPTransport.cpp
@@ -30,6 +30,8 @@
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/outputStreamSocketAdapter.hpp"
+#include "vmime/utility/streamUtils.hpp"
#include "vmime/net/defaultConnectionInfos.hpp"
diff --git a/src/net/transport.cpp b/src/net/transport.cpp
index dd4663d..f8ca7b7 100644
--- a/src/net/transport.cpp
+++ b/src/net/transport.cpp
@@ -27,6 +27,9 @@
#include "vmime/mailboxList.hpp"
#include "vmime/message.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/parameter.cpp b/src/parameter.cpp
index d757e1b..ccbe1a5 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -27,6 +27,9 @@
#include "vmime/text.hpp"
#include "vmime/encoding.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+
namespace vmime
{
diff --git a/src/parsedMessageAttachment.cpp b/src/parsedMessageAttachment.cpp
index bde56aa..cb7d71d 100644
--- a/src/parsedMessageAttachment.cpp
+++ b/src/parsedMessageAttachment.cpp
@@ -26,6 +26,8 @@
#include "vmime/stringContentHandler.hpp"
#include "vmime/contentDisposition.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/security/cert/X509Certificate.cpp b/src/security/cert/X509Certificate.cpp
index 1cd079c..8df4e5e 100644
--- a/src/security/cert/X509Certificate.cpp
+++ b/src/security/cert/X509Certificate.cpp
@@ -28,6 +28,8 @@
#include "vmime/security/cert/X509Certificate.hpp"
+#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
+
namespace vmime {
namespace security {
diff --git a/src/security/sasl/SASLContext.cpp b/src/security/sasl/SASLContext.cpp
index 51c2bed..4bb33c1 100644
--- a/src/security/sasl/SASLContext.cpp
+++ b/src/security/sasl/SASLContext.cpp
@@ -33,6 +33,9 @@
#include "vmime/utility/encoder/encoderFactory.hpp"
#include "vmime/utility/stream.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
namespace vmime {
diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp
index 2ebd073..89a36b4 100644
--- a/src/streamContentHandler.cpp
+++ b/src/streamContentHandler.cpp
@@ -23,6 +23,10 @@
#include "vmime/streamContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
namespace vmime
{
diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp
index 4e85a6c..5a1e72c 100644
--- a/src/stringContentHandler.cpp
+++ b/src/stringContentHandler.cpp
@@ -23,6 +23,10 @@
#include "vmime/stringContentHandler.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/utility/encoder/defaultEncoder.cpp b/src/utility/encoder/defaultEncoder.cpp
index 4d0ffb5..e2d226e 100644
--- a/src/utility/encoder/defaultEncoder.cpp
+++ b/src/utility/encoder/defaultEncoder.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/encoder/defaultEncoder.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
namespace vmime {
namespace utility {
diff --git a/src/utility/inputStream.cpp b/src/utility/inputStream.cpp
new file mode 100644
index 0000000..dd0adf4
--- /dev/null
+++ b/src/utility/inputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamAdapter.cpp b/src/utility/inputStreamAdapter.cpp
new file mode 100644
index 0000000..b44b084
--- /dev/null
+++ b/src/utility/inputStreamAdapter.cpp
@@ -0,0 +1,70 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamAdapter::inputStreamAdapter(std::istream& is)
+ : m_stream(is)
+{
+}
+
+
+bool inputStreamAdapter::eof() const
+{
+ return (m_stream.eof());
+}
+
+
+void inputStreamAdapter::reset()
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.seekg(0, std::ios::beg);
+ m_stream.clear();
+}
+
+
+stream::size_type inputStreamAdapter::read
+ (value_type* const data, const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.read(data, count);
+ return (m_stream.gcount());
+}
+
+
+stream::size_type inputStreamAdapter::skip(const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.ignore(count);
+ return (m_stream.gcount());
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamByteBufferAdapter.cpp b/src/utility/inputStreamByteBufferAdapter.cpp
new file mode 100644
index 0000000..92e779f
--- /dev/null
+++ b/src/utility/inputStreamByteBufferAdapter.cpp
@@ -0,0 +1,90 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamByteBufferAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
+ : m_buffer(buffer), m_length(length), m_pos(0)
+{
+}
+
+
+bool inputStreamByteBufferAdapter::eof() const
+{
+ return m_pos >= m_length;
+}
+
+
+void inputStreamByteBufferAdapter::reset()
+{
+ m_pos = 0;
+}
+
+
+stream::size_type inputStreamByteBufferAdapter::read
+ (value_type* const data, const size_type count)
+{
+ const size_type remaining = m_length - m_pos;
+
+ if (remaining < count)
+ {
+ std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
+ m_pos += remaining;
+
+ return remaining;
+ }
+ else
+ {
+ std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
+ m_pos += count;
+
+ return count;
+ }
+}
+
+
+stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
+{
+ const size_type remaining = m_length - m_pos;
+
+ if (remaining < count)
+ {
+ m_pos += remaining;
+ return remaining;
+ }
+ else
+ {
+ m_pos += count;
+ return count;
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamPointerAdapter.cpp b/src/utility/inputStreamPointerAdapter.cpp
new file mode 100644
index 0000000..4d03e30
--- /dev/null
+++ b/src/utility/inputStreamPointerAdapter.cpp
@@ -0,0 +1,46 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamPointerAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
+ : inputStreamAdapter(*is), m_stream(is), m_own(own)
+{
+}
+
+
+inputStreamPointerAdapter::~inputStreamPointerAdapter()
+{
+ if (m_own)
+ delete (m_stream);
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamSocketAdapter.cpp b/src/utility/inputStreamSocketAdapter.cpp
new file mode 100644
index 0000000..b93cc3c
--- /dev/null
+++ b/src/utility/inputStreamSocketAdapter.cpp
@@ -0,0 +1,82 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamSocketAdapter.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include "vmime/net/socket.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
+ : m_socket(sok)
+{
+}
+
+
+bool inputStreamSocketAdapter::eof() const
+{
+ // Can't know...
+ return false;
+}
+
+
+void inputStreamSocketAdapter::reset()
+{
+ // Not supported
+}
+
+
+stream::size_type inputStreamSocketAdapter::read
+ (value_type* const data, const size_type count)
+{
+ return m_socket.receiveRaw(data, count);
+}
+
+
+stream::size_type inputStreamSocketAdapter::skip
+ (const size_type /* count */)
+{
+ // Not supported
+ return 0;
+}
+
+
+stream::size_type inputStreamSocketAdapter::getBlockSize()
+{
+ return m_socket.getBlockSize();
+}
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
diff --git a/src/utility/inputStreamStringAdapter.cpp b/src/utility/inputStreamStringAdapter.cpp
new file mode 100644
index 0000000..31c9fda
--- /dev/null
+++ b/src/utility/inputStreamStringAdapter.cpp
@@ -0,0 +1,94 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamStringAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
+ : m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
+{
+}
+
+
+inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
+ const string::size_type begin, const string::size_type end)
+ : m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
+{
+}
+
+
+bool inputStreamStringAdapter::eof() const
+{
+ return (m_pos >= m_end);
+}
+
+
+void inputStreamStringAdapter::reset()
+{
+ m_pos = m_begin;
+}
+
+
+stream::size_type inputStreamStringAdapter::read
+ (value_type* const data, const size_type count)
+{
+ if (m_pos + count >= m_end)
+ {
+ const size_type remaining = m_end - m_pos;
+
+ std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
+ m_pos = m_end;
+ return (remaining);
+ }
+ else
+ {
+ std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+stream::size_type inputStreamStringAdapter::skip(const size_type count)
+{
+ if (m_pos + count >= m_end)
+ {
+ const size_type remaining = m_end - m_pos;
+ m_pos = m_end;
+ return (remaining);
+ }
+ else
+ {
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamStringProxyAdapter.cpp b/src/utility/inputStreamStringProxyAdapter.cpp
new file mode 100644
index 0000000..5e4b60b
--- /dev/null
+++ b/src/utility/inputStreamStringProxyAdapter.cpp
@@ -0,0 +1,89 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/inputStreamStringProxyAdapter.hpp"
+#include "vmime/utility/stringProxy.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
+ : m_buffer(buffer), m_pos(0)
+{
+}
+
+
+bool inputStreamStringProxyAdapter::eof() const
+{
+ return (m_pos >= m_buffer.length());
+}
+
+
+void inputStreamStringProxyAdapter::reset()
+{
+ m_pos = 0;
+}
+
+
+stream::size_type inputStreamStringProxyAdapter::read
+ (value_type* const data, const size_type count)
+{
+ const size_type remaining = m_buffer.length() - m_pos;
+
+ if (count > remaining)
+ {
+ std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
+ m_pos = m_buffer.length();
+ return (remaining);
+ }
+ else
+ {
+ std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
+{
+ const size_type remaining = m_buffer.length() - m_pos;
+
+ if (count > remaining)
+ {
+ m_pos = m_buffer.length();
+ return (remaining);
+ }
+ else
+ {
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStream.cpp b/src/utility/outputStream.cpp
new file mode 100644
index 0000000..8a65db5
--- /dev/null
+++ b/src/utility/outputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/outputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamAdapter.cpp b/src/utility/outputStreamAdapter.cpp
new file mode 100644
index 0000000..2da94f1
--- /dev/null
+++ b/src/utility/outputStreamAdapter.cpp
@@ -0,0 +1,54 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/outputStreamAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamAdapter::outputStreamAdapter(std::ostream& os)
+ : m_stream(os)
+{
+}
+
+
+void outputStreamAdapter::write
+ (const value_type* const data, const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.write(data, count);
+}
+
+
+void outputStreamAdapter::flush()
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.flush();
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamByteArrayAdapter.cpp b/src/utility/outputStreamByteArrayAdapter.cpp
new file mode 100644
index 0000000..97b27d2
--- /dev/null
+++ b/src/utility/outputStreamByteArrayAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/outputStreamByteArrayAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
+ : m_array(array)
+{
+}
+
+
+void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
+{
+ m_array.insert(m_array.end(), data, data + count);
+}
+
+
+void outputStreamByteArrayAdapter::flush()
+{
+ // Do nothing
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamSocketAdapter.cpp b/src/utility/outputStreamSocketAdapter.cpp
new file mode 100644
index 0000000..d933e73
--- /dev/null
+++ b/src/utility/outputStreamSocketAdapter.cpp
@@ -0,0 +1,68 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/outputStreamSocketAdapter.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include "vmime/net/socket.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
+ : m_socket(sok)
+{
+}
+
+
+void outputStreamSocketAdapter::write
+ (const value_type* const data, const size_type count)
+{
+ m_socket.sendRaw(data, count);
+}
+
+
+void outputStreamSocketAdapter::flush()
+{
+ // Do nothing
+}
+
+
+stream::size_type outputStreamSocketAdapter::getBlockSize()
+{
+ return m_socket.getBlockSize();
+}
+
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
diff --git a/src/utility/outputStreamStringAdapter.cpp b/src/utility/outputStreamStringAdapter.cpp
new file mode 100644
index 0000000..62b2a72
--- /dev/null
+++ b/src/utility/outputStreamStringAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/outputStreamStringAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
+ : m_buffer(buffer)
+{
+}
+
+
+void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
+{
+ m_buffer.append(data, count);
+}
+
+
+void outputStreamStringAdapter::flush()
+{
+ // Do nothing
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index ec30b7d..1c940c2 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -22,503 +22,18 @@
//
#include "vmime/utility/stream.hpp"
-#include "vmime/utility/stringProxy.hpp"
-#include // for std::copy
-#include // for std::back_inserter
-
-#if VMIME_HAVE_MESSAGING_FEATURES
- #include "vmime/net/socket.hpp"
-#endif
namespace vmime {
namespace utility {
-// stream
-
stream::size_type stream::getBlockSize()
{
return 32768; // 32 KB
}
-// Helpers
-
-outputStream& operator<<(outputStream& os, const stream::value_type c)
-{
- os.write(&c, 1);
- return (os);
-}
-
-
-outputStream& operator<<(outputStream& os, const string& str)
-{
- os.write(str.data(), str.length());
- return (os);
-}
-
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
-{
- return bufferedStreamCopy(is, os, 0, NULL);
-}
-
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
- const stream::size_type length, progressListener* progress)
-{
- const stream::size_type blockSize =
- std::min(is.getBlockSize(), os.getBlockSize());
-
- std::vector vbuffer(blockSize);
-
- stream::value_type* buffer = &vbuffer.front();
- stream::size_type total = 0;
-
- if (progress != NULL)
- progress->start(length);
-
- while (!is.eof())
- {
- const stream::size_type read = is.read(buffer, blockSize);
-
- if (read != 0)
- {
- os.write(buffer, read);
- total += read;
-
- if (progress != NULL)
- progress->progress(total, std::max(total, length));
- }
- }
-
- if (progress != NULL)
- progress->stop(total);
-
- return (total);
-}
-
-
-
-// outputStreamAdapter
-
-outputStreamAdapter::outputStreamAdapter(std::ostream& os)
- : m_stream(os)
-{
-}
-
-
-void outputStreamAdapter::write
- (const value_type* const data, const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.write(data, count);
-}
-
-
-void outputStreamAdapter::flush()
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.flush();
-}
-
-
-
-// outputStreamStringAdapter
-
-outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
- : m_buffer(buffer)
-{
-}
-
-
-void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
-{
- m_buffer.append(data, count);
-}
-
-
-void outputStreamStringAdapter::flush()
-{
- // Do nothing
-}
-
-
-
-// outputStreamByteArrayAdapter
-
-outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
- : m_array(array)
-{
-}
-
-
-void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
-{
- m_array.insert(m_array.end(), data, data + count);
-}
-
-
-void outputStreamByteArrayAdapter::flush()
-{
- // Do nothing
-}
-
-
-
-// inputStreamAdapter
-
-inputStreamAdapter::inputStreamAdapter(std::istream& is)
- : m_stream(is)
-{
-}
-
-
-bool inputStreamAdapter::eof() const
-{
- return (m_stream.eof());
-}
-
-
-void inputStreamAdapter::reset()
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.seekg(0, std::ios::beg);
- m_stream.clear();
-}
-
-
-stream::size_type inputStreamAdapter::read
- (value_type* const data, const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.read(data, count);
- return (m_stream.gcount());
-}
-
-
-stream::size_type inputStreamAdapter::skip(const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.ignore(count);
- return (m_stream.gcount());
-}
-
-
-
-// inputStreamStringAdapter
-
-inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
- : m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
-{
-}
-
-
-inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
- const string::size_type begin, const string::size_type end)
- : m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
-{
-}
-
-
-bool inputStreamStringAdapter::eof() const
-{
- return (m_pos >= m_end);
-}
-
-
-void inputStreamStringAdapter::reset()
-{
- m_pos = m_begin;
-}
-
-
-stream::size_type inputStreamStringAdapter::read
- (value_type* const data, const size_type count)
-{
- if (m_pos + count >= m_end)
- {
- const size_type remaining = m_end - m_pos;
-
- std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
- m_pos = m_end;
- return (remaining);
- }
- else
- {
- std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
- m_pos += count;
- return (count);
- }
-}
-
-
-stream::size_type inputStreamStringAdapter::skip(const size_type count)
-{
- if (m_pos + count >= m_end)
- {
- const size_type remaining = m_end - m_pos;
- m_pos = m_end;
- return (remaining);
- }
- else
- {
- m_pos += count;
- return (count);
- }
-}
-
-
-
-// inputStreamStringProxyAdapter
-
-inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
- : m_buffer(buffer), m_pos(0)
-{
-}
-
-
-bool inputStreamStringProxyAdapter::eof() const
-{
- return (m_pos >= m_buffer.length());
-}
-
-
-void inputStreamStringProxyAdapter::reset()
-{
- m_pos = 0;
-}
-
-
-stream::size_type inputStreamStringProxyAdapter::read
- (value_type* const data, const size_type count)
-{
- const size_type remaining = m_buffer.length() - m_pos;
-
- if (count > remaining)
- {
- std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
- m_pos = m_buffer.length();
- return (remaining);
- }
- else
- {
- std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
- m_pos += count;
- return (count);
- }
-}
-
-
-stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
-{
- const size_type remaining = m_buffer.length() - m_pos;
-
- if (count > remaining)
- {
- m_pos = m_buffer.length();
- return (remaining);
- }
- else
- {
- m_pos += count;
- return (count);
- }
-}
-
-
-
-// inputStreamPointerAdapter
-
-inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
- : m_stream(is), m_own(own)
-{
-}
-
-
-inputStreamPointerAdapter::inputStreamPointerAdapter(const inputStreamPointerAdapter&)
- : inputStream(), m_stream(NULL), m_own(false)
-{
- // Not copiable
-}
-
-
-inputStreamPointerAdapter::~inputStreamPointerAdapter()
-{
- if (m_own)
- delete (m_stream);
-}
-
-
-bool inputStreamPointerAdapter::eof() const
-{
- return (m_stream->eof());
-}
-
-
-void inputStreamPointerAdapter::reset()
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->seekg(0, std::ios::beg);
- m_stream->clear();
-}
-
-
-stream::size_type inputStreamPointerAdapter::read
- (value_type* const data, const size_type count)
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->read(data, count);
- return (m_stream->gcount());
-}
-
-
-stream::size_type inputStreamPointerAdapter::skip(const size_type count)
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->ignore(count);
- return (m_stream->gcount());
-}
-
-
-
-// inputStreamByteBufferAdapter
-
-inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
- : m_buffer(buffer), m_length(length), m_pos(0)
-{
-}
-
-
-bool inputStreamByteBufferAdapter::eof() const
-{
- return m_pos >= m_length;
-}
-
-
-void inputStreamByteBufferAdapter::reset()
-{
- m_pos = 0;
-}
-
-
-stream::size_type inputStreamByteBufferAdapter::read
- (value_type* const data, const size_type count)
-{
- const size_type remaining = m_length - m_pos;
-
- if (remaining < count)
- {
- std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
- m_pos += remaining;
-
- return remaining;
- }
- else
- {
- std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
- m_pos += count;
-
- return count;
- }
-}
-
-
-stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
-{
- const size_type remaining = m_length - m_pos;
-
- if (remaining < count)
- {
- m_pos += remaining;
- return remaining;
- }
- else
- {
- m_pos += count;
- return count;
- }
-}
-
-
-
-#ifdef VMIME_HAVE_MESSAGING_FEATURES
-
-
-// outputStreamSocketAdapter
-
-outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
- : m_socket(sok)
-{
-}
-
-
-void outputStreamSocketAdapter::write
- (const value_type* const data, const size_type count)
-{
- m_socket.sendRaw(data, count);
-}
-
-
-void outputStreamSocketAdapter::flush()
-{
- // Do nothing
-}
-
-
-stream::size_type outputStreamSocketAdapter::getBlockSize()
-{
- return m_socket.getBlockSize();
-}
-
-
-
-// inputStreamSocketAdapter
-
-inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
- : m_socket(sok)
-{
-}
-
-
-bool inputStreamSocketAdapter::eof() const
-{
- // Can't know...
- return false;
-}
-
-
-void inputStreamSocketAdapter::reset()
-{
- // Not supported
-}
-
-
-stream::size_type inputStreamSocketAdapter::read
- (value_type* const data, const size_type count)
-{
- return m_socket.receiveRaw(data, count);
-}
-
-
-stream::size_type inputStreamSocketAdapter::skip
- (const size_type /* count */)
-{
- // Not supported
- return 0;
-}
-
-
-stream::size_type inputStreamSocketAdapter::getBlockSize()
-{
- return m_socket.getBlockSize();
-}
-
-
-#endif // VMIME_HAVE_MESSAGING_FEATURES
-
-
} // utility
} // vmime
diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp
new file mode 100644
index 0000000..f1d3b9d
--- /dev/null
+++ b/src/utility/streamUtils.cpp
@@ -0,0 +1,92 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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 "vmime/utility/streamUtils.hpp"
+
+#include // for std::copy
+#include // for std::back_inserter
+
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStream& operator<<(outputStream& os, const stream::value_type c)
+{
+ os.write(&c, 1);
+ return (os);
+}
+
+
+outputStream& operator<<(outputStream& os, const string& str)
+{
+ os.write(str.data(), str.length());
+ return (os);
+}
+
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
+{
+ return bufferedStreamCopy(is, os, 0, NULL);
+}
+
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
+ const stream::size_type length, progressListener* progress)
+{
+ const stream::size_type blockSize =
+ std::min(is.getBlockSize(), os.getBlockSize());
+
+ std::vector vbuffer(blockSize);
+
+ stream::value_type* buffer = &vbuffer.front();
+ stream::size_type total = 0;
+
+ if (progress != NULL)
+ progress->start(length);
+
+ while (!is.eof())
+ {
+ const stream::size_type read = is.read(buffer, blockSize);
+
+ if (read != 0)
+ {
+ os.write(buffer, read);
+ total += read;
+
+ if (progress != NULL)
+ progress->progress(total, std::max(total, length));
+ }
+ }
+
+ if (progress != NULL)
+ progress->stop(total);
+
+ return (total);
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp
index a4ba6d2..74344b5 100644
--- a/src/utility/stringProxy.cpp
+++ b/src/utility/stringProxy.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/stringProxy.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include
#include
diff --git a/src/word.cpp b/src/word.cpp
index aeaa737..79060a1 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -28,6 +28,9 @@
#include "vmime/utility/smartPtr.hpp"
#include "vmime/parserHelpers.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
#include "vmime/utility/encoder/encoder.hpp"
#include "vmime/utility/encoder/b64Encoder.hpp"
#include "vmime/utility/encoder/qpEncoder.hpp"
diff --git a/src/wordEncoder.cpp b/src/wordEncoder.cpp
index 67bd7a1..194a189 100644
--- a/src/wordEncoder.cpp
+++ b/src/wordEncoder.cpp
@@ -33,6 +33,9 @@
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime
{
diff --git a/vmime/base.hpp b/vmime/base.hpp
index 60e637d..b794031 100644
--- a/vmime/base.hpp
+++ b/vmime/base.hpp
@@ -35,7 +35,6 @@
#include "vmime/config.hpp"
#include "vmime/types.hpp"
#include "vmime/constants.hpp"
-#include "vmime/utility/stream.hpp"
#include "vmime/utility/smartPtr.hpp"
@@ -255,7 +254,26 @@ namespace vmime
return y.dynamicCast ();
}
+ /** Inherit from this class to indicate the subclass is not copyable,
+ * ie. you want to prohibit copy construction and copy assignment.
+ */
+ class noncopyable
+ {
+ protected:
+
+ noncopyable() { }
+ virtual ~noncopyable() { }
+
+ private:
+
+ noncopyable(const noncopyable&);
+ void operator=(const noncopyable&);
+ };
+
} // vmime
+#include "vmime/utility/stream.hpp"
+
+
#endif // VMIME_BASE_HPP_INCLUDED
diff --git a/vmime/charset.hpp b/vmime/charset.hpp
index b2e241c..5f5e8e5 100644
--- a/vmime/charset.hpp
+++ b/vmime/charset.hpp
@@ -26,6 +26,8 @@
#include "vmime/base.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
#include "vmime/component.hpp"
diff --git a/vmime/component.hpp b/vmime/component.hpp
index b38127f..12b0406 100644
--- a/vmime/component.hpp
+++ b/vmime/component.hpp
@@ -26,6 +26,8 @@
#include "vmime/base.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
namespace vmime
diff --git a/vmime/net/imap/IMAPParser.hpp b/vmime/net/imap/IMAPParser.hpp
index d71c3ca..f430510 100644
--- a/vmime/net/imap/IMAPParser.hpp
+++ b/vmime/net/imap/IMAPParser.hpp
@@ -37,6 +37,9 @@
#include "vmime/utility/encoder/b64Encoder.hpp"
#include "vmime/utility/encoder/qpEncoder.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+
#include "vmime/platform.hpp"
#include "vmime/net/timeoutHandler.hpp"
@@ -3825,7 +3828,7 @@ public:
: m_date_time(NULL), m_number(NULL), m_envelope(NULL),
m_uniqueid(NULL), m_nstring(NULL), m_body(NULL), m_flag_list(NULL),
m_section(NULL)
-
+
{
}
diff --git a/vmime/utility/filteredStream.hpp b/vmime/utility/filteredStream.hpp
index 00be785..2a55edd 100644
--- a/vmime/utility/filteredStream.hpp
+++ b/vmime/utility/filteredStream.hpp
@@ -27,7 +27,8 @@
#include
-#include "vmime/utility/stream.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
namespace vmime {
diff --git a/vmime/utility/inputStream.hpp b/vmime/utility/inputStream.hpp
new file mode 100644
index 0000000..4a76a7d
--- /dev/null
+++ b/vmime/utility/inputStream.hpp
@@ -0,0 +1,76 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
+
+
+#include "vmime/utility/stream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** Simple input stream.
+ */
+
+class inputStream : public stream
+{
+public:
+
+ /** Test for end of stream (no more data to read).
+ *
+ * @return true if we have reached the end of stream, false otherwise
+ */
+ virtual bool eof() const = 0;
+
+ /** Set the read pointer to the beginning of the stream.
+ *
+ * @warning WARNING: this may not work for all stream types.
+ */
+ virtual void reset() = 0;
+
+ /** Read data from the stream.
+ *
+ * @param data will receive the data read
+ * @param count maximum number of bytes to read
+ * @return number of bytes read
+ */
+ virtual size_type read(value_type* const data, const size_type count) = 0;
+
+ /** Skip a number of bytes.
+ *
+ * @param count maximum number of bytes to ignore
+ * @return number of bytes skipped
+ */
+ virtual size_type skip(const size_type count) = 0;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAM_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamAdapter.hpp b/vmime/utility/inputStreamAdapter.hpp
new file mode 100644
index 0000000..278ab52
--- /dev/null
+++ b/vmime/utility/inputStreamAdapter.hpp
@@ -0,0 +1,64 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+
+#include
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for C++ standard input streams.
+ */
+
+class inputStreamAdapter : public inputStream
+{
+public:
+
+ /** @param is input stream to wrap
+ */
+ inputStreamAdapter(std::istream& is);
+
+ bool eof() const;
+ void reset();
+ size_type read(value_type* const data, const size_type count);
+ size_type skip(const size_type count);
+
+private:
+
+ std::istream& m_stream;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamByteBufferAdapter.hpp b/vmime/utility/inputStreamByteBufferAdapter.hpp
new file mode 100644
index 0000000..0f6a442
--- /dev/null
+++ b/vmime/utility/inputStreamByteBufferAdapter.hpp
@@ -0,0 +1,63 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for reading from an array of bytes.
+ */
+
+class inputStreamByteBufferAdapter : public inputStream
+{
+public:
+
+ inputStreamByteBufferAdapter(const byte_t* buffer, size_type length);
+
+ bool eof() const;
+ void reset();
+ size_type read(value_type* const data, const size_type count);
+ size_type skip(const size_type count);
+
+private:
+
+ const byte_t* m_buffer;
+ const size_type m_length;
+
+ size_type m_pos;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMBYTEBUFFERADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamPointerAdapter.hpp b/vmime/utility/inputStreamPointerAdapter.hpp
new file mode 100644
index 0000000..44e9bad
--- /dev/null
+++ b/vmime/utility/inputStreamPointerAdapter.hpp
@@ -0,0 +1,63 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStreamAdapter.hpp"
+
+#include
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for pointer to C++ standard input stream.
+ */
+
+class inputStreamPointerAdapter : public inputStreamAdapter
+{
+public:
+
+ /** @param is input stream to wrap
+ * @param own if set to 'true', the pointer will be deleted when
+ * this object is destroyed
+ */
+ inputStreamPointerAdapter(std::istream* is, const bool own = true);
+ ~inputStreamPointerAdapter();
+
+private:
+
+ std::istream* m_stream;
+ const bool m_own;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMPOINTERADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamSocketAdapter.hpp b/vmime/utility/inputStreamSocketAdapter.hpp
new file mode 100644
index 0000000..0f99c21
--- /dev/null
+++ b/vmime/utility/inputStreamSocketAdapter.hpp
@@ -0,0 +1,77 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+namespace vmime {
+namespace net {
+ class socket; // forward reference
+} // net
+} // vmime
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An input stream that is connected to a socket.
+ */
+
+class inputStreamSocketAdapter : public inputStream
+{
+public:
+
+ inputStreamSocketAdapter(net::socket& sok);
+
+ bool eof() const;
+ void reset();
+ size_type read(value_type* const data, const size_type count);
+ size_type skip(const size_type count);
+
+ size_type getBlockSize();
+
+private:
+
+ inputStreamSocketAdapter(const inputStreamSocketAdapter&);
+
+ net::socket& m_socket;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamStringAdapter.hpp b/vmime/utility/inputStreamStringAdapter.hpp
new file mode 100644
index 0000000..a7d986f
--- /dev/null
+++ b/vmime/utility/inputStreamStringAdapter.hpp
@@ -0,0 +1,66 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for string input.
+ */
+
+class inputStreamStringAdapter : public inputStream
+{
+public:
+
+ inputStreamStringAdapter(const string& buffer);
+ inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end);
+
+ bool eof() const;
+ void reset();
+ size_type read(value_type* const data, const size_type count);
+ size_type skip(const size_type count);
+
+private:
+
+ inputStreamStringAdapter(const inputStreamStringAdapter&);
+
+ const string m_buffer; // do _NOT_ keep a reference...
+ const string::size_type m_begin;
+ const string::size_type m_end;
+ string::size_type m_pos;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/inputStreamStringProxyAdapter.hpp b/vmime/utility/inputStreamStringProxyAdapter.hpp
new file mode 100644
index 0000000..74b3f60
--- /dev/null
+++ b/vmime/utility/inputStreamStringProxyAdapter.hpp
@@ -0,0 +1,68 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+class stringProxy;
+
+
+/** An adapter class for stringProxy input.
+ */
+
+class inputStreamStringProxyAdapter : public inputStream
+{
+public:
+
+ /** @param buffer stringProxy object to wrap
+ */
+ inputStreamStringProxyAdapter(const stringProxy& buffer);
+
+ bool eof() const;
+ void reset();
+ size_type read(value_type* const data, const size_type count);
+ size_type skip(const size_type count);
+
+private:
+
+ inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
+
+ const stringProxy& m_buffer;
+ string::size_type m_pos;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_INPUTSTREAMSTRINGPROXYADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/outputStream.hpp b/vmime/utility/outputStream.hpp
new file mode 100644
index 0000000..7372d20
--- /dev/null
+++ b/vmime/utility/outputStream.hpp
@@ -0,0 +1,107 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
+#define VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
+
+
+#include "vmime/utility/stream.hpp"
+
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++6
+# include
+#endif
+
+
+namespace vmime {
+namespace utility {
+
+
+/** Simple output stream.
+ */
+
+class outputStream : public stream
+{
+public:
+
+ /** Write data to the stream.
+ *
+ * @param data buffer containing data to write
+ * @param count number of bytes to write
+ */
+ virtual void write(const value_type* const data, const size_type count) = 0;
+
+ /** Flush this output stream and forces any buffered output
+ * bytes to be written out to the stream.
+ */
+ virtual void flush() = 0;
+};
+
+
+// Helpers functions
+
+outputStream& operator<<(outputStream& os, const string& str);
+outputStream& operator<<(outputStream& os, const stream::value_type c);
+
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1200) // Internal compiler error with VC++6
+
+inline outputStream& operator<<(outputStream& os, const char* str)
+{
+ os.write(str, ::strlen(str));
+ return (os);
+}
+
+#else
+
+template
+outputStream& operator<<(outputStream& os, const char (&str)[N])
+{
+ os.write(str, N - 1);
+ return (os);
+}
+
+#endif // defined(_MSC_VER) && (_MSC_VER <= 1200)
+
+
+template
+outputStream& operator<<(outputStream& os, const T& t)
+{
+ std::ostringstream oss;
+ oss.imbue(std::locale::classic()); // no formatting
+
+ oss << t;
+
+ os << oss.str();
+
+ return (os);
+}
+
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_OUTPUTSTREAM_HPP_INCLUDED
+
diff --git a/vmime/utility/outputStreamAdapter.hpp b/vmime/utility/outputStreamAdapter.hpp
new file mode 100644
index 0000000..be55d8d
--- /dev/null
+++ b/vmime/utility/outputStreamAdapter.hpp
@@ -0,0 +1,62 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/outputStream.hpp"
+
+#include
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for C++ standard output streams.
+ */
+
+class outputStreamAdapter : public outputStream
+{
+public:
+
+ /** @param os output stream to wrap
+ */
+ outputStreamAdapter(std::ostream& os);
+
+ void write(const value_type* const data, const size_type count);
+ void flush();
+
+private:
+
+ std::ostream& m_stream;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_OUTPUTSTREAMADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/outputStreamByteArrayAdapter.hpp b/vmime/utility/outputStreamByteArrayAdapter.hpp
new file mode 100644
index 0000000..bf7d839
--- /dev/null
+++ b/vmime/utility/outputStreamByteArrayAdapter.hpp
@@ -0,0 +1,58 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/outputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for byte array output.
+ */
+
+class outputStreamByteArrayAdapter : public outputStream
+{
+public:
+
+ outputStreamByteArrayAdapter(byteArray& array);
+
+ void write(const value_type* const data, const size_type count);
+ void flush();
+
+private:
+
+ byteArray& m_array;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_OUTPUTSTREAMBYTEARRAYADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/outputStreamSocketAdapter.hpp b/vmime/utility/outputStreamSocketAdapter.hpp
new file mode 100644
index 0000000..e3d3eb0
--- /dev/null
+++ b/vmime/utility/outputStreamSocketAdapter.hpp
@@ -0,0 +1,75 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/outputStream.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+namespace vmime {
+namespace net {
+ class socket; // forward reference
+} // net
+} // vmime
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An output stream that is connected to a socket.
+ */
+
+class outputStreamSocketAdapter : public outputStream
+{
+public:
+
+ outputStreamSocketAdapter(net::socket& sok);
+
+ void write(const value_type* const data, const size_type count);
+ void flush();
+
+ size_type getBlockSize();
+
+private:
+
+ outputStreamSocketAdapter(const outputStreamSocketAdapter&);
+
+ net::socket& m_socket;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
+
+#endif // VMIME_UTILITY_OUTPUTSTREAMSOCKETADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/outputStreamStringAdapter.hpp b/vmime/utility/outputStreamStringAdapter.hpp
new file mode 100644
index 0000000..8c8b304
--- /dev/null
+++ b/vmime/utility/outputStreamStringAdapter.hpp
@@ -0,0 +1,59 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+#define VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+
+
+#include "vmime/utility/outputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** An adapter class for string output.
+ */
+
+class outputStreamStringAdapter : public outputStream
+{
+public:
+
+ outputStreamStringAdapter(string& buffer);
+
+ void write(const value_type* const data, const size_type count);
+ void flush();
+
+size_type getBlockSize(){return 8192;}
+private:
+
+ string& m_buffer;
+};
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_OUTPUTSTREAMSTRINGADAPTER_HPP_INCLUDED
+
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index 1faab55..566ab9d 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -25,40 +25,22 @@
#define VMIME_UTILITY_STREAM_HPP_INCLUDED
-#include
-#include
#include
#include "vmime/config.hpp"
#include "vmime/types.hpp"
-
-#include "vmime/utility/progressListener.hpp"
-
-
-#if VMIME_HAVE_MESSAGING_FEATURES
- namespace vmime {
- namespace net {
- class socket; // forward reference
- } // net
- } // vmime
-#endif
-
-#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++6
-# include
-#endif
+#include "vmime/base.hpp"
namespace vmime {
namespace utility {
-class stringProxy;
-
/** Base class for input/output stream.
*/
-class stream : public object
+class stream : public object, private noncopyable
{
public:
@@ -81,365 +63,6 @@ public:
};
-
-/** Simple output stream.
- */
-
-class outputStream : public stream
-{
-public:
-
- /** Write data to the stream.
- *
- * @param data buffer containing data to write
- * @param count number of bytes to write
- */
- virtual void write(const value_type* const data, const size_type count) = 0;
-
- /** Flush this output stream and forces any buffered output
- * bytes to be written out to the stream.
- */
- virtual void flush() = 0;
-};
-
-
-
-/** Simple input stream.
- */
-
-class inputStream : public stream
-{
-public:
-
- /** Test for end of stream (no more data to read).
- *
- * @return true if we have reached the end of stream, false otherwise
- */
- virtual bool eof() const = 0;
-
- /** Set the read pointer to the beginning of the stream.
- *
- * @warning WARNING: this may not work for all stream types.
- */
- virtual void reset() = 0;
-
- /** Read data from the stream.
- *
- * @param data will receive the data read
- * @param count maximum number of bytes to read
- * @return number of bytes read
- */
- virtual size_type read(value_type* const data, const size_type count) = 0;
-
- /** Skip a number of bytes.
- *
- * @param count maximum number of bytes to ignore
- * @return number of bytes skipped
- */
- virtual size_type skip(const size_type count) = 0;
-};
-
-
-
-// Helpers functions
-
-outputStream& operator<<(outputStream& os, const string& str);
-outputStream& operator<<(outputStream& os, const stream::value_type c);
-
-
-#if defined(_MSC_VER) && (_MSC_VER <= 1200) // Internal compiler error with VC++6
-
-inline outputStream& operator<<(outputStream& os, const char* str)
-{
- os.write(str, ::strlen(str));
- return (os);
-}
-
-#else
-
-template
-outputStream& operator<<(outputStream& os, const char (&str)[N])
-{
- os.write(str, N - 1);
- return (os);
-}
-
-#endif // defined(_MSC_VER) && (_MSC_VER <= 1200)
-
-
-template
-outputStream& operator<<(outputStream& os, const T& t)
-{
- std::ostringstream oss;
- oss.imbue(std::locale::classic()); // no formatting
-
- oss << t;
-
- os << oss.str();
-
- return (os);
-}
-
-
-/** Copy data from one stream into another stream using a buffered method.
- *
- * @param is input stream (source data)
- * @param os output stream (destination for data)
- * @return number of bytes copied
- */
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os);
-
-/** Copy data from one stream into another stream using a buffered method
- * and notify progress state of the operation.
- *
- * @param is input stream (source data)
- * @param os output stream (destination for data)
- * @param length predicted number of bytes to copy
- * @param progress listener to notify
- * @return number of bytes copied
- */
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
- const stream::size_type length, progressListener* progress);
-
-
-// Adapters
-
-
-/** An adapter class for C++ standard output streams.
- */
-
-class outputStreamAdapter : public outputStream
-{
-public:
-
- /** @param os output stream to wrap
- */
- outputStreamAdapter(std::ostream& os);
-
- void write(const value_type* const data, const size_type count);
- void flush();
-
-private:
-
- std::ostream& m_stream;
-};
-
-
-/** An adapter class for string output.
- */
-
-class outputStreamStringAdapter : public outputStream
-{
-public:
-
- outputStreamStringAdapter(string& buffer);
-
- void write(const value_type* const data, const size_type count);
- void flush();
-
-size_type getBlockSize(){return 8192;}
-private:
-
- string& m_buffer;
-};
-
-
-/** An adapter class for byte array output.
- */
-
-class outputStreamByteArrayAdapter : public outputStream
-{
-public:
-
- outputStreamByteArrayAdapter(byteArray& array);
-
- void write(const value_type* const data, const size_type count);
- void flush();
-
-private:
-
- byteArray& m_array;
-};
-
-
-/** An adapter class for C++ standard input streams.
- */
-
-class inputStreamAdapter : public inputStream
-{
-public:
-
- /** @param is input stream to wrap
- */
- inputStreamAdapter(std::istream& is);
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
-private:
-
- std::istream& m_stream;
-};
-
-
-/** An adapter class for string input.
- */
-
-class inputStreamStringAdapter : public inputStream
-{
-public:
-
- inputStreamStringAdapter(const string& buffer);
- inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end);
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
-private:
-
- inputStreamStringAdapter(const inputStreamStringAdapter&);
-
- const string m_buffer; // do _NOT_ keep a reference...
- const string::size_type m_begin;
- const string::size_type m_end;
- string::size_type m_pos;
-};
-
-
-/** An adapter class for stringProxy input.
- */
-
-class inputStreamStringProxyAdapter : public inputStream
-{
-public:
-
- /** @param buffer stringProxy object to wrap
- */
- inputStreamStringProxyAdapter(const stringProxy& buffer);
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
-private:
-
- inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
-
- const stringProxy& m_buffer;
- string::size_type m_pos;
-};
-
-
-/** An adapter class for pointer to C++ standard input stream.
- */
-
-class inputStreamPointerAdapter : public inputStream
-{
-public:
-
- /** @param is input stream to wrap
- * @param own if set to 'true', the pointer will be deleted when
- * this object is destroyed
- */
- inputStreamPointerAdapter(std::istream* is, const bool own = true);
- ~inputStreamPointerAdapter();
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
-private:
-
- inputStreamPointerAdapter(const inputStreamPointerAdapter&);
-
- std::istream* m_stream;
- const bool m_own;
-};
-
-
-/** An adapter class for reading from an array of bytes.
- */
-
-class inputStreamByteBufferAdapter : public inputStream
-{
-public:
-
- inputStreamByteBufferAdapter(const byte_t* buffer, size_type length);
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
-private:
-
- const byte_t* m_buffer;
- const size_type m_length;
-
- size_type m_pos;
-};
-
-
-#if VMIME_HAVE_MESSAGING_FEATURES
-
-
-/** An output stream that is connected to a socket.
- */
-
-class outputStreamSocketAdapter : public outputStream
-{
-public:
-
- outputStreamSocketAdapter(net::socket& sok);
-
- void write(const value_type* const data, const size_type count);
- void flush();
-
- size_type getBlockSize();
-
-private:
-
- outputStreamSocketAdapter(const outputStreamSocketAdapter&);
-
- net::socket& m_socket;
-};
-
-
-/** An input stream that is connected to a socket.
- */
-
-class inputStreamSocketAdapter : public inputStream
-{
-public:
-
- inputStreamSocketAdapter(net::socket& sok);
-
- bool eof() const;
- void reset();
- size_type read(value_type* const data, const size_type count);
- size_type skip(const size_type count);
-
- size_type getBlockSize();
-
-private:
-
- inputStreamSocketAdapter(const inputStreamSocketAdapter&);
-
- net::socket& m_socket;
-};
-
-
-#endif // VMIME_HAVE_MESSAGING_FEATURES
-
-
} // utility
} // vmime
diff --git a/vmime/utility/streamUtils.hpp b/vmime/utility/streamUtils.hpp
new file mode 100644
index 0000000..cdf70aa
--- /dev/null
+++ b/vmime/utility/streamUtils.hpp
@@ -0,0 +1,66 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard
+//
+// 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.
+//
+
+#ifndef VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
+#define VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
+
+
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/outputStream.hpp"
+
+#include "vmime/utility/progressListener.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+/** Copy data from one stream into another stream using a buffered method.
+ *
+ * @param is input stream (source data)
+ * @param os output stream (destination for data)
+ * @return number of bytes copied
+ */
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os);
+
+/** Copy data from one stream into another stream using a buffered method
+ * and notify progress state of the operation.
+ *
+ * @param is input stream (source data)
+ * @param os output stream (destination for data)
+ * @param length predicted number of bytes to copy
+ * @param progress listener to notify
+ * @return number of bytes copied
+ */
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
+ const stream::size_type length, progressListener* progress);
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_UTILITY_STREAMUTILS_HPP_INCLUDED
+
diff --git a/vmime/utility/stringProxy.hpp b/vmime/utility/stringProxy.hpp
index 21c65ea..66a6dfd 100644
--- a/vmime/utility/stringProxy.hpp
+++ b/vmime/utility/stringProxy.hpp
@@ -29,6 +29,7 @@
#include "vmime/types.hpp"
#include "vmime/utility/stream.hpp"
+#include "vmime/utility/outputStream.hpp"
#include "vmime/utility/progressListener.hpp"
diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp
index f187b9e..fd04853 100644
--- a/vmime/vmime.hpp
+++ b/vmime/vmime.hpp
@@ -68,6 +68,22 @@
// Encoders
#include "vmime/utility/encoder/encoderFactory.hpp"
+// Streams
+#include "vmime/utility/filteredStream.hpp"
+#include "vmime/utility/inputStream.hpp"
+#include "vmime/utility/inputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
+#include "vmime/utility/inputStreamPointerAdapter.hpp"
+#include "vmime/utility/inputStreamSocketAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+#include "vmime/utility/outputStream.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
+#include "vmime/utility/outputStreamSocketAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
// Message builder/parser
#include "vmime/messageBuilder.hpp"
#include "vmime/messageParser.hpp"
--
1.7.10.4
From be30b47f09c5358db2ac8e42fa2bb4a14ec24c51 Mon Sep 17 00:00:00 2001
From: Vincent Richard
Date: Mon, 16 Apr 2012 22:32:33 +0200
Subject: [PATCH 37/42] Added ability to parse directly from an input stream
(eg. file). This allows very big messages to be
parsed without loading the whole message data into
memory.
diff --git a/ChangeLog b/ChangeLog
index 8fdcdb0..1b5b2cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,12 @@
VERSION 0.9.2svn
================
+2012-04-16 Vincent Richard
+
+ * MIME Parser can now operate directly on an input stream (eg. file).
+ This allows very big messages to be parsed without loading the whole
+ message data into memory.
+
2010-11-16 Vincent Richard
* Started version 0.9.2.
diff --git a/SConstruct b/SConstruct
index ea5c4eb..2690172 100644
--- a/SConstruct
+++ b/SConstruct
@@ -153,11 +153,14 @@ libvmime_sources = [
'utility/inputStreamSocketAdapter.cpp', 'utility/inputStreamSocketAdapter.hpp',
'utility/inputStreamStringAdapter.cpp', 'utility/inputStreamStringAdapter.hpp',
'utility/inputStreamStringProxyAdapter.cpp', 'utility/inputStreamStringProxyAdapter.hpp',
+ 'utility/seekableInputStream.hpp',
+ 'utility/seekableInputStreamRegionAdapter.cpp', 'utility/seekableInputStreamRegionAdapter.hpp',
'utility/outputStream.cpp', 'utility/outputStream.hpp',
'utility/outputStreamAdapter.cpp', 'utility/outputStreamAdapter.hpp',
'utility/outputStreamByteArrayAdapter.cpp', 'utility/outputStreamByteArrayAdapter.hpp',
'utility/outputStreamSocketAdapter.cpp', 'utility/outputStreamSocketAdapter.hpp',
'utility/outputStreamStringAdapter.cpp', 'utility/outputStreamStringAdapter.hpp',
+ 'utility/parserInputStreamAdapter.cpp', 'utility/parserInputStreamAdapter.hpp',
'utility/stringProxy.cpp', 'utility/stringProxy.hpp',
'utility/stringUtils.cpp', 'utility/stringUtils.hpp',
'utility/url.cpp', 'utility/url.hpp',
diff --git a/src/addressList.cpp b/src/addressList.cpp
index 31a2a3d..f06460d 100644
--- a/src/addressList.cpp
+++ b/src/addressList.cpp
@@ -50,7 +50,7 @@ addressList::~addressList()
}
-void addressList::parse(const string& buffer, const string::size_type position,
+void addressList::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
removeAllAddresses();
@@ -72,7 +72,7 @@ void addressList::parse(const string& buffer, const string::size_type position,
}
-void addressList::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void addressList::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
string::size_type pos = curLinePos;
@@ -248,9 +248,9 @@ const std::vector ][ > addressList::getAddressList()
}
-const std::vector ][ > addressList::getChildComponents() const
+const std::vector ][ > addressList::getChildComponents()
{
- std::vector ][ > list;
+ std::vector ][ > list;
copy_vector(m_list, list);
diff --git a/src/body.cpp b/src/body.cpp
index 9d7d57f..732fa8b 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -31,10 +31,13 @@
#include "vmime/utility/random.hpp"
+#include "vmime/utility/seekableInputStreamRegionAdapter.hpp"
+
#include "vmime/parserHelpers.hpp"
#include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp"
+#include "vmime/streamContentHandler.hpp"
namespace vmime
@@ -52,11 +55,28 @@ body::~body()
}
-void body::parse(const string& buffer, const string::size_type position,
- const string::size_type end, string::size_type* newPosition)
+void body::parseImpl
+ (ref parser,
+ const utility::stream::size_type position,
+ const utility::stream::size_type end,
+ utility::stream::size_type* newPosition)
{
removeAllParts();
+ m_prologText.clear();
+ m_epilogText.clear();
+
+ if (end == position)
+ {
+
+ setParsedBounds(position, end);
+
+ if (newPosition)
+ *newPosition = end;
+
+ return;
+ }
+
// Check whether the body is a MIME-multipart
bool isMultipart = false;
string boundary;
@@ -80,37 +100,61 @@ void body::parse(const string& buffer, const string::size_type position,
{
// No "boundary" parameter specified: we can try to
// guess it by scanning the body contents...
- string::size_type pos = buffer.find("\n--", position);
+ utility::stream::size_type pos = position;
+
+ parser->seek(pos);
+
+ if (pos + 2 < end && parser->matchBytes("--", 2))
+ {
+ pos += 2;
+ }
+ else
+ {
+ pos = parser->findNext("\n--", position);
- if ((pos != string::npos) && (pos < end))
+ if ((pos != utility::stream::npos) && (pos + 3 < end))
+ pos += 3; // skip \n--
+ }
+
+ if ((pos != utility::stream::npos) && (pos < end))
{
- pos += 3;
+ parser->seek(pos);
- const string::size_type start = pos;
+ // Read some bytes after boundary separator
+ utility::stream::value_type buffer[256];
+ const utility::stream::size_type bufferLen =
+ parser->read(buffer, std::min(end - pos, sizeof(buffer) / sizeof(buffer[0])));
- char_t c = buffer[pos];
- string::size_type length = 0;
+ buffer[sizeof(buffer) / sizeof(buffer[0]) - 1] = '\0';
+ // Extract boundary from buffer (stop at first CR or LF).
// We have to stop after a reasonnably long boundary length (100)
// not to take the whole body contents for a boundary...
- while (pos < end && length < 100 && !(c == '\r' || c == '\n'))
+ string::value_type boundaryBytes[100];
+ string::size_type boundaryLen = 0;
+
+ for (string::value_type c = buffer[0] ;
+ boundaryLen < bufferLen && boundaryLen < 100 && !(c == '\r' || c == '\n') ;
+ c = buffer[++boundaryLen])
{
- ++length;
- c = buffer[pos++];
+ boundaryBytes[boundaryLen] = buffer[boundaryLen];
}
- if (pos < end && length < 100)
+ if (boundaryLen >= 1 && boundaryLen < 100)
{
// RFC #1521, Page 31:
// "...the boundary parameter, which consists of 1 to 70
// characters from a set of characters known to be very
// robust through email gateways, and NOT ending with
// white space..."
- while (pos != start && parserHelpers::isSpace(buffer[pos - 1]))
- --pos;
-
- boundary = string(buffer.begin() + start,
- buffer.begin() + pos);
+ while (boundaryLen != 0 &&
+ parserHelpers::isSpace(boundaryBytes[boundaryLen - 1]))
+ {
+ boundaryLen--;
+ }
+
+ if (boundaryLen >= 1)
+ boundary = string(boundaryBytes, boundaryBytes + boundaryLen);
}
}
}
@@ -126,51 +170,79 @@ void body::parse(const string& buffer, const string::size_type position,
{
const string boundarySep("--" + boundary);
- string::size_type partStart = position;
- string::size_type pos = position;
+ utility::stream::size_type partStart = position;
+ utility::stream::size_type pos = position;
bool lastPart = false;
- while (pos != string::npos && pos < end)
+ while (pos != utility::stream::npos && pos < end)
{
- pos = buffer.find(boundarySep, pos);
-
- if (pos == string::npos ||
- ((pos == 0 || buffer[pos - 1] == '\n') &&
- (buffer[pos + boundarySep.length()] == '\r' ||
- buffer[pos + boundarySep.length()] == '\n' ||
- buffer[pos + boundarySep.length()] == '-'
- )
- )
- )
+ pos = parser->findNext(boundarySep, pos);
+
+ if (pos == utility::stream::npos)
+ break; // not found
+
+ if (pos != 0)
{
- break;
+ parser->seek(pos - 1);
+
+ if (parser->peekByte() != '\n')
+ {
+ // Boundary is not at a beginning of a line
+ pos++;
+ continue;
+ }
+
+ parser->skip(1 + boundarySep.length());
+ }
+ else
+ {
+ parser->seek(pos + boundarySep.length());
}
- // boundary not a beginning of line, or just a prefix of another, continue the search.
+ const utility::stream::value_type next = parser->peekByte();
+
+ if (next == '\r' || next == '\n' || next == '-')
+ break;
+
+ // Boundary is a prefix of another, continue the search
pos++;
}
- if (pos != string::npos && pos < end)
+ if (pos != utility::stream::npos && pos < end)
{
vmime::text text;
- text.parse(buffer, position, pos);
+ text.parse(parser, position, pos);
m_prologText = text.getWholeBuffer();
}
- for (int index = 0 ; !lastPart && (pos != string::npos) && (pos < end) ; ++index)
+ for (int index = 0 ; !lastPart && (pos != utility::stream::npos) && (pos < end) ; ++index)
{
- string::size_type partEnd = pos;
+ utility::stream::size_type partEnd = pos;
// Get rid of the [CR]LF just before the boundary string
- if (pos >= (position + 1) && buffer[pos - 1] == '\n') --partEnd;
- if (pos >= (position + 2) && buffer[pos - 2] == '\r') --partEnd;
+ if (pos >= (position + 1))
+ {
+ parser->seek(pos - 1);
+
+ if (parser->peekByte() == '\n')
+ --partEnd;
+ }
+
+ if (pos >= (position + 2))
+ {
+ parser->seek(pos - 2);
+
+ if (parser->peekByte() == '\r')
+ --partEnd;
+ }
// Check whether it is the last part (boundary terminated by "--")
pos += boundarySep.length();
+ parser->seek(pos);
- if (pos + 1 < end && buffer[pos] == '-' && buffer[pos + 1] == '-')
+ if (pos + 1 < end && parser->matchBytes("--", 2))
{
lastPart = true;
pos += 2;
@@ -180,15 +252,15 @@ void body::parse(const string& buffer, const string::size_type position,
// "...(If a boundary appears to end with white space, the
// white space must be presumed to have been added by a
// gateway, and must be deleted.)..."
- while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t'))
- ++pos;
+ parser->seek(pos);
+ pos += parser->skipIf(parserHelpers::isSpaceOrTab, end);
// End of boundary line
- if (pos + 1 < end && buffer[pos] == '\r' && buffer[pos + 1] =='\n')
+ if (pos + 1 < end && parser->matchBytes("\r\n", 2))
{
pos += 2;
}
- else if (pos < end && buffer[pos] == '\n')
+ else if (pos < end && parser->peekByte() == '\n')
{
++pos;
}
@@ -202,7 +274,7 @@ void body::parse(const string& buffer, const string::size_type position,
if (partEnd < partStart)
std::swap(partStart, partEnd);
- part->parse(buffer, partStart, partEnd, NULL);
+ part->parse(parser, partStart, partEnd, NULL);
part->m_parent = m_part;
m_parts.push_back(part);
@@ -210,23 +282,37 @@ void body::parse(const string& buffer, const string::size_type position,
partStart = pos;
- while (pos != string::npos && pos < end)
+ while (pos != utility::stream::npos && pos < end)
{
- pos = buffer.find(boundarySep, pos);
-
- if (pos == string::npos ||
- ((pos == 0 || buffer[pos - 1] == '\n') &&
- (buffer[pos + boundarySep.length()] == '\r' ||
- buffer[pos + boundarySep.length()] == '\n' ||
- buffer[pos + boundarySep.length()] == '-'
- )
- )
- )
+ pos = parser->findNext(boundarySep, pos);
+
+ if (pos == utility::stream::npos)
+ break; // not found
+
+ if (pos != 0)
{
- break;
+ parser->seek(pos - 1);
+
+ if (parser->peekByte() != '\n')
+ {
+ // Boundary is not at a beginning of a line
+ pos++;
+ continue;
+ }
+
+ parser->skip(1 + boundarySep.length());
+ }
+ else
+ {
+ parser->seek(pos + boundarySep.length());
}
- // boundary not a beginning of line, or just a prefix of another, continue the search.
+ const utility::stream::value_type next = parser->peekByte();
+
+ if (next == '\r' || next == '\n' || next == '-')
+ break;
+
+ // Boundary is a prefix of another, continue the search
pos++;
}
}
@@ -234,13 +320,13 @@ void body::parse(const string& buffer, const string::size_type position,
m_contents = vmime::create ();
// Last part was not found: recover from missing boundary
- if (!lastPart && pos == string::npos)
+ if (!lastPart && pos == utility::stream::npos)
{
ref part = vmime::create ();
try
{
- part->parse(buffer, partStart, end);
+ part->parse(parser, partStart, end);
}
catch (std::exception&)
{
@@ -255,7 +341,7 @@ void body::parse(const string& buffer, const string::size_type position,
else if (partStart < end)
{
vmime::text text;
- text.parse(buffer, partStart, end);
+ text.parse(parser, partStart, end);
m_epilogText = text.getWholeBuffer();
}
@@ -282,7 +368,13 @@ void body::parse(const string& buffer, const string::size_type position,
}
// Extract the (encoded) contents
- m_contents = vmime::create (buffer, position, end, enc);
+ const utility::stream::size_type length = end - position;
+
+ ref contentStream =
+ vmime::create
+ (parser->getUnderlyingStream(), position, length);
+
+ m_contents = vmime::create (contentStream, length, enc);
}
setParsedBounds(position, end);
@@ -292,7 +384,7 @@ void body::parse(const string& buffer, const string::size_type position,
}
-void body::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void body::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
// MIME-Multipart
@@ -862,9 +954,9 @@ const std::vector ][ > body::getPartList()
}
-const std::vector ][ > body::getChildComponents() const
+const std::vector ][ > body::getChildComponents()
{
- std::vector ][ > list;
+ std::vector ][ > list;
copy_vector(m_parts, list);
diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp
index 7d60461..522cbb2 100644
--- a/src/bodyPart.cpp
+++ b/src/bodyPart.cpp
@@ -46,15 +46,18 @@ bodyPart::bodyPart(weak_ref parentPart)
}
-void bodyPart::parse(const string& buffer, const string::size_type position,
- const string::size_type end, string::size_type* newPosition)
+void bodyPart::parseImpl
+ (ref parser,
+ const utility::stream::size_type position,
+ const utility::stream::size_type end,
+ utility::stream::size_type* newPosition)
{
// Parse the headers
string::size_type pos = position;
- m_header->parse(buffer, pos, end, &pos);
+ m_header->parse(parser, pos, end, &pos);
// Parse the body contents
- m_body->parse(buffer, pos, end, NULL);
+ m_body->parse(parser, pos, end, NULL);
setParsedBounds(position, end);
@@ -63,7 +66,7 @@ void bodyPart::parse(const string& buffer, const string::size_type position,
}
-void bodyPart::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void bodyPart::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
m_header->generate(os, maxLineLength);
@@ -142,9 +145,9 @@ ref bodyPart::getParentPart() const
}
-const std::vector ][ > bodyPart::getChildComponents() const
+const std::vector ][ > bodyPart::getChildComponents()
{
- std::vector ][ > list;
+ std::vector ][ > list;
list.push_back(m_header);
list.push_back(m_body);
diff --git a/src/charset.cpp b/src/charset.cpp
index 0fda450..705664f 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -57,7 +57,7 @@ charset::charset(const char* name)
}
-void charset::parse(const string& buffer, const string::size_type position,
+void charset::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_name = utility::stringUtils::trim
@@ -74,7 +74,7 @@ void charset::parse(const string& buffer, const string::size_type position,
}
-void charset::generate(utility::outputStream& os, const string::size_type /* maxLineLength */,
+void charset::generateImpl(utility::outputStream& os, const string::size_type /* maxLineLength */,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
os << m_name;
@@ -142,9 +142,9 @@ void charset::copyFrom(const component& other)
}
-const std::vector ][ > charset::getChildComponents() const
+const std::vector ][ > charset::getChildComponents()
{
- return std::vector ][ >();
+ return std::vector ][ >();
}
diff --git a/src/component.cpp b/src/component.cpp
index 139cf66..e93aacf 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -23,6 +23,9 @@
#include "vmime/component.hpp"
#include "vmime/base.hpp"
+
+#include "vmime/utility/streamUtils.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
#include "vmime/utility/outputStreamAdapter.hpp"
#include
@@ -43,9 +46,102 @@ component::~component()
}
+void component::parse
+ (ref inputStream, const utility::stream::size_type length)
+{
+ parse(inputStream, 0, length, NULL);
+}
+
+
+void component::parse
+ (ref inputStream, const utility::stream::size_type position,
+ const utility::stream::size_type end, utility::stream::size_type* newPosition)
+{
+ m_parsedOffset = m_parsedLength = 0;
+
+ ref seekableStream =
+ inputStream.dynamicCast ();
+
+ if (seekableStream == NULL || end == 0)
+ {
+ // Read the whole stream into a buffer
+ std::ostringstream oss;
+ utility::outputStreamAdapter ossAdapter(oss);
+
+ utility::bufferedStreamCopyRange(*inputStream, ossAdapter, position, end - position);
+
+ const string buffer = oss.str();
+ parseImpl(buffer, 0, buffer.length(), NULL);
+ }
+ else
+ {
+ ref parser =
+ vmime::create (seekableStream);
+
+ parseImpl(parser, position, end, newPosition);
+ }
+}
+
+
void component::parse(const string& buffer)
{
- parse(buffer, 0, buffer.length(), NULL);
+ m_parsedOffset = m_parsedLength = 0;
+
+ parseImpl(buffer, 0, buffer.length(), NULL);
+}
+
+
+void component::parse
+ (const string& buffer, const string::size_type position,
+ const string::size_type end, string::size_type* newPosition)
+{
+ m_parsedOffset = m_parsedLength = 0;
+
+ parseImpl(buffer, position, end, newPosition);
+}
+
+
+void component::offsetParsedBounds(const utility::stream::size_type offset)
+{
+ // Offset parsed bounds of this component
+ if (m_parsedLength != 0)
+ m_parsedOffset += offset;
+
+ // Offset parsed bounds of our children
+ std::vector ][ > children = getChildComponents();
+
+ for (unsigned int i = 0, n = children.size() ; i < n ; ++i)
+ children[i]->offsetParsedBounds(offset);
+}
+
+
+void component::parseImpl
+ (ref parser, const utility::stream::size_type position,
+ const utility::stream::size_type end, utility::stream::size_type* newPosition)
+{
+ const std::string buffer = parser->extract(position, end);
+ parseImpl(buffer, 0, buffer.length(), newPosition);
+
+ // Recursivey offset parsed bounds on children
+ if (position != 0)
+ offsetParsedBounds(position);
+
+ if (newPosition != NULL)
+ *newPosition += position;
+}
+
+
+void component::parseImpl
+ (const string& buffer, const string::size_type position,
+ const string::size_type end, string::size_type* newPosition)
+{
+ ref stream =
+ vmime::create (buffer);
+
+ ref parser =
+ vmime::create (stream);
+
+ parseImpl(parser, position, end, newPosition);
}
@@ -61,6 +157,26 @@ const string component::generate(const string::size_type maxLineLength,
}
+void component::generate
+ (utility::outputStream& os,
+ const string::size_type maxLineLength,
+ const string::size_type curLinePos,
+ string::size_type* newLinePos) const
+{
+ generateImpl(os, maxLineLength, curLinePos, newLinePos);
+}
+
+
+void component::generate
+ (ref os,
+ const string::size_type maxLineLength,
+ const string::size_type curLinePos,
+ string::size_type* newLinePos) const
+{
+ generateImpl(*os, maxLineLength, curLinePos, newLinePos);
+}
+
+
string::size_type component::getParsedOffset() const
{
return (m_parsedOffset);
@@ -80,22 +196,5 @@ void component::setParsedBounds(const string::size_type start, const string::siz
}
-const std::vector ][ > component::getChildComponents()
-{
- const std::vector ][ > constList =
- const_cast (this)->getChildComponents();
-
- std::vector ][ > list;
-
- const std::vector ][ >::size_type count = constList.size();
+} // vmime
- list.resize(count);
-
- for (std::vector ][ >::size_type i = 0 ; i < count ; ++i)
- list[i] = constList[i].constCast ();
-
- return (list);
-}
-
-
-}
diff --git a/src/contentDisposition.cpp b/src/contentDisposition.cpp
index 0ab7c45..253dbba 100644
--- a/src/contentDisposition.cpp
+++ b/src/contentDisposition.cpp
@@ -47,7 +47,7 @@ contentDisposition::contentDisposition(const contentDisposition& type)
}
-void contentDisposition::parse(const string& buffer, const string::size_type position,
+void contentDisposition::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_name = utility::stringUtils::trim(utility::stringUtils::toLower
@@ -60,7 +60,7 @@ void contentDisposition::parse(const string& buffer, const string::size_type pos
}
-void contentDisposition::generate(utility::outputStream& os, const string::size_type /* maxLineLength */,
+void contentDisposition::generateImpl(utility::outputStream& os, const string::size_type /* maxLineLength */,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
os << m_name;
@@ -122,9 +122,9 @@ void contentDisposition::setName(const string& name)
}
-const std::vector ][ > contentDisposition::getChildComponents() const
+const std::vector ][ > contentDisposition::getChildComponents()
{
- return std::vector ][ >();
+ return std::vector ][ >();
}
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index 089a900..0d97b2f 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -67,7 +67,7 @@ zone = "UT" / "GMT" ; Universal Time
*/
-void datetime::parse(const string& buffer, const string::size_type position,
+void datetime::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
const string::value_type* const pend = buffer.data() + end;
@@ -588,7 +588,7 @@ void datetime::parse(const string& buffer, const string::size_type position,
}
-void datetime::generate(utility::outputStream& os, const string::size_type /* maxLineLength */,
+void datetime::generateImpl(utility::outputStream& os, const string::size_type /* maxLineLength */,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
static const string::value_type* dayNames[] =
@@ -784,9 +784,9 @@ ref datetime::clone() const
}
-const std::vector ][ > datetime::getChildComponents() const
+const std::vector ][ > datetime::getChildComponents()
{
- return std::vector ][ >();
+ return std::vector ][ >();
}
diff --git a/src/disposition.cpp b/src/disposition.cpp
index b8059a7..24a4579 100644
--- a/src/disposition.cpp
+++ b/src/disposition.cpp
@@ -79,9 +79,9 @@ disposition& disposition::operator=(const disposition& other)
}
-const std::vector ][ > disposition::getChildComponents() const
+const std::vector ][ > disposition::getChildComponents()
{
- return std::vector ][ >();
+ return std::vector ][ >();
}
@@ -171,7 +171,7 @@ const std::vector disposition::getModifierList() const
}
-void disposition::parse(const string& buffer, const string::size_type position,
+void disposition::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
// disposition-mode ";" disposition-type
@@ -276,7 +276,7 @@ void disposition::parse(const string& buffer, const string::size_type position,
}
-void disposition::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void disposition::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
string::size_type pos = curLinePos;
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 5d99ab6..343a822 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -61,7 +61,7 @@ encoding::encoding(const encoding& enc)
}
-void encoding::parse(const string& buffer, const string::size_type position,
+void encoding::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_usage = USAGE_UNKNOWN;
@@ -80,7 +80,7 @@ void encoding::parse(const string& buffer, const string::size_type position,
}
-void encoding::generate(utility::outputStream& os, const string::size_type /* maxLineLength */,
+void encoding::generateImpl(utility::outputStream& os, const string::size_type /* maxLineLength */,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
os << m_name;
@@ -268,9 +268,9 @@ void encoding::setUsage(const EncodingUsage usage)
}
-const std::vector ][ > encoding::getChildComponents() const
+const std::vector ][ > encoding::getChildComponents()
{
- return std::vector ][ >();
+ return std::vector ][ >();
}
diff --git a/src/header.cpp b/src/header.cpp
index 443aab8..fcdca2c 100644
--- a/src/header.cpp
+++ b/src/header.cpp
@@ -61,7 +61,7 @@ field-body-contents =
specials tokens, or else consisting of texts>
*/
-void header::parse(const string& buffer, const string::size_type position,
+void header::parseImpl(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
string::size_type pos = position;
@@ -83,7 +83,7 @@ void header::parse(const string& buffer, const string::size_type position,
}
-void header::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void header::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
// Generate the fields
@@ -337,9 +337,9 @@ const std::vector ][ > header::getFieldList()
}
-const std::vector ][ > header::getChildComponents() const
+const std::vector ][ > header::getChildComponents()
{
- std::vector ][ > list;
+ std::vector ][ > list;
copy_vector(m_fields, list);
diff --git a/src/headerField.cpp b/src/headerField.cpp
index d1d4236..a8460aa 100644
--- a/src/headerField.cpp
+++ b/src/headerField.cpp
@@ -262,14 +262,14 @@ ref headerField::parseNext(const string& buffer, const string::siz
}
-void headerField::parse(const string& buffer, const string::size_type position, const string::size_type end,
+void headerField::parseImpl(const string& buffer, const string::size_type position, const string::size_type end,
string::size_type* newPosition)
{
m_value->parse(buffer, position, end, newPosition);
}
-void headerField::generate(utility::outputStream& os, const string::size_type maxLineLength,
+void headerField::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
os << m_name + ": ";
@@ -296,9 +296,9 @@ bool headerField::isCustom() const
}
-const std::vector ][ > headerField::getChildComponents() const
+const std::vector ][ > headerField::getChildComponents()
{
- std::vector ][ > list;
+ std::vector ]