diff --git a/examples/example6.cpp b/examples/example6.cpp index 2d1b737a..97102e18 100644 --- a/examples/example6.cpp +++ b/examples/example6.cpp @@ -108,21 +108,21 @@ static std::ostream& operator<<(std::ostream& os, const vmime::exception& e) * @param s structure object * @param level current depth */ -static void printStructure(const vmime::net::structure& s, const int level = 0) +static void printStructure(vmime::ref s, const int level = 0) { - for (int i = 1 ; i <= s.getCount() ; ++i) + for (int i = 0 ; i < s->getPartCount() ; ++i) { - const vmime::net::part& part = s[i]; + vmime::ref part = s->getPartAt(i); for (int j = 0 ; j < level * 2 ; ++j) std::cout << " "; - std::cout << part.getNumber() << ". " - << part.getType().generate() - << " [" << part.getSize() << " byte(s)]" + std::cout << (part->getNumber() + 1) << ". " + << part->getType().generate() + << " [" << part->getSize() << " byte(s)]" << std::endl; - printStructure(part.getStructure(), level + 1); + printStructure(part->getStructure(), level + 1); } } diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp index 3dd6c021..05c37bf7 100644 --- a/src/net/imap/IMAPMessage.cpp +++ b/src/net/imap/IMAPMessage.cpp @@ -50,8 +50,8 @@ private: public: - const structure& getStructure() const; - structure& getStructure(); + ref getStructure() const; + ref getStructure(); weak_ref getParent() const { return (m_parent); } @@ -59,12 +59,12 @@ public: const int getSize() const { return (m_size); } const int getNumber() const { return (m_number); } - const header& getHeader() const + ref getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); else - return (*m_header); + return m_header; } @@ -112,22 +112,20 @@ private: class IMAPstructure : public structure { -private: +public: IMAPstructure() { } -public: - IMAPstructure(const IMAPParser::body* body) { - m_parts.push_back(IMAPpart::create(NULL, 1, body)); + m_parts.push_back(IMAPpart::create(NULL, 0, body)); } IMAPstructure(ref parent, const std::vector & list) { - int number = 1; + int number = 0; for (std::vector ::const_iterator it = list.begin() ; it != list.end() ; ++it, ++number) @@ -137,36 +135,36 @@ public: } - const part& operator[](const int x) const + ref getPartAt(const int x) const { - return (*m_parts[x - 1]); + return m_parts[x]; } - part& operator[](const int x) + ref getPartAt(const int x) { - return (*m_parts[x - 1]); + return m_parts[x]; } - const int getCount() const + const int getPartCount() const { - return (m_parts.size()); + return m_parts.size(); } - static IMAPstructure* emptyStructure() + static ref emptyStructure() { - return (&m_emptyStructure); + return (m_emptyStructure); } private: - static IMAPstructure m_emptyStructure; + static ref m_emptyStructure; std::vector > m_parts; }; -IMAPstructure IMAPstructure::m_emptyStructure; +ref IMAPstructure::m_emptyStructure = vmime::create (); @@ -208,21 +206,21 @@ IMAPpart::IMAPpart(ref parent, const int number, const IMAPParser::bo } -const class structure& IMAPpart::getStructure() const +ref IMAPpart::getStructure() const { if (m_structure != NULL) - return (*m_structure); + return (m_structure); else - return (*IMAPstructure::emptyStructure()); + return (IMAPstructure::emptyStructure()); } -class structure& IMAPpart::getStructure() +ref IMAPpart::getStructure() { if (m_structure != NULL) - return (*m_structure); + return (m_structure); else - return (*IMAPstructure::emptyStructure()); + return (IMAPstructure::emptyStructure()); } @@ -331,21 +329,21 @@ const int IMAPMessage::getFlags() const } -const structure& IMAPMessage::getStructure() const +ref IMAPMessage::getStructure() const { if (m_structure == NULL) throw exceptions::unfetched_object(); - return (*m_structure); + return m_structure; } -structure& IMAPMessage::getStructure() +ref IMAPMessage::getStructure() { if (m_structure == NULL) throw exceptions::unfetched_object(); - return (*m_structure); + return m_structure; } @@ -369,17 +367,17 @@ void IMAPMessage::extract(utility::outputStream& os, utility::progressionListene void IMAPMessage::extractPart - (const part& p, utility::outputStream& os, utility::progressionListener* progress, + (ref p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool peek) const { if (!m_folder) throw exceptions::folder_not_found(); - extract(&p, os, progress, start, length, false, peek); + extract(p, os, progress, start, length, false, peek); } -void IMAPMessage::fetchPartHeader(part& p) +void IMAPMessage::fetchPartHeader(ref p) { if (!m_folder) throw exceptions::folder_not_found(); @@ -387,13 +385,13 @@ void IMAPMessage::fetchPartHeader(part& p) std::ostringstream oss; utility::outputStreamAdapter ossAdapter(oss); - extract(&p, ossAdapter, NULL, 0, -1, true, true); + extract(p, ossAdapter, NULL, 0, -1, true, true); - static_cast (p).getOrCreateHeader().parse(oss.str()); + p.dynamicCast ()->getOrCreateHeader().parse(oss.str()); } -void IMAPMessage::extract(const part* p, utility::outputStream& os, +void IMAPMessage::extract(ref p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const { @@ -404,7 +402,7 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os, if (p != NULL) { - weak_ref currentPart = static_cast (p); + weak_ref currentPart = p.dynamicCast (); std::vector numbers; numbers.push_back(currentPart->getNumber()); @@ -421,7 +419,7 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os, for (std::vector ::reverse_iterator it = numbers.rbegin() ; it != numbers.rend() ; ++it) { if (it != numbers.rbegin()) section << "."; - section << *it; + section << (*it + 1); } } diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp index 358b6046..1d596fbd 100644 --- a/src/net/maildir/maildirMessage.cpp +++ b/src/net/maildir/maildirMessage.cpp @@ -47,8 +47,8 @@ public: ~maildirPart(); - const structure& getStructure() const; - structure& getStructure(); + ref getStructure() const; + ref getStructure(); weak_ref getParent() const { return (m_parent); } @@ -56,12 +56,12 @@ public: const int getSize() const { return (m_size); } const int getNumber() const { return (m_number); } - const header& getHeader() const + ref getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); else - return (*m_header); + return m_header; } header& getOrCreateHeader() @@ -103,58 +103,56 @@ private: class maildirStructure : public structure { -private: +public: maildirStructure() { } -public: - maildirStructure(weak_ref parent, const bodyPart& part) { - m_parts.push_back(vmime::create (parent, 1, part)); + m_parts.push_back(vmime::create (parent, 0, part)); } maildirStructure(weak_ref parent, const std::vector >& list) { - int number = 1; + int number = 0; for (unsigned int i = 0 ; i < list.size() ; ++i) m_parts.push_back(vmime::create (parent, number, *list[i])); } - const part& operator[](const int x) const + ref getPartAt(const int x) const { - return (*m_parts[x - 1]); + return m_parts[x]; } - part& operator[](const int x) + ref getPartAt(const int x) { - return (*m_parts[x - 1]); + return m_parts[x]; } - const int getCount() const + const int getPartCount() const { - return (m_parts.size()); + return m_parts.size(); } - static maildirStructure* emptyStructure() + static ref emptyStructure() { - return (&m_emptyStructure); + return m_emptyStructure; } private: - static maildirStructure m_emptyStructure; + static ref m_emptyStructure; std::vector > m_parts; }; -maildirStructure maildirStructure::m_emptyStructure; +ref maildirStructure::m_emptyStructure = vmime::create (); @@ -187,21 +185,21 @@ maildirPart::~maildirPart() } -const structure& maildirPart::getStructure() const +ref maildirPart::getStructure() const { if (m_structure != NULL) - return (*m_structure); + return m_structure; else - return (*maildirStructure::emptyStructure()); + return maildirStructure::emptyStructure(); } -structure& maildirPart::getStructure() +ref maildirPart::getStructure() { if (m_structure != NULL) - return (*m_structure); + return m_structure; else - return (*maildirStructure::emptyStructure()); + return maildirStructure::emptyStructure(); } @@ -258,21 +256,21 @@ const bool maildirMessage::isExpunged() const } -const structure& maildirMessage::getStructure() const +ref maildirMessage::getStructure() const { if (m_structure == NULL) throw exceptions::unfetched_object(); - return (*m_structure); + return m_structure; } -structure& maildirMessage::getStructure() +ref maildirMessage::getStructure() { if (m_structure == NULL) throw exceptions::unfetched_object(); - return (*m_structure); + return m_structure; } @@ -311,7 +309,7 @@ void maildirMessage::extract(utility::outputStream& os, } -void maildirMessage::extractPart(const part& p, utility::outputStream& os, +void maildirMessage::extractPart(ref p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool peek) const { @@ -367,9 +365,9 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progression } -void maildirMessage::fetchPartHeader(part& p) +void maildirMessage::fetchPartHeader(ref p) { - maildirPart& mp = dynamic_cast (p); + ref mp = p.dynamicCast (); utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory(); @@ -379,10 +377,10 @@ void maildirMessage::fetchPartHeader(part& p) ref reader = file->getFileReader(); ref is = reader->getInputStream(); - is->skip(mp.getHeaderParsedOffset()); + is->skip(mp->getHeaderParsedOffset()); utility::stream::value_type buffer[1024]; - utility::stream::size_type remaining = mp.getHeaderParsedLength(); + utility::stream::size_type remaining = mp->getHeaderParsedLength(); string contents; contents.reserve(remaining); @@ -397,7 +395,7 @@ void maildirMessage::fetchPartHeader(part& p) contents.append(buffer, read); } - mp.getOrCreateHeader().parse(contents); + mp->getOrCreateHeader().parse(contents); } diff --git a/src/net/message.cpp b/src/net/message.cpp index 0c55d1da..98ba4228 100644 --- a/src/net/message.cpp +++ b/src/net/message.cpp @@ -24,21 +24,21 @@ namespace vmime { namespace net { -const part& part::operator[](const int x) const +ref part::getPartAt(const int pos) const { - return (getStructure()[x]); + return getStructure()->getPartAt(pos); } -part& part::operator[](const int x) +ref part::getPartAt(const int pos) { - return (getStructure()[x]); + return getStructure()->getPartAt(pos); } -const int part::getCount() const +const int part::getPartCount() const { - return (getStructure().getCount()); + return getStructure()->getPartCount(); } diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp index b2e2fae4..d9e452be 100644 --- a/src/net/pop3/POP3Message.cpp +++ b/src/net/pop3/POP3Message.cpp @@ -87,13 +87,13 @@ const int POP3Message::getFlags() const } -const structure& POP3Message::getStructure() const +ref POP3Message::getStructure() const { throw exceptions::operation_not_supported(); } -structure& POP3Message::getStructure() +ref POP3Message::getStructure() { throw exceptions::operation_not_supported(); } @@ -145,7 +145,7 @@ void POP3Message::extract(utility::outputStream& os, void POP3Message::extractPart - (const part& /* p */, utility::outputStream& /* os */, + (ref /* p */, utility::outputStream& /* os */, utility::progressionListener* /* progress */, const int /* start */, const int /* length */, const bool /* peek */) const @@ -154,7 +154,7 @@ void POP3Message::extractPart } -void POP3Message::fetchPartHeader(part& /* p */) +void POP3Message::fetchPartHeader(ref /* p */) { throw exceptions::operation_not_supported(); } diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp index bac54219..5de9b671 100644 --- a/vmime/net/imap/IMAPMessage.hpp +++ b/vmime/net/imap/IMAPMessage.hpp @@ -60,8 +60,8 @@ public: const bool isExpunged() const; - const structure& getStructure() const; - structure& getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -69,9 +69,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(part& p); + void fetchPartHeader(ref p); private: @@ -79,7 +79,7 @@ private: void processFetchResponse(const int options, const IMAPParser::msg_att* msgAtt); - void extract(const part* p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const; + void extract(ref p, utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const; void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest); diff --git a/vmime/net/maildir/maildirMessage.hpp b/vmime/net/maildir/maildirMessage.hpp index 82aa9976..1810fbc0 100644 --- a/vmime/net/maildir/maildirMessage.hpp +++ b/vmime/net/maildir/maildirMessage.hpp @@ -58,8 +58,8 @@ public: const bool isExpunged() const; - const structure& getStructure() const; - structure& getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -67,9 +67,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(part& p); + void fetchPartHeader(ref p); private: diff --git a/vmime/net/message.hpp b/vmime/net/message.hpp index 640f945c..1e4a22b4 100644 --- a/vmime/net/message.hpp +++ b/vmime/net/message.hpp @@ -52,20 +52,20 @@ public: * * @return structure of the part */ - virtual const structure& getStructure() const = 0; + virtual ref getStructure() const = 0; /** Return the structure of this part. * * @return structure of the part */ - virtual structure& getStructure() = 0; + virtual ref getStructure() = 0; /** Return the header section for this part (you must fetch header * before using this function: see message::fetchPartHeader). * * @return header section */ - virtual const header& getHeader() const = 0; + virtual ref getHeader() const = 0; /** Return the media-type of the content in this part. * @@ -79,35 +79,34 @@ public: */ virtual const int getSize() const = 0; - /** Return the part sequence number (index) + /** Return the part sequence number (index). + * The first part is at index zero. * * @return part number */ - virtual const int getNumber() const = 0; // begin at 1 + virtual const int getNumber() const = 0; - /** Return the sub-part at the specified position. - * This provide easy access to parts: - * Eg: "message->extractPart(message->getStructure()[3][1][2])". + /** Return the sub-part at the specified position (zero is the + * first part). * - * @param x index of the sub-part - * @return sub-part at position 'x' + * @param pos index of the sub-part + * @return sub-part at position 'pos' */ - const part& operator[](const int x) const; + ref getPartAt(const int pos) const; - /** Return the sub-part at the specified position. - * This provide easy access to parts: - * Eg: "message->extractPart(message->getStructure()[3][1][2])". + /** Return the sub-part at the specified position (zero is the + * first part). * - * @param x index of the sub-part - * @return sub-part at position 'x' + * @param pos index of the sub-part + * @return sub-part at position 'pos' */ - part& operator[](const int x); + ref getPartAt(const int pos); /** Return the number of sub-parts in this part. * * @return number of sub-parts */ - const int getCount() const; + const int getPartCount() const; }; @@ -126,26 +125,26 @@ public: virtual ~structure() { } /** Return the part at the specified position (first - * part is at position 1). + * part is at position 0). * - * @param x position - * @return part at position 'x' + * @param pos position + * @return part at position 'pos' */ - virtual const part& operator[](const int x) const = 0; + virtual ref getPartAt(const int pos) const = 0; /** Return the part at the specified position (first - * part is at position 1). + * part is at position 0). * - * @param x position - * @return part at position 'x' + * @param pos position + * @return part at position 'pos' */ - virtual part& operator[](const int x) = 0; + virtual ref getPartAt(const int pos) = 0; /** Return the number of parts in this part. * * @return number of parts */ - virtual const int getCount() const = 0; + virtual const int getPartCount() const = 0; }; @@ -171,13 +170,13 @@ public: * * @return MIME structure of the message */ - virtual const structure& getStructure() const = 0; + virtual ref getStructure() const = 0; /** Return the MIME structure of the message (must fetch before). * * @return MIME structure of the message */ - virtual structure& getStructure() = 0; + virtual ref getStructure() = 0; /** Return a reference to the header fields of the message (must fetch before). * @@ -275,13 +274,13 @@ public: * be supported by the protocol (IMAP supports this), but it will NOT throw * an exception if not supported. */ - virtual void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0; + virtual void extractPart(ref p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0; /** Fetch the MIME header for the specified part. * * @param p the part for which to fetch the header */ - virtual void fetchPartHeader(part& p) = 0; + virtual void fetchPartHeader(ref p) = 0; }; diff --git a/vmime/net/pop3/POP3Message.hpp b/vmime/net/pop3/POP3Message.hpp index f4c48bb6..922eb057 100644 --- a/vmime/net/pop3/POP3Message.hpp +++ b/vmime/net/pop3/POP3Message.hpp @@ -60,8 +60,8 @@ public: const bool isExpunged() const; - const structure& getStructure() const; - structure& getStructure(); + ref getStructure() const; + ref getStructure(); ref getHeader() const; @@ -69,9 +69,9 @@ public: void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(const part& p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extractPart(ref p, utility::outputStream& os, utility::progressionListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void fetchPartHeader(part& p); + void fetchPartHeader(ref p); private: