aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2006-04-05 17:48:09 +0000
committerVincent Richard <[email protected]>2006-04-05 17:48:09 +0000
commitb16c5ca684382677ae298eed6253c75d2eaf9806 (patch)
tree50f33a0641261ac7e925640ceb142ba0ebc6df44
parentRefactored and cleaned up smart pointers. (diff)
downloadvmime-b16c5ca684382677ae298eed6253c75d2eaf9806.tar.gz
vmime-b16c5ca684382677ae298eed6253c75d2eaf9806.zip
Clean up.
-rw-r--r--SConstruct3
-rw-r--r--src/addressList.cpp31
-rw-r--r--src/net/imap/IMAPMessage.cpp31
-rw-r--r--src/net/imap/IMAPUtils.cpp20
-rw-r--r--src/net/pop3/POP3Folder.cpp42
-rw-r--r--src/net/pop3/POP3Utils.cpp70
-rw-r--r--vmime/addressList.hpp8
-rw-r--r--vmime/base.hpp4
-rw-r--r--vmime/net/imap/IMAPMessage.hpp5
-rw-r--r--vmime/net/imap/IMAPUtils.hpp9
-rw-r--r--vmime/net/pop3/POP3Folder.hpp2
-rw-r--r--vmime/net/pop3/POP3Utils.hpp67
12 files changed, 219 insertions, 73 deletions
diff --git a/SConstruct b/SConstruct
index fa618044..07fc4cc1 100644
--- a/SConstruct
+++ b/SConstruct
@@ -234,7 +234,8 @@ libvmime_messaging_proto_sources = [
'net/pop3/POP3Store.cpp', 'net/pop3/POP3Store.hpp',
'net/pop3/POP3SStore.cpp', 'net/pop3/POP3SStore.hpp',
'net/pop3/POP3Folder.cpp', 'net/pop3/POP3Folder.hpp',
- 'net/pop3/POP3Message.cpp', 'net/pop3/POP3Message.hpp'
+ 'net/pop3/POP3Message.cpp', 'net/pop3/POP3Message.hpp',
+ 'net/pop3/POP3Utils.cpp', 'net/pop3/POP3Utils.hpp'
]
],
[
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
+
diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp
index c1a2febf..9a2a37ba 100644
--- a/vmime/addressList.hpp
+++ b/vmime/addressList.hpp
@@ -151,6 +151,14 @@ public:
*/
const std::vector <ref <address> > getAddressList();
+ /** Return a list of mailboxes.
+ * If some addresses are actually groups, mailboxes are recursively
+ * extracted from these groups.
+ *
+ * @return list of mailboxes
+ */
+ ref <mailboxList> toMailboxList() const;
+
private:
std::vector <ref <address> > m_list;
diff --git a/vmime/base.hpp b/vmime/base.hpp
index 75ba7ebc..12c2474b 100644
--- a/vmime/base.hpp
+++ b/vmime/base.hpp
@@ -232,7 +232,7 @@ namespace vmime
* Use "vmime::clone(obj)" instead of "obj->clone().cast <objtype>()".
*/
template <class T>
- ref <T> clone(ref <T> x)
+ ref <T> clone(ref <const T> x)
{
return x->clone().template dynamicCast <T>();
}
@@ -241,7 +241,7 @@ namespace vmime
* Use "vmime::clone(obj)" instead of "obj.clone().cast <objtype>()".
*/
template <class T>
- ref <T> clone(T& x)
+ ref <T> clone(const T& x)
{
return x.clone().template dynamicCast <T>();
}
diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp
index 7e8c6b07..2d112cf8 100644
--- a/vmime/net/imap/IMAPMessage.hpp
+++ b/vmime/net/imap/IMAPMessage.hpp
@@ -28,8 +28,6 @@
#include "vmime/net/message.hpp"
#include "vmime/net/folder.hpp"
-#include "vmime/mailboxList.hpp"
-
namespace vmime {
namespace net {
@@ -86,9 +84,6 @@ private:
void extract(ref <const part> p, utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const bool headerOnly, const bool peek) const;
- void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest);
-
-
ref <header> getOrCreateHeader();
diff --git a/vmime/net/imap/IMAPUtils.hpp b/vmime/net/imap/IMAPUtils.hpp
index 0dd5ad78..dc2f7c11 100644
--- a/vmime/net/imap/IMAPUtils.hpp
+++ b/vmime/net/imap/IMAPUtils.hpp
@@ -31,6 +31,8 @@
#include "vmime/net/folder.hpp"
#include "vmime/net/imap/IMAPParser.hpp"
+#include "vmime/mailboxList.hpp"
+
#include <vector>
@@ -93,6 +95,13 @@ public:
* @return fetch request
*/
static const string buildFetchRequest(const std::vector <int>& list, const int options);
+
+ /** Convert a parser-style address list to a mailbox list.
+ *
+ * @param src input address list
+ * @param dest output mailbox list
+ */
+ static void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest);
};
diff --git a/vmime/net/pop3/POP3Folder.hpp b/vmime/net/pop3/POP3Folder.hpp
index db4854f2..28a63c93 100644
--- a/vmime/net/pop3/POP3Folder.hpp
+++ b/vmime/net/pop3/POP3Folder.hpp
@@ -126,8 +126,6 @@ private:
void onClose();
- void parseMultiListOrUidlResponse(const string& response, std::map <int, string>& result);
-
weak_ref <POP3Store> m_store;
diff --git a/vmime/net/pop3/POP3Utils.hpp b/vmime/net/pop3/POP3Utils.hpp
new file mode 100644
index 00000000..a760fa74
--- /dev/null
+++ b/vmime/net/pop3/POP3Utils.hpp
@@ -0,0 +1,67 @@
+//
+// 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
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#ifndef VMIME_NET_POP3_POP3UTILS_HPP_INCLUDED
+#define VMIME_NET_POP3_POP3UTILS_HPP_INCLUDED
+
+
+#include <map>
+
+#include "vmime/config.hpp"
+#include "vmime/types.hpp"
+
+
+namespace vmime {
+namespace net {
+namespace pop3 {
+
+
+class POP3Utils
+{
+public:
+
+ /** Parse a response of type ([integer] [string] \n)*.
+ * This is used in LIST or UIDL commands:
+ *
+ * C: UIDL
+ * S: +OK
+ * S: 1 whqtswO00WBw418f9t5JxYwZ
+ * S: 2 QhdPYR:00WBw1Ph7x7
+ * S: .
+ *
+ * @param response raw response string as returned by the server
+ * @return an associative array which map a message number to its
+ * data (either UID or size)
+ */
+ static void parseMultiListOrUidlResponse
+ (const string& response, std::map <int, string>& result);
+};
+
+
+} // pop3
+} // net
+} // vmime
+
+
+#endif // VMIME_NET_POP3_POP3UTILS_HPP_INCLUDED
+