diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/vmime/net/folderAttributes.hpp | 1 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPConnection.cpp | 13 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPFolder.cpp | 6 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPMessagePart.cpp | 13 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPMessagePart.hpp | 2 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPParser.hpp | 102 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPTag.cpp | 24 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPTag.hpp | 8 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPUtils.cpp | 5 | ||||
| -rw-r--r-- | src/vmime/net/imap/IMAPUtils.hpp | 2 | ||||
| -rw-r--r-- | src/vmime/net/maildir/maildirMessagePart.cpp | 11 | ||||
| -rw-r--r-- | src/vmime/net/maildir/maildirMessagePart.hpp | 2 | ||||
| -rw-r--r-- | src/vmime/net/message.hpp | 7 | ||||
| -rw-r--r-- | src/vmime/net/pop3/POP3Folder.cpp | 1 | ||||
| -rw-r--r-- | src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp | 5 | ||||
| -rw-r--r-- | src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp | 10 | ||||
| -rw-r--r-- | src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp | 2 | ||||
| -rw-r--r-- | src/vmime/word.cpp | 2 |
18 files changed, 157 insertions, 59 deletions
diff --git a/src/vmime/net/folderAttributes.hpp b/src/vmime/net/folderAttributes.hpp index b91347b5..715b72a8 100644 --- a/src/vmime/net/folderAttributes.hpp +++ b/src/vmime/net/folderAttributes.hpp @@ -67,6 +67,7 @@ public: enum SpecialUses { SPECIALUSE_NONE, /**< User folder, no special use (or unknown). */ SPECIALUSE_ALL, /**< Virtual folder containing all messages. */ + SPECIALUSE_INBOX, /**< Inbox. */ SPECIALUSE_ARCHIVE, /**< Folder is used to archives messages (server-dependent). */ SPECIALUSE_DRAFTS, /**< Folder is used to hold draft messages - typically, messages that are being composed but have not yet been sent. */ diff --git a/src/vmime/net/imap/IMAPConnection.cpp b/src/vmime/net/imap/IMAPConnection.cpp index 2ea48e34..df3da1c3 100644 --- a/src/vmime/net/imap/IMAPConnection.cpp +++ b/src/vmime/net/imap/IMAPConnection.cpp @@ -92,7 +92,6 @@ IMAPConnection::IMAPConnection( } m_parser = make_shared <IMAPParser>(); - m_parser->setTag(m_tag); m_parser->setTracer(m_tracer); } @@ -287,7 +286,7 @@ void IMAPConnection::authenticate() { shared_ptr <IMAPConnection> conn = dynamicCast <IMAPConnection>(shared_from_this()); IMAPCommand::LOGIN(username, password)->send(conn); - scoped_ptr <IMAPParser::response> resp(m_parser->readResponse()); + scoped_ptr <IMAPParser::response> resp(m_parser->readResponse(*m_tag)); if (resp->isBad()) { @@ -409,7 +408,7 @@ void IMAPConnection::authenticateSASL() { for (bool cont = true ; cont ; ) { - scoped_ptr <IMAPParser::response> resp(m_parser->readResponse()); + scoped_ptr <IMAPParser::response> resp(m_parser->readResponse(*m_tag)); if (resp->response_done && resp->response_done->response_tagged && @@ -522,7 +521,7 @@ void IMAPConnection::startTLS() { IMAPCommand::STARTTLS()->send(dynamicCast <IMAPConnection>(shared_from_this())); - scoped_ptr <IMAPParser::response> resp(m_parser->readResponse()); + scoped_ptr <IMAPParser::response> resp(m_parser->readResponse(*m_tag)); if (resp->isBad() || resp->response_done->response_tagged-> resp_cond_state->status != IMAPParser::resp_cond_state::OK) { @@ -624,7 +623,7 @@ void IMAPConnection::fetchCapabilities() { IMAPCommand::CAPABILITY()->send(dynamicCast <IMAPConnection>(shared_from_this())); - scoped_ptr <IMAPParser::response> resp(m_parser->readResponse()); + scoped_ptr <IMAPParser::response> resp(m_parser->readResponse(*m_tag)); if (resp->response_done->response_tagged-> resp_cond_state->status == IMAPParser::resp_cond_state::OK) { @@ -733,7 +732,7 @@ void IMAPConnection::initHierarchySeparator() { IMAPCommand::LIST("", "")->send(dynamicCast <IMAPConnection>(shared_from_this())); - scoped_ptr <IMAPParser::response> resp(m_parser->readResponse()); + scoped_ptr <IMAPParser::response> resp(m_parser->readResponse(*m_tag)); if (resp->isBad() || resp->response_done->response_tagged-> resp_cond_state->status != IMAPParser::resp_cond_state::OK) { @@ -801,7 +800,7 @@ void IMAPConnection::sendRaw(const byte_t* buffer, const size_t count) { IMAPParser::response* IMAPConnection::readResponse(IMAPParser::literalHandler* lh) { - return m_parser->readResponse(lh); + return m_parser->readResponse(*m_tag, lh); } diff --git a/src/vmime/net/imap/IMAPFolder.cpp b/src/vmime/net/imap/IMAPFolder.cpp index e3bc958f..98bc05d8 100644 --- a/src/vmime/net/imap/IMAPFolder.cpp +++ b/src/vmime/net/imap/IMAPFolder.cpp @@ -244,6 +244,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable) { IMAPUtils::mailboxFlagsToFolderAttributes( connection, + m_path, *responseData->mailbox_data->mailbox_flag_list, *m_attribs ); @@ -527,6 +528,7 @@ int IMAPFolder::testExistAndGetType() { // Get the folder type/flags at the same time IMAPUtils::mailboxFlagsToFolderAttributes( m_connection, + m_path, *mailboxData->mailbox_list->mailbox_flag_list, attribs ); @@ -755,6 +757,7 @@ std::vector <shared_ptr <folder> > IMAPFolder::getFolders(const bool recursive) IMAPUtils::mailboxFlagsToFolderAttributes( m_connection, + path, *mailboxData->mailbox_list->mailbox_flag_list, *attribs ); @@ -1058,7 +1061,7 @@ void IMAPFolder::setMessageFlags( const std::vector <string> flagList = IMAPUtils::messageFlagList(flags); - if (!flagList.empty()) { + if ((mode == message::FLAG_MODE_SET) || !flagList.empty()) { // Send the request IMAPCommand::STORE(msgs, mode, flagList)->send(m_connection); @@ -1523,6 +1526,7 @@ void IMAPFolder::processStatusUpdate(const IMAPParser::response* resp) { folderAttributes attribs; IMAPUtils::mailboxFlagsToFolderAttributes( m_connection, + m_path, *(*it)->response_data->mailbox_data->mailbox_list->mailbox_flag_list, attribs ); diff --git a/src/vmime/net/imap/IMAPMessagePart.cpp b/src/vmime/net/imap/IMAPMessagePart.cpp index 37ccfd97..746fe9a4 100644 --- a/src/vmime/net/imap/IMAPMessagePart.cpp +++ b/src/vmime/net/imap/IMAPMessagePart.cpp @@ -95,6 +95,13 @@ IMAPMessagePart::IMAPMessagePart( } } } + + if (part->body_ext_1part && part->body_ext_1part->body_fld_dsp) { + auto *cdisp = part->body_ext_1part->body_fld_dsp->str(); + if (cdisp) { + m_dispType = contentDisposition(cdisp->value); + } + } } m_structure = null; @@ -133,6 +140,12 @@ const mediaType& IMAPMessagePart::getType() const { } +const contentDisposition &IMAPMessagePart::getDisposition() const { + + return m_dispType; +} + + size_t IMAPMessagePart::getSize() const { return m_size; diff --git a/src/vmime/net/imap/IMAPMessagePart.hpp b/src/vmime/net/imap/IMAPMessagePart.hpp index 4a636dd8..34ea1725 100644 --- a/src/vmime/net/imap/IMAPMessagePart.hpp +++ b/src/vmime/net/imap/IMAPMessagePart.hpp @@ -66,6 +66,7 @@ public: shared_ptr <const IMAPMessagePart> getParent() const; const mediaType& getType() const; + const contentDisposition &getDisposition() const; size_t getSize() const; size_t getNumber() const; string getName() const; @@ -92,6 +93,7 @@ private: size_t m_size; string m_name; mediaType m_mediaType; + contentDisposition m_dispType; }; diff --git a/src/vmime/net/imap/IMAPParser.hpp b/src/vmime/net/imap/IMAPParser.hpp index 76019d2e..281fcb67 100644 --- a/src/vmime/net/imap/IMAPParser.hpp +++ b/src/vmime/net/imap/IMAPParser.hpp @@ -271,24 +271,13 @@ public: } + ~IMAPParser() { - /** Set the tag currently used by this parser. - * - * @param tag IMAP command tag - */ - void setTag(const shared_ptr <IMAPTag>& tag) { - - m_tag = tag; + for (auto it = m_pendingResponses.begin() ; it != m_pendingResponses.end() ; ++it) { + delete it->second; + } } - /** Return the tag currently used by this parser. - * - * @return IMAP command tag - */ - shared_ptr <const IMAPTag> getTag() const { - - return m_tag.lock(); - } /** Set the socket currently used by this parser to receive data * from server. @@ -613,13 +602,12 @@ public: DECLARE_COMPONENT(xtag) - bool parseImpl(IMAPParser& parser, string& line, size_t* currentPos) { + bool parseImpl(IMAPParser& /* parser */, string& line, size_t* currentPos) { size_t pos = *currentPos; bool end = false; - string tagString; tagString.reserve(10); while (!end && pos < line.length()) { @@ -654,14 +642,11 @@ public: } } - if (tagString == string(*parser.getTag())) { - *currentPos = pos; - return true; - } else { - // Invalid tag - return false; - } + *currentPos = pos; + return true; } + + string tagString; }; @@ -1141,7 +1126,7 @@ public: value = text->value; } - DEBUG_FOUND("string[quoted]", "<length=" << m_value.length() << ", value='" << m_value << "'>"); + DEBUG_FOUND("string[quoted]", "<length=" << value.length() << ", value='" << value << "'>"); // literal ::= "{" number "}" CRLF *CHAR8 } else { @@ -1660,8 +1645,12 @@ public: } else { - type = KEYWORD_OR_EXTENSION; - VIMAP_PARSER_GET(atom, flag_keyword); + if (!parser.isStrict() && VIMAP_PARSER_TRY_CHECK(one_char <'*'> )) { + type = STAR; // map "*" to "\*" + } else { + type = KEYWORD_OR_EXTENSION; + VIMAP_PARSER_GET(atom, flag_keyword); + } } *currentPos = pos; @@ -4389,7 +4378,7 @@ public: size_t pos = *currentPos; - VIMAP_PARSER_CHECK(IMAPParser::xtag); + VIMAP_PARSER_GET(IMAPParser::xtag, tag); VIMAP_PARSER_CHECK(SPACE); VIMAP_PARSER_GET(IMAPParser::resp_cond_state, resp_cond_state); @@ -4409,6 +4398,7 @@ public: } + std::unique_ptr <IMAPParser::xtag> tag; std::unique_ptr <IMAPParser::resp_cond_state> resp_cond_state; }; @@ -4569,22 +4559,53 @@ public: // The main functions used to parse a response // - response* readResponse(literalHandler* lh = NULL) { + response* readResponse(const IMAPTag& tag, literalHandler* lh = NULL) { - size_t pos = 0; - string line = readLine(); + while (true) { - m_literalHandler = lh; - response* resp = get <response>(line, &pos); - m_literalHandler = NULL; + auto it = m_pendingResponses.find(std::string(tag)); - if (!resp) { - throw exceptions::invalid_response("", m_errorResponseLine); - } + if (it != m_pendingResponses.end()) { + auto* resp = it->second; + m_pendingResponses.erase(it); + return resp; + } - resp->setErrorLog(lastLine()); + size_t pos = 0; + string line = readLine(); - return (resp); + m_literalHandler = lh; + response* resp = get <response>(line, &pos); + m_literalHandler = NULL; + + if (!resp) { + throw exceptions::invalid_response("", m_errorResponseLine); + } + + resp->setErrorLog(lastLine()); + + // If there is a continue_req, return the response immediately + for (auto &respData : resp->continue_req_or_response_data) { + if (respData->continue_req) { + return resp; + } + } + + // Else, return response if the tag is the one we expect + if (resp->response_done && resp->response_done->response_tagged && + resp->response_done->response_tagged->tag) { + + if (tag == resp->response_done->response_tagged->tag->tagString) { + return resp; + } else { + // Not our response tag, cache it for later + m_pendingResponses[resp->response_done->response_tagged->tag->tagString] = resp; + } + } else { + // Untagged response + return resp; + } + } } @@ -4740,7 +4761,6 @@ public: private: - weak_ptr <IMAPTag> m_tag; weak_ptr <socket> m_socket; shared_ptr <tracer> m_tracer; @@ -4758,6 +4778,8 @@ private: string m_lastLine; string m_errorResponseLine; + std::map <std::string, response*> m_pendingResponses; + public: /** Read a line from the input buffer. The function blocks until a diff --git a/src/vmime/net/imap/IMAPTag.cpp b/src/vmime/net/imap/IMAPTag.cpp index 69f48477..52cd2123 100644 --- a/src/vmime/net/imap/IMAPTag.cpp +++ b/src/vmime/net/imap/IMAPTag.cpp @@ -85,6 +85,30 @@ const IMAPTag IMAPTag::operator++(int) { } +bool IMAPTag::operator<(const IMAPTag &other) const { + + return m_number < other.m_number; +} + + +bool IMAPTag::operator==(const IMAPTag &other) const { + + return m_number == other.m_number; +} + + +bool IMAPTag::operator!=(const IMAPTag &other) const { + + return m_number != other.m_number; +} + + +bool IMAPTag::operator==(const std::string &tag) const { + + return m_tag == tag; +} + + int IMAPTag::maximumNumber() const { return sm_maxNumber - 1; diff --git a/src/vmime/net/imap/IMAPTag.hpp b/src/vmime/net/imap/IMAPTag.hpp index d4292fde..cbab9429 100644 --- a/src/vmime/net/imap/IMAPTag.hpp +++ b/src/vmime/net/imap/IMAPTag.hpp @@ -44,11 +44,11 @@ class VMIME_EXPORT IMAPTag : public object { private: IMAPTag(const int number); - IMAPTag(const IMAPTag& tag); public: IMAPTag(); + IMAPTag(const IMAPTag& tag); IMAPTag& operator++(); // ++IMAPTag const IMAPTag operator++(int); // IMAPTag++ @@ -58,6 +58,12 @@ public: operator string() const; + bool operator<(const IMAPTag &other) const; + bool operator==(const IMAPTag &other) const; + bool operator!=(const IMAPTag &other) const; + + bool operator==(const std::string &tag) const; + private: void generate(); diff --git a/src/vmime/net/imap/IMAPUtils.cpp b/src/vmime/net/imap/IMAPUtils.cpp index 273531fd..59b1e181 100644 --- a/src/vmime/net/imap/IMAPUtils.cpp +++ b/src/vmime/net/imap/IMAPUtils.cpp @@ -390,6 +390,7 @@ const folder::path::component IMAPUtils::fromModifiedUTF7(const string& text) { // static void IMAPUtils::mailboxFlagsToFolderAttributes( const shared_ptr <const IMAPConnection>& cnt, + const folder::path &path, const IMAPParser::mailbox_flag_list& list, folderAttributes& attribs ) { @@ -471,6 +472,10 @@ void IMAPUtils::mailboxFlagsToFolderAttributes( } } + if (path.getSize() == 1 && path.getLastComponent().getBuffer() == "INBOX") { + specialUse = folderAttributes::SPECIALUSE_INBOX; + } + attribs.setSpecialUse(specialUse); attribs.setType(type); attribs.setFlags(flags); diff --git a/src/vmime/net/imap/IMAPUtils.hpp b/src/vmime/net/imap/IMAPUtils.hpp index 123bc8c7..d4bd1356 100644 --- a/src/vmime/net/imap/IMAPUtils.hpp +++ b/src/vmime/net/imap/IMAPUtils.hpp @@ -70,11 +70,13 @@ public: /** Parse mailbox flags and fill in folder attributes. * * @param cnt reference to current IMAP connection (for testing capabilities) + * @param path folder full path * @param list list of mailbox flags * @param attribs reference to an object holding folder attributes */ static void mailboxFlagsToFolderAttributes( const shared_ptr <const IMAPConnection>& cnt, + const folder::path &path, const IMAPParser::mailbox_flag_list& list, folderAttributes& attribs ); diff --git a/src/vmime/net/maildir/maildirMessagePart.cpp b/src/vmime/net/maildir/maildirMessagePart.cpp index 9d30e24d..7448d7ee 100644 --- a/src/vmime/net/maildir/maildirMessagePart.cpp +++ b/src/vmime/net/maildir/maildirMessagePart.cpp @@ -54,6 +54,11 @@ maildirMessagePart::maildirMessagePart( m_size = part.getBody()->getContents()->getLength(); m_mediaType = part.getBody()->getContentType(); + + auto cdispField = part.getHeader()->ContentDisposition(); + if (cdispField) { + m_dispType = dynamic_cast <const contentDisposition&>(*cdispField->getValue()); + } } @@ -103,6 +108,12 @@ const mediaType& maildirMessagePart::getType() const { } +const contentDisposition &maildirMessagePart::getDisposition() const { + + return m_dispType; +} + + size_t maildirMessagePart::getSize() const { return m_size; diff --git a/src/vmime/net/maildir/maildirMessagePart.hpp b/src/vmime/net/maildir/maildirMessagePart.hpp index dd863a2b..5ecc739e 100644 --- a/src/vmime/net/maildir/maildirMessagePart.hpp +++ b/src/vmime/net/maildir/maildirMessagePart.hpp @@ -61,6 +61,7 @@ public: weak_ptr <const maildirMessagePart> getParent() const { return (m_parent); } const mediaType& getType() const; + const contentDisposition &getDisposition() const; size_t getSize() const; size_t getNumber() const; @@ -85,6 +86,7 @@ private: size_t m_number; size_t m_size; mediaType m_mediaType; + contentDisposition m_dispType; size_t m_headerParsedOffset; size_t m_headerParsedLength; diff --git a/src/vmime/net/message.hpp b/src/vmime/net/message.hpp index c0a2839b..86798795 100644 --- a/src/vmime/net/message.hpp +++ b/src/vmime/net/message.hpp @@ -33,6 +33,7 @@ #include "vmime/header.hpp" #include "vmime/mediaType.hpp" +#include "vmime/contentDisposition.hpp" #include "vmime/utility/progressListener.hpp" #include "vmime/utility/stream.hpp" @@ -85,6 +86,12 @@ public: */ virtual const mediaType& getType() const = 0; + /** Return the disposition type of the content in this part. + * + * @return content disposition type + */ + virtual const contentDisposition &getDisposition() const = 0; + /** Return the size of this part. * * @return size of the part (in bytes) diff --git a/src/vmime/net/pop3/POP3Folder.cpp b/src/vmime/net/pop3/POP3Folder.cpp index 4ca494fe..b69a483d 100644 --- a/src/vmime/net/pop3/POP3Folder.cpp +++ b/src/vmime/net/pop3/POP3Folder.cpp @@ -103,6 +103,7 @@ const folderAttributes POP3Folder::getAttributes() { attribs.setType(folderAttributes::TYPE_CONTAINS_FOLDERS); } else if (m_path.getSize() == 1 && m_path[0].getBuffer() == "INBOX") { attribs.setType(folderAttributes::TYPE_CONTAINS_MESSAGES); + attribs.setSpecialUse(folderAttributes::SPECIALUSE_INBOX); } else { throw exceptions::folder_not_found(); } diff --git a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp index eea2a15b..53e4eaee 100644 --- a/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp +++ b/src/vmime/net/tls/gnutls/TLSSocket_GnuTLS.cpp @@ -94,8 +94,6 @@ void TLSSocket_GnuTLS::connect(const string& address, const port_t port) { try { - gnutls_server_name_set(*m_session->m_gnutlsSession, GNUTLS_NAME_DNS, address.c_str(), address.size()); - m_wrapped->connect(address, port); handshake(); @@ -319,6 +317,9 @@ void TLSSocket_GnuTLS::handshake() { // Start handshaking process try { + string peerName = getPeerName(); + + gnutls_server_name_set(*m_session->m_gnutlsSession, GNUTLS_NAME_DNS, peerName.c_str(), peerName.size()); while (true) { diff --git a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp index 8ab75439..978f0ca6 100644 --- a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp +++ b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp @@ -122,8 +122,9 @@ TLSSocket_OpenSSL::~TLSSocket_OpenSSL() { void TLSSocket_OpenSSL::createSSLHandle() { if (m_wrapped->isConnected()) { - - if (m_address.empty()) { + string peerName = getPeerName(); + + if (peerName.empty()) { throw exceptions::tls_exception("Unknown host name, will not be able to set SNI"); } @@ -167,7 +168,7 @@ void TLSSocket_OpenSSL::createSSLHandle() { } SSL_set_bio(m_ssl, sockBio, sockBio); - SSL_set_tlsext_host_name(m_ssl, m_address.c_str()); + SSL_set_tlsext_host_name(m_ssl, peerName.c_str()); SSL_set_connect_state(m_ssl); SSL_set_mode(m_ssl, SSL_MODE_AUTO_RETRY | SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); @@ -183,8 +184,7 @@ void TLSSocket_OpenSSL::connect(const string& address, const port_t port) { try { m_wrapped->connect(address, port); - m_address = address; - + createSSLHandle(); handshake(); diff --git a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp index 233bd25a..e30df680 100644 --- a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp +++ b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp @@ -116,8 +116,6 @@ private: shared_ptr <socket> m_wrapped; - std::string m_address; - bool m_connected; byte_t m_buffer[65536]; diff --git a/src/vmime/word.cpp b/src/vmime/word.cpp index b8061eee..2607e90d 100644 --- a/src/vmime/word.cpp +++ b/src/vmime/word.cpp @@ -596,7 +596,7 @@ void word::generate( } else { if (!state->isFirstWord && - state->prevWordIsEncoded && + (state->prevWordIsEncoded || ctx.getInternationalizedEmailSupport()) && !state->lastCharIsSpace && !parserHelpers::isSpace(*curLineStart)) { |
