⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop3folder.cpp

📁 MIME解析的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}	}	if (progress)		progress->stop(total);}void POP3Folder::fetchMessage(ref <message> msg, const int options){	ref <POP3Store> store = m_store.acquire();	if (!store)		throw exceptions::illegal_state("Store disconnected");	else if (!isOpen())		throw exceptions::illegal_state("Folder not open");	msg.dynamicCast <POP3Message>()->fetch		(thisRef().dynamicCast <POP3Folder>(), options);	if (options & FETCH_SIZE)	{		// Send the "LIST" command		std::ostringstream command;		command.imbue(std::locale::classic());		command << "LIST " << msg->getNumber();		store->sendRequest(command.str());		// Get the response		string response;		store->readResponse(response, false, NULL);		if (store->isSuccessResponse(response))		{			store->stripResponseCode(response, response);			// C: LIST 2			// S: +OK 2 4242			string::iterator it = response.begin();			while (it != response.end() && (*it == ' ' || *it == '\t')) ++it;			while (it != response.end() && !(*it == ' ' || *it == '\t')) ++it;			while (it != response.end() && (*it == ' ' || *it == '\t')) ++it;			if (it != response.end())			{				int size = 0;				std::istringstream iss(string(it, response.end()));				iss >> size;				msg.dynamicCast <POP3Message>()->m_size = size;			}		}	}	if (options & FETCH_UID)	{		// Send the "UIDL" command		std::ostringstream command;		command.imbue(std::locale::classic());		command << "UIDL " << msg->getNumber();		store->sendRequest(command.str());		// Get the response		string response;		store->readResponse(response, false, NULL);		if (store->isSuccessResponse(response))		{			store->stripResponseCode(response, response);			// C: UIDL 2			// S: +OK 2 QhdPYR:00WBw1Ph7x7			string::iterator it = response.begin();			while (it != response.end() && (*it == ' ' || *it == '\t')) ++it;			while (it != response.end() && !(*it == ' ' || *it == '\t')) ++it;			while (it != response.end() && (*it == ' ' || *it == '\t')) ++it;			if (it != response.end())			{				msg.dynamicCast <POP3Message>()->m_uid =					string(it, response.end());			}		}	}}int POP3Folder::getFetchCapabilities() const{	return (FETCH_ENVELOPE | FETCH_CONTENT_INFO |	        FETCH_SIZE | FETCH_FULL_HEADER | FETCH_UID |	        FETCH_IMPORTANCE);}ref <folder> POP3Folder::getParent(){	if (m_path.isEmpty())		return NULL;	else		return vmime::create <POP3Folder>(m_path.getParent(), m_store.acquire());}ref <const store> POP3Folder::getStore() const{	return m_store.acquire();}ref <store> POP3Folder::getStore(){	return m_store.acquire();}void POP3Folder::registerMessage(POP3Message* msg){	m_messages.insert(MessageMap::value_type(msg, msg->getNumber()));}void POP3Folder::unregisterMessage(POP3Message* msg){	m_messages.erase(msg);}void POP3Folder::onStoreDisconnected(){	m_store = NULL;}void POP3Folder::deleteMessage(const int num){	ref <POP3Store> store = m_store.acquire();	if (!store)		throw exceptions::illegal_state("Store disconnected");	else if (!isOpen())		throw exceptions::illegal_state("Folder not open");	std::ostringstream command;	command.imbue(std::locale::classic());	command << "DELE " << num;	store->sendRequest(command.str());	string response;	store->readResponse(response, false);	if (!store->isSuccessResponse(response))		throw exceptions::command_error("DELE", response);	// Update local flags	for (std::map <POP3Message*, int>::iterator it =	     m_messages.begin() ; it != m_messages.end() ; ++it)	{		POP3Message* msg = (*it).first;		if (msg->getNumber() == num)			msg->m_deleted = true;	}	// Notify message flags changed	std::vector <int> nums;	nums.push_back(num);	events::messageChangedEvent event		(thisRef().dynamicCast <folder>(),		 events::messageChangedEvent::TYPE_FLAGS, nums);	notifyMessageChanged(event);}void POP3Folder::deleteMessages(const int from, const int to){	ref <POP3Store> store = m_store.acquire();	if (from < 1 || (to < from && to != -1))		throw exceptions::invalid_argument();	if (!store)		throw exceptions::illegal_state("Store disconnected");	else if (!isOpen())		throw exceptions::illegal_state("Folder not open");	const int to2 = (to == -1 ? m_messageCount : to);	for (int i = from ; i <= to2 ; ++i)	{		std::ostringstream command;		command.imbue(std::locale::classic());		command << "DELE " << i;		store->sendRequest(command.str());		string response;		store->readResponse(response, false);		if (!store->isSuccessResponse(response))			throw exceptions::command_error("DELE", response);	}	// Update local flags	for (std::map <POP3Message*, int>::iterator it =	     m_messages.begin() ; it != m_messages.end() ; ++it)	{		POP3Message* msg = (*it).first;		if (msg->getNumber() >= from && msg->getNumber() <= to2)			msg->m_deleted = true;	}	// Notify message flags changed	std::vector <int> nums;	for (int i = from ; i <= to2 ; ++i)		nums.push_back(i);	events::messageChangedEvent event		(thisRef().dynamicCast <folder>(),		 events::messageChangedEvent::TYPE_FLAGS, nums);	notifyMessageChanged(event);}void POP3Folder::deleteMessages(const std::vector <int>& nums){	ref <POP3Store> store = m_store.acquire();	if (nums.empty())		throw exceptions::invalid_argument();	if (!store)		throw exceptions::illegal_state("Store disconnected");	else if (!isOpen())		throw exceptions::illegal_state("Folder not open");	for (std::vector <int>::const_iterator	     it = nums.begin() ; it != nums.end() ; ++it)	{		std::ostringstream command;		command.imbue(std::locale::classic());		command << "DELE " << (*it);		store->sendRequest(command.str());		string response;		store->readResponse(response, false);		if (!store->isSuccessResponse(response))			throw exceptions::command_error("DELE", response);	}	// Sort message list	std::vector <int> list;	list.resize(nums.size());	std::copy(nums.begin(), nums.end(), list.begin());	std::sort(list.begin(), list.end());	// Update local flags	for (std::map <POP3Message*, int>::iterator it =	     m_messages.begin() ; it != m_messages.end() ; ++it)	{		POP3Message* msg = (*it).first;		if (std::binary_search(list.begin(), list.end(), msg->getNumber()))			msg->m_deleted = true;	}	// Notify message flags changed	events::messageChangedEvent event		(thisRef().dynamicCast <folder>(),		 events::messageChangedEvent::TYPE_FLAGS, list);	notifyMessageChanged(event);}void POP3Folder::setMessageFlags(const int /* from */, const int /* to */,	const int /* flags */, const int /* mode */){	throw exceptions::operation_not_supported();}void POP3Folder::setMessageFlags(const std::vector <int>& /* nums */,	const int /* flags */, const int /* mode */){	throw exceptions::operation_not_supported();}void POP3Folder::rename(const folder::path& /* newPath */){	throw exceptions::operation_not_supported();}void POP3Folder::addMessage(ref <vmime::message> /* msg */, const int /* flags */,	vmime::datetime* /* date */, utility::progressListener* /* progress */){	throw exceptions::operation_not_supported();}void POP3Folder::addMessage(utility::inputStream& /* is */, const int /* size */, const int /* flags */,	vmime::datetime* /* date */, utility::progressListener* /* progress */){	throw exceptions::operation_not_supported();}void POP3Folder::copyMessage(const folder::path& /* dest */, const int /* num */){	throw exceptions::operation_not_supported();}void POP3Folder::copyMessages(const folder::path& /* dest */, const int /* from */, const int /* to */){	throw exceptions::operation_not_supported();}void POP3Folder::copyMessages(const folder::path& /* dest */, const std::vector <int>& /* nums */){	throw exceptions::operation_not_supported();}void POP3Folder::status(int& count, int& unseen){	ref <POP3Store> store = m_store.acquire();	if (!store)		throw exceptions::illegal_state("Store disconnected");	else if (!isOpen())		throw exceptions::illegal_state("Folder not open");	store->sendRequest("STAT");	string response;	store->readResponse(response, false);	if (!store->isSuccessResponse(response))		throw exceptions::command_error("STAT", response);	store->stripResponseCode(response, response);	std::istringstream iss(response);	iss >> count;	unseen = count;	// Update local message count	if (m_messageCount != count)	{		const int oldCount = m_messageCount;		m_messageCount = count;		if (count > oldCount)		{			std::vector <int> nums;			nums.reserve(count - oldCount);			for (int i = oldCount + 1, j = 0 ; i <= count ; ++i, ++j)				nums[j] = i;			// Notify message count changed			events::messageCountEvent event				(thisRef().dynamicCast <folder>(),				 events::messageCountEvent::TYPE_ADDED, nums);			notifyMessageCount(event);			// Notify folders with the same path			for (std::list <POP3Folder*>::iterator it = store->m_folders.begin() ;			     it != store->m_folders.end() ; ++it)			{				if ((*it) != this && (*it)->getFullPath() == m_path)				{					(*it)->m_messageCount = count;					events::messageCountEvent event						((*it)->thisRef().dynamicCast <folder>(),						 events::messageCountEvent::TYPE_ADDED, nums);					(*it)->notifyMessageCount(event);				}			}		}	}}void POP3Folder::expunge(){	// Not supported by POP3 protocol (deleted messages are automatically	// expunged at the end of the session...).}} // pop3} // net} // vmime

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -