/** * @file pendingupdates.cc * @brief <---> * @author Andreas Aardal Hanssen * @date 2002-2005 */ #include "pendingupdates.h" #include "iodevice.h" #include "iofactory.h" #include "mailbox.h" #include "message.h" #include "session.h" #include #include #include using namespace std; using namespace Binc; PendingUpdates::PendingUpdates() : expunges(), flagupdates() { recent = 0; exists = 0; newrecent = false; newexists = false; } PendingUpdates::~PendingUpdates() {} void PendingUpdates::addExpunged(unsigned int uid) { expunges.push_back(uid); } void PendingUpdates::addFlagUpdates(unsigned int sqnr, unsigned int uid, unsigned int flags, const vector &cflags) { flagupdates[sqnr] = flags; sqnrtouid[sqnr] = uid; sqnrtocflags[sqnr] = cflags; } void PendingUpdates::setExists(unsigned int n) { exists = n; newexists = true; } void PendingUpdates::setRecent(unsigned int n) { recent = n; newrecent = true; } unsigned int PendingUpdates::getExists() const { return exists; } unsigned int PendingUpdates::getRecent() const { return recent; } bool PendingUpdates::newExists() const { return newexists; } bool PendingUpdates::newRecent() const { return newrecent; } PendingUpdates::expunged_const_iterator::expunged_const_iterator() {} PendingUpdates::expunged_const_iterator::expunged_const_iterator( vector::iterator i) : internal(i) {} unsigned int PendingUpdates::expunged_const_iterator::operator*() const { return *internal; } void PendingUpdates::expunged_const_iterator::operator++() { ++internal; } bool PendingUpdates::expunged_const_iterator::operator==(expunged_const_iterator i) const { return internal == i.internal; } bool PendingUpdates::expunged_const_iterator::operator!=(expunged_const_iterator i) const { return internal != i.internal; } PendingUpdates::expunged_const_iterator PendingUpdates::beginExpunged() { return expunged_const_iterator(expunges.begin()); } PendingUpdates::expunged_const_iterator PendingUpdates::endExpunged() { return expunged_const_iterator(expunges.end()); } PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator() {} PendingUpdates::flagupdates_const_iterator::flagupdates_const_iterator( map::iterator i, map> *j, map *sqnrmap) : internal(i) , sqnrtocflags(j) { sqnrtouid = sqnrmap; } void PendingUpdates::flagupdates_const_iterator::operator++() { ++internal; } bool PendingUpdates::flagupdates_const_iterator::operator!=(flagupdates_const_iterator i) const { return internal != i.internal; } PendingUpdates::flagupdates_const_iterator PendingUpdates::beginFlagUpdates() { return flagupdates_const_iterator(flagupdates.begin(), &sqnrtocflags, &sqnrtouid); } PendingUpdates::flagupdates_const_iterator PendingUpdates::endFlagUpdates() { return flagupdates_const_iterator(flagupdates.end(), &sqnrtocflags, &sqnrtouid); } unsigned int PendingUpdates::flagupdates_const_iterator::first() const { return internal->first; } unsigned int PendingUpdates::flagupdates_const_iterator::second() const { return internal->second; } vector PendingUpdates::flagupdates_const_iterator::getCustomFlags() const { return (*sqnrtocflags)[internal->first]; } unsigned int PendingUpdates::flagupdates_const_iterator::getUID() const { return (*sqnrtouid)[internal->first]; } bool Binc::pendingUpdates(Mailbox *mailbox, int type, bool rescan, bool showAll, bool forceScan, bool uidfetchflags) { Session &session = Session::getInstance(); if (mailbox == nullptr) return true; PendingUpdates p; if (!mailbox->getUpdates(rescan, type, p, forceScan)) { session.setLastError(mailbox->getLastError()); return false; } if (type & PendingUpdates::EXPUNGE) { PendingUpdates::expunged_const_iterator i = p.beginExpunged(); PendingUpdates::expunged_const_iterator e = p.endExpunged(); while (i != e) { bincClient << "* " << *i << " EXPUNGE" << endl; ++i; } } if (((type & PendingUpdates::EXISTS) && p.newExists()) || showAll) bincClient << "* " << p.getExists() << " EXISTS" << endl; if (((type & PendingUpdates::RECENT) && p.newRecent()) || showAll) bincClient << "* " << p.getRecent() << " RECENT" << endl; if (type & PendingUpdates::FLAGS) { PendingUpdates::flagupdates_const_iterator i = p.beginFlagUpdates(); PendingUpdates::flagupdates_const_iterator e = p.endFlagUpdates(); while (i != e) { int flags = i.second(); vector flagv; if (flags & Message::F_SEEN) flagv.push_back("\\Seen"); if (flags & Message::F_ANSWERED) flagv.push_back("\\Answered"); if (flags & Message::F_DELETED) flagv.push_back("\\Deleted"); if (flags & Message::F_DRAFT) flagv.push_back("\\Draft"); if (flags & Message::F_RECENT) flagv.push_back("\\Recent"); if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged"); bincClient << "* " << i.first() << " FETCH (FLAGS ("; for (vector::const_iterator k = flagv.begin(); k != flagv.end(); ++k) { if (k != flagv.begin()) bincClient << " "; bincClient << *k; } vector customFlags = i.getCustomFlags(); for (auto it = customFlags.cbegin(); it != customFlags.cend(); ++it) { if (flagv.size() > 0 || it != customFlags.cbegin()) bincClient << " "; bincClient << *it; } bincClient << ")"; if (uidfetchflags) bincClient << " UID " << i.getUID(); bincClient << ")" << endl; ++i; } } return true; }