bugfixes for upcoming 1.2.2 release

This commit is contained in:
Guenter Obiltschnig 2006-08-31 09:33:39 +00:00
parent 7dc7c657f3
commit 81ddac4ead
8 changed files with 74 additions and 13 deletions

View File

@ -1,7 +1,7 @@
// //
// MailMessage.h // MailMessage.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#2 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
@ -200,6 +200,7 @@ protected:
void readHeader(std::istream& istr); void readHeader(std::istream& istr);
void readMultipart(std::istream& istr, PartHandler& handler); void readMultipart(std::istream& istr, PartHandler& handler);
void readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler); void readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
void handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
static const std::string& contentTransferEncodingToString(ContentTransferEncoding encoding); static const std::string& contentTransferEncodingToString(ContentTransferEncoding encoding);
static int lineLength(const std::string& str); static int lineLength(const std::string& str);
static void appendRecipient(const MailRecipient& recipient, std::string& str); static void appendRecipient(const MailRecipient& recipient, std::string& str);

View File

@ -1,7 +1,7 @@
// //
// MultipartReader.h // MultipartReader.h
// //
// $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#1 $ // $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#2 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
@ -112,6 +112,10 @@ class Net_API MultipartReader
/// an input stream and optionally a boundary string. /// an input stream and optionally a boundary string.
/// - while hasNextPart() returns true, call nextPart() /// - while hasNextPart() returns true, call nextPart()
/// and read the part from stream(). /// and read the part from stream().
///
/// Always ensure that you read all data from the part
/// stream, otherwise the MultipartReader will fail to
/// find the next part.
{ {
public: public:
explicit MultipartReader(std::istream& istr); explicit MultipartReader(std::istream& istr);

View File

@ -1,7 +1,7 @@
// //
// HTMLForm.cpp // HTMLForm.cpp
// //
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#1 $ // $Id: //poco/1.2/Net/src/HTMLForm.cpp#2 $
// //
// Library: Net // Library: Net
// Package: HTML // Package: HTML
@ -288,6 +288,8 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
if (params.has("filename")) if (params.has("filename"))
{ {
handler.handlePart(header, reader.stream()); handler.handlePart(header, reader.stream());
// Ensure that the complete part has been read.
while (reader.stream().good()) reader.stream().get();
} }
else else
{ {

View File

@ -1,7 +1,7 @@
// //
// MailMessage.cpp // MailMessage.cpp
// //
// $Id: //poco/1.2/Net/src/MailMessage.cpp#1 $ // $Id: //poco/1.2/Net/src/MailMessage.cpp#2 $
// //
// Library: Net // Library: Net
// Package: Mail // Package: Mail
@ -405,20 +405,29 @@ void MailMessage::readPart(std::istream& istr, const MessageHeader& header, Part
if (icompare(encoding, CTE_QUOTED_PRINTABLE) == 0) if (icompare(encoding, CTE_QUOTED_PRINTABLE) == 0)
{ {
QuotedPrintableDecoder decoder(istr); QuotedPrintableDecoder decoder(istr);
handler.handlePart(header, decoder); handlePart(decoder, header, handler);
} }
else if (icompare(encoding, CTE_BASE64) == 0) else if (icompare(encoding, CTE_BASE64) == 0)
{ {
Base64Decoder decoder(istr); Base64Decoder decoder(istr);
handler.handlePart(header, decoder); handlePart(decoder, header, handler);
} }
else else
{ {
handler.handlePart(header, istr); handlePart(istr, header, handler);
} }
} }
void MailMessage::handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler)
{
handler.handlePart(header, istr);
// Read remaining characters from stream in case
// the handler failed to read the complete stream.
while (istr.good()) istr.get();
}
void MailMessage::setRecipientHeaders(MessageHeader& headers) const void MailMessage::setRecipientHeaders(MessageHeader& headers) const
{ {
std::string to; std::string to;

View File

@ -1,7 +1,7 @@
// //
// MultipartReader.cpp // MultipartReader.cpp
// //
// $Id: //poco/1.2/Net/src/MultipartReader.cpp#1 $ // $Id: //poco/1.2/Net/src/MultipartReader.cpp#2 $
// //
// Library: Net // Library: Net
// Package: Messages // Package: Messages
@ -106,8 +106,8 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length)
if (ch == '\r') if (ch == '\r')
{ {
ch = _istr.get(); // '\n' ch = _istr.get(); // '\n'
return 0;
} }
return 0;
} }
else if (ch == '-' && _istr.peek() == '-') else if (ch == '-' && _istr.peek() == '-')
{ {

View File

@ -1,7 +1,7 @@
// //
// SocketNotifier.cpp // SocketNotifier.cpp
// //
// $Id: //poco/1.2/Net/src/SocketNotifier.cpp#1 $ // $Id: //poco/1.2/Net/src/SocketNotifier.cpp#2 $
// //
// Library: Net // Library: Net
// Package: Reactor // Package: Reactor
@ -64,7 +64,7 @@ void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractOb
else if (observer.accepts(pReactor->_pErrorNotification)) else if (observer.accepts(pReactor->_pErrorNotification))
_events.insert(pReactor->_pErrorNotification.get()); _events.insert(pReactor->_pErrorNotification.get());
else if (observer.accepts(pReactor->_pTimeoutNotification)) else if (observer.accepts(pReactor->_pTimeoutNotification))
_events.insert(pReactor->_pErrorNotification.get()); _events.insert(pReactor->_pTimeoutNotification.get());
} }

View File

@ -1,7 +1,7 @@
// //
// MultipartReaderTest.cpp // MultipartReaderTest.cpp
// //
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.cpp#1 $ // $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.cpp#2 $
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@ -329,6 +329,49 @@ void MultipartReaderTest::testRobustness()
} }
void MultipartReaderTest::testUnixLineEnds()
{
std::string s("\n--MIME_boundary_01234567\nname1: value1\n\nthis is part 1\n--MIME_boundary_01234567\n\nthis is part 2\n\n--MIME_boundary_01234567--\n");
std::istringstream istr(s);
MultipartReader r(istr, "MIME_boundary_01234567");
assert (r.hasNextPart());
MessageHeader h;
r.nextPart(h);
assert (h.size() == 1);
assert (h["name1"] == "value1");
std::istream& i = r.stream();
int ch = i.get();
std::string part;
while (ch >= 0)
{
part += (char) ch;
ch = i.get();
}
assert (part == "this is part 1");
assert (r.hasNextPart());
r.nextPart(h);
assert (h.empty());
std::istream& ii = r.stream();
part.clear();
ch = ii.get();
while (ch >= 0)
{
part += (char) ch;
ch = ii.get();
}
assert (part == "this is part 2\n");
try
{
r.nextPart(h);
fail("no more parts - must throw");
}
catch (MultipartException&)
{
}
}
void MultipartReaderTest::setUp() void MultipartReaderTest::setUp()
{ {
} }
@ -351,6 +394,7 @@ CppUnit::Test* MultipartReaderTest::suite()
CppUnit_addTest(pSuite, MultipartReaderTest, testPreamble); CppUnit_addTest(pSuite, MultipartReaderTest, testPreamble);
CppUnit_addTest(pSuite, MultipartReaderTest, testBadBoundary); CppUnit_addTest(pSuite, MultipartReaderTest, testBadBoundary);
CppUnit_addTest(pSuite, MultipartReaderTest, testRobustness); CppUnit_addTest(pSuite, MultipartReaderTest, testRobustness);
CppUnit_addTest(pSuite, MultipartReaderTest, testUnixLineEnds);
return pSuite; return pSuite;
} }

View File

@ -1,7 +1,7 @@
// //
// MultipartReaderTest.h // MultipartReaderTest.h
// //
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.h#1 $ // $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.h#2 $
// //
// Definition of the MultipartReaderTest class. // Definition of the MultipartReaderTest class.
// //
@ -54,6 +54,7 @@ public:
void testPreamble(); void testPreamble();
void testBadBoundary(); void testBadBoundary();
void testRobustness(); void testRobustness();
void testUnixLineEnds();
void setUp(); void setUp();
void tearDown(); void tearDown();