Report sending progress when chunking is supported.

This commit is contained in:
Vincent Richard 2014-01-05 13:53:44 +01:00
parent 46963a3d99
commit 8e51494486
4 changed files with 28 additions and 6 deletions

View File

@ -40,9 +40,13 @@ namespace net {
namespace smtp {
SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter(shared_ptr <SMTPConnection> conn)
: m_connection(conn), m_bufferSize(0), m_chunkCount(0)
SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter
(shared_ptr <SMTPConnection> 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);
}

View File

@ -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 <SMTPConnection> conn);
SMTPChunkingOutputStreamAdapter(shared_ptr <SMTPConnection> 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;
};

View File

@ -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);

View File

@ -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();
}