Skip to content

Commit 81ddac4

Browse files
committed
bugfixes for upcoming 1.2.2 release
1 parent 7dc7c65 commit 81ddac4

8 files changed

Lines changed: 74 additions & 13 deletions

File tree

‎Net/include/Poco/Net/MailMessage.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MailMessage.h
33
//
4-
// $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#1 $
4+
// $Id: //poco/1.2/Net/include/Poco/Net/MailMessage.h#2 $
55
//
66
// Library: Net
77
// Package: Mail
@@ -200,6 +200,7 @@ class Net_API MailMessage: public MessageHeader
200200
void readHeader(std::istream& istr);
201201
void readMultipart(std::istream& istr, PartHandler& handler);
202202
void readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
203+
void handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler);
203204
static const std::string& contentTransferEncodingToString(ContentTransferEncoding encoding);
204205
static int lineLength(const std::string& str);
205206
static void appendRecipient(const MailRecipient& recipient, std::string& str);

‎Net/include/Poco/Net/MultipartReader.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MultipartReader.h
33
//
4-
// $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#1 $
4+
// $Id: //poco/1.2/Net/include/Poco/Net/MultipartReader.h#2 $
55
//
66
// Library: Net
77
// Package: Messages
@@ -112,6 +112,10 @@ class Net_API MultipartReader
112112
/// an input stream and optionally a boundary string.
113113
/// - while hasNextPart() returns true, call nextPart()
114114
/// and read the part from stream().
115+
///
116+
/// Always ensure that you read all data from the part
117+
/// stream, otherwise the MultipartReader will fail to
118+
/// find the next part.
115119
{
116120
public:
117121
explicit MultipartReader(std::istream& istr);

‎Net/src/HTMLForm.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HTMLForm.cpp
33
//
4-
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#1 $
4+
// $Id: //poco/1.2/Net/src/HTMLForm.cpp#2 $
55
//
66
// Library: Net
77
// Package: HTML
@@ -288,6 +288,8 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
288288
if (params.has("filename"))
289289
{
290290
handler.handlePart(header, reader.stream());
291+
// Ensure that the complete part has been read.
292+
while (reader.stream().good()) reader.stream().get();
291293
}
292294
else
293295
{

‎Net/src/MailMessage.cpp‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MailMessage.cpp
33
//
4-
// $Id: //poco/1.2/Net/src/MailMessage.cpp#1 $
4+
// $Id: //poco/1.2/Net/src/MailMessage.cpp#2 $
55
//
66
// Library: Net
77
// Package: Mail
@@ -405,20 +405,29 @@ void MailMessage::readPart(std::istream& istr, const MessageHeader& header, Part
405405
if (icompare(encoding, CTE_QUOTED_PRINTABLE) == 0)
406406
{
407407
QuotedPrintableDecoder decoder(istr);
408-
handler.handlePart(header, decoder);
408+
handlePart(decoder, header, handler);
409409
}
410410
else if (icompare(encoding, CTE_BASE64) == 0)
411411
{
412412
Base64Decoder decoder(istr);
413-
handler.handlePart(header, decoder);
413+
handlePart(decoder, header, handler);
414414
}
415415
else
416416
{
417-
handler.handlePart(header, istr);
417+
handlePart(istr, header, handler);
418418
}
419419
}
420420

421421

422+
void MailMessage::handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler)
423+
{
424+
handler.handlePart(header, istr);
425+
// Read remaining characters from stream in case
426+
// the handler failed to read the complete stream.
427+
while (istr.good()) istr.get();
428+
}
429+
430+
422431
void MailMessage::setRecipientHeaders(MessageHeader& headers) const
423432
{
424433
std::string to;

‎Net/src/MultipartReader.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MultipartReader.cpp
33
//
4-
// $Id: //poco/1.2/Net/src/MultipartReader.cpp#1 $
4+
// $Id: //poco/1.2/Net/src/MultipartReader.cpp#2 $
55
//
66
// Library: Net
77
// Package: Messages
@@ -106,8 +106,8 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length)
106106
if (ch == '\r')
107107
{
108108
ch = _istr.get(); // '\n'
109-
return 0;
110109
}
110+
return 0;
111111
}
112112
else if (ch == '-' && _istr.peek() == '-')
113113
{

‎Net/src/SocketNotifier.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// SocketNotifier.cpp
33
//
4-
// $Id: //poco/1.2/Net/src/SocketNotifier.cpp#1 $
4+
// $Id: //poco/1.2/Net/src/SocketNotifier.cpp#2 $
55
//
66
// Library: Net
77
// Package: Reactor
@@ -64,7 +64,7 @@ void SocketNotifier::addObserver(SocketReactor* pReactor, const Poco::AbstractOb
6464
else if (observer.accepts(pReactor->_pErrorNotification))
6565
_events.insert(pReactor->_pErrorNotification.get());
6666
else if (observer.accepts(pReactor->_pTimeoutNotification))
67-
_events.insert(pReactor->_pErrorNotification.get());
67+
_events.insert(pReactor->_pTimeoutNotification.get());
6868
}
6969

7070

‎Net/testsuite/src/MultipartReaderTest.cpp‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MultipartReaderTest.cpp
33
//
4-
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.cpp#1 $
4+
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.cpp#2 $
55
//
66
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
77
// and Contributors.
@@ -329,6 +329,49 @@ void MultipartReaderTest::testRobustness()
329329
}
330330

331331

332+
void MultipartReaderTest::testUnixLineEnds()
333+
{
334+
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");
335+
std::istringstream istr(s);
336+
MultipartReader r(istr, "MIME_boundary_01234567");
337+
assert (r.hasNextPart());
338+
MessageHeader h;
339+
r.nextPart(h);
340+
assert (h.size() == 1);
341+
assert (h["name1"] == "value1");
342+
std::istream& i = r.stream();
343+
int ch = i.get();
344+
std::string part;
345+
while (ch >= 0)
346+
{
347+
part += (char) ch;
348+
ch = i.get();
349+
}
350+
assert (part == "this is part 1");
351+
assert (r.hasNextPart());
352+
r.nextPart(h);
353+
assert (h.empty());
354+
std::istream& ii = r.stream();
355+
part.clear();
356+
ch = ii.get();
357+
while (ch >= 0)
358+
{
359+
part += (char) ch;
360+
ch = ii.get();
361+
}
362+
assert (part == "this is part 2\n");
363+
364+
try
365+
{
366+
r.nextPart(h);
367+
fail("no more parts - must throw");
368+
}
369+
catch (MultipartException&)
370+
{
371+
}
372+
}
373+
374+
332375
void MultipartReaderTest::setUp()
333376
{
334377
}
@@ -351,6 +394,7 @@ CppUnit::Test* MultipartReaderTest::suite()
351394
CppUnit_addTest(pSuite, MultipartReaderTest, testPreamble);
352395
CppUnit_addTest(pSuite, MultipartReaderTest, testBadBoundary);
353396
CppUnit_addTest(pSuite, MultipartReaderTest, testRobustness);
397+
CppUnit_addTest(pSuite, MultipartReaderTest, testUnixLineEnds);
354398

355399
return pSuite;
356400
}

‎Net/testsuite/src/MultipartReaderTest.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// MultipartReaderTest.h
33
//
4-
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.h#1 $
4+
// $Id: //poco/1.2/Net/testsuite/src/MultipartReaderTest.h#2 $
55
//
66
// Definition of the MultipartReaderTest class.
77
//
@@ -54,6 +54,7 @@ class MultipartReaderTest: public CppUnit::TestCase
5454
void testPreamble();
5555
void testBadBoundary();
5656
void testRobustness();
57+
void testUnixLineEnds();
5758

5859
void setUp();
5960
void tearDown();

0 commit comments

Comments
 (0)