コード例 #1
0
ファイル: offlinejob.cpp プロジェクト: snakamura/q3
bool qmimap4::CopyOfflineJob::apply(Account* pAccount,
									Imap4* pImap4,
									bool* pbClosed) const
{
	assert(pAccount);
	assert(pImap4);
	assert(pbClosed);
	
	assert(!listUidFrom_.empty());
	assert(listUidFrom_.size() == listItemTo_.size());
	
	Folder* pFolder = pAccount->getFolder(wstrFolderTo_.get());
	if (pFolder && pFolder->getType() == Folder::TYPE_NORMAL) {
		NormalFolder* pNormalFolder = static_cast<NormalFolder*>(pFolder);
		if (!pNormalFolder->loadMessageHolders())
			return false;
		
		wstring_ptr wstrName(Util::getFolderName(pNormalFolder));
		
		// TODO
		// Apply flags
		
		MultipleRange range(&listUidFrom_[0], listUidFrom_.size(), true);
		if (!pImap4->copy(range, wstrName.get()))
			return false;
		if (bMove_) {
			Flags flags(Imap4::FLAG_DELETED);
			if (!pImap4->setFlags(range, flags, flags))
				return false;
		}
		
		Lock<Account> lock(*pAccount);
		
		MessageHolderList l;
		l.reserve(listItemTo_.size());
		for (ItemList::const_iterator it = listItemTo_.begin(); it != listItemTo_.end(); ++it) {
			MessageHolder* pmh = pNormalFolder->getMessageHolderById((*it).nId_);
			if (pmh && pmh->isFlag(MessageHolder::FLAG_LOCAL))
				l.push_back(pmh);
		}
		if (!pAccount->unstoreMessages(l, 0))
			return false;
	}
	
	return true;
}
コード例 #2
0
ファイル: offlinejob.cpp プロジェクト: snakamura/q3
bool qmimap4::AppendOfflineJob::apply(Account* pAccount,
									  Imap4* pImap4,
									  bool* pbClosed) const
{
	assert(pAccount);
	assert(pImap4);
	assert(pbClosed);
	
	Folder* pFolder = pAccount->getFolder(wstrFolder_.get());
	if (pFolder && pFolder->getType() == Folder::TYPE_NORMAL) {
		NormalFolder* pNormalFolder = static_cast<NormalFolder*>(pFolder);
		Lock<Account> lock(*pAccount);
		MessagePtrLock mpl(pNormalFolder->getMessageById(nId_));
		if (mpl && mpl->isFlag(MessageHolder::FLAG_LOCAL)) {
			wstring_ptr wstrName(Util::getFolderName(pNormalFolder));
			
			Message msg;
			if (!mpl->getMessage(Account::GMF_ALL, 0, SECURITYMODE_NONE, &msg))
				return false;
			
			xstring_size_ptr strContent(msg.getContent());
			if (!strContent.get())
				return false;
			
			wstring_ptr wstrLabel(mpl->getLabel());
			const WCHAR* pwszLabel = wstrLabel.get();
			std::auto_ptr<Flags> pFlags(Util::getImap4FlagsFromLabels(mpl->getFlags(),
				&pwszLabel, pwszLabel && *pwszLabel ? 1 : 0));
			if (!pFlags.get())
				return false;
			if (!pImap4->append(wstrName.get(), strContent.get(), strContent.size(), *pFlags))
				return false;
			
			if (!pAccount->unstoreMessages(MessageHolderList(1, mpl), 0))
				return false;
		}
	}
	
	return true;
}
コード例 #3
0
ファイル: offlinejob.cpp プロジェクト: snakamura/q3
bool qmimap4::OfflineJobManager::apply(Account* pAccount,
									   Imap4* pImap4,
									   ReceiveSessionCallback* pCallback)
{
	assert(pImap4);
	
	Lock<CriticalSection> lock(cs_);
	
	bModified_ = true;
	
	{
		struct Deleter
		{
			typedef OfflineJobManager::JobList JobList;
			
			Deleter(JobList& l) :
				l_(l)
			{
			}
			
			~Deleter()
			{
				JobList::iterator it = std::find_if(l_.begin(), l_.end(),
					std::not1(std::bind2nd(std::equal_to<OfflineJob*>(), 0)));
				l_.erase(l_.begin(), it);
			}
			
			JobList& l_;
		} deleter(listJob_);
		
		pCallback->setRange(0, listJob_.size());
		
		Folder* pPrevFolder = 0;
		for (JobList::size_type n = 0; n < listJob_.size(); ++n) {
			pCallback->setPos(n + 1);
			
			OfflineJob*& pJob = listJob_[n];
			if (pJob->getFolder()) {
				Folder* pFolder = pAccount->getFolder(pJob->getFolder());
				if (pFolder && pFolder != pPrevFolder &&
					pFolder->getType() == Folder::TYPE_NORMAL) {
					wstring_ptr wstrName(Util::getFolderName(
						static_cast<NormalFolder*>(pFolder)));
					if (!pImap4->select(wstrName.get()))
						return false;
					pPrevFolder = pFolder;
				}
			}
			
			bool bClosed = false;
			if (!pJob->apply(pAccount, pImap4, &bClosed))
				return false;
			if (bClosed)
				pPrevFolder = 0;
			
			delete pJob;
			pJob = 0;
		}
	}
	
	if (!save()) {
		// TODO
	}
	
	return true;
}