diff --git a/src/vmime/net/imap/IMAPConnection.cpp b/src/vmime/net/imap/IMAPConnection.cpp index 0bde327b..57f2ff5e 100644 --- a/src/vmime/net/imap/IMAPConnection.cpp +++ b/src/vmime/net/imap/IMAPConnection.cpp @@ -72,6 +72,9 @@ IMAPConnection::IMAPConnection(shared_ptr store, shared_ptr (); + + m_parser = make_shared (); + m_parser->setTag(m_tag); } @@ -135,7 +138,8 @@ void IMAPConnection::connect() m_socket->connect(address, port); - m_parser = make_shared (m_tag, m_socket, m_timeoutHandler); + m_parser->setSocket(m_socket); + m_parser->setTimeoutHandler(m_timeoutHandler); setState(STATE_NON_AUTHENTICATED); @@ -808,6 +812,7 @@ shared_ptr IMAPConnection::getSocket() const void IMAPConnection::setSocket(shared_ptr sok) { m_socket = sok; + m_parser->setSocket(sok); } diff --git a/src/vmime/net/imap/IMAPParser.hpp b/src/vmime/net/imap/IMAPParser.hpp index 88f63c64..ba0ea195 100644 --- a/src/vmime/net/imap/IMAPParser.hpp +++ b/src/vmime/net/imap/IMAPParser.hpp @@ -237,23 +237,50 @@ class VMIME_EXPORT IMAPParser : public object { public: - IMAPParser(weak_ptr tag, weak_ptr sok, weak_ptr _timeoutHandler) - : m_tag(tag), m_socket(sok), m_progress(NULL), m_strict(false), - m_literalHandler(NULL), m_timeoutHandler(_timeoutHandler) + IMAPParser() + : m_tag(), m_socket(), m_progress(NULL), m_strict(false), + m_literalHandler(NULL), m_timeoutHandler() { } + /** Set the tag currently used by this parser. + * + * @param tag IMAP command tag + */ + void setTag(shared_ptr tag) + { + m_tag = tag; + } + + /** Return the tag currently used by this parser. + * + * @return IMAP command tag + */ shared_ptr getTag() const { return m_tag.lock(); } + /** Set the socket currently used by this parser to receive data + * from server. + * + * @param sok socket + */ void setSocket(shared_ptr sok) { m_socket = sok; } + /** Set the timeout handler currently used by this parser. + * + * @param toh timeout handler + */ + void setTimeoutHandler(shared_ptr toh) + { + m_timeoutHandler = toh; + } + /** Set whether we operate in strict mode (this may not work * with some servers which are not fully standard-compliant). * diff --git a/tests/net/imap/IMAPParserTest.cpp b/tests/net/imap/IMAPParserTest.cpp index e598a548..b93e4b58 100644 --- a/tests/net/imap/IMAPParserTest.cpp +++ b/tests/net/imap/IMAPParserTest.cpp @@ -49,8 +49,11 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) "a001 OK Capability completed.\r\n"); vmime::shared_ptr parser = - vmime::make_shared - (tag, vmime::dynamicCast (socket), toh); + vmime::make_shared (); + + parser->setTag(tag); + parser->setSocket(socket); + parser->setTimeoutHandler(toh); parser->setStrict(false); VASSERT_NO_THROW("non-strict mode", parser->readResponse(/* literalHandler */ NULL)); @@ -87,8 +90,11 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) socket->localSend("+\r\n"); vmime::shared_ptr parser = - vmime::make_shared - (tag, vmime::dynamicCast (socket), toh); + vmime::make_shared (); + + parser->setTag(tag); + parser->setSocket(socket); + parser->setTimeoutHandler(toh); parser->setStrict(false); VASSERT_NO_THROW("non-strict mode", parser->readResponse());