diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/addressList.cpp | 31 | ||||
| -rw-r--r-- | src/net/imap/IMAPMessage.cpp | 31 | ||||
| -rw-r--r-- | src/net/imap/IMAPUtils.cpp | 20 | ||||
| -rw-r--r-- | src/net/pop3/POP3Folder.cpp | 42 | ||||
| -rw-r--r-- | src/net/pop3/POP3Utils.cpp | 70 |
5 files changed, 131 insertions, 63 deletions
diff --git a/src/addressList.cpp b/src/addressList.cpp index 9b779d0e..dfc67a8f 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -25,6 +25,7 @@ #include "vmime/parserHelpers.hpp" #include "vmime/exception.hpp" #include "vmime/mailboxList.hpp" +#include "vmime/mailboxGroup.hpp" namespace vmime @@ -257,4 +258,34 @@ const std::vector <ref <const component> > addressList::getChildComponents() con } +ref <mailboxList> addressList::toMailboxList() const +{ + ref <mailboxList> res = vmime::create <mailboxList>(); + + for (std::vector <ref <address> >::const_iterator it = m_list.begin() ; + it != m_list.end() ; ++it) + { + ref <const address> addr = *it; + + if (addr->isGroup()) + { + const std::vector <ref <const mailbox> > mailboxes = + addr.dynamicCast <const mailboxGroup>()->getMailboxList(); + + for (std::vector <ref <const mailbox> >::const_iterator jt = mailboxes.begin() ; + jt != mailboxes.end() ; ++jt) + { + res->appendMailbox(vmime::clone(*jt)); + } + } + else + { + res->appendMailbox(addr->clone().dynamicCast <mailbox>()); + } + } + + return res; +} + + } // vmime diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp index e796afaf..47e77de4 100644 --- a/src/net/imap/IMAPMessage.cpp +++ b/src/net/imap/IMAPMessage.cpp @@ -568,41 +568,41 @@ void IMAPMessage::processFetchResponse // From mailboxList from; - convertAddressList(*(env->env_from()), from); + IMAPUtils::convertAddressList(*(env->env_from()), from); if (!from.isEmpty()) hdr->From()->setValue(*(from.getMailboxAt(0))); // To mailboxList to; - convertAddressList(*(env->env_to()), to); + IMAPUtils::convertAddressList(*(env->env_to()), to); hdr->To()->setValue(to); // Sender mailboxList sender; - convertAddressList(*(env->env_sender()), sender); + IMAPUtils::convertAddressList(*(env->env_sender()), sender); if (!sender.isEmpty()) hdr->Sender()->setValue(*(sender.getMailboxAt(0))); // Reply-to mailboxList replyTo; - convertAddressList(*(env->env_reply_to()), replyTo); + IMAPUtils::convertAddressList(*(env->env_reply_to()), replyTo); if (!replyTo.isEmpty()) hdr->ReplyTo()->setValue(*(replyTo.getMailboxAt(0))); // Cc mailboxList cc; - convertAddressList(*(env->env_cc()), cc); + IMAPUtils::convertAddressList(*(env->env_cc()), cc); if (!cc.isEmpty()) hdr->Cc()->setValue(cc); // Bcc mailboxList bcc; - convertAddressList(*(env->env_bcc()), bcc); + IMAPUtils::convertAddressList(*(env->env_bcc()), bcc); if (!bcc.isEmpty()) hdr->Bcc()->setValue(bcc); @@ -674,25 +674,6 @@ ref <header> IMAPMessage::getOrCreateHeader() } -void IMAPMessage::convertAddressList - (const IMAPParser::address_list& src, mailboxList& dest) -{ - for (std::vector <IMAPParser::address*>::const_iterator - it = src.addresses().begin() ; it != src.addresses().end() ; ++it) - { - const IMAPParser::address& addr = **it; - - text name; - text::decodeAndUnfold(addr.addr_name()->value(), &name); - - string email = addr.addr_mailbox()->value() - + "@" + addr.addr_host()->value(); - - dest.appendMailbox(vmime::create <mailbox>(name, email)); - } -} - - void IMAPMessage::setFlags(const int flags, const int mode) { ref <IMAPFolder> folder = m_folder.acquire(); diff --git a/src/net/imap/IMAPUtils.cpp b/src/net/imap/IMAPUtils.cpp index cd611163..6e3c869c 100644 --- a/src/net/imap/IMAPUtils.cpp +++ b/src/net/imap/IMAPUtils.cpp @@ -623,6 +623,26 @@ const string IMAPUtils::buildFetchRequest(const std::vector <int>& list, const i } +// static +void IMAPUtils::convertAddressList + (const IMAPParser::address_list& src, mailboxList& dest) +{ + for (std::vector <IMAPParser::address*>::const_iterator + it = src.addresses().begin() ; it != src.addresses().end() ; ++it) + { + const IMAPParser::address& addr = **it; + + text name; + text::decodeAndUnfold(addr.addr_name()->value(), &name); + + string email = addr.addr_mailbox()->value() + + "@" + addr.addr_host()->value(); + + dest.appendMailbox(vmime::create <mailbox>(name, email)); + } +} + + } // imap } // net } // vmime diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp index acffff7d..657e1bdd 100644 --- a/src/net/pop3/POP3Folder.cpp +++ b/src/net/pop3/POP3Folder.cpp @@ -22,6 +22,8 @@ #include "vmime/net/pop3/POP3Store.hpp" #include "vmime/net/pop3/POP3Message.hpp" +#include "vmime/net/pop3/POP3Utils.hpp" + #include "vmime/exception.hpp" @@ -354,7 +356,7 @@ void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int opti // S: 2 12653 // S: . std::map <int, string> result; - parseMultiListOrUidlResponse(response, result); + POP3Utils::parseMultiListOrUidlResponse(response, result); for (std::vector <ref <message> >::iterator it = msg.begin() ; it != msg.end() ; ++it) @@ -399,7 +401,7 @@ void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int opti // S: 2 QhdPYR:00WBw1Ph7x7 // S: . std::map <int, string> result; - parseMultiListOrUidlResponse(response, result); + POP3Utils::parseMultiListOrUidlResponse(response, result); for (std::vector <ref <message> >::iterator it = msg.begin() ; it != msg.end() ; ++it) @@ -821,42 +823,6 @@ void POP3Folder::expunge() } -void POP3Folder::parseMultiListOrUidlResponse(const string& response, std::map <int, string>& result) -{ - std::istringstream iss(response); - std::map <int, string> ids; - - string line; - - while (std::getline(iss, line)) - { - string::iterator it = line.begin(); - - while (it != line.end() && (*it == ' ' || *it == '\t')) - ++it; - - if (it != line.end()) - { - int number = 0; - - while (it != line.end() && (*it >= '0' && *it <= '9')) - { - number = (number * 10) + (*it - '0'); - ++it; - } - - while (it != line.end() && !(*it == ' ' || *it == '\t')) ++it; - while (it != line.end() && (*it == ' ' || *it == '\t')) ++it; - - if (it != line.end()) - { - result.insert(std::map <int, string>::value_type(number, string(it, line.end()))); - } - } - } -} - - } // pop3 } // net } // vmime diff --git a/src/net/pop3/POP3Utils.cpp b/src/net/pop3/POP3Utils.cpp new file mode 100644 index 00000000..a2f1857c --- /dev/null +++ b/src/net/pop3/POP3Utils.cpp @@ -0,0 +1,70 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2006 Vincent Richard <[email protected]> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along along +// with this program; if not, write to the Free Software Foundation, Inc., Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.. +// + +#include "vmime/net/pop3/POP3Utils.hpp" + +#include <sstream> + + +namespace vmime { +namespace net { +namespace pop3 { + + +// static +void POP3Utils::parseMultiListOrUidlResponse(const string& response, std::map <int, string>& result) +{ + std::istringstream iss(response); + std::map <int, string> ids; + + string line; + + while (std::getline(iss, line)) + { + string::iterator it = line.begin(); + + while (it != line.end() && (*it == ' ' || *it == '\t')) + ++it; + + if (it != line.end()) + { + int number = 0; + + while (it != line.end() && (*it >= '0' && *it <= '9')) + { + number = (number * 10) + (*it - '0'); + ++it; + } + + while (it != line.end() && !(*it == ' ' || *it == '\t')) ++it; + while (it != line.end() && (*it == ' ' || *it == '\t')) ++it; + + if (it != line.end()) + { + result.insert(std::map <int, string>::value_type(number, string(it, line.end()))); + } + } + } +} + + +} // pop3 +} // net +} // vmime + |
