Clean up.
This commit is contained in:
parent
e9501b48d8
commit
b16c5ca684
@ -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'
|
||||
]
|
||||
],
|
||||
[
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
70
src/net/pop3/POP3Utils.cpp
Normal file
70
src/net/pop3/POP3Utils.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2006 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// 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
|
||||
|
@ -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;
|
||||
|
@ -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>();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
@ -126,8 +126,6 @@ private:
|
||||
|
||||
void onClose();
|
||||
|
||||
void parseMultiListOrUidlResponse(const string& response, std::map <int, string>& result);
|
||||
|
||||
|
||||
weak_ref <POP3Store> m_store;
|
||||
|
||||
|
67
vmime/net/pop3/POP3Utils.hpp
Normal file
67
vmime/net/pop3/POP3Utils.hpp
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2002-2006 Vincent Richard <vincent@vincent-richard.net>
|
||||
//
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user