From 8e5149448674088faf61aa9d8060f933c7520dc5 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 5 Jan 2014 13:53:44 +0100 Subject: [PATCH] Report sending progress when chunking is supported. --- .../smtp/SMTPChunkingOutputStreamAdapter.cpp | 18 ++++++++++++++++-- .../smtp/SMTPChunkingOutputStreamAdapter.hpp | 8 +++++++- src/vmime/net/smtp/SMTPTransport.cpp | 6 ++++-- tests/net/smtp/SMTPTransportTestUtils.hpp | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp index 69f63bc9..5f59e381 100644 --- a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp +++ b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.cpp @@ -40,9 +40,13 @@ namespace net { namespace smtp { -SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter(shared_ptr conn) - : m_connection(conn), m_bufferSize(0), m_chunkCount(0) +SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter + (shared_ptr conn, const size_t size, utility::progressListener* progress) + : m_connection(conn), m_bufferSize(0), m_chunkCount(0), + m_totalSize(size), m_totalSent(0), m_progress(progress) { + if (progress) + progress->start(size); } @@ -61,6 +65,14 @@ void SMTPChunkingOutputStreamAdapter::sendChunk ++m_chunkCount; + if (m_progress) + { + m_totalSent += count; + m_totalSize = std::max(m_totalSize, m_totalSent); + + m_progress->progress(m_totalSent, m_totalSize); + } + // If PIPELINING is not supported, read one response for this BDAT command if (!m_connection->hasExtension("PIPELINING")) { @@ -128,6 +140,8 @@ void SMTPChunkingOutputStreamAdapter::flush() { sendChunk(m_buffer, m_bufferSize, /* last */ true); m_bufferSize = 0; + + m_progress->stop(m_totalSize); } diff --git a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp index cfb3f50f..56d72fb1 100644 --- a/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp +++ b/src/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp @@ -32,6 +32,7 @@ #include "vmime/utility/outputStream.hpp" +#include "vmime/utility/progressListener.hpp" namespace vmime { @@ -48,7 +49,8 @@ class VMIME_EXPORT SMTPChunkingOutputStreamAdapter : public utility::outputStrea { public: - SMTPChunkingOutputStreamAdapter(shared_ptr conn); + SMTPChunkingOutputStreamAdapter(shared_ptr conn, + const size_t size, utility::progressListener* progress); void flush(); @@ -72,6 +74,10 @@ private: size_t m_bufferSize; unsigned int m_chunkCount; + + size_t m_totalSize; + size_t m_totalSent; + utility::progressListener* m_progress; }; diff --git a/src/vmime/net/smtp/SMTPTransport.cpp b/src/vmime/net/smtp/SMTPTransport.cpp index e2174dfb..56adfa21 100644 --- a/src/vmime/net/smtp/SMTPTransport.cpp +++ b/src/vmime/net/smtp/SMTPTransport.cpp @@ -369,11 +369,13 @@ void SMTPTransport::send } // Send message envelope + const size_t msgSize = msg->getGeneratedSize(ctx); + sendEnvelope(expeditor, recipients, sender, - /* sendDATACommand */ false, msg->getGeneratedSize(ctx)); + /* sendDATACommand */ false, msgSize); // Send the message by chunks - SMTPChunkingOutputStreamAdapter chunkStream(m_connection); + SMTPChunkingOutputStreamAdapter chunkStream(m_connection, msgSize, progress); msg->generate(ctx, chunkStream); diff --git a/tests/net/smtp/SMTPTransportTestUtils.hpp b/tests/net/smtp/SMTPTransportTestUtils.hpp index c3296092..108d32d1 100644 --- a/tests/net/smtp/SMTPTransportTestUtils.hpp +++ b/tests/net/smtp/SMTPTransportTestUtils.hpp @@ -410,7 +410,7 @@ public: vmime::size_t getChunkBufferSize() const { - static vmime::net::smtp::SMTPChunkingOutputStreamAdapter chunkStream(vmime::null); + static vmime::net::smtp::SMTPChunkingOutputStreamAdapter chunkStream(vmime::null, 0, NULL); return chunkStream.getBlockSize(); }