From: Jan Engelhardt <[email protected]>

References: KC-263
---
 Rebased this patch onto 8.1.0 upstream release. - xnox.

 inetmapi/ECVMIMEUtils.cpp            |  40 ++---
 inetmapi/ECVMIMEUtils.h              |   5 +-
 inetmapi/MAPISMTPTransport.cpp       | 102 +++++-------
 inetmapi/MAPISMTPTransport.h         |  17 +-
 inetmapi/MAPIToVMIME.cpp             | 155 +++++++++---------
 inetmapi/MAPIToVMIME.h               |  19 +--
 inetmapi/SMIMEMessage.cpp            |   8 +-
 inetmapi/SMIMEMessage.h              |   3 +-
 inetmapi/VMIMEToMAPI.cpp             | 295 ++++++++++++++++++-----------------
 inetmapi/VMIMEToMAPI.h               |  46 +++---
 inetmapi/inetmapi.cpp                |   4 +-
 inetmapi/inputStreamMAPIAdapter.cpp  |   7 +-
 inetmapi/inputStreamMAPIAdapter.h    |  10 +-
 inetmapi/mapiAttachment.cpp          |  17 +-
 inetmapi/mapiAttachment.h            |   4 +-
 inetmapi/mapiTextPart.cpp            | 159 +++++++++----------
 inetmapi/mapiTextPart.h              |  56 +++----
 inetmapi/outputStreamMAPIAdapter.cpp |   4 +-
 inetmapi/outputStreamMAPIAdapter.h   |   7 +-
 inetmapi/serviceRegistration.inl     |  10 +-
 20 files changed, 479 insertions(+), 489 deletions(-)

--- a/inetmapi/ECVMIMEUtils.cpp
+++ b/inetmapi/ECVMIMEUtils.cpp
@@ -19,7 +19,7 @@
 
 // Damn windows header defines max which break C++ header files
 #undef max
-
+#include <memory>
 #include <iostream>
 
 #include "ECVMIMEUtils.h"
@@ -38,6 +38,7 @@
 #include <kopano/EMSAbTag.h>
 #include <kopano/ECABEntryID.h>
 #include <kopano/mapi_ptr.h>
+#include <vmime/base.hpp>
 
 using namespace std;
 
@@ -63,8 +64,9 @@
 class mapiTimeoutHandlerFactory : public vmime::net::timeoutHandlerFactory
 {
 public:
-       vmime::ref<vmime::net::timeoutHandler> create() {
-               return vmime::create<mapiTimeoutHandler>();
+       vmime::shared_ptr<vmime::net::timeoutHandler> create(void)
+       {
+               return vmime::make_shared<mapiTimeoutHandler>();
        };
 };
 
@@ -106,7 +108,7 @@
 
                if (bAddrFetchSuccess && bItemIsAUser) {
                        if (setRecips.find(strEmail) == setRecips.end()) {
-                               
recipients.appendMailbox(vmime::create<vmime::mailbox>(convert_to<string>(strEmail)));
+                               
recipients.appendMailbox(vmime::make_shared<vmime::mailbox>(convert_to<string>(strEmail)));
                                setRecips.insert(strEmail);
                                lpLogger->Log(EC_LOGLEVEL_DEBUG, "RCPT TO: 
%ls", strEmail.c_str());     
                        }
@@ -146,7 +148,7 @@
                                }
                        } else {
                                if (setRecips.find(strEmail) == 
setRecips.end()) {
-                                       
recipients.appendMailbox(vmime::create<vmime::mailbox>(convert_to<string>(strEmail)));
+                                       
recipients.appendMailbox(vmime::make_shared<vmime::mailbox>(convert_to<string>(strEmail)));
                                        setRecips.insert(strEmail);
 
                                        lpLogger->Log(EC_LOGLEVEL_DEBUG, 
"Sending to group-address %s instead of expanded list", 
convert_to<std::string>(strEmail).c_str());
@@ -266,7 +268,10 @@
        return hr;
 }
 
-HRESULT ECVMIMESender::HrMakeRecipientsList(LPADRBOOK lpAdrBook, LPMESSAGE 
lpMessage, vmime::ref<vmime::message> vmMessage, vmime::mailboxList 
&recipients, bool bAllowEveryone, bool bAlwaysExpandDistrList)
+HRESULT ECVMIMESender::HrMakeRecipientsList(LPADRBOOK lpAdrBook,
+    LPMESSAGE lpMessage, vmime::shared_ptr<vmime::message> vmMessage,
+    vmime::mailboxList &recipients, bool bAllowEveryone,
+    bool bAlwaysExpandDistrList)
 {
        HRESULT hr = hrSuccess;
        SRestriction sRestriction;
@@ -318,14 +323,16 @@
 // This function does not catch the vmime exception
 // it should be handled by the calling party.
 
-HRESULT ECVMIMESender::sendMail(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage, 
vmime::ref<vmime::message> vmMessage, bool bAllowEveryone, bool 
bAlwaysExpandDistrList)
+HRESULT ECVMIMESender::sendMail(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage,
+    vmime::shared_ptr<vmime::message> vmMessage, bool bAllowEveryone,
+    bool bAlwaysExpandDistrList)
 {
        HRESULT hr = hrSuccess;
        vmime::mailbox expeditor;
        vmime::mailboxList recipients;
-       vmime::ref<vmime::messaging::session> vmSession;
-       vmime::ref<vmime::messaging::transport> vmTransport;
-       vmime::ref<vmime::net::smtp::MAPISMTPTransport> mapiTransport = NULL;
+       vmime::shared_ptr<vmime::messaging::session> vmSession;
+       vmime::shared_ptr<vmime::messaging::transport> vmTransport;
+       vmime::shared_ptr<vmime::net::smtp::MAPISMTPTransport> mapiTransport;
 
        if (lpMessage == NULL || vmMessage == NULL)
                return MAPI_E_INVALID_PARAMETER;
@@ -335,23 +342,20 @@
 
        try {
                // Session initialization (global properties)
-               vmSession = vmime::create <vmime::net::session>();
+               vmSession = vmime::net::session::create();
 
                // set the server address and port, plus type of service by use 
of url
                // and get our special mapismtp mailer
                vmime::utility::url url("mapismtp", smtphost, smtpport);
                vmTransport = vmSession->getTransport(url);
-               
vmTransport->setTimeoutHandlerFactory(vmime::create<mapiTimeoutHandlerFactory>());
+               
vmTransport->setTimeoutHandlerFactory(vmime::make_shared<mapiTimeoutHandlerFactory>());
 
                // cast to access interface extra's
-               mapiTransport = 
vmTransport.dynamicCast<vmime::net::smtp::MAPISMTPTransport>();
+               mapiTransport = 
vmime::dynamicCast<vmime::net::smtp::MAPISMTPTransport>(vmTransport);
 
                // get expeditor for 'mail from:' smtp command
                try {
-                       const vmime::mailbox& mbox = 
*vmMessage->getHeader()->findField(vmime::fields::FROM)->
-                               getValue().dynamicCast <const vmime::mailbox>();
-
-                       expeditor = mbox;
+                       expeditor = 
*vmime::dynamicCast<vmime::mailbox>(vmMessage->getHeader()->findField(vmime::fields::FROM)->getValue());
                }
                catch (vmime::exceptions::no_such_field&) {
                        throw vmime::exceptions::no_expeditor();
@@ -375,7 +379,7 @@
 
         // Remove BCC headers from the message we're about to send
         try {
-                       vmime::ref <vmime::headerField> bcc = 
vmMessage->getHeader()->findField(vmime::fields::BCC);
+               auto bcc = 
vmMessage->getHeader()->findField(vmime::fields::BCC);
                        vmMessage->getHeader()->removeField(bcc);
         }
         catch (vmime::exceptions::no_such_field&) { }
--- a/inetmapi/ECVMIMEUtils.h
+++ b/inetmapi/ECVMIMEUtils.h
@@ -18,6 +18,7 @@
 #ifndef ECVMIMEUTILS
 #define ECVMIMEUTILS
 
+#include <memory>
 #include <string>
 #include <set>
 #include <kopano/zcdefs.h>
@@ -27,13 +28,13 @@
 
 class ECVMIMESender _kc_final : public ECSender {
 private:
-       HRESULT HrMakeRecipientsList(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage, 
vmime::ref<vmime::message> vmMessage, vmime::mailboxList &recipients, bool 
bAllowEveryone, bool bAlwaysExpandDistrList);
+       HRESULT HrMakeRecipientsList(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage, 
vmime::shared_ptr<vmime::message> vmMessage, vmime::mailboxList &recipients, 
bool bAllowEveryone, bool bAlwaysExpandDistrList);
        HRESULT HrExpandGroup(LPADRBOOK lpAdrBook, LPSPropValue lpGroupName, 
LPSPropValue lpGroupEntryID, vmime::mailboxList &recipients, 
std::set<std::wstring> &setGroups, std::set<std::wstring> &setRecips, bool 
bAllowEveryone);
        HRESULT HrAddRecipsFromTable(LPADRBOOK lpAdrBook, IMAPITable *lpTable, 
vmime::mailboxList &recipients, std::set<std::wstring> &setGroups, 
std::set<std::wstring> &setRecips, bool bAllowEveryone, bool 
bAlwaysExpandDistrList);
 
 public:
        ECVMIMESender(ECLogger *newlpLogger, std::string strSMTPHost, int port);
-       HRESULT sendMail(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage, 
vmime::ref<vmime::message> vmMessage, bool bAllowEveryone, bool 
bAlwaysExpandDistrList);
+       HRESULT sendMail(LPADRBOOK lpAdrBook, LPMESSAGE lpMessage, 
vmime::shared_ptr<vmime::message> vmMessage, bool bAllowEveryone, bool 
bAlwaysExpandDistrList);
 };
 
 #endif
--- a/inetmapi/MAPISMTPTransport.cpp
+++ b/inetmapi/MAPISMTPTransport.cpp
@@ -51,6 +51,8 @@
 #include "vmime/mailboxList.hpp"
 
 #include "vmime/utility/filteredStream.hpp"
+#include <vmime/utility/outputStreamSocketAdapter.hpp>
+#include <vmime/utility/streamUtils.hpp>
 #include "vmime/utility/stringUtils.hpp"
 #include "vmime/net/defaultConnectionInfos.hpp"
 
@@ -83,7 +85,7 @@
 namespace net {
 namespace smtp {
 
-MAPISMTPTransport::MAPISMTPTransport(ref <session> sess, ref 
<security::authenticator> auth, const bool secured)
+MAPISMTPTransport::MAPISMTPTransport(vmime::shared_ptr <session> sess, 
vmime::shared_ptr <security::authenticator> auth, const bool secured)
        : transport(sess, getInfosInstance(), auth), m_socket(NULL),
          m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL),
          m_isSMTPS(secured), m_secured(false), m_lpLogger(NULL),
@@ -129,21 +131,17 @@
 #if VMIME_HAVE_TLS_SUPPORT
        if (m_isSMTPS)  // dedicated port/SMTPS
        {
-               ref <tls::TLSSession> tlsSession =
-                       vmime::create 
<tls::TLSSession>(getCertificateVerifier());
-
-               ref <tls::TLSSocket> tlsSocket =
-                       tlsSession->getSocket(m_socket);
-
+               auto tlsSession = 
tls::TLSSession::create(getCertificateVerifier(), 
getSession()->getTLSProperties());
+               auto tlsSocket = tlsSession->getSocket(m_socket);
                m_socket = tlsSocket;
 
                m_secured = true;
-               m_cntInfos = vmime::create 
<tls::TLSSecuredConnectionInfos>(address, port, tlsSession, tlsSocket);
+               m_cntInfos = 
vmime::make_shared<tls::TLSSecuredConnectionInfos>(address, port, tlsSession, 
tlsSocket);
        }
        else
 #endif // VMIME_HAVE_TLS_SUPPORT
        {
-               m_cntInfos = vmime::create <defaultConnectionInfos>(address, 
port);
+               m_cntInfos = 
vmime::make_shared<defaultConnectionInfos>(address, port);
        }
 
        if (m_lpLogger && m_lpLogger->Log(EC_LOGLEVEL_DEBUG))
@@ -159,7 +157,7 @@
        // eg:  C: <connection to server>
        // ---  S: 220 smtp.domain.com Service ready
 
-       ref <SMTPResponse> resp;
+       vmime::shared_ptr<SMTPResponse> resp;
 
        if ((resp = readResponse())->getCode() != 220)
        {
@@ -225,8 +223,7 @@
 
        sendRequest("EHLO " + platform::getHandler()->getHostName());
 
-       ref <SMTPResponse> resp;
-
+       vmime::shared_ptr<SMTPResponse> resp;
        if ((resp = readResponse())->getCode() != 250)
        {
                // Next, try "Basic" SMTP
@@ -286,7 +283,7 @@
                throw exceptions::command_error("AUTH", "ESMTP not supported.");
        }
 
-       getAuthenticator()->setService(thisRef().dynamicCast <service>());
+       
getAuthenticator()->setService(vmime::dynamicCast<service>(shared_from_this()));
 
 #if VMIME_HAVE_SASL_SUPPORT
        // First, try SASL authentication
@@ -328,7 +325,7 @@
 
 void MAPISMTPTransport::authenticateSASL()
 {
-       if (!getAuthenticator().dynamicCast 
<security::sasl::SASLAuthenticator>())
+       if 
(!vmime::dynamicCast<security::sasl::SASLAuthenticator>(getAuthenticator()))
                throw exceptions::authentication_error("No SASL authenticator 
available.");
 
        // Obtain SASL mechanisms supported by server from ESMTP extensions
@@ -339,10 +336,8 @@
        if (saslMechs.empty())
                throw exceptions::authentication_error("No SASL mechanism 
available.");
 
-       std::vector <ref <security::sasl::SASLMechanism> > mechList;
-
-       ref <security::sasl::SASLContext> saslContext =
-               vmime::create <security::sasl::SASLContext>();
+       std::vector<vmime::shared_ptr<security::sasl::SASLMechanism> > mechList;
+       auto saslContext = security::sasl::SASLContext::create();
 
        for (unsigned int i = 0 ; i < saslMechs.size() ; ++i)
        {
@@ -361,14 +356,12 @@
                throw exceptions::authentication_error("No SASL mechanism 
available.");
 
        // Try to suggest a mechanism among all those supported
-       ref <security::sasl::SASLMechanism> suggestedMech =
-               saslContext->suggestMechanism(mechList);
-
+       auto suggestedMech = saslContext->suggestMechanism(mechList);
        if (!suggestedMech)
                throw exceptions::authentication_error("Unable to suggest SASL 
mechanism.");
 
        // Allow application to choose which mechanisms to use
-       mechList = getAuthenticator().dynamicCast 
<security::sasl::SASLAuthenticator>()->
+       mechList = 
vmime::dynamicCast<security::sasl::SASLAuthenticator>(getAuthenticator())->
                getAcceptableMechanisms(mechList, suggestedMech);
 
        if (mechList.empty())
@@ -377,19 +370,15 @@
        // Try each mechanism in the list in turn
        for (unsigned int i = 0 ; i < mechList.size() ; ++i)
        {
-               ref <security::sasl::SASLMechanism> mech = mechList[i];
-
-               ref <security::sasl::SASLSession> saslSession =
-                       saslContext->createSession("smtp", getAuthenticator(), 
mech);
-
+               auto mech = mechList[i];
+               auto saslSession = saslContext->createSession("smtp", 
getAuthenticator(), mech);
                saslSession->init();
 
                sendRequest("AUTH " + mech->getName());
 
                for (bool cont = true ; cont ; )
                {
-                       ref <SMTPResponse> response = readResponse();
-
+                       auto response = readResponse();
                        switch (response->getCode())
                        {
                        case 235:
@@ -400,10 +389,10 @@
                        case 334:
                        {
                                byte_t* challenge = 0;
-                               int challengeLen = 0;
+                               size_t challengeLen = 0;
 
                                byte_t* resp = 0;
-                               int respLen = 0;
+                               size_t respLen = 0;
 
                                try
                                {
@@ -458,24 +447,18 @@
        try
        {
                sendRequest("STARTTLS");
-
-               ref <SMTPResponse> resp = readResponse();
-
+               auto resp = readResponse();
                if (resp->getCode() != 220)
                        throw exceptions::command_error("STARTTLS", 
resp->getText());
 
-               ref <tls::TLSSession> tlsSession =
-                       vmime::create 
<tls::TLSSession>(getCertificateVerifier());
-
-               ref <tls::TLSSocket> tlsSocket =
-                       tlsSession->getSocket(m_socket);
-
-               tlsSocket->handshake(m_timeoutHandler);
+               auto tlsSession = 
tls::TLSSession::create(getCertificateVerifier(), 
getSession()->getTLSProperties());
+               auto tlsSocket = tlsSession->getSocket(m_socket);
+               tlsSocket->handshake();
 
                m_socket = tlsSocket;
 
                m_secured = true;
-               m_cntInfos = vmime::create <tls::TLSSecuredConnectionInfos>
+               m_cntInfos = vmime::make_shared<tls::TLSSecuredConnectionInfos>
                        (m_cntInfos->getHost(), m_cntInfos->getPort(), 
tlsSession, tlsSocket);
        }
        catch (exceptions::command_error&)
@@ -536,8 +519,7 @@
 
        sendRequest("NOOP");
 
-       ref <SMTPResponse> resp = readResponse();
-
+       auto resp = readResponse();
        if (resp->getCode() != 250)
                throw exceptions::command_error("NOOP", resp->getText());
 }
@@ -545,9 +527,9 @@
 //                             
 // Only this function is altered, to return per recipient failure.
 //                             
-void MAPISMTPTransport::send(const mailbox& expeditor, const mailboxList& 
recipients,
-                         utility::inputStream& is, const 
utility::stream::size_type size,
-                         utility::progressListener* progress)
+void MAPISMTPTransport::send(const mailbox &expeditor,
+    const mailboxList &recipients, utility::inputStream &is, size_t size,
+    utility::progressListener *progress, const mailbox &sender)
 {
        if (!isConnected())
                throw exceptions::not_connected();
@@ -559,7 +541,7 @@
                throw exceptions::no_expeditor();
 
        // Emit the "MAIL" command
-       ref <SMTPResponse> resp;
+       vmime::shared_ptr<SMTPResponse> resp;
        string strSend;
        bool bDSN = m_bDSNRequest;
        
@@ -568,7 +550,7 @@
                bDSN = false; // Disable DSN because the server does not 
support this.
        }
 
-       strSend = "MAIL FROM: <" + expeditor.getEmail() + ">";
+       strSend = "MAIL FROM: <" + expeditor.getEmail().toString() + ">";
        if (bDSN) {
                strSend += " RET=HDRS";
                if (!m_strDSNTrackid.empty())
@@ -586,12 +568,11 @@
        // Emit a "RCPT TO" command for each recipient
        mTemporaryFailedRecipients.clear();
        mPermanentFailedRecipients.clear();
-       for (int i = 0 ; i < recipients.getMailboxCount() ; ++i)
-       {
+       for (size_t i = 0 ; i < recipients.getMailboxCount(); ++i) {
                const mailbox& mbox = *recipients.getMailboxAt(i);
                unsigned int code;
 
-               strSend = "RCPT TO: <" + mbox.getEmail() + ">";
+               strSend = "RCPT TO: <" + mbox.getEmail().toString() + ">";
                if (bDSN)
                         strSend += " NOTIFY=SUCCESS,DELAY";
 
@@ -601,7 +582,7 @@
 
                sFailedRecip entry;
                entry.strRecipName = 
(WCHAR*)mbox.getName().getConvertedText(charset(CHARSET_WCHAR)).c_str(); // 
does this work?, or convert to utf-8 then wstring?
-               entry.strRecipEmail = mbox.getEmail();
+               entry.strRecipEmail = mbox.getEmail().toString();
                entry.ulSMTPcode = code;
                entry.strSMTPResponse = resp->getText();
 
@@ -655,7 +636,7 @@
        fos.flush();
 
        // Send end-of-data delimiter
-       m_socket->sendRaw("\r\n.\r\n", 5);
+       m_socket->sendRaw(reinterpret_cast<const vmime::byte_t *>("\r\n.\r\n"), 
5);
 
        if ((resp = readResponse())->getCode() != 250)
        {
@@ -695,9 +676,11 @@
                m_socket->send(buffer);
 }
 
-ref <SMTPResponse> MAPISMTPTransport::readResponse()
+vmime::shared_ptr <SMTPResponse> MAPISMTPTransport::readResponse(void)
 {
-       ref <SMTPResponse> resp = SMTPResponse::readResponse(m_socket, 
m_timeoutHandler);
+    vmime::shared_ptr<tracer> t;
+    auto resp = SMTPResponse::readResponse(t, m_socket, m_timeoutHandler, 
m_response_state);
+    m_response_state = resp->getCurrentState();
        if (m_lpLogger && m_lpLogger->Log(EC_LOGLEVEL_DEBUG))
                m_lpLogger->Log(EC_LOGLEVEL_DEBUG, "> %d %s", resp->getCode(), 
resp->getText().c_str());
        return resp;
--- a/inetmapi/MAPISMTPTransport.h
+++ b/inetmapi/MAPISMTPTransport.h
@@ -51,6 +51,7 @@
 #include "vmime/net/socket.hpp"
 #include "vmime/net/timeoutHandler.hpp"
 
+#include <vmime/net/smtp/SMTPResponse.hpp>
 #include "vmime/net/smtp/SMTPServiceInfos.hpp"
 
 #include <inetmapi/inetmapi.h>
@@ -69,7 +70,7 @@
 class MAPISMTPTransport _kc_final : public transport {
 public:
 
-       MAPISMTPTransport(ref <session> sess, ref <security::authenticator> 
auth, const bool secured = false);
+       MAPISMTPTransport(vmime::shared_ptr<session> sess, 
vmime::shared_ptr<security::authenticator> auth, const bool secured = false);
        ~MAPISMTPTransport();
 
        const std::string getProtocolName(void) const { return "mapismtp"; }
@@ -83,10 +84,10 @@
 
        void noop();
 
-       void send(const mailbox& expeditor, const mailboxList& recipients, 
utility::inputStream& is, const utility::stream::size_type size, 
utility::progressListener* progress = NULL);
+       void send(const mailbox &expeditor, const mailboxList &recipients, 
utility::inputStream &, size_t, utility::progressListener * = NULL, const 
mailbox &sender = mailbox());
 
        bool isSecuredConnection(void) const { return m_secured; }
-       ref<connectionInfos> getConnectionInfos(void) const { return 
m_cntInfos; }
+       vmime::shared_ptr<connectionInfos> getConnectionInfos(void) const { 
return m_cntInfos; }
 
        // additional functions
        const std::vector<sFailedRecip> &getPermanentFailedRecipients(void) 
const { return mPermanentFailedRecipients; }
@@ -97,7 +98,7 @@
 private:
 
        void sendRequest(const string& buffer, const bool end = true);
-       ref <SMTPResponse> readResponse();
+       vmime::shared_ptr<SMTPResponse> readResponse(void);
 
        void internalDisconnect();
 
@@ -111,18 +112,17 @@
        void startTLS();
 #endif // VMIME_HAVE_TLS_SUPPORT
 
-       ref <socket> m_socket;
+       vmime::shared_ptr<socket> m_socket;
        bool m_authentified;
 
        bool m_extendedSMTP;
        std::map <string, std::vector <string> > m_extensions;
-
-       ref <timeoutHandler> m_timeoutHandler;
+       vmime::shared_ptr<timeoutHandler> m_timeoutHandler;
 
        const bool m_isSMTPS;
 
        bool m_secured;
-       ref <connectionInfos> m_cntInfos;
+       vmime::shared_ptr<connectionInfos> m_cntInfos;
 
 
        // Service infos
@@ -135,6 +135,7 @@
        ECLogger *m_lpLogger;
        bool m_bDSNRequest;
        std::string m_strDSNTrackid;
+       SMTPResponse::state m_response_state;
 };
 
 
--- a/inetmapi/MAPIToVMIME.cpp
+++ b/inetmapi/MAPIToVMIME.cpp
@@ -191,7 +191,7 @@
 HRESULT MAPIToVMIME::processRecipients(IMessage *lpMessage, 
vmime::messageBuilder *lpVMMessageBuilder)
 {
        HRESULT                 hr                                      = 
hrSuccess;
-       vmime::ref<vmime::address>      vmMailbox;
+       vmime::shared_ptr<vmime::address> vmMailbox;
        LPMAPITABLE             lpRecipientTable        = NULL;
        LPSRowSet               pRows                           = NULL;
        LPSPropValue    pPropRecipType          = NULL;
@@ -269,7 +269,7 @@
                        }
 
                        // No recipients were in the 'To' .. add 'undisclosed 
recipients'
-                       vmime::ref<vmime::mailboxGroup> undisclosed = 
vmime::create<vmime::mailboxGroup>(vmime::text("undisclosed-recipients"));
+                       vmime::shared_ptr<vmime::mailboxGroup> undisclosed = 
vmime::make_shared<vmime::mailboxGroup>(vmime::text("undisclosed-recipients"));
                        
lpVMMessageBuilder->getRecipients().appendAddress(undisclosed);
                }
                        
@@ -323,9 +323,9 @@
        ULONG                   ulAttachmentMethod      = 0;
        IMessage*               lpAttachedMessage       = NULL;
 
-       vmime::ref<vmime::utility::inputStream> inputDataStream = NULL;
-       vmime::ref<mapiAttachment> vmMapiAttach = NULL;
-       vmime::ref<vmime::attachment> vmMsgAtt = NULL;
+       vmime::shared_ptr<vmime::utility::inputStream> inputDataStream;
+       vmime::shared_ptr<mapiAttachment> vmMapiAttach;
+       vmime::shared_ptr<vmime::attachment> vmMsgAtt;
        std::string             strContentId;
        std::string             strContentLocation;
        bool                    bHidden = false;
@@ -358,7 +358,7 @@
        }
 
        if (ulAttachmentMethod == ATTACH_EMBEDDED_MSG) {
-               vmime::ref<vmime::message> vmNewMess;
+               vmime::shared_ptr<vmime::message> vmNewMess;
                std::string strBuff;
                vmime::utility::outputStreamStringAdapter mout(strBuff);
 
@@ -408,7 +408,7 @@
                }
                sopt = sopt_keep;
 
-               vmMsgAtt = 
vmime::create<vmime::parsedMessageAttachment>(vmNewMess);
+               vmMsgAtt = 
vmime::make_shared<vmime::parsedMessageAttachment>(vmNewMess);
                lpVMMessageBuilder->appendAttachment(vmMsgAtt);
        } else if (ulAttachmentMethod == ATTACH_BY_VALUE) {
                hr = lpMessage->OpenAttach(ulAttachmentNum, NULL, 
MAPI_BEST_ACCESS, &lpAttach);
@@ -438,7 +438,8 @@
         }
                
                try {
-                       inputDataStream = 
vmime::create<inputStreamMAPIAdapter>(lpStream);      // add ref to lpStream
+                       // add ref to lpStream
+                       inputDataStream = 
vmime::make_shared<inputStreamMAPIAdapter>(lpStream);
 
                        // Set filename
                        szFilename = L"data.bin";
@@ -466,9 +467,9 @@
                                vmime::mapiTextPart& textPart = 
dynamic_cast<vmime::mapiTextPart&>(*lpVMMessageBuilder->getTextPart());
                                // had szFilename .. but how, on inline?
                                // @todo find out how Content-Disposition 
receives highchar filename... always utf-8?
-                               
textPart.addObject(vmime::create<vmime::streamContentHandler>(inputDataStream, 
0), vmime::encoding("base64"), vmMIMEType, strContentId, string(), 
strContentLocation);
+                               
textPart.addObject(vmime::make_shared<vmime::streamContentHandler>(inputDataStream,
 0), vmime::encoding("base64"), vmMIMEType, strContentId, string(), 
strContentLocation);
                        } else {
-                               vmMapiAttach = 
vmime::create<mapiAttachment>(vmime::create<vmime::streamContentHandler>(inputDataStream,
 0),
+                               vmMapiAttach = 
make_shared<mapiAttachment>(vmime::make_shared<vmime::streamContentHandler>(inputDataStream,
 0),
                                                                                
                                         bSendBinary ? 
vmime::encoding("base64") : vmime::encoding("quoted-printable"),
                                                                                
                                         vmMIMEType, strContentId,
                                                                                
                                         
vmime::word(m_converter.convert_to<string>(m_strCharset.c_str(), szFilename, 
rawsize(szFilename), CHARSET_WCHAR), m_vmCharset));
@@ -709,27 +710,26 @@
  * @param[in]  boundary        new boundary string to use.
  * @return Always hrSuccess
  */
-HRESULT MAPIToVMIME::setBoundaries(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, const std::string& boundary)
+HRESULT MAPIToVMIME::setBoundaries(vmime::shared_ptr<vmime::header> vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, const std::string& boundary)
 {
-       int i = 0;
-       vmime::ref<vmime::contentTypeField> vmCTF;
+       vmime::shared_ptr<vmime::contentTypeField> vmCTF;
 
        try {
-               vmCTF = 
vmHeader->findField(vmime::fields::CONTENT_TYPE).dynamicCast 
<vmime::contentTypeField>();
+               vmCTF = 
vmime::dynamicCast<vmime::contentTypeField>(vmHeader->findField(vmime::fields::CONTENT_TYPE));
        }
        catch (vmime::exceptions::no_such_field) {
                return hrSuccess;
        }
 
-       if(vmCTF->getValue().dynamicCast<vmime::mediaType>()->getType() == 
vmime::mediaTypes::MULTIPART) {
+       if (vmime::dynamicCast<vmime::mediaType>(vmCTF->getValue())->getType() 
== vmime::mediaTypes::MULTIPART) {
                // This is a multipart, so set the boundary for this part
                vmCTF->setBoundary(boundary);
         
                // Set boundaries on children also
-               for (i = 0; i < vmBody->getPartCount(); ++i) {
+               for (size_t i = 0; i < vmBody->getPartCount(); ++i) {
                        std::ostringstream os;
-
-                       vmime::ref<vmime::bodyPart> vmBodyPart = 
vmBody->getPartAt(i);
+                       vmime::shared_ptr<vmime::bodyPart> vmBodyPart = 
vmBody->getPartAt(i);
 
                        os << boundary << "_" << i;
             
@@ -748,13 +748,13 @@
  * @param[out] lpvmMessage             vmime message version of lpMessage
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::BuildNoteMessage(IMessage *lpMessage, bool bSkipContent, 
vmime::ref<vmime::message> *lpvmMessage)
+HRESULT MAPIToVMIME::BuildNoteMessage(IMessage *lpMessage, bool bSkipContent, 
vmime::shared_ptr<vmime::message> *lpvmMessage)
 {
        HRESULT                                 hr                              
        = hrSuccess;
        LPSPropValue                    lpDeliveryDate          = NULL;
        LPSPropValue                    lpTransportHeaders      = NULL;
        vmime::messageBuilder   vmMessageBuilder;
-       vmime::ref<vmime::message>                      vmMessage;
+       vmime::shared_ptr<vmime::message>                       vmMessage;
 
        // construct the message..
        try {
@@ -766,7 +766,7 @@
                vmMessage = vmMessageBuilder.construct();
                // message builder has set Date header to now(). this will be 
overwritten.
 
-               vmime::ref<vmime::header> vmHeader = vmMessage->getHeader();
+               auto vmHeader = vmMessage->getHeader();
 
                hr = handleExtraHeaders(lpMessage, vmHeader);
                if (hr!= hrSuccess)
@@ -810,8 +810,8 @@
                                strHeaders += "\r\n\r\n";
                                headers.parse(strHeaders);
                                
-                               for (int i = 0; i < headers.getFieldCount(); 
++i) {
-                                       vmime::ref<vmime::headerField> vmField 
= headers.getFieldAt(i);
+                               for (size_t i = 0; i < headers.getFieldCount(); 
++i) {
+                                       vmime::shared_ptr<vmime::headerField> 
vmField = headers.getFieldAt(i);
                                        std::string name = vmField->getName();
 
                                        // Received checks start of string to 
accept Received-SPF
@@ -822,7 +822,7 @@
                                        } else if (strncasecmp(name.c_str(), 
"list-", strlen("list-")) == 0 ||
                                                           
strcasecmp(name.c_str(), "precedence") == 0) {
                                                // Just append at the end of 
this list, order is not important
-                                               
vmHeader->appendField(vmField->clone().dynamicCast<vmime::headerField>());
+                                               
vmHeader->appendField(vmime::dynamicCast<vmime::headerField>(vmField->clone()));
                                        }
                                }
                        } catch (vmime::exception& e) {
@@ -835,9 +835,9 @@
 
                // POP3 wants the delivery date as received header to correctly 
show in outlook
                if (sopt.add_received_date && lpDeliveryDate) {
-                       vmime::headerFieldFactory* hff = 
vmime::headerFieldFactory::getInstance();
-                       vmime::ref<vmime::headerField> rf = 
hff->create(vmime::fields::RECEIVED);
-                       
rf->getValue().dynamicCast<vmime::relay>()->setDate(FiletimeTovmimeDatetime(lpDeliveryDate->Value.ft));
+                       auto hff = vmime::headerFieldFactory::getInstance();
+                       vmime::shared_ptr<vmime::headerField> rf = 
hff->create(vmime::fields::RECEIVED);
+                       
vmime::dynamicCast<vmime::relay>(rf->getValue())->setDate(FiletimeTovmimeDatetime(lpDeliveryDate->Value.ft));
                        // set received header at the start
                        vmHeader->insertFieldBefore(0, rf);
                }
@@ -880,10 +880,11 @@
  * @param[out] lpvmMessage             vmime message version of lpMessage
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::BuildMDNMessage(IMessage *lpMessage, 
vmime::ref<vmime::message> *lpvmMessage)
+HRESULT MAPIToVMIME::BuildMDNMessage(IMessage *lpMessage,
+    vmime::shared_ptr<vmime::message> *lpvmMessage)
 {
        HRESULT                         hr = hrSuccess;
-       vmime::ref<vmime::message>      vmMessage = NULL;
+       vmime::shared_ptr<vmime::message> vmMessage;
        IStream*                        lpBodyStream = NULL;
        LPSPropValue            lpiNetMsgId = NULL;
        LPSPropValue            lpMsgClass = NULL;
@@ -896,8 +897,8 @@
        vmime::disposition      dispo;
        string                          reportingUA; //empty
        std::vector<string>     reportingUAProducts; //empty
-       vmime::ref<vmime::message>      vmMsgOriginal;
-       vmime::ref<vmime::address>      vmRecipientbox;
+       vmime::shared_ptr<vmime::message> vmMsgOriginal;
+       vmime::shared_ptr<vmime::address> vmRecipientbox;
        string                          strActionMode;
        std::wstring            strOut;
 
@@ -911,7 +912,7 @@
        }
 
        try {
-               vmMsgOriginal = vmime::create<vmime::message>();
+               vmMsgOriginal = vmime::make_shared<vmime::message>();
 
                // Create original vmime message
                if (HrGetOneProp(lpMessage, PR_INTERNET_MESSAGE_ID_A, 
&lpiNetMsgId) == hrSuccess)
@@ -940,7 +941,7 @@
                                goto exit;
                        } else {
                                // no recipient, but need to continue ... is 
this correct??
-                               vmRecipientbox = 
vmime::create<vmime::mailbox>(string("undisclosed-recipients"));
+                               vmRecipientbox = 
vmime::make_shared<vmime::mailbox>(string("undisclosed-recipients"));
                        }
                } else {
                        hr = getMailBox(&pRows->aRow[0], &vmRecipientbox);
@@ -956,7 +957,7 @@
                        goto exit;
                }
 
-               vmime::mdn::sendableMDNInfos mdnInfos(vmMsgOriginal, 
*vmRecipientbox.dynamicCast<vmime::mailbox>().get());
+               vmime::mdn::sendableMDNInfos mdnInfos(vmMsgOriginal, 
*vmime::dynamicCast<vmime::mailbox>(vmRecipientbox).get());
                
                //FIXME: Get the ActionMode and sending mode from the property 
0x0081001E.
                //              And the type in property 0x0080001E.
@@ -1080,11 +1081,11 @@
  * @param[out] lpvmMessage             message to send to SMTP or Gateway 
client
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::convertMAPIToVMIME(IMessage *lpMessage, 
vmime::ref<vmime::message> *lpvmMessage) {
+HRESULT MAPIToVMIME::convertMAPIToVMIME(IMessage *lpMessage, 
vmime::shared_ptr<vmime::message> *lpvmMessage) {
        HRESULT                                 hr                              
        = hrSuccess;
        LPSPropValue                    lpInternetCPID          = NULL;
        LPSPropValue                    lpMsgClass                      = NULL;
-       vmime::ref<vmime::message>      vmMessage;
+       vmime::shared_ptr<vmime::message>       vmMessage;
        const char *lpszCharset = NULL;
        char *                                  lpszRawSMTP                     
= NULL;
        LPMAPITABLE                             lpAttachmentTable       = NULL;
@@ -1212,7 +1213,7 @@
 
                if (strcasecmp(lpMsgClass->Value.lpszA, "IPM.Note.SMIME") != 0) 
{
                        std::string strRawSMTP = lpszRawSMTP;
-                       vmime::ref<SMIMEMessage> vmSMIMEMessage = 
vmime::create<SMIMEMessage>();
+                       auto vmSMIMEMessage = 
vmime::make_shared<SMIMEMessage>();
                        
                        // not sure why this was needed, and causes problems, 
eg ZCP-12994.
                        
//vmMessage->getHeader()->removeField(vmMessage->getHeader()->findField(vmime::fields::MIME_VERSION));
@@ -1260,7 +1261,7 @@
 
                        // copy via string so we can set the size of the string 
since it's binary
                        vmime::string inString(lpszRawSMTP, 
(size_t)sStreamStat.cbSize.QuadPart);
-                       
vmMessage->getBody()->setContents(vmime::create<vmime::stringContentHandler>(inString));
+                       
vmMessage->getBody()->setContents(vmime::make_shared<vmime::stringContentHandler>(inString));
 
                        // vmime now encodes the body too, so I don't have to
                        
vmMessage->getHeader()->appendField(vmime::headerFieldFactory::getInstance()->create(vmime::fields::CONTENT_TRANSFER_ENCODING,
 "base64"));
@@ -1397,10 +1398,11 @@
  * @return MAPI error code
  * @retval MAPI_E_INVALID_PARAMTER email address in row is not usable for the 
SMTP protocol
  */
-HRESULT MAPIToVMIME::getMailBox(LPSRow lpRow, vmime::ref<vmime::address> 
*lpvmMailbox)
+HRESULT MAPIToVMIME::getMailBox(LPSRow lpRow,
+    vmime::shared_ptr<vmime::address> *lpvmMailbox)
 {
        HRESULT hr;
-       vmime::ref<vmime::address> vmMailboxNew;
+       vmime::shared_ptr<vmime::address> vmMailboxNew;
        std::wstring strName, strEmail, strType;
        LPSPropValue pPropObjectType = NULL;
 
@@ -1414,18 +1416,18 @@
 
        if (strName.empty() && !strEmail.empty()) {
                // email address only
-               vmMailboxNew = 
vmime::create<vmime::mailbox>(m_converter.convert_to<string>(strEmail));
+               vmMailboxNew = 
vmime::make_shared<vmime::mailbox>(m_converter.convert_to<string>(strEmail));
        } else if (strEmail.find('@') != string::npos) {
                // email with fullname
-               vmMailboxNew = 
vmime::create<vmime::mailbox>(getVmimeTextFromWide(strName), 
m_converter.convert_to<string>(strEmail));
+               vmMailboxNew = 
vmime::make_shared<vmime::mailbox>(getVmimeTextFromWide(strName), 
m_converter.convert_to<string>(strEmail));
        } else if (pPropObjectType && pPropObjectType->Value.ul == 
MAPI_DISTLIST) {
                // if mailing to a group without email address
-               vmMailboxNew = 
vmime::create<vmime::mailboxGroup>(getVmimeTextFromWide(strName));
+               vmMailboxNew = 
vmime::make_shared<vmime::mailboxGroup>(getVmimeTextFromWide(strName));
        } else if (sopt.no_recipients_workaround == true) {
                // gateway must always return an mailbox object
                if (strEmail.empty())
                        strEmail = L"@";        // force having an address to 
avoid vmime problems
-               vmMailboxNew = 
vmime::create<vmime::mailbox>(getVmimeTextFromWide(strName), 
m_converter.convert_to<string>(strEmail));
+               vmMailboxNew = 
vmime::make_shared<vmime::mailbox>(getVmimeTextFromWide(strName), 
m_converter.convert_to<string>(strEmail));
        } else {
                if (strEmail.empty()) {
                        // not an email address and not a group: invalid
@@ -1465,7 +1467,7 @@
        // set the encoder of plaintext body part
        vmime::encoding bodyEncoding("quoted-printable");
        // will skip enters in q-p encoding, "fixes" plaintext mails to be more 
plain text
-       vmime::ref<vmime::utility::encoder::encoder> vmBodyEncoder = 
bodyEncoding.getEncoder();
+       vmime::shared_ptr<vmime::utility::encoder::encoder> vmBodyEncoder = 
bodyEncoding.getEncoder();
        vmBodyEncoder->getProperties().setProperty("text", true);
 
        *bestBody = plaintext;
@@ -1540,11 +1542,11 @@
                                // convert from HTML charset to vmime output 
charset
                                strHTMLOut = 
m_converter.convert_to<string>(m_vmCharset.getName().c_str(), strHTMLOut, 
rawsize(strHTMLOut), m_strHTMLCharset.c_str());
                        }
-                       vmime::ref<vmime::mapiTextPart> textPart = 
lpVMMessageBuilder->getTextPart().dynamicCast<vmime::mapiTextPart>();
-                       
textPart->setText(vmime::create<vmime::stringContentHandler>(strHTMLOut));
+                       vmime::shared_ptr<vmime::mapiTextPart> textPart = 
vmime::dynamicCast<vmime::mapiTextPart>(lpVMMessageBuilder->getTextPart());
+                       
textPart->setText(vmime::make_shared<vmime::stringContentHandler>(strHTMLOut));
                        textPart->setCharset(m_vmCharset);
                        if (!strBodyConverted.empty())
-                               
textPart->setPlainText(vmime::create<vmime::stringContentHandler>(strBodyConverted));
+                               
textPart->setPlainText(vmime::make_shared<vmime::stringContentHandler>(strBodyConverted));
                } else { // else just plaintext
                        if (!strBodyConverted.empty()) {
                                // make sure we give vmime CRLF data, so SMTP 
servers (qmail) won't complain on the forced plaintext
@@ -1563,7 +1565,7 @@
                                vmBodyEncoder->encode(in, out);
 
                                
lpVMMessageBuilder->getTextPart()->setCharset(m_vmCharset);
-                               
lpVMMessageBuilder->getTextPart().dynamicCast<vmime::mapiTextPart>()->setPlainText(vmime::create<vmime::stringContentHandler>(outString,
 bodyEncoding));
+                               
vmime::dynamicCast<vmime::mapiTextPart>(lpVMMessageBuilder->getTextPart())->setPlainText(vmime::make_shared<vmime::stringContentHandler>(outString,
 bodyEncoding));
                        }
                }
        }
@@ -1610,7 +1612,7 @@
  * @param[in]  vmHeader        vmime header object to add X headers to
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::handleXHeaders(IMessage *lpMessage, 
vmime::ref<vmime::header> vmHeader) {
+HRESULT MAPIToVMIME::handleXHeaders(IMessage *lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader) {
        HRESULT hr;
        ULONG i;
        ULONG cValues;
@@ -1619,7 +1621,7 @@
        LPSPropValue lpPropArray = NULL;
        ULONG cNames;
        LPMAPINAMEID *lppNames = NULL;
-       vmime::headerFieldFactory* hff = 
vmime::headerFieldFactory::getInstance();
+       auto hff = vmime::headerFieldFactory::getInstance();
 
        // get all props on message
        hr = lpMessage->GetPropList(0, &lpsAllTags);
@@ -1713,7 +1715,7 @@
  * @param[in]  vmHeader        Add headers to this vmime header object
  * @return always hrSuccess
  */
-HRESULT MAPIToVMIME::handleExtraHeaders(IMessage *lpMessage, 
vmime::ref<vmime::header> vmHeader) {
+HRESULT MAPIToVMIME::handleExtraHeaders(IMessage *lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader) {
        HRESULT hr = hrSuccess;
        SPropValuePtr ptrMessageId;
        LPSPropValue lpImportance = NULL;
@@ -1722,13 +1724,13 @@
        LPSPropValue lpConversationTopic = NULL;
        LPSPropValue lpNormSubject = NULL;
        LPSPropValue lpSensitivity = NULL;
-       vmime::headerFieldFactory* hff = 
vmime::headerFieldFactory::getInstance();
+       auto hff = vmime::headerFieldFactory::getInstance();
        LPSPropValue lpExpiryTime = NULL;
 
        // Conversation headers. New Message-Id header is set just before 
sending.
        if (HrGetOneProp(lpMessage, PR_IN_REPLY_TO_ID_A, &ptrMessageId) == 
hrSuccess && ptrMessageId->Value.lpszA[0]) {
-               vmime::ref<vmime::messageId> mid = 
vmime::create<vmime::messageId>(ptrMessageId->Value.lpszA);
-               
vmHeader->InReplyTo()->getValue().dynamicCast<vmime::messageIdSequence>()->appendMessageId(mid);
+               vmime::shared_ptr<vmime::messageId> mid = 
vmime::make_shared<vmime::messageId>(ptrMessageId->Value.lpszA);
+               
vmime::dynamicCast<vmime::messageIdSequence>(vmHeader->InReplyTo()->getValue())->appendMessageId(mid);
        }
 
        // Outlook never adds this property
@@ -1738,9 +1740,8 @@
 
                const size_t n = ids.size();
                for (size_t i = 0; i < n; ++i) {
-                       vmime::ref<vmime::messageId> mid = 
vmime::create<vmime::messageId>(ids.at(i));
-
-                       
vmHeader->References()->getValue().dynamicCast<vmime::messageIdSequence>()->appendMessageId(mid);
+                       vmime::shared_ptr<vmime::messageId> mid = 
vmime::make_shared<vmime::messageId>(ids.at(i));
+                       
vmime::dynamicCast<vmime::messageIdSequence>(vmHeader->References()->getValue())->appendMessageId(mid);
                }
        }
 
@@ -1764,7 +1765,7 @@
                vmime::string inString;
                inString.assign((const 
char*)lpConversationIndex->Value.bin.lpb, lpConversationIndex->Value.bin.cb);
 
-               vmime::ref<vmime::utility::encoder::encoder> enc = 
vmime::utility::encoder::encoderFactory::getInstance()->create("base64");
+               vmime::shared_ptr<vmime::utility::encoder::encoder> enc = 
vmime::utility::encoder::encoderFactory::getInstance()->create("base64");
                vmime::utility::inputStreamStringAdapter in(inString);
                vmime::string outString;
                vmime::utility::outputStreamStringAdapter out(outString);
@@ -1922,7 +1923,7 @@
  * @param[in]  vmHeader        vmime header object to modify.
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::handleSenderInfo(IMessage *lpMessage, 
vmime::ref<vmime::header> vmHeader) {
+HRESULT MAPIToVMIME::handleSenderInfo(IMessage *lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader) {
        HRESULT hr = hrSuccess;
        ULONG cValues;
        LPSPropValue lpProps = NULL;
@@ -2017,14 +2018,14 @@
                if (!strResEmail.empty() && strResEmail != strEmail) {
                        // use user added from address
                        if (strResName.empty() || strName == strResEmail)
-                               
mbl.appendMailbox(vmime::create<vmime::mailbox>(m_converter.convert_to<string>(strResEmail)));
+                               
mbl.appendMailbox(vmime::make_shared<vmime::mailbox>(m_converter.convert_to<string>(strResEmail)));
                        else
-                               
mbl.appendMailbox(vmime::create<vmime::mailbox>(getVmimeTextFromWide(strResName),
 m_converter.convert_to<string>(strResEmail)));
+                               
mbl.appendMailbox(vmime::make_shared<vmime::mailbox>(getVmimeTextFromWide(strResName),
 m_converter.convert_to<string>(strResEmail)));
                } else {
                        if (strName.empty() || strName == strEmail)
-                               
mbl.appendMailbox(vmime::create<vmime::mailbox>(m_converter.convert_to<string>(strEmail)));
+                               
mbl.appendMailbox(vmime::make_shared<vmime::mailbox>(m_converter.convert_to<string>(strEmail)));
                        else
-                               
mbl.appendMailbox(vmime::create<vmime::mailbox>(getVmimeTextFromWide(strName), 
m_converter.convert_to<string>(strEmail)));
+                               
mbl.appendMailbox(vmime::make_shared<vmime::mailbox>(getVmimeTextFromWide(strName),
 m_converter.convert_to<string>(strEmail)));
                }
                vmHeader->DispositionNotificationTo()->setValue(mbl);
        }
@@ -2048,7 +2049,9 @@
  * @param[in]  vmHeader        vmime header object to modify.
  * @return Mapi error code
  */
-HRESULT MAPIToVMIME::handleReplyTo(IMessage *lpMessage, 
vmime::ref<vmime::header> vmHeader) {
+HRESULT MAPIToVMIME::handleReplyTo(IMessage *lpMessage,
+    vmime::shared_ptr<vmime::header> vmHeader)
+{
        HRESULT                 hr = hrSuccess;
        LPSPropValue    lpReplyTo = NULL;
        FLATENTRYLIST   *lpEntryList = NULL;
@@ -2144,9 +2147,9 @@
 
        // vmime can only set 1 email address in the ReplyTo field.
        if (!strName.empty() && strName != strEmail)
-               
vmHeader->ReplyTo()->setValue(vmime::create<vmime::mailbox>(getVmimeTextFromWide(strName),
 m_converter.convert_to<string>(strEmail)));
+               
vmHeader->ReplyTo()->setValue(vmime::make_shared<vmime::mailbox>(getVmimeTextFromWide(strName),
 m_converter.convert_to<string>(strEmail)));
        else
-               
vmHeader->ReplyTo()->setValue(vmime::create<vmime::mailbox>(m_converter.convert_to<string>(strEmail)));
+               
vmHeader->ReplyTo()->setValue(vmime::make_shared<vmime::mailbox>(m_converter.convert_to<string>(strEmail)));
 
        hr = hrSuccess;
 
@@ -2287,9 +2290,8 @@
                        bestBody == realRTF)
                {
                    // Send either TNEF or iCal data
-                   
-                       vmime::ref<vmime::attachment> vmTNEFAtt;
-                       vmime::ref<vmime::utility::inputStream> inputDataStream 
= NULL;
+                       vmime::shared_ptr<vmime::attachment> vmTNEFAtt;
+                       vmime::shared_ptr<vmime::utility::inputStream> 
inputDataStream = NULL;
 
                        /* 
                         * Send TNEF information for this message if we really 
need to, or otherwise iCal
@@ -2298,7 +2300,7 @@
                        if (lstOLEAttach.size() == 0 && iUseTnef <= 0 && 
lpMessageClass && (strncasecmp("IPM.Note", lpMessageClass->Value.lpszA, 8) != 
0)) {
                                // iCAL
                                string ical, method;
-                               vmime::ref<mapiAttachment> vmAttach = NULL;
+                               vmime::shared_ptr<mapiAttachment> vmAttach = 
NULL;
 
                                lpLogger->Log(EC_LOGLEVEL_INFO, "Adding ICS 
attachment for extra information");
 
@@ -2316,8 +2318,8 @@
                                        goto tnef_anyway;
                                }
 
-                               vmime::ref<vmime::mapiTextPart> lpvmMapiText = 
lpVMMessageBuilder->getTextPart().dynamicCast<vmime::mapiTextPart>();
-                               
lpvmMapiText->setOtherText(vmime::create<vmime::stringContentHandler>(ical));
+                               vmime::shared_ptr<vmime::mapiTextPart> 
lpvmMapiText = 
vmime::dynamicCast<vmime::mapiTextPart>(lpVMMessageBuilder->getTextPart());
+                               
lpvmMapiText->setOtherText(vmime::make_shared<vmime::stringContentHandler>(ical));
                                
lpvmMapiText->setOtherContentType(vmime::mediaType(vmime::mediaTypes::TEXT, 
"calendar"));
                                
lpvmMapiText->setOtherContentEncoding(vmime::encoding(vmime::encodingTypes::EIGHT_BIT));
                                lpvmMapiText->setOtherMethod(method);
@@ -2368,11 +2370,11 @@
                                // Write the stream
                                hr = tnef.Finish();
 
-                               inputDataStream = 
vmime::create<inputStreamMAPIAdapter>(lpStream);
+                               inputDataStream = 
vmime::make_shared<inputStreamMAPIAdapter>(lpStream);
                        
                                // Now, add the stream as an attachment to the 
message, filename winmail.dat 
                                // and MIME type 'application/ms-tnef', no 
content-id
-                               vmTNEFAtt = 
vmime::create<mapiAttachment>(vmime::create<vmime::streamContentHandler>(inputDataStream,
 0),
+                               vmTNEFAtt = 
make_shared<mapiAttachment>(vmime::make_shared<vmime::streamContentHandler>(inputDataStream,
 0),
                                                                                
                                  vmime::encoding("base64"), 
vmime::mediaType("application/ms-tnef"), string(),
                                                                                
                                  vmime::word("winmail.dat"));
                                                                                
          
--- a/inetmapi/MAPIToVMIME.h
+++ b/inetmapi/MAPIToVMIME.h
@@ -18,6 +18,7 @@
 #ifndef MAPITOVMIME
 #define MAPITOVMIME
 
+#include <memory>
 #include <mapix.h>
 
 #include <string>
@@ -36,7 +37,7 @@
        MAPIToVMIME(IMAPISession *lpSession, IAddrBook *lpAddrBook, ECLogger 
*newlogger, sending_options sopt);
        ~MAPIToVMIME();
 
-       HRESULT convertMAPIToVMIME(IMessage *lpMessage, 
vmime::ref<vmime::message> *lpvmMessage);
+       HRESULT convertMAPIToVMIME(IMessage *lpMessage, 
vmime::shared_ptr<vmime::message> *lpvmMessage);
        std::wstring getConversionError(void) const;
 
 private:
@@ -55,23 +56,23 @@
        HRESULT fillVMIMEMail(IMessage *lpMessage, bool bSkipContent, 
vmime::messageBuilder* lpVMMessageBuilder);
 
        HRESULT handleTextparts(IMessage* lpMessage, vmime::messageBuilder* 
lpVMMessageBuilder, eBestBody *bestBody);
-       HRESULT getMailBox(LPSRow lpRow, vmime::ref<vmime::address> 
*lpvmMailbox);
+       HRESULT getMailBox(LPSRow lpRow, vmime::shared_ptr<vmime::address> 
*lpvmMailbox);
        HRESULT processRecipients(IMessage* lpMessage, vmime::messageBuilder* 
lpVMMessageBuilder);
-       HRESULT handleExtraHeaders(IMessage *lpMessage, 
vmime::ref<vmime::header> vmHeader);
-       HRESULT handleReplyTo(IMessage* lpMessage, vmime::ref<vmime::header> 
vmHeader);
+       HRESULT handleExtraHeaders(IMessage *lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader);
+       HRESULT handleReplyTo(IMessage* lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader);
        HRESULT handleContactEntryID(ULONG cValues, LPSPropValue lpProps, 
std::wstring &strName, std::wstring &strType, std::wstring &strEmail);
-       HRESULT handleSenderInfo(IMessage* lpMessage, vmime::ref<vmime::header> 
vmHeader);
+       HRESULT handleSenderInfo(IMessage* lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader);
 
        HRESULT handleAttachments(IMessage* lpMessage, vmime::messageBuilder* 
lpVMMessageBuilder);
        HRESULT handleSingleAttachment(IMessage* lpMessage, LPSRow lpRow, 
vmime::messageBuilder* lpVMMessageBuilder);
        HRESULT parseMimeTypeFromFilename(std::wstring strFilename, 
vmime::mediaType *lpMT, bool *lpbSendBinary);
-       HRESULT setBoundaries(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, const std::string& boundary);
-       HRESULT handleXHeaders(IMessage* lpMessage, vmime::ref<vmime::header> 
vmHeader);
+       HRESULT setBoundaries(vmime::shared_ptr<vmime::header> vmHeader, 
vmime::shared_ptr<vmime::body> vmBody, const std::string& boundary);
+       HRESULT handleXHeaders(IMessage* lpMessage, 
vmime::shared_ptr<vmime::header> vmHeader);
        HRESULT handleTNEF(IMessage* lpMessage, vmime::messageBuilder* 
lpVMMessageBuilder, eBestBody bestBody);
 
        // build Messages
-       HRESULT BuildNoteMessage(IMessage *lpMessage, bool bSkipContent, 
vmime::ref<vmime::message> *lpvmMessage);
-       HRESULT BuildMDNMessage(IMessage *lpMessage, vmime::ref<vmime::message> 
*lpvmMessage);
+       HRESULT BuildNoteMessage(IMessage *lpMessage, bool bSkipContent, 
vmime::shared_ptr<vmime::message> *lpvmMessage);
+       HRESULT BuildMDNMessage(IMessage *lpMessage, 
vmime::shared_ptr<vmime::message> *lpvmMessage);
 
        // util
        void capitalize(char *s);
--- a/inetmapi/SMIMEMessage.cpp
+++ b/inetmapi/SMIMEMessage.cpp
@@ -24,11 +24,13 @@
 {
 }
 
-void SMIMEMessage::generate(vmime::utility::outputStream& os, const 
std::string::size_type maxLineLength, const std::string::size_type curLinePos, 
std::string::size_type* newLinePos) const
+void SMIMEMessage::generateImpl(const vmime::generationContext &ctx,
+    vmime::utility::outputStream &os, size_t curLinePos,
+    size_t *newLinePos) const
 {
     if(!m_body.empty()) {
         // Generate headers
-        getHeader()->generate(os, maxLineLength);
+        getHeader()->generate(ctx, os);
 
         // Concatenate S/MIME body without CRLF since it also contains some 
additional headers
         os << m_body;
@@ -37,7 +39,7 @@
                *newLinePos = 0;
     } else {
         // Normal generation
-        vmime::message::generate(os, maxLineLength, curLinePos, newLinePos);
+        vmime::message::generate(ctx, os, curLinePos, newLinePos);
     }
 }
 
--- a/inetmapi/SMIMEMessage.h
+++ b/inetmapi/SMIMEMessage.h
@@ -20,6 +20,7 @@
 
 #include <vmime/message.hpp>
 #include <vmime/utility/stream.hpp>
+#include <vmime/generationContext.hpp>
 
 /**
  * We are adding a bit of functionality to vmime::message here for S/MIME 
support.
@@ -46,7 +47,7 @@
 public:
     SMIMEMessage();
 
-       void generate(vmime::utility::outputStream& os, const 
std::string::size_type maxLineLength = 
vmime::options::getInstance()->message.maxLineLength(), const 
std::string::size_type curLinePos = 0, std::string::size_type* newLinePos = 
NULL) const;
+       void generateImpl(const vmime::generationContext &, 
vmime::utility::outputStream &, size_t curLinePos = 0, size_t *newLinePos = 
NULL) const;
 
     void setSMIMEBody(std::string &body);    
     
--- a/inetmapi/VMIMEToMAPI.cpp
+++ b/inetmapi/VMIMEToMAPI.cpp
@@ -131,7 +131,7 @@
  */
 HRESULT VMIMEToMAPI::createIMAPProperties(const std::string &input, 
std::string *lpEnvelope, std::string *lpBody, std::string *lpBodyStructure)
 {
-       vmime::ref<vmime::message> vmMessage = vmime::create<vmime::message>();
+       auto vmMessage = vmime::make_shared<vmime::message>();
        vmMessage->parse(input);
 
        if (lpBody || lpBodyStructure)
@@ -197,7 +197,7 @@
                }
 
                // turn buffer into a message
-               vmime::ref<vmime::message> vmMessage = 
vmime::create<vmime::message>();
+               auto vmMessage = vmime::make_shared<vmime::message>();
                vmMessage->parse(input);
 
                // save imap data first, seems vmMessage may be altered in the 
rest of the code.
@@ -228,8 +228,7 @@
                        }
                        
                        // Include the entire rfc822 data in an attachment for 
the client to check
-                       vmime::ref<vmime::header> vmHeader = 
vmMessage->getHeader();
-
+                       auto vmHeader = vmMessage->getHeader();
                        hr = lpMessage->CreateAttach(NULL, 0, &ulAttNr, &lpAtt);
                        if (hr != hrSuccess)
                                goto exit;
@@ -361,7 +360,9 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::fillMAPIMail(vmime::ref<vmime::message> vmMessage, 
IMessage *lpMessage) {
+HRESULT VMIMEToMAPI::fillMAPIMail(vmime::shared_ptr<vmime::message> vmMessage,
+    IMessage *lpMessage)
+{
        HRESULT hr;
        SPropValue sPropDefaults[3];
 
@@ -390,9 +391,9 @@
                // turn buffer into a message
 
                // get the part header and find out what it is...
-               vmime::ref<vmime::header> vmHeader = vmMessage->getHeader();
-               vmime::ref<vmime::body> vmBody = vmMessage->getBody();
-               vmime::ref<vmime::mediaType> mt = 
vmHeader->ContentType()->getValue().dynamicCast<vmime::mediaType>();
+               auto vmHeader = vmMessage->getHeader();
+               auto vmBody = vmMessage->getBody();
+               auto mt = 
vmime::dynamicCast<vmime::mediaType>(vmHeader->ContentType()->getValue());
 
                // pass recipients somewhere else 
                hr = handleRecipients(vmHeader, lpMessage);
@@ -411,21 +412,19 @@
                if (vmime::mdn::MDNHelper::isMDN(vmMessage) == true)
                {
                        vmime::mdn::receivedMDNInfos receivedMDN = 
vmime::mdn::MDNHelper::getReceivedMDN(vmMessage);
-
-                       vmime::ref<vmime::body> myBody = vmMessage->getBody();
+                       auto myBody = vmMessage->getBody();
                        // it is possible to get 3 bodyparts.
                        // text/plain, message/disposition-notification, 
text/rfc822-headers
                        // the third part seems optional. and some clients send 
multipart/alternative instead of text/plain.
                        // Loop to get text/plain body or multipart/alternative.
-                       for (int i = 0; i < myBody->getPartCount(); ++i) {
-                               vmime::ref<vmime::bodyPart> bPart = 
myBody->getPartAt(i);
-                               vmime::ref<vmime::headerField> ctf = 
bPart->getHeader()->findField(vmime::fields::CONTENT_TYPE);
-
-                               if( (ctf->getValue().dynamicCast 
<vmime::mediaType>()->getType() == vmime::mediaTypes::TEXT &&
-                                    ctf->getValue().dynamicCast 
<vmime::mediaType>()->getSubType() == vmime::mediaTypes::TEXT_PLAIN)
-                               ||  (ctf->getValue().dynamicCast 
<vmime::mediaType>()->getType() == vmime::mediaTypes::MULTIPART &&
-                                    ctf->getValue().dynamicCast 
<vmime::mediaType>()->getSubType() == vmime::mediaTypes::MULTIPART_ALTERNATIVE) 
)
-                               {
+                       for (size_t i = 0; i < myBody->getPartCount(); ++i) {
+                               auto bPart = myBody->getPartAt(i);
+                               auto ctf = 
bPart->getHeader()->findField(vmime::fields::CONTENT_TYPE);
+
+                               if 
((vmime::dynamicCast<vmime::mediaType>(ctf->getValue())->getType() == 
vmime::mediaTypes::TEXT &&
+                                    
vmime::dynamicCast<vmime::mediaType>(ctf->getValue())->getSubType() == 
vmime::mediaTypes::TEXT_PLAIN) ||
+                                   
(vmime::dynamicCast<vmime::mediaType>(ctf->getValue())->getType() == 
vmime::mediaTypes::MULTIPART &&
+                                    
vmime::dynamicCast<vmime::mediaType>(ctf->getValue())->getSubType() == 
vmime::mediaTypes::MULTIPART_ALTERNATIVE)) {
                                        hr = dissect_body(bPart->getHeader(), 
bPart->getBody(), lpMessage);
                                        if (hr != hrSuccess) {
                                                
lpLogger->Log(EC_LOGLEVEL_ERROR, "Unable to parse MDN mail body");
@@ -496,7 +495,9 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::handleHeaders(vmime::ref<vmime::header> vmHeader, 
IMessage* lpMessage) {
+HRESULT VMIMEToMAPI::handleHeaders(vmime::shared_ptr<vmime::header> vmHeader,
+    IMessage *lpMessage)
+{
        HRESULT                 hr = hrSuccess;
        std::string             strInternetMessageId, strInReplyTos, 
strReferences;
        std::wstring    wstrSubject;
@@ -562,16 +563,16 @@
 
                // set subject
                if(vmHeader->hasField(vmime::fields::SUBJECT)) {
-                       wstrSubject = 
getWideFromVmimeText(*vmHeader->Subject()->getValue().dynamicCast<vmime::text>());
+                       wstrSubject = 
getWideFromVmimeText(*vmime::dynamicCast<vmime::text>(vmHeader->Subject()->getValue()));
                        msgProps[nProps].ulPropTag = PR_SUBJECT_W;
                        msgProps[nProps++].Value.lpszW = (WCHAR 
*)wstrSubject.c_str();
                }
 
                // set ReplyTo
-               if 
(!vmHeader->ReplyTo()->getValue().dynamicCast<vmime::mailbox>()->isEmpty()) {
+               if 
(!vmime::dynamicCast<vmime::mailbox>(vmHeader->ReplyTo()->getValue())->isEmpty())
 {
                        // First, set PR_REPLY_RECIPIENT_NAMES
-                       wstrReplyTo = 
getWideFromVmimeText(vmHeader->ReplyTo()->getValue().dynamicCast<vmime::mailbox>()->getName());
-                       wstrReplyToMail = 
m_converter.convert_to<wstring>(vmHeader->ReplyTo()->getValue().dynamicCast<vmime::mailbox>()->getEmail());
+                       wstrReplyTo = 
getWideFromVmimeText(vmime::dynamicCast<vmime::mailbox>(vmHeader->ReplyTo()->getValue())->getName());
+                       wstrReplyToMail = 
m_converter.convert_to<wstring>(vmime::dynamicCast<vmime::mailbox>(vmHeader->ReplyTo()->getValue())->getEmail().toString());
                        if (wstrReplyTo.empty())
                                wstrReplyTo = wstrReplyToMail;
 
@@ -611,10 +612,10 @@
                // setting sent time
                if(vmHeader->hasField(vmime::fields::DATE)) {
                        msgProps[nProps].ulPropTag = PR_CLIENT_SUBMIT_TIME;
-                       msgProps[nProps++].Value.ft = 
vmimeDatetimeToFiletime(*vmHeader->Date()->getValue().dynamicCast<vmime::datetime>());
+                       msgProps[nProps++].Value.ft = 
vmimeDatetimeToFiletime(*vmime::dynamicCast<vmime::datetime>(vmHeader->Date()->getValue()));
 
                        // set sent date (actual send date, disregarding 
timezone)
-                       vmime::datetime d = 
*vmHeader->Date()->getValue().dynamicCast<vmime::datetime>();
+                       vmime::datetime d = 
*vmime::dynamicCast<vmime::datetime>(vmHeader->Date()->getValue());
                        d.setTime(0,0,0,0);
                        msgProps[nProps].ulPropTag = PR_EC_CLIENT_SUBMIT_DATE;
                        msgProps[nProps++].Value.ft = 
vmimeDatetimeToFiletime(d);
@@ -626,7 +627,7 @@
                bool found_date = false;
                if (m_dopt.use_received_date || m_mailState.ulMsgInMsg) {
                        try {
-                               vmime::ref<vmime::relay> recv = 
vmHeader->findField("Received")->getValue().dynamicCast<vmime::relay>();
+                               auto recv = 
vmime::dynamicCast<vmime::relay>(vmHeader->findField("Received")->getValue());
                                if (recv) {
                                        date = recv->getDate();
                                        found_date = true;
@@ -634,7 +635,7 @@
                        }
                        catch (...) {
                                if (m_mailState.ulMsgInMsg) {
-                                       date = 
*vmHeader->Date()->getValue().dynamicCast<vmime::datetime>();
+                                       date = 
*vmime::dynamicCast<vmime::datetime>(vmHeader->Date()->getValue());
                                        found_date = true;
                                } else {
                                        date = vmime::datetime::now();
@@ -657,10 +658,9 @@
 
                // The real sender of the mail
                if(vmHeader->hasField(vmime::fields::FROM)) {
-                       strFromEmail = 
vmHeader->From()->getValue().dynamicCast<vmime::mailbox>()->getEmail();
-                       if 
(!vmHeader->From()->getValue().dynamicCast<vmime::mailbox>()->getName().isEmpty())
 {
-                               wstrFromName = 
getWideFromVmimeText(vmHeader->From()->getValue().dynamicCast<vmime::mailbox>()->getName());
-                       }
+                       strFromEmail = 
vmime::dynamicCast<vmime::mailbox>(vmHeader->From()->getValue())->getEmail().toString();
+                       if 
(!vmime::dynamicCast<vmime::mailbox>(vmHeader->From()->getValue())->getName().isEmpty())
+                               wstrFromName = 
getWideFromVmimeText(vmime::dynamicCast<vmime::mailbox>(vmHeader->From()->getValue())->getName());
 
                        hr = modifyFromAddressBook(&lpRecipProps, 
&ulRecipProps, strFromEmail.c_str(), wstrFromName.c_str(), MAPI_ORIG, 
(LPSPropTagArray)&sptaRecipPropsSentRepr);
                        if (hr == hrSuccess) {
@@ -703,14 +703,14 @@
                
                if (vmHeader->hasField(vmime::fields::SENDER) || 
vmHeader->hasField(vmime::fields::FROM)) {
                        // The original sender of the mail account (if non 
sender exist then the FROM)
-                       strSenderEmail = 
vmHeader->Sender()->getValue().dynamicCast<vmime::mailbox>()->getEmail();
-                       
if(vmHeader->Sender()->getValue().dynamicCast<vmime::mailbox>()->getName().isEmpty()
 && strSenderEmail.empty()) {
+                       strSenderEmail = 
vmime::dynamicCast<vmime::mailbox>(vmHeader->Sender()->getValue())->getEmail().toString();
+                       if 
(vmime::dynamicCast<vmime::mailbox>(vmHeader->Sender()->getValue())->getName().isEmpty()
 && strSenderEmail.empty()) {
                                // Fallback on the original from address
                                wstrSenderName = wstrFromName;
                                strSenderEmail = strFromEmail;
                        } else {
-                               if 
(!vmHeader->Sender()->getValue().dynamicCast<vmime::mailbox>()->getName().isEmpty())
 {
-                                       wstrSenderName = 
getWideFromVmimeText(vmHeader->Sender()->getValue().dynamicCast<vmime::mailbox>()->getName());
+                               if 
(!vmime::dynamicCast<vmime::mailbox>(vmHeader->Sender()->getValue())->getName().isEmpty())
 {
+                                       wstrSenderName = 
getWideFromVmimeText(vmime::dynamicCast<vmime::mailbox>(vmHeader->Sender()->getValue())->getName());
                                } else {
                                        wstrSenderName = 
m_converter.convert_to<wstring>(strSenderEmail);
                                }
@@ -757,7 +757,7 @@
                //Conversation topic
                if (vmHeader->hasField("Thread-Topic"))
                {
-                       wstring convTT = 
getWideFromVmimeText(*vmHeader->findField("Thread-Topic")->getValue().dynamicCast<vmime::text>());
+                       wstring convTT = 
getWideFromVmimeText(*vmime::dynamicCast<vmime::text>(vmHeader->findField("Thread-Topic")->getValue()));
 
                        sConTopic.ulPropTag = PR_CONVERSATION_TOPIC_W;
                        sConTopic.Value.lpszW = (WCHAR *)convTT.c_str();
@@ -784,8 +784,7 @@
 
                        string threadIndex = 
vmHeader->findField("Thread-Index")->getValue()->generate();
 
-                       vmime::ref<vmime::utility::encoder::encoder> enc = 
vmime::utility::encoder::encoderFactory::getInstance()->create("base64");
-
+                       auto enc = 
vmime::utility::encoder::encoderFactory::getInstance()->create("base64");
                        vmime::utility::inputStreamStringAdapter 
in(threadIndex);                       
                        vmime::utility::outputStreamStringAdapter 
out(outString);
 
@@ -906,13 +905,13 @@
                // read receipt request
                // note: vmime never checks if the given pos to getMailboxAt() 
and similar functions is valid, so we check if the list is empty before using it
                if (vmHeader->hasField("Disposition-Notification-To") &&
-                       
!vmHeader->DispositionNotificationTo()->getValue().dynamicCast<vmime::mailboxList>()->isEmpty())
+                   
!vmime::dynamicCast<vmime::mailboxList>(vmHeader->DispositionNotificationTo()->getValue())->isEmpty())
                {
-                       vmime::ref<vmime::mailbox> mbReadReceipt = 
vmHeader->DispositionNotificationTo()->getValue().dynamicCast<vmime::mailboxList>()->getMailboxAt(0);
 // we only use the 1st
+                       auto mbReadReceipt = 
vmime::dynamicCast<vmime::mailboxList>(vmHeader->DispositionNotificationTo()->getValue())->getMailboxAt(0);
 // we only use the 1st
                        if (mbReadReceipt && !mbReadReceipt->isEmpty())
                        {
                                wstring wstrRRName = 
getWideFromVmimeText(mbReadReceipt->getName());
-                               wstring wstrRREmail = 
m_converter.convert_to<wstring>(mbReadReceipt->getEmail());
+                               wstring wstrRREmail = 
m_converter.convert_to<wstring>(mbReadReceipt->getEmail().toString());
 
                                if (wstrRRName.empty())
                                        wstrRRName = wstrRREmail;
@@ -944,8 +943,8 @@
                        }
                }
 
-               std::vector<vmime::ref<vmime::headerField> > hf = 
vmHeader->getFieldList();
-               std::vector<vmime::ref<vmime::headerField> >::const_iterator 
hfi;
+               std::vector<vmime::shared_ptr<vmime::headerField> > hf = 
vmHeader->getFieldList();
+               std::vector<vmime::shared_ptr<vmime::headerField> 
>::const_iterator hfi;
                for (hfi = hf.begin(); hfi != hf.end(); ++hfi) {
                        string value, name = (*hfi)->getName();
                        
@@ -1092,15 +1091,16 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::handleRecipients(vmime::ref<vmime::header> vmHeader, 
IMessage* lpMessage) {
+HRESULT VMIMEToMAPI::handleRecipients(vmime::shared_ptr<vmime::header> 
vmHeader,
+    IMessage *lpMessage)
+{
        HRESULT         hr                              = hrSuccess;
        LPADRLIST       lpRecipients    = NULL;
 
        try {
-               vmime::ref<vmime::addressList> lpVMAListRecip = 
vmHeader->To()->getValue().dynamicCast<vmime::addressList>();
-               vmime::ref<vmime::addressList> lpVMAListCopyRecip = 
vmHeader->Cc()->getValue().dynamicCast<vmime::addressList>();
-               vmime::ref<vmime::addressList> lpVMAListBlCpRecip = 
vmHeader->Bcc()->getValue().dynamicCast<vmime::addressList>();
-
+               auto lpVMAListRecip = 
vmime::dynamicCast<vmime::addressList>(vmHeader->To()->getValue());
+               auto lpVMAListCopyRecip = 
vmime::dynamicCast<vmime::addressList>(vmHeader->Cc()->getValue());
+               auto lpVMAListBlCpRecip = 
vmime::dynamicCast<vmime::addressList>(vmHeader->Bcc()->getValue());
                int iAdresCount = lpVMAListRecip->getAddressCount() + 
lpVMAListCopyRecip->getAddressCount() + lpVMAListBlCpRecip->getAddressCount();
 
                if (iAdresCount == 0)
@@ -1180,14 +1180,16 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::modifyRecipientList(LPADRLIST lpRecipients, 
vmime::ref<vmime::addressList> vmAddressList, ULONG ulRecipType) {
+HRESULT VMIMEToMAPI::modifyRecipientList(LPADRLIST lpRecipients,
+    vmime::shared_ptr<vmime::addressList> vmAddressList, ULONG ulRecipType)
+{
        HRESULT                 hr                              = hrSuccess;
        int                             iAddressCount   = 
vmAddressList->getAddressCount();
        ULONG                   cbEntryID               = 0;
        LPENTRYID               lpEntryID               = NULL;
-       vmime::ref<vmime::mailbox> mbx  = NULL;
-       vmime::ref<vmime::mailboxGroup> grp     = NULL;
-       vmime::ref<vmime::address> vmAddress = NULL;
+       vmime::shared_ptr<vmime::mailbox> mbx;
+       vmime::shared_ptr<vmime::mailboxGroup> grp;
+       vmime::shared_ptr<vmime::address> vmAddress;
        std::wstring    wstrName;
        std::string             strEmail, strSearch;
        unsigned int    iRecipNum               = 0;
@@ -1208,7 +1210,7 @@
                        vmAddress = vmAddressList->getAddressAt(iRecip);
                        
                        if (vmAddress->isGroup()) {
-                               grp = 
vmAddress.dynamicCast<vmime::mailboxGroup>();
+                               grp = 
vmime::dynamicCast<vmime::mailboxGroup>(vmAddress);
                                if (!grp)
                                        continue;
                                strEmail.clear();
@@ -1216,10 +1218,10 @@
                                if (grp->isEmpty() && vmText == 
vmime::text("undisclosed-recipients"))
                                        continue;
                        } else {
-                               mbx = vmAddress.dynamicCast<vmime::mailbox>();
+                               mbx = 
vmime::dynamicCast<vmime::mailbox>(vmAddress);
                                if (!mbx)
                                        continue;
-                               strEmail = mbx->getEmail();
+                               strEmail = mbx->getEmail().toString();
                                vmText = mbx->getName();
                        }
 
@@ -1553,14 +1555,15 @@
  * ordered from boring-to-interesting, the list returned by this function is
  * interesting-to-boring.
  */
-static std::list<unsigned int> vtm_order_alternatives(vmime::ref<vmime::body> 
vmBody)
+static std::list<unsigned int>
+vtm_order_alternatives(vmime::shared_ptr<vmime::body> vmBody)
 {
-       vmime::ref<vmime::header> vmHeader;
-       vmime::ref<vmime::bodyPart> vmBodyPart;
-       vmime::ref<vmime::mediaType> mt;
+       vmime::shared_ptr<vmime::header> vmHeader;
+       vmime::shared_ptr<vmime::bodyPart> vmBodyPart;
+       vmime::shared_ptr<vmime::mediaType> mt;
        std::list<unsigned int> lBodies, pgtext;
 
-       for (int i = 0; i < vmBody->getPartCount(); ++i) {
+       for (size_t i = 0; i < vmBody->getPartCount(); ++i) {
                vmBodyPart = vmBody->getPartAt(i);
                vmHeader = vmBodyPart->getHeader();
                if (!vmHeader->hasField(vmime::fields::CONTENT_TYPE)) {
@@ -1568,7 +1571,7 @@
                        lBodies.push_front(i);
                        continue;
                }
-               mt = 
vmHeader->ContentType()->getValue().dynamicCast<vmime::mediaType>();
+               mt = 
vmime::dynamicCast<vmime::mediaType>(vmHeader->ContentType()->getValue());
                // mostly better alternatives for text/plain, so try that last
                if (mt->getType() == vmime::mediaTypes::TEXT && 
mt->getSubType() == vmime::mediaTypes::TEXT_PLAIN)
                        lBodies.push_back(i);
@@ -1578,8 +1581,8 @@
        return lBodies;
 }
 
-HRESULT VMIMEToMAPI::dissect_multipart(vmime::ref<vmime::header> vmHeader,
-    vmime::ref<vmime::body> vmBody, IMessage *lpMessage,
+HRESULT VMIMEToMAPI::dissect_multipart(vmime::shared_ptr<vmime::header> 
vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage *lpMessage,
     bool bFilterDouble, bool bAppendBody)
 {
        bool bAlternative = false;
@@ -1594,7 +1597,7 @@
        }
 
        // check new multipart type
-       vmime::ref<vmime::mediaType> mt = 
vmHeader->ContentType()->getValue().dynamicCast<vmime::mediaType>();
+       auto mt = 
vmime::dynamicCast<vmime::mediaType>(vmHeader->ContentType()->getValue());
        if (mt->getSubType() == "appledouble")
                bFilterDouble = true;
        else if (mt->getSubType() == "mixed")
@@ -1613,12 +1616,12 @@
 
        if (!bAlternative) {
                // recursively process multipart message
-               for (int i = 0; i < vmBody->getPartCount(); ++i) {
-                       vmime::ref<vmime::bodyPart> vmBodyPart = 
vmBody->getPartAt(i);
+               for (size_t i = 0; i < vmBody->getPartCount(); ++i) {
+                       auto vmBodyPart = vmBody->getPartAt(i);
 
                        hr = dissect_body(vmBodyPart->getHeader(), 
vmBodyPart->getBody(), lpMessage, bFilterDouble, bAppendBody);
                        if (hr != hrSuccess) {
-                               lpLogger->Log(EC_LOGLEVEL_ERROR, 
"dissect_multipart: Unable to parse sub multipart %d of mail body", i);
+                               lpLogger->Log(EC_LOGLEVEL_ERROR, 
"dissect_multipart: Unable to parse sub multipart %zu of mail body", i);
                                return hr;
                        }
                }
@@ -1629,7 +1632,7 @@
 
        // recursively process multipart alternatives in reverse to select best 
body first
        for (list<unsigned int>::const_iterator i = lBodies.begin(); i != 
lBodies.end(); ++i) {
-               vmime::ref<vmime::bodyPart> vmBodyPart = vmBody->getPartAt(*i);
+               auto vmBodyPart = vmBody->getPartAt(*i);
 
                lpLogger->Log(EC_LOGLEVEL_DEBUG, "Trying to parse alternative 
multipart %d of mail body", *i);
 
@@ -1644,7 +1647,8 @@
        return hr;
 }
 
-void VMIMEToMAPI::dissect_message(vmime::ref<vmime::body> vmBody, IMessage 
*lpMessage)
+void VMIMEToMAPI::dissect_message(vmime::shared_ptr<vmime::body> vmBody,
+    IMessage *lpMessage)
 {
        // Create Attach
        ULONG ulAttNr = 0;
@@ -1712,8 +1716,9 @@
                pAtt->Release();
 }
 
-HRESULT VMIMEToMAPI::dissect_ical(vmime::ref<vmime::header> vmHeader,
-    vmime::ref<vmime::body> vmBody, IMessage *lpMessage, bool bIsAttachment)
+HRESULT VMIMEToMAPI::dissect_ical(vmime::shared_ptr<vmime::header> vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage *lpMessage,
+    bool bIsAttachment)
 {
        HRESULT hr;
        // ical file
@@ -1849,9 +1854,9 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::dissect_body(vmime::ref<vmime::header> vmHeader,
-    vmime::ref<vmime::body> vmBody, IMessage *lpMessage, bool filterDouble,
-    bool appendBody)
+HRESULT VMIMEToMAPI::dissect_body(vmime::shared_ptr<vmime::header> vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage *lpMessage,
+    bool filterDouble, bool appendBody)
 {
        HRESULT hr = hrSuccess;
        IStream *lpStream = NULL;
@@ -1864,11 +1869,11 @@
                ++m_mailState.mime_vtag_nest;
 
        try {
-               vmime::ref<vmime::mediaType> mt = 
vmHeader->ContentType()->getValue().dynamicCast<vmime::mediaType>();
+               auto mt = 
vmime::dynamicCast<vmime::mediaType>(vmHeader->ContentType()->getValue());
                bool force_raw = false;
 
                try {
-                       bIsAttachment = 
vmHeader->ContentDisposition()->getValue().dynamicCast<vmime::contentDisposition>()->getName()
 == vmime::contentDispositionTypes::ATTACHMENT;
+                       bIsAttachment = 
vmime::dynamicCast<vmime::contentDisposition>(vmHeader->ContentDisposition()->getValue())->getName()
 == vmime::contentDispositionTypes::ATTACHMENT;
                } catch (vmime::exception) {
                        // ignore exception, a header needed to detect 
attachment status could not be used
                        // probably can not happen, but better safe than sorry.
@@ -1969,8 +1974,8 @@
                                goto exit;
                        }
                } else if (mt->getType() == vmime::mediaTypes::APPLICATION && 
mt->getSubType() == vmime::mediaTypes::APPLICATION_OCTET_STREAM) {
-                       if 
(vmHeader->ContentDisposition().dynamicCast<vmime::contentDispositionField>()->hasParameter("filename")
 ||
-                               
vmHeader->ContentType().dynamicCast<vmime::contentTypeField>()->hasParameter("name"))
 {
+                       if 
(vmime::dynamicCast<vmime::contentDispositionField>(vmHeader->ContentDisposition())->hasParameter("filename")
 ||
+                           
vmime::dynamicCast<vmime::contentTypeField>(vmHeader->ContentType())->hasParameter("name"))
 {
                                // should be attachment
                                hr = handleAttachment(vmHeader, vmBody, 
lpMessage);
                                if (hr != hrSuccess)
@@ -2028,13 +2033,12 @@
  * Returns the transfer-decoded data.
  */
 std::string
-VMIMEToMAPI::content_transfer_decode(vmime::ref<vmime::body> im_body) const
+VMIMEToMAPI::content_transfer_decode(vmime::shared_ptr<vmime::body> im_body) 
const
 {
        /* TODO: Research how conversion could be minimized using streams. */
        std::string data;
        vmime::utility::outputStreamStringAdapter str_adap(data);
-       vmime::ref<const vmime::contentHandler> im_cont =
-               im_body->getContents();
+       auto im_cont = im_body->getContents();
 
        try {
                im_cont->extract(str_adap);
@@ -2057,11 +2061,10 @@
  * new character set for it.
  */
 vmime::charset
-VMIMEToMAPI::get_mime_encoding(vmime::ref<vmime::header> im_header,
-    vmime::ref<vmime::body> im_body) const
+VMIMEToMAPI::get_mime_encoding(vmime::shared_ptr<vmime::header> im_header,
+    vmime::shared_ptr<vmime::body> im_body) const
 {
-       vmime::ref<const vmime::contentTypeField> ctf =
-               im_header->ContentType().dynamicCast<vmime::contentTypeField>();
+       auto ctf = 
vmime::dynamicCast<vmime::contentTypeField>(im_header->ContentType());
 
        if (ctf != NULL && ctf->hasParameter("charset"))
                return im_body->getCharset();
@@ -2144,7 +2147,9 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::handleTextpart(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAppendBody) {
+HRESULT VMIMEToMAPI::handleTextpart(vmime::shared_ptr<vmime::header> vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage* lpMessage, bool 
bAppendBody)
+{
        HRESULT hr = S_OK;
        IStream *lpStream = NULL;
 
@@ -2337,7 +2342,9 @@
  * But with conversion to MAPI, we have this seemingly lossy conversion
  * stage. :-(
  */
-HRESULT VMIMEToMAPI::handleHTMLTextpart(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAppendBody) {
+HRESULT VMIMEToMAPI::handleHTMLTextpart(vmime::shared_ptr<vmime::header> 
vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage *lpMessage, bool 
bAppendBody)
+{
        HRESULT         hr                              = hrSuccess;
        IStream*        lpHTMLStream    = NULL; 
        ULONG           cbWritten               = 0;
@@ -2485,7 +2492,8 @@
                HrSetOneProp(lpMessage, &sCodepage);
 
                // we may have received a text part to append to the HTML body
-               if 
(vmHeader->ContentType()->getValue().dynamicCast<vmime::mediaType>()->getSubType()
 == vmime::mediaTypes::TEXT_PLAIN) {
+               if 
(vmime::dynamicCast<vmime::mediaType>(vmHeader->ContentType()->getValue())->getSubType()
 ==
+                   vmime::mediaTypes::TEXT_PLAIN) {
                        // escape and wrap with <pre> tags
                        std::wstring strwBody = 
m_converter.convert_to<std::wstring>(CHARSET_WCHAR "//IGNORE", strHTML, 
rawsize(strHTML), mime_charset.getName().c_str());
                        strHTML = "<pre>";
@@ -2559,7 +2567,9 @@
  * @return             MAPI error code.
  * @retval             MAPI_E_CALL_FAILED      Caught an exception, which 
breaks the conversion.
  */
-HRESULT VMIMEToMAPI::handleAttachment(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAllowEmpty) {
+HRESULT VMIMEToMAPI::handleAttachment(vmime::shared_ptr<vmime::header> 
vmHeader,
+    vmime::shared_ptr<vmime::body> vmBody, IMessage *lpMessage, bool 
bAllowEmpty)
+{
        HRESULT         hr                      = hrSuccess;
        IStream         *lpStream       = NULL; 
        LPATTACH        lpAtt           = NULL;
@@ -2568,10 +2578,10 @@
        std::wstring strLongFilename;
        int                     nProps = 0;
        SPropValue      attProps[12];
-       vmime::ref<vmime::contentDispositionField> cdf; // parameters of 
Content-Disposition header
-       vmime::ref<vmime::contentDisposition> cdv;              // value of 
Content-Disposition header
-       vmime::ref<vmime::contentTypeField> ctf;        
-       vmime::ref<vmime::mediaType> mt;
+       vmime::shared_ptr<vmime::contentDispositionField> cdf;  // parameters 
of Content-Disposition header
+       vmime::shared_ptr<vmime::contentDisposition> cdv;               // 
value of Content-Disposition header
+       vmime::shared_ptr<vmime::contentTypeField> ctf;
+       vmime::shared_ptr<vmime::mediaType> mt;
 
        memset(attProps, 0, sizeof(attProps));
 
@@ -2589,10 +2599,10 @@
        try {
                // attach adapter, generate in right encoding
                outputStreamMAPIAdapter osMAPI(lpStream);
-               cdf = 
vmHeader->ContentDisposition().dynamicCast<vmime::contentDispositionField>();
-               cdv = cdf->getValue().dynamicCast<vmime::contentDisposition>();
-               ctf = 
vmHeader->ContentType().dynamicCast<vmime::contentTypeField>();
-               mt = ctf->getValue().dynamicCast<vmime::mediaType>();
+               cdf = 
vmime::dynamicCast<vmime::contentDispositionField>(vmHeader->ContentDisposition());
+               cdv = 
vmime::dynamicCast<vmime::contentDisposition>(cdf->getValue());
+               ctf = 
vmime::dynamicCast<vmime::contentTypeField>(vmHeader->ContentType());
+               mt = vmime::dynamicCast<vmime::mediaType>(ctf->getValue());
 
                try {
                        vmBody->getContents()->generate(osMAPI, 
vmime::encoding(vmime::encodingTypes::BINARY));
@@ -2630,7 +2640,7 @@
                attProps[nProps++].Value.ul = ATTACH_BY_VALUE;
 
                // vmHeader->ContentId() is headerField ->getValue() returns 
headerFieldValue, which messageId is.
-               strId = 
vmHeader->ContentId()->getValue().dynamicCast<vmime::messageId>()->getId();
+               strId = 
vmime::dynamicCast<vmime::messageId>(vmHeader->ContentId()->getValue())->getId();
                if (!strId.empty()) {
                        // only set this property when string is present
                        // otherwise, you don't get the 'save attachments' list 
in the main menu of outlook
@@ -2639,7 +2649,7 @@
                }
 
                try {
-                       strLocation = 
vmHeader->ContentLocation()->getValue().dynamicCast<vmime::text>()->getConvertedText(MAPI_CHARSET);
+                       strLocation = 
vmime::dynamicCast<vmime::text>(vmHeader->ContentLocation()->getValue())->getConvertedText(MAPI_CHARSET);
                }
                catch (vmime::exceptions::charset_conv_error) { }
                if (!strLocation.empty()) {
@@ -2964,8 +2974,8 @@
        std::string myword;
        std::wstring ret;
 
-       const std::vector<vmime::ref<const vmime::word> >& words = 
vmText.getWordList();
-       std::vector<vmime::ref<const vmime::word> >::const_iterator i, j;
+       const auto &words = vmText.getWordList();
+       std::vector<vmime::shared_ptr<const vmime::word> >::const_iterator i, j;
        for (i = words.begin(); i != words.end(); ++i) {
                /*
                 * RFC 5322 ยง2.2 specifies header field bodies consist of
@@ -3289,7 +3299,7 @@
  * 
  * @return string with IMAP envelope list part
  */
-std::string VMIMEToMAPI::mailboxToEnvelope(vmime::ref<vmime::mailbox> mbox)
+std::string VMIMEToMAPI::mailboxToEnvelope(vmime::shared_ptr<vmime::mailbox> 
mbox)
 {
        vector<string> lMBox;
        string buffer;
@@ -3308,7 +3318,7 @@
 
        lMBox.push_back("NIL"); // at-domain-list (source route) ... whatever 
that means
 
-       buffer = "\"" + mbox->getEmail() + "\"";
+       buffer = "\"" + mbox->getEmail().toString() + "\"";
        pos = buffer.find("@");
        if (pos != string::npos)
                boost::algorithm::replace_first(buffer, "@", "\" \"");
@@ -3327,7 +3337,7 @@
  * 
  * @return string with IMAP envelope list part
  */
-std::string VMIMEToMAPI::addressListToEnvelope(vmime::ref<vmime::addressList> 
aList)
+std::string 
VMIMEToMAPI::addressListToEnvelope(vmime::shared_ptr<vmime::addressList> aList)
 {
        list<string> lAddr;
        string buffer;
@@ -3342,7 +3352,7 @@
                
        for (int i = 0; i < aCount; ++i) {
                try {
-                       buffer += 
mailboxToEnvelope(aList->getAddressAt(i).dynamicCast<vmime::mailbox>());
+                       buffer += 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(aList->getAddressAt(i)));
                        lAddr.push_back(buffer);
                } catch (vmime::exception &e) {
                }
@@ -3367,7 +3377,8 @@
  * 
  * @return MAPI Error code
  */
-HRESULT VMIMEToMAPI::createIMAPEnvelope(vmime::ref<vmime::message> vmMessage, 
IMessage* lpMessage)
+HRESULT VMIMEToMAPI::createIMAPEnvelope(vmime::shared_ptr<vmime::message> 
vmMessage,
+    IMessage *lpMessage)
 {
        HRESULT hr = hrSuccess;
        std::string buffer;
@@ -3394,21 +3405,21 @@
  * 
  * @return ENVELOPE data
  */
-std::string VMIMEToMAPI::createIMAPEnvelope(vmime::ref<vmime::message> 
vmMessage)
+std::string VMIMEToMAPI::createIMAPEnvelope(vmime::shared_ptr<vmime::message> 
vmMessage)
 {
        vector<string> lItems;
-       vmime::ref<vmime::header> vmHeader = vmMessage->getHeader();
+       auto vmHeader = vmMessage->getHeader();
        std::string buffer;
        vmime::utility::outputStreamStringAdapter os(buffer);
 
        // date
        try {
-               vmime::ref<vmime::datetime> date;
+               vmime::shared_ptr<vmime::datetime> date;
                try {
-                       date = 
vmHeader->Date()->getValue().dynamicCast<vmime::datetime>();
+                       date = 
vmime::dynamicCast<vmime::datetime>(vmHeader->Date()->getValue());
                } catch (vmime::exception &e) {
                        // date must not be empty, so force now() as the 
timestamp
-                       date = 
vmime::create<vmime::datetime>(vmime::datetime::now());
+                       date = 
vmime::make_shared<vmime::datetime>(vmime::datetime::now());
                }
                date->generate(os);
                lItems.push_back("\"" + buffer + "\"");
@@ -3431,7 +3442,7 @@
 
        // from
        try {
-               buffer = 
mailboxToEnvelope(vmHeader->From()->getValue().dynamicCast<vmime::mailbox>());
+               buffer = 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(vmHeader->From()->getValue()));
                lItems.push_back("(" + buffer + ")");
        } catch (vmime::exception &e) {
                // this is not allowed, but better than nothing
@@ -3441,7 +3452,7 @@
 
        // sender
        try {
-               buffer = 
mailboxToEnvelope(vmHeader->Sender()->getValue().dynamicCast<vmime::mailbox>());
+               buffer = 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(vmHeader->Sender()->getValue()));
                lItems.push_back("(" + buffer + ")");
        } catch (vmime::exception &e) {
                lItems.push_back(lItems.back());
@@ -3450,7 +3461,7 @@
 
        // reply-to
        try {
-               buffer = 
mailboxToEnvelope(vmHeader->ReplyTo()->getValue().dynamicCast<vmime::mailbox>());
+               buffer = 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(vmHeader->ReplyTo()->getValue()));
                lItems.push_back("(" + buffer + ")");
        } catch (vmime::exception &e) {
                lItems.push_back(lItems.back());
@@ -3459,7 +3470,7 @@
 
        // ((to),(to))
        try {
-               buffer = 
addressListToEnvelope(vmHeader->To()->getValue().dynamicCast<vmime::addressList>());
+               buffer = 
addressListToEnvelope(vmime::dynamicCast<vmime::addressList>(vmHeader->To()->getValue()));
                lItems.push_back(buffer);
        } catch (vmime::exception &e) {
                lItems.push_back("NIL");
@@ -3468,10 +3479,10 @@
 
        // ((cc),(cc))
        try {
-               vmime::ref<vmime::addressList> aList = 
vmHeader->Cc()->getValue().dynamicCast<vmime::addressList>();
+               auto aList = 
vmime::dynamicCast<vmime::addressList>(vmHeader->Cc()->getValue());
                int aCount = aList->getAddressCount();
                for (int i = 0; i < aCount; ++i)
-                       buffer += 
mailboxToEnvelope(aList->getAddressAt(i).dynamicCast<vmime::mailbox>());
+                       buffer += 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(aList->getAddressAt(i)));
                lItems.push_back(buffer.empty() ? "NIL" : "(" + buffer + ")");
        } catch (vmime::exception &e) {
                lItems.push_back("NIL");
@@ -3480,10 +3491,10 @@
 
        // ((bcc),(bcc))
        try {
-               vmime::ref<vmime::addressList> aList = 
vmHeader->Bcc()->getValue().dynamicCast<vmime::addressList>();
+               auto aList = 
vmime::dynamicCast<vmime::addressList>(vmHeader->Bcc()->getValue());
                int aCount = aList->getAddressCount();
                for (int i = 0; i < aCount; ++i)
-                       buffer += 
mailboxToEnvelope(aList->getAddressAt(i).dynamicCast<vmime::mailbox>());
+                       buffer += 
mailboxToEnvelope(vmime::dynamicCast<vmime::mailbox>(aList->getAddressAt(i)));
                lItems.push_back(buffer.empty() ? "NIL" : "(" + buffer + ")");
        } catch (vmime::exception &e) {
                lItems.push_back("NIL");
@@ -3522,7 +3533,8 @@
  * 
  * @return MAPI error code
  */
-HRESULT VMIMEToMAPI::createIMAPBody(const string &input, 
vmime::ref<vmime::message> vmMessage, IMessage* lpMessage)
+HRESULT VMIMEToMAPI::createIMAPBody(const string &input,
+    vmime::shared_ptr<vmime::message> vmMessage, IMessage *lpMessage)
 {
        SPropValue sProps[4];
        string strBody;
@@ -3555,24 +3567,25 @@
  * 
  * @return always success
  */
-HRESULT VMIMEToMAPI::messagePartToStructure(const string &input, 
vmime::ref<vmime::bodyPart> vmBodyPart, std::string *lpSimple, std::string 
*lpExtended)
+HRESULT VMIMEToMAPI::messagePartToStructure(const string &input,
+    vmime::shared_ptr<vmime::bodyPart> vmBodyPart, std::string *lpSimple,
+    std::string *lpExtended)
 {
        HRESULT hr = hrSuccess;
        list<string> lBody;
        list<string> lBodyStructure;
-       vmime::ref<vmime::header> vmHeaderPart = vmBodyPart->getHeader();
+       auto vmHeaderPart = vmBodyPart->getHeader();
 
        try {
-               vmime::ref<vmime::contentTypeField> ctf;
+               vmime::shared_ptr<vmime::contentTypeField> ctf;
                if (vmHeaderPart->hasField(vmime::fields::CONTENT_TYPE)) {
                        // use Content-Type header from part
-                       ctf = 
vmHeaderPart->ContentType().dynamicCast<vmime::contentTypeField>();
+                       ctf = 
vmime::dynamicCast<vmime::contentTypeField>(vmHeaderPart->ContentType());
                } else {
                        // create empty default Content-Type header
-                       ctf = 
vmime::headerFieldFactory::getInstance()->create("Content-Type", 
"").dynamicCast<vmime::contentTypeField>();
+                       ctf = 
vmime::dynamicCast<vmime::contentTypeField>(vmime::headerFieldFactory::getInstance()->create("Content-Type",
 ""));
                }
-               vmime::ref<vmime::mediaType> mt = 
ctf->getValue().dynamicCast<vmime::mediaType>();
-
+               auto mt = vmime::dynamicCast<vmime::mediaType>(ctf->getValue());
                if (mt->getType() == vmime::mediaTypes::MULTIPART) {
                        // handle multipart
                        // alternative, mixed, related
@@ -3583,7 +3596,7 @@
                        // function please:
                        string strBody;
                        string strBodyStructure;
-                       for (int i = 0; i < 
vmBodyPart->getBody()->getPartCount(); ++i) {
+                       for (size_t i = 0; i < 
vmBodyPart->getBody()->getPartCount(); ++i) {
                                messagePartToStructure(input, 
vmBodyPart->getBody()->getPartAt(i), &strBody, &strBodyStructure);
                                lBody.push_back(strBody);
                                lBodyStructure.push_back(strBodyStructure);
@@ -3641,21 +3654,22 @@
  * 
  * @return always success
  */
-HRESULT VMIMEToMAPI::bodyPartToStructure(const string &input, 
vmime::ref<vmime::bodyPart> vmBodyPart, std::string *lpSimple, std::string 
*lpExtended)
+HRESULT VMIMEToMAPI::bodyPartToStructure(const string &input,
+    vmime::shared_ptr<vmime::bodyPart> vmBodyPart, std::string *lpSimple,
+    std::string *lpExtended)
 {
        string strPart;
        list<string> lBody;
        list<string> lBodyStructure;
        string buffer;
        vmime::utility::outputStreamStringAdapter os(buffer);
-       vmime::ref<vmime::header> vmHeaderPart = vmBodyPart->getHeader();
-
-       vmime::ref<vmime::contentTypeField> ctf;
-       vmime::ref<vmime::mediaType> mt;
+       auto vmHeaderPart = vmBodyPart->getHeader();
+       vmime::shared_ptr<vmime::contentTypeField> ctf;
+       vmime::shared_ptr<vmime::mediaType> mt;
 
        try {
-               ctf = 
vmHeaderPart->findField(vmime::fields::CONTENT_TYPE).dynamicCast<vmime::contentTypeField>();
-               mt = ctf->getValue().dynamicCast<vmime::mediaType>();
+               ctf = 
vmime::dynamicCast<vmime::contentTypeField>(vmHeaderPart->findField(vmime::fields::CONTENT_TYPE));
+               mt = vmime::dynamicCast<vmime::mediaType>(ctf->getValue());
        }
        catch (vmime::exception &e) {
                // create with text/plain; charset=us-ascii ?
@@ -3671,7 +3685,7 @@
        lBody.push_back(parameterizedFieldToStructure(ctf));
 
        try {
-               buffer = 
vmHeaderPart->findField(vmime::fields::CONTENT_ID)->getValue().dynamicCast<vmime::messageId>()->getId();
+               buffer = 
vmime::dynamicCast<vmime::messageId>(vmHeaderPart->findField(vmime::fields::CONTENT_ID)->getValue())->getId();
                lBody.push_back(buffer.empty() ? "NIL" : "\"<" + buffer + 
">\"");
        }
        catch (vmime::exception &e) {
@@ -3716,7 +3730,7 @@
        if (mt->getType() == vmime::mediaTypes::MESSAGE && mt->getSubType() == 
vmime::mediaTypes::MESSAGE_RFC822) {
                string strSubSingle;
                string strSubExtended;
-               vmime::ref<vmime::message> subMessage = 
vmime::create<vmime::message>();
+               auto subMessage = vmime::make_shared<vmime::message>();
 
                // From RFC:
                // A body type of type MESSAGE and subtype RFC822 contains,
@@ -3765,7 +3779,7 @@
  * 
  * @return IMAP list part
  */
-std::string VMIMEToMAPI::getStructureExtendedFields(vmime::ref<vmime::header> 
vmHeaderPart)
+std::string 
VMIMEToMAPI::getStructureExtendedFields(vmime::shared_ptr<vmime::header> 
vmHeaderPart)
 {
        list<string> lItems;
        string buffer;
@@ -3774,9 +3788,8 @@
        // content-disposition header
        try {
                // use findField because we want an exception when missing
-               vmime::ref<vmime::contentDispositionField> cdf = 
vmHeaderPart->findField(vmime::fields::CONTENT_DISPOSITION).dynamicCast<vmime::contentDispositionField>();
-               vmime::ref<vmime::contentDisposition> cd = 
cdf->getValue().dynamicCast<vmime::contentDisposition>();
-
+               auto cdf = 
vmime::dynamicCast<vmime::contentDispositionField>(vmHeaderPart->findField(vmime::fields::CONTENT_DISPOSITION));
+               auto cd = 
vmime::dynamicCast<vmime::contentDisposition>(cdf->getValue());
                lItems.push_back("(\"" + cd->getName() + "\" " + 
parameterizedFieldToStructure(cdf) + ")");
        }
        catch (vmime::exception &e) {
@@ -3806,15 +3819,15 @@
  * 
  * @return IMAP list
  */
-std::string 
VMIMEToMAPI::parameterizedFieldToStructure(vmime::ref<vmime::parameterizedHeaderField>
 vmParamField)
+std::string 
VMIMEToMAPI::parameterizedFieldToStructure(vmime::shared_ptr<vmime::parameterizedHeaderField>
 vmParamField)
 {
        list<string> lParams;
        string buffer;
        vmime::utility::outputStreamStringAdapter os(buffer);
 
        try {
-               vector <vmime::ref<vmime::parameter> > vParams = 
vmParamField->getParameterList();
-               std::vector<vmime::ref<vmime::parameter> >::const_iterator 
iParam;
+               vector <vmime::shared_ptr<vmime::parameter> > vParams = 
vmParamField->getParameterList();
+               std::vector<vmime::shared_ptr<vmime::parameter> 
>::const_iterator iParam;
 
                for (iParam = vParams.begin(); iParam != vParams.end(); 
++iParam) {
                        lParams.push_back("\"" + (*iParam)->getName() + "\"");
--- a/inetmapi/VMIMEToMAPI.h
+++ b/inetmapi/VMIMEToMAPI.h
@@ -75,25 +75,25 @@
        sMailState m_mailState;
        convert_context m_converter;
 
-       HRESULT fillMAPIMail(vmime::ref<vmime::message> vmMessage, IMessage 
*lpMessage);
-       HRESULT dissect_body(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage *lpMessage, bool filterDouble = false, 
bool appendBody = false);
-       void dissect_message(vmime::ref<vmime::body>, IMessage *);
-       HRESULT dissect_multipart(vmime::ref<vmime::header>, 
vmime::ref<vmime::body>, IMessage *, bool filterDouble = false, bool appendBody 
= false);
-       HRESULT dissect_ical(vmime::ref<vmime::header>, 
vmime::ref<vmime::body>, IMessage *, bool bIsAttachment);
-
-       HRESULT handleHeaders(vmime::ref<vmime::header> vmHeader, IMessage* 
lpMessage);
-       HRESULT handleRecipients(vmime::ref<vmime::header> vmHeader, IMessage* 
lpMessage);
-       HRESULT modifyRecipientList(LPADRLIST lpRecipients, 
vmime::ref<vmime::addressList> vmAddressList, ULONG ulRecipType);
+       HRESULT fillMAPIMail(vmime::shared_ptr<vmime::message>, IMessage 
*lpMessage);
+       HRESULT dissect_body(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage *lpMessage, bool filterDouble = false, 
bool appendBody = false);
+       void dissect_message(vmime::shared_ptr<vmime::body>, IMessage *);
+       HRESULT dissect_multipart(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage *, bool filterDouble = false, bool 
appendBody = false);
+       HRESULT dissect_ical(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage *, bool bIsAttachment);
+
+       HRESULT handleHeaders(vmime::shared_ptr<vmime::header>, IMessage* 
lpMessage);
+       HRESULT handleRecipients(vmime::shared_ptr<vmime::header>, IMessage* 
lpMessage);
+       HRESULT modifyRecipientList(LPADRLIST lpRecipients, 
vmime::shared_ptr<vmime::addressList>, ULONG ulRecipType);
        HRESULT modifyFromAddressBook(LPSPropValue *lppPropVals, ULONG 
*lpulValues, const char *email, const WCHAR *fullname, ULONG ulRecipType, 
LPSPropTagArray lpPropsList);
 
-       std::string content_transfer_decode(vmime::ref<vmime::body>) const;
-       vmime::charset get_mime_encoding(vmime::ref<vmime::header>, 
vmime::ref<vmime::body>) const;
+       std::string content_transfer_decode(vmime::shared_ptr<vmime::body>) 
const;
+       vmime::charset get_mime_encoding(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>) const;
        int renovate_encoding(std::string &, const std::vector<std::string> &);
        int renovate_encoding(std::wstring &, std::string &, const 
std::vector<std::string> &);
 
-       HRESULT handleTextpart(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAppendBody);
-       HRESULT handleHTMLTextpart(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAppendBody);
-       HRESULT handleAttachment(vmime::ref<vmime::header> vmHeader, 
vmime::ref<vmime::body> vmBody, IMessage* lpMessage, bool bAllowEmpty = true);
+       HRESULT handleTextpart(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAppendBody);
+       HRESULT handleHTMLTextpart(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAppendBody);
+       HRESULT handleAttachment(vmime::shared_ptr<vmime::header>, 
vmime::shared_ptr<vmime::body>, IMessage* lpMessage, bool bAllowEmpty = true);
        HRESULT handleMessageToMeProps(IMessage *lpMessage, LPADRLIST 
lpRecipients);
 
        int getCharsetFromHTML(const std::string &strHTML, vmime::charset 
*htmlCharset);
@@ -102,17 +102,17 @@
        
        HRESULT postWriteFixups(IMessage *lpMessage);
 
-       std::string mailboxToEnvelope(vmime::ref<vmime::mailbox> mbox);
-       std::string addressListToEnvelope(vmime::ref<vmime::addressList> mbox);
-       HRESULT createIMAPEnvelope(vmime::ref<vmime::message> vmMessage, 
IMessage* lpMessage);
-       std::string createIMAPEnvelope(vmime::ref<vmime::message> vmMessage);
-
-       HRESULT createIMAPBody(const std::string &input, 
vmime::ref<vmime::message> vmMessage, IMessage* lpMessage);
-
-       HRESULT messagePartToStructure(const std::string &input, 
vmime::ref<vmime::bodyPart> vmBodyPart, std::string *lpSimple, std::string 
*lpExtended);
-       HRESULT bodyPartToStructure(const std::string &input, 
vmime::ref<vmime::bodyPart> vmBodyPart, std::string *lpSimple, std::string 
*lpExtended);
-       std::string getStructureExtendedFields(vmime::ref<vmime::header> 
vmHeaderPart);
-       std::string 
parameterizedFieldToStructure(vmime::ref<vmime::parameterizedHeaderField> 
vmParamField);
+       std::string mailboxToEnvelope(vmime::shared_ptr<vmime::mailbox>);
+       std::string addressListToEnvelope(vmime::shared_ptr<vmime::addressList> 
mbox);
+       HRESULT createIMAPEnvelope(vmime::shared_ptr<vmime::message>, IMessage* 
lpMessage);
+       std::string createIMAPEnvelope(vmime::shared_ptr<vmime::message>);
+
+       HRESULT createIMAPBody(const std::string &input, 
vmime::shared_ptr<vmime::message>, IMessage* lpMessage);
+
+       HRESULT messagePartToStructure(const std::string &input, 
vmime::shared_ptr<vmime::bodyPart>, std::string *lpSimple, std::string 
*lpExtended);
+       HRESULT bodyPartToStructure(const std::string &input, 
vmime::shared_ptr<vmime::bodyPart>, std::string *lpSimple, std::string 
*lpExtended);
+       std::string getStructureExtendedFields(vmime::shared_ptr<vmime::header> 
vmHeaderPart);
+       std::string 
parameterizedFieldToStructure(vmime::shared_ptr<vmime::parameterizedHeaderField>);
        std::string::size_type countBodyLines(const std::string &input, 
std::string::size_type start, std::string::size_type length);
 };
 
--- a/inetmapi/inetmapi.cpp
+++ b/inetmapi/inetmapi.cpp
@@ -180,7 +180,7 @@
        LPSPropValue    lpTime          = NULL;
        LPSPropValue    lpMessageId     = NULL;
        MAPIToVMIME*    mToVM           = new MAPIToVMIME(lpSession, 
lpAddrBook, lpLogger, sopt);
-       vmime::ref<vmime::message>      lpVMMessage     = NULL;
+       vmime::shared_ptr<vmime::message>       lpVMMessage     = NULL;
        vmime::utility::outputStreamAdapter adapter(os);
 
        InitializeVMime();
@@ -224,7 +224,7 @@
 {
        HRESULT                 hr      = hrSuccess;
        MAPIToVMIME             *mToVM  = new MAPIToVMIME(lpSession, 
lpAddrBook, lpLogger, sopt);
-       vmime::ref<vmime::message>      vmMessage;
+       vmime::shared_ptr<vmime::message>       vmMessage;
        ECVMIMESender           *mailer = 
dynamic_cast<ECVMIMESender*>(mailer_base);
        wstring                 wstrError;
        SPropArrayPtr   ptrProps;
--- a/inetmapi/inputStreamMAPIAdapter.cpp
+++ b/inetmapi/inputStreamMAPIAdapter.cpp
@@ -36,12 +36,11 @@
                lpStream->Release();
 }
 
-vmime::utility::stream::size_type inputStreamMAPIAdapter::read(value_type* 
data, const size_type count)
+size_t inputStreamMAPIAdapter::read(unsigned char *data, size_t count)
 {
        ULONG ulSize = 0;
 
-       lpStream->Read((unsigned char *)data, count, &ulSize);
-
+       lpStream->Read(data, count, &ulSize);
        if (ulSize != count)
                this->ateof = true;
 
@@ -59,7 +58,7 @@
        this->ateof = false;
 }
 
-vmime::utility::stream::size_type inputStreamMAPIAdapter::skip(const size_type 
count)
+size_t inputStreamMAPIAdapter::skip(size_t count)
 {
        ULARGE_INTEGER ulSize;
        LARGE_INTEGER move;
--- a/inetmapi/inputStreamMAPIAdapter.h
+++ b/inetmapi/inputStreamMAPIAdapter.h
@@ -20,17 +20,17 @@
 
 #include <kopano/zcdefs.h>
 #include <mapidefs.h>
-#include <vmime/utility/stream.hpp>
+#include <vmime/utility/inputStream.hpp>
 
 class inputStreamMAPIAdapter _kc_final : public vmime::utility::inputStream {
 public:
        inputStreamMAPIAdapter(IStream *lpStream);
        virtual ~inputStreamMAPIAdapter();
 
-       virtual size_type read(value_type* const data, const size_type count);
-       virtual size_type skip(const size_type count);
-       virtual void reset();
-       virtual bool eof(void) const { return this->ateof; }
+       virtual size_t read(vmime::byte_t *, size_t) _kc_override;
+       virtual size_t skip(size_t) _kc_override;
+       virtual void reset(void) _kc_override;
+       virtual bool eof(void) const _kc_override { return this->ateof; }
 
 private:
        bool    ateof;
--- a/inetmapi/mapiAttachment.cpp
+++ b/inetmapi/mapiAttachment.cpp
@@ -14,14 +14,18 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
-
+#include <memory>
 #include "mapiAttachment.h"
 
 #include <vmime/contentDispositionField.hpp>
 #include <vmime/contentTypeField.hpp>
 #include <vmime/messageId.hpp>
 
-mapiAttachment::mapiAttachment(vmime::ref <const vmime::contentHandler> data, 
const vmime::encoding& enc, const vmime::mediaType& type, const std::string& 
contentid, const vmime::word filename, const vmime::text& desc, const 
vmime::word& name) : defaultAttachment(data, enc, type, desc, name)
+mapiAttachment::mapiAttachment(vmime::shared_ptr<const vmime::contentHandler> 
data,
+    const vmime::encoding &enc, const vmime::mediaType &type,
+    const std::string &contentid, const vmime::word filename,
+    const vmime::text &desc, const vmime::word &name) :
+       defaultAttachment(data, enc, type, desc, name)
 {
        m_filename = filename;
        m_contentid = contentid;
@@ -34,14 +38,11 @@
        m_charset = ch;
 }
 
-void mapiAttachment::generatePart(vmime::ref<vmime::bodyPart> part) const
+void mapiAttachment::generatePart(vmime::shared_ptr<vmime::bodyPart> part) 
const
 {
        vmime::defaultAttachment::generatePart(part);
-
-       part->getHeader()->ContentDisposition().dynamicCast 
<vmime::contentDispositionField>()->setFilename(m_filename);
-
-       vmime::ref<vmime::contentTypeField> ctf = 
part->getHeader()->ContentType().dynamicCast <vmime::contentTypeField>();
-
+       
vmime::dynamicCast<vmime::contentDispositionField>(part->getHeader()->ContentDisposition())->setFilename(m_filename);
+       auto ctf = 
vmime::dynamicCast<vmime::contentTypeField>(part->getHeader()->ContentType());
        ctf->getParameter("name")->setValue(m_filename);
        if (m_hasCharset)
                ctf->setCharset(vmime::charset(m_charset));
--- a/inetmapi/mapiAttachment.h
+++ b/inetmapi/mapiAttachment.h
@@ -26,7 +26,7 @@
 {
 public:
 
-       mapiAttachment(vmime::ref <const vmime::contentHandler> data,
+       mapiAttachment(vmime::shared_ptr<const vmime::contentHandler> data,
                                   const vmime::encoding& enc,
                                   const vmime::mediaType& type,
                                   const std::string& contentid,
@@ -44,7 +44,7 @@
        bool m_hasCharset;
        vmime::charset m_charset;
 
-       void generatePart(vmime::ref<vmime::bodyPart> part) const;
+       void generatePart(vmime::shared_ptr<vmime::bodyPart> part) const;
 };
 
 #endif
--- a/inetmapi/mapiTextPart.cpp
+++ b/inetmapi/mapiTextPart.cpp
@@ -41,6 +41,7 @@
 // the GNU General Public License cover the whole combination.
 //
 
+#include <memory>
 #include "mapiTextPart.h"
 #include "vmime/exception.hpp"
 
@@ -51,25 +52,15 @@
 
 #include "vmime/emptyContentHandler.hpp"
 #include "vmime/stringContentHandler.hpp"
+#include <vmime/utility/outputStreamAdapter.hpp>
 
 namespace vmime
 {
 
-       /** Create a new object and return a reference to it.
-        * vmime only goes as far as p4... 
-        * @return reference to the new object
-        */
-       template <class T, class P0, class P1, class P2, class P3, class P4, 
class P5>
-       static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const 
P3& p3, const P4& p4, const P5& p5) { 
-               return ref <T>::fromPtr(new T(p0, p1, p2, p3, p4, p5));
-       }
-                                            
-                                            
-
 mapiTextPart::mapiTextPart()
-       : m_plainText(vmime::create <emptyContentHandler>()),
-         m_text(vmime::create <emptyContentHandler>()),
-         m_otherText(vmime::create <emptyContentHandler>())
+       : m_plainText(vmime::make_shared<emptyContentHandler>()),
+         m_text(vmime::make_shared<emptyContentHandler>()),
+         m_otherText(vmime::make_shared<emptyContentHandler>())
 {
        m_bHaveOtherCharset = false;
 }
@@ -83,7 +74,7 @@
                return (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
 }
 
-int mapiTextPart::getPartCount() const
+size_t mapiTextPart::getPartCount() const
 {
        int count = 0;
        if (!m_plainText->isEmpty())
@@ -95,13 +86,14 @@
        return count;
 }
 
-void mapiTextPart::generateIn(ref <bodyPart> /* message */, ref <bodyPart> 
parent) const
+void mapiTextPart::generateIn(vmime::shared_ptr<bodyPart> /* message */,
+    vmime::shared_ptr<bodyPart> parent) const
 {
        // Plain text
        if (!m_plainText->isEmpty())
        {
                // -- Create a new part
-               ref <bodyPart> part = vmime::create <bodyPart>();
+               auto part = vmime::make_shared<bodyPart>();
                parent->getBody()->appendPart(part);
 
                // -- Set contents
@@ -114,7 +106,7 @@
        // -- Create a new part
        if (!m_text->isEmpty())
        {
-       ref <bodyPart> htmlPart = vmime::create <bodyPart>();
+               auto htmlPart = vmime::make_shared<bodyPart>();
 
        // -- Set contents
        htmlPart->getBody()->setContents(m_text,
@@ -125,7 +117,7 @@
        if (!m_objects.empty())
        {
                // Create a "multipart/related" body part
-               ref <bodyPart> relPart = vmime::create <bodyPart>();
+               auto relPart = vmime::make_shared<bodyPart>();
                parent->getBody()->appendPart(relPart);
 
                relPart->getHeader()->ContentType()->
@@ -135,10 +127,10 @@
                relPart->getBody()->appendPart(htmlPart);
 
                // Also add objects into this part
-               for (std::vector <ref <embeddedObject> >::const_iterator it = 
m_objects.begin() ;
+               for (std::vector <vmime::shared_ptr <embeddedObject> 
>::const_iterator it = m_objects.begin() ;
                     it != m_objects.end() ; ++it)
                {
-                       ref <bodyPart> objPart = vmime::create <bodyPart>();
+                       auto objPart = vmime::make_shared <bodyPart>();
                        relPart->getBody()->appendPart(objPart);
 
                        string id = (*it)->getId();
@@ -159,7 +151,7 @@
                        //encoding(encodingTypes::BASE64);
 
                        if (!name.empty())
-                               
objPart->getHeader()->ContentDisposition().dynamicCast<contentDispositionField>()->setFilename(name);
+                               
vmime::dynamicCast<vmime::contentDispositionField>(objPart->getHeader()->ContentDisposition())->setFilename(vmime::word(name));
 
                        
objPart->getBody()->setContents((*it)->getData()->clone());
                }
@@ -175,16 +167,15 @@
        if (!m_otherText->isEmpty())
        {
                // -- Create a new part
-               ref <bodyPart> otherPart = vmime::create <bodyPart>();
-
+               auto otherPart = vmime::make_shared<bodyPart>();
                parent->getBody()->appendPart(otherPart);
 
                // used by ical
                if (!m_otherMethod.empty())
                {
-                       vmime::ref<vmime::parameter> p = 
vmime::create<parameter>("method");
-                       p->parse(m_otherMethod);
-                       
otherPart->getHeader()->ContentType().dynamicCast<contentTypeField>()->appendParameter(p);
+                       auto p = vmime::make_shared<vmime::parameter>("method");
+                       p->component::parse(m_otherMethod);
+                       
vmime::dynamicCast<contentTypeField>(otherPart->getHeader()->ContentType())->appendParameter(p);
                }
 
                // -- Set contents
@@ -193,11 +184,12 @@
 }
 
 void mapiTextPart::findEmbeddedParts(const bodyPart& part,
-       std::vector <ref <const bodyPart> >& cidParts, std::vector <ref <const 
bodyPart> >& locParts)
+       std::vector<vmime::shared_ptr<const bodyPart> > &cidParts,
+       std::vector<vmime::shared_ptr<const bodyPart> > &locParts)
 {
-       for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
+       for (size_t i = 0 ; i < part.getBody()->getPartCount() ; ++i)
        {
-               ref <const bodyPart> p = part.getBody()->getPartAt(i);
+               auto p = part.getBody()->getPartAt(i);
 
                // For a part to be an embedded object, it must have a
                // Content-Id field or a Content-Location field.
@@ -236,24 +228,26 @@
 
        try
        {
-               const ref <const headerField> ctf = 
part.getHeader()->ContentType();
-               type = *ctf->getValue().dynamicCast <const mediaType>();
+               auto ctf = part.getHeader()->ContentType();
+               type = *vmime::dynamicCast<const 
vmime::mediaType>(ctf->getValue());
        }
        catch (exceptions::no_such_field)
        {
                // No "Content-type" field: assume "application/octet-stream".
        }
 
-       m_objects.push_back(vmime::create <embeddedObject>
-               (part.getBody()->getContents()->clone().dynamicCast 
<contentHandler>(),
-                part.getBody()->getEncoding(), id, type, string(), string()));
+       m_objects.push_back(vmime::make_shared<embeddedObject>(
+               
vmime::dynamicCast<vmime::contentHandler>(part.getBody()->getContents()->clone()),
+               part.getBody()->getEncoding(), id, type, string(), string()));
 }
 
-void mapiTextPart::parse(ref <const bodyPart> message, ref <const bodyPart> 
parent, ref <const bodyPart> textPart)
+void mapiTextPart::parse(vmime::shared_ptr<const vmime::bodyPart> message,
+    vmime::shared_ptr<const vmime::bodyPart> parent,
+    vmime::shared_ptr<const vmime::bodyPart> textPart)
 {
        // Search for possible embedded objects in the _whole_ message.
-       std::vector <ref <const bodyPart> > cidParts;
-       std::vector <ref <const bodyPart> > locParts;
+       std::vector<vmime::shared_ptr<const vmime::bodyPart> > cidParts;
+       std::vector<vmime::shared_ptr<const vmime::bodyPart> > locParts;
 
        findEmbeddedParts(*message, cidParts, locParts);
 
@@ -269,58 +263,50 @@
 
        try
        {
-               const ref <const contentTypeField> ctf =
-                       
textPart->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast 
<contentTypeField>();
-
+               auto ctf = 
vmime::dynamicCast<vmime::contentTypeField>(textPart->getHeader()->findField(fields::CONTENT_TYPE));
                m_charset = ctf->getCharset();
        }
        catch (exceptions::no_such_field)
        {
                // No "Content-type" field.
        }
-       catch (exceptions::no_such_parameter)
+       catch (std::out_of_range)
        {
                // No "charset" parameter.
        }
 
        // Extract embedded objects. The algorithm is quite simple: for each 
previously
        // found inline part, we check if its CID/Location is contained in the 
HTML text.
-       for (std::vector <ref <const bodyPart> >::const_iterator p = 
cidParts.begin() ; p != cidParts.end() ; ++p)
-       {
-               const ref <const headerField> midField =
-                       (*p)->getHeader()->findField(fields::CONTENT_ID);
-
-               const messageId mid = *midField->getValue().dynamicCast <const 
messageId>();
+       for (const auto &part : cidParts) {
+               auto midField = 
part->getHeader()->findField(fields::CONTENT_ID);
+               auto mid = *vmime::dynamicCast<const 
vmime::messageId>(midField->getValue());
 
                if (data.find("CID:" + mid.getId()) != string::npos ||
                    data.find("cid:" + mid.getId()) != string::npos)
                {
                        // This part is referenced in the HTML text.
                        // Add it to the embedded object list.
-                       addEmbeddedObject(**p, mid.getId());
+                       addEmbeddedObject(*part, mid.getId());
                }
        }
 
-       for (std::vector <ref <const bodyPart> >::const_iterator p = 
locParts.begin() ; p != locParts.end() ; ++p)
-       {
-               const ref <const headerField> locField =
-                       (*p)->getHeader()->findField(fields::CONTENT_LOCATION);
-
-               const text loc = *locField->getValue().dynamicCast <const 
text>();
+       for (const auto &part : locParts) {
+               auto locField = 
part->getHeader()->findField(fields::CONTENT_LOCATION);
+               auto loc = *vmime::dynamicCast<const 
vmime::text>(locField->getValue());
                const string locStr = loc.getWholeBuffer();
 
                if (data.find(locStr) != string::npos)
                {
                        // This part is referenced in the HTML text.
                        // Add it to the embedded object list.
-                       addEmbeddedObject(**p, locStr);
+                       addEmbeddedObject(*part, locStr);
                }
        }
 
        // Extract plain text, if any.
        if (!findPlainTextPart(*message, *parent, *textPart))
        {
-               m_plainText = vmime::create <emptyContentHandler>();
+               m_plainText = vmime::make_shared<vmime::emptyContentHandler>();
        }
 }
 
@@ -329,22 +315,18 @@
        // We search for the nearest "multipart/alternative" part.
        try
        {
-               const ref <const headerField> ctf =
-                       part.getHeader()->findField(fields::CONTENT_TYPE);
-
-               const mediaType type = *ctf->getValue().dynamicCast <const 
mediaType>();
+               auto ctf = part.getHeader()->findField(fields::CONTENT_TYPE);
+               auto type = *vmime::dynamicCast<const 
vmime::mediaType>(ctf->getValue());
 
                if (type.getType() == mediaTypes::MULTIPART &&
                    type.getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
                {
-                       ref <const bodyPart> foundPart = NULL;
-
-                       for (int i = 0 ; i < part.getBody()->getPartCount() ; 
++i)
-                       {
-                               const ref <const bodyPart> p = 
part.getBody()->getPartAt(i);
+                       vmime::shared_ptr<const vmime::bodyPart> foundPart;
 
-                               if (p == &parent ||     // if "text/html" is in 
"multipart/related"
-                                   p == &textPart)     // if not...
+                       for (size_t i = 0; i < part.getBody()->getPartCount(); 
++i) {
+                               auto p = part.getBody()->getPartAt(i);
+                               if (p.get() == &parent ||     // if "text/html" 
is in "multipart/related"
+                                   p.get() == &textPart)     // if not...
                                {
                                        foundPart = p;
                                }
@@ -355,16 +337,13 @@
                                bool found = false;
 
                                // Now, search for the alternative plain text 
part
-                               for (int i = 0 ; !found && i < 
part.getBody()->getPartCount() ; ++i)
-                               {
-                                       const ref <const bodyPart> p = 
part.getBody()->getPartAt(i);
+                               for (size_t i = 0; !found && i < 
part.getBody()->getPartCount(); ++i) {
+                                       auto p = part.getBody()->getPartAt(i);
 
                                        try
                                        {
-                                               const ref <const headerField> 
ctf =
-                                                       
p->getHeader()->findField(fields::CONTENT_TYPE);
-
-                                               const mediaType type = 
*ctf->getValue().dynamicCast <const mediaType>();
+                                               auto ctf = 
p->getHeader()->findField(fields::CONTENT_TYPE);
+                                               auto type = 
*vmime::dynamicCast<const vmime::mediaType>(ctf->getValue());
 
                                                if (type.getType() == 
mediaTypes::TEXT &&
                                                    type.getSubType() == 
mediaTypes::TEXT_PLAIN)
@@ -393,10 +372,8 @@
 
        bool found = false;
 
-       for (int i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i)
-       {
+       for (size_t i = 0; !found && i < part.getBody()->getPartCount(); ++i)
                found = findPlainTextPart(*part.getBody()->getPartAt(i), 
parent, textPart);
-       }
 
        return found;
 }
@@ -406,12 +383,12 @@
        m_charset = ch;
 }
 
-void mapiTextPart::setPlainText(ref <contentHandler> plainText)
+void mapiTextPart::setPlainText(vmime::shared_ptr<vmime::contentHandler> 
plainText)
 {
        m_plainText = plainText->clone();
 }
 
-void mapiTextPart::setOtherText(ref <contentHandler> otherText)
+void mapiTextPart::setOtherText(vmime::shared_ptr<vmime::contentHandler> 
otherText)
 {
        m_otherText = otherText->clone();
 }
@@ -437,30 +414,31 @@
        m_bHaveOtherCharset = true;
 }
 
-void mapiTextPart::setText(ref <contentHandler> text)
+void mapiTextPart::setText(vmime::shared_ptr<vmime::contentHandler> text)
 {
        m_text = text->clone();
 }
 
-const ref <const mapiTextPart::embeddedObject> mapiTextPart::findObject(const 
string& id_) const
+vmime::shared_ptr<const mapiTextPart::embeddedObject>
+mapiTextPart::findObject(const std::string &id_) const
 {
        const string id = cleanId(id_);
 
-       for (std::vector <ref <embeddedObject> >::const_iterator o = 
m_objects.begin() ;
+       for (std::vector <vmime::shared_ptr <embeddedObject> >::const_iterator 
o = m_objects.begin() ;
             o != m_objects.end() ; ++o)
        {
                if ((*o)->getId() == id)
                        return *o;
        }
 
-       throw exceptions::no_object_found();
+       throw vmime::null;
 }
 
 bool mapiTextPart::hasObject(const string& id_) const
 {
        const string id = cleanId(id_);
 
-       for (std::vector <ref <embeddedObject> >::const_iterator o = 
m_objects.begin() ;
+       for (std::vector <vmime::shared_ptr <embeddedObject> >::const_iterator 
o = m_objects.begin() ;
             o != m_objects.end() ; ++o)
        {
                if ((*o)->getId() == id)
@@ -470,8 +448,9 @@
        return false;
 }
 
-const string mapiTextPart::addObject(ref <contentHandler> data,
-       const encoding& enc, const mediaType& type)
+const std::string
+mapiTextPart::addObject(vmime::shared_ptr<vmime::contentHandler> data,
+    const vmime::encoding &enc, const vmime::mediaType &type)
 {
        const messageId mid(messageId::generateId());
        const string id = mid.getId();
@@ -479,20 +458,23 @@
        return "CID:" + addObject(data, enc, type, id);
 }
 
-const string mapiTextPart::addObject(ref <contentHandler> data, const 
mediaType& type)
+const string mapiTextPart::addObject(vmime::shared_ptr<vmime::contentHandler> 
data,
+    const vmime::mediaType &type)
 {
        return addObject(data, encoding::decide(data), type);
 }
 
 const string mapiTextPart::addObject(const string& data, const mediaType& type)
 {
-       ref <stringContentHandler> cts = vmime::create 
<stringContentHandler>(data);
+       auto cts = vmime::make_shared<vmime::stringContentHandler>(data);
        return addObject(cts, encoding::decide(cts), type);
 }
 
-const string mapiTextPart::addObject(ref <contentHandler> data, const 
encoding& enc, const mediaType& type, const string& id, const string& name, 
const string& loc)
+const string mapiTextPart::addObject(vmime::shared_ptr<vmime::contentHandler> 
data,
+    const vmime::encoding &enc, const vmime::mediaType &type,
+    const std::string &id, const std::string &name, const std::string &loc)
 {
-       m_objects.push_back(vmime::create <embeddedObject>(data, enc, id, type, 
name, loc));
+       m_objects.push_back(vmime::make_shared<embeddedObject>(data, enc, id, 
type, name, loc));
        return (id);
 }
 
@@ -517,11 +499,12 @@
 // mapiTextPart::embeddedObject
 //
 
-mapiTextPart::embeddedObject::embeddedObject
-       (ref <contentHandler> data, const encoding& enc,
-        const string& id, const mediaType& type, const string& name, const 
string& loc)
-       : m_data(data->clone().dynamicCast <contentHandler>()),
-         m_encoding(enc), m_id(id), m_type(type), m_name(name), m_loc(loc)
+mapiTextPart::embeddedObject::embeddedObject(vmime::shared_ptr<vmime::contentHandler>
 data,
+    const vmime::encoding &enc, const std::string &id,
+    const vmime::mediaType &type, const std::string &name,
+    const std::string &loc) :
+       m_data(vmime::dynamicCast<vmime::contentHandler>(data->clone())),
+       m_encoding(enc), m_id(id), m_type(type), m_name(name), m_loc(loc)
 {
 }
 
--- a/inetmapi/mapiTextPart.h
+++ b/inetmapi/mapiTextPart.h
@@ -45,6 +45,7 @@
 #define VMIME_MAPITEXTPART_HPP_INCLUDED
 
 #include <kopano/zcdefs.h>
+#include <memory>
 #include "vmime/textPart.hpp"
 #include "vmime/messageId.hpp"
 #include "vmime/encoding.hpp"
@@ -63,17 +64,17 @@
 public:
 
        mapiTextPart();
-       const mediaType getType() const;
-       const charset &getCharset(void) const { return m_charset; }
-       void setCharset(const charset& ch);
+       const mediaType getType(void) const _kc_override;
+       const charset &getCharset(void) const _kc_override { return m_charset; }
+       void setCharset(const charset &ch) _kc_override;
 
        /* plain text */
-       const ref<const contentHandler> getPlainText(void) const { return 
m_plainText; }
-       void setPlainText(ref <contentHandler> plainText);
+       vmime::shared_ptr<const contentHandler> getPlainText(void) const { 
return m_plainText; }
+       void setPlainText(vmime::shared_ptr<contentHandler> plainText);
 
        /* 'other' text */
-       const ref<const contentHandler> getOtherText(void) const { return 
m_otherText; }
-       void setOtherText(ref <contentHandler> otherText);
+       vmime::shared_ptr<const contentHandler> getOtherText(void) const { 
return m_otherText; }
+       void setOtherText(vmime::shared_ptr<contentHandler> otherText);
        /* extra 'other' properties */
        void setOtherContentType(const mediaType& type);
        void setOtherContentEncoding(const encoding& enc);
@@ -81,8 +82,8 @@
        void setOtherCharset(const charset& ch);
 
        /* html + plain + 'other' text */
-       const ref<const contentHandler> getText(void) const { return m_text; }
-       void setText(ref <contentHandler> text);
+       const vmime::shared_ptr<const contentHandler> getText(void) const { 
return m_text; }
+       void setText(vmime::shared_ptr<contentHandler> text);
 
        /** Embedded object (eg: image for &lt;IMG> tag).
          */
@@ -90,14 +91,14 @@
        {
        public:
 
-               embeddedObject(ref <contentHandler> data, const encoding& enc,
+           embeddedObject(vmime::shared_ptr<contentHandler> data, const 
encoding& enc,
                               const string& id, const mediaType& type, const 
string& name, const string& loc);
 
                /** Return data stored in this embedded object.
                  *
                  * @return stored data
                  */
-               const ref<const contentHandler> getData(void) const { return 
m_data; }
+           const vmime::shared_ptr<const contentHandler> getData(void) const { 
return m_data; }
 
                /** Return the encoding used for data in this
                  * embedded object.
@@ -132,8 +133,7 @@
                const std::string &getName(void) const { return m_name; }
 
        private:
-
-               ref <contentHandler> m_data;
+               vmime::shared_ptr<contentHandler> m_data;
                encoding m_encoding;
                string m_id;
                mediaType m_type;
@@ -156,7 +156,7 @@
          * @param id object identifier
          * @return embedded object with the specified identifier
          */
-       const ref <const embeddedObject> findObject(const string& id) const;
+       vmime::shared_ptr<const embeddedObject> findObject(const string &id) 
const;
 
        /** Return the number of embedded objects.
          *
@@ -169,7 +169,7 @@
          * @param pos position of the embedded object
          * @return embedded object at position 'pos'
          */
-       const ref<const embeddedObject> getObjectAt(int pos) const { return 
m_objects[pos]; }
+       vmime::shared_ptr<const embeddedObject> getObjectAt(int pos) const { 
return m_objects[pos]; }
 
        /** Embed an object and returns a string which identifies it.
          * The returned identifier is suitable for use in the 'src' attribute
@@ -194,7 +194,7 @@
          * @return an unique object identifier used to identify the new
          * object among all other embedded objects
          */
-       const string addObject(ref <contentHandler> data, const mediaType& 
type);
+       const string addObject(vmime::shared_ptr<contentHandler> data, const 
mediaType &type);
 
        /** Embed an object and returns a string which identifies it.
          * The returned identifier is suitable for use in the 'src' attribute
@@ -206,7 +206,7 @@
          * @return an unique object identifier used to identify the new
          * object among all other embedded objects
          */
-       const string addObject(ref <contentHandler> data, const encoding& enc, 
const mediaType& type);
+       const string addObject(vmime::shared_ptr<contentHandler> data, const 
encoding &enc, const mediaType &type);
 
        /** Embed an object and returns a string which identifies it.
         *
@@ -219,29 +219,27 @@
         * @return an unique object identifier used to identify the new
         * object among all other embedded objects
         */
-       const string addObject(ref <contentHandler> data, const encoding& enc, 
const mediaType& type, const string& id, const string& name = string(), const 
string& loc = string());
+       const string addObject(vmime::shared_ptr<contentHandler> data, const 
encoding &enc, const mediaType &type, const string &id, const string &name = 
string(), const string &loc = string());
 
-       int getPartCount() const;
+       size_t getPartCount() const _kc_override;
 
-       void generateIn(ref <bodyPart> message, ref <bodyPart> parent) const;
-       void parse(ref <const bodyPart> message, ref <const bodyPart> parent, 
ref <const bodyPart> textPart);
+       void generateIn(vmime::shared_ptr<bodyPart> message, 
vmime::shared_ptr<bodyPart> parent) const _kc_override;
+       void parse(vmime::shared_ptr<const bodyPart> message, 
vmime::shared_ptr<const bodyPart> parent, vmime::shared_ptr<const bodyPart> 
textPart) _kc_override;
 
 private:
-
-       ref <contentHandler> m_plainText;
-       ref <contentHandler> m_text;    /* htmlText */
+       vmime::shared_ptr<contentHandler> m_plainText;
+       vmime::shared_ptr<contentHandler> m_text; /* htmlText */
        charset m_charset;
-
-       ref <contentHandler> m_otherText;
+       vmime::shared_ptr<contentHandler> m_otherText;
        mediaType m_otherMediaType;
        encoding m_otherEncoding;
        string m_otherMethod;                   /* ical special */
        charset m_otherCharset;
        bool m_bHaveOtherCharset;
 
-       std::vector <ref <embeddedObject> > m_objects;
+       std::vector<vmime::shared_ptr<embeddedObject> > m_objects;
 
-       void findEmbeddedParts(const bodyPart& part, std::vector <ref <const 
bodyPart> >& cidParts, std::vector <ref <const bodyPart> >& locParts);
+       void findEmbeddedParts(const bodyPart& part, 
std::vector<vmime::shared_ptr<const bodyPart> > &cidParts, 
std::vector<vmime::shared_ptr<const bodyPart> > &locParts);
        void addEmbeddedObject(const bodyPart& part, const string& id);
 
        bool findPlainTextPart(const bodyPart& part, const bodyPart& parent, 
const bodyPart& textPart);
--- a/inetmapi/outputStreamMAPIAdapter.cpp
+++ b/inetmapi/outputStreamMAPIAdapter.cpp
@@ -35,9 +35,9 @@
                lpStream->Release();
 }
 
-void outputStreamMAPIAdapter::write(const value_type* const data, const 
size_type count)
+void outputStreamMAPIAdapter::writeImpl(const vmime::byte_t *data, size_t 
count)
 {
-       lpStream->Write((unsigned char *)data,count,NULL);
+       lpStream->Write(data, count, NULL);
 }
 
 void outputStreamMAPIAdapter::flush()
--- a/inetmapi/outputStreamMAPIAdapter.h
+++ b/inetmapi/outputStreamMAPIAdapter.h
@@ -19,14 +19,15 @@
 #define OUTPUT_STREAM_MAPI_ADAPTER_H
 
 #include <mapidefs.h>
-#include <vmime/utility/stream.hpp>
+#include <sys/types.h>
+#include <vmime/utility/outputStream.hpp>
 
 class outputStreamMAPIAdapter : public vmime::utility::outputStream {
 public:
        outputStreamMAPIAdapter(IStream *lpStream);
        virtual ~outputStreamMAPIAdapter();
-       void write(const value_type* const data, const size_type count);
-       void flush();
+       virtual void writeImpl(const unsigned char *, const size_t);
+       virtual void flush(void) override;
 
 private:
        IStream *lpStream;
--- a/inetmapi/serviceRegistration.inl
+++ b/inetmapi/serviceRegistration.inl
@@ -21,6 +21,7 @@
 // the GNU General Public License cover the whole combination.
 //
 
+#include <memory>
 #include "vmime/net/serviceFactory.hpp"
 
 
@@ -41,11 +42,10 @@
        {
        }
 
-       ref <service> create
-               (ref <session> sess,
-                ref <security::authenticator> auth) const
+       vmime::shared_ptr<service> create(vmime::shared_ptr<session> sess,
+           vmime::shared_ptr<security::authenticator> auth) const
        {
-               return vmime::create <S>(sess, auth);
+               return vmime::make_shared<S>(sess, auth);
        }
 
        const serviceInfos& getInfos() const
@@ -80,7 +80,7 @@
        serviceRegisterer(const string& protocol, const service::Type type)
        {
                serviceFactory::getInstance()->registerService
-                       (vmime::create <vmime::net::registeredServiceImpl <S> 
>(protocol, type));
+                       (vmime::make_shared<net::registeredServiceImpl<S> 
>(protocol, type));
        }
 };
 

Reply via email to