diff --git a/kmail/messageproperty.cpp b/kmail/messageproperty.cpp index 66444ff878..e325855ed7 100644 --- a/kmail/messageproperty.cpp +++ b/kmail/messageproperty.cpp @@ -1,173 +1,190 @@ /* Message Property - + This file is part of KMail, the KDE mail client. Copyright (c) Don Sanders KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail 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 In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifdef HAVE_CONFIG_H #include #endif #include "messageproperty.h" using namespace KMail; QMap > MessageProperty::sFolders; +QMap MessageProperty::sKeepSerialNumber; QMap > MessageProperty::sHandlers; QMap MessageProperty::sTransfers; QMap MessageProperty::sSerialCache; bool MessageProperty::filtering( Q_UINT32 serNum ) { return sFolders.contains( serNum ); } void MessageProperty::setFiltering( Q_UINT32 serNum, bool filter ) { assert(!filtering(serNum) || !filter); if (filter && !filtering(serNum)) sFolders.replace(serNum, QGuardedPtr(0) ); else if (!filter) sFolders.remove(serNum); } bool MessageProperty::filtering( const KMMsgBase *msgBase ) { return filtering( msgBase->getMsgSerNum() ); } void MessageProperty::setFiltering( const KMMsgBase *msgBase, bool filter ) { setFiltering( msgBase->getMsgSerNum(), filter ); } KMFolder* MessageProperty::filterFolder( Q_UINT32 serNum ) { - if (sFolders.contains(serNum)) - return sFolders[serNum].operator->(); - return 0; + QMap >::const_iterator it = sFolders.find( serNum ); + return it == sFolders.constEnd() ? 0 : (*it).operator->(); } void MessageProperty::setFilterFolder( Q_UINT32 serNum, KMFolder* folder ) { - sFolders.replace(serNum, QGuardedPtr(folder) ); + sFolders.insert(serNum, QGuardedPtr(folder) ); } KMFolder* MessageProperty::filterFolder( const KMMsgBase *msgBase ) { return filterFolder( msgBase->getMsgSerNum() ); } void MessageProperty::setFilterFolder( const KMMsgBase *msgBase, KMFolder* folder ) { setFilterFolder( msgBase->getMsgSerNum(), folder ); } ActionScheduler* MessageProperty::filterHandler( Q_UINT32 serNum ) { - if ( sHandlers.contains( serNum )) - return sHandlers[serNum].operator->(); - return 0; + QMap >::const_iterator it = sHandlers.find( serNum ); + return it == sHandlers.constEnd() ? 0 : (*it).operator->(); } void MessageProperty::setFilterHandler( Q_UINT32 serNum, ActionScheduler* handler ) { if (handler) - sHandlers.replace( serNum, QGuardedPtr(handler) ); + sHandlers.insert( serNum, QGuardedPtr(handler) ); else sHandlers.remove( serNum ); } ActionScheduler* MessageProperty::filterHandler( const KMMsgBase *msgBase ) { return filterHandler( msgBase->getMsgSerNum() ); } void MessageProperty::setFilterHandler( const KMMsgBase *msgBase, ActionScheduler* handler ) { setFilterHandler( msgBase->getMsgSerNum(), handler ); } bool MessageProperty::transferInProgress( Q_UINT32 serNum ) { - if (sTransfers.contains(serNum)) - return sTransfers[serNum]; - return false; + QMap::const_iterator it = sTransfers.find( serNum ); + return it == sTransfers.constEnd() ? false : *it; } void MessageProperty::setTransferInProgress( Q_UINT32 serNum, bool transfer, bool force ) { int transferInProgress = 0; - if (sTransfers.contains(serNum)) - transferInProgress = sTransfers[serNum]; + QMap::const_iterator it = sTransfers.find( serNum ); + if (it != sTransfers.constEnd()) + transferInProgress = *it; if ( force && !transfer ) transferInProgress = 0; else transfer ? ++transferInProgress : --transferInProgress; if ( transferInProgress < 0 ) transferInProgress = 0; if (transferInProgress) - sTransfers.replace( serNum, transferInProgress ); + sTransfers.insert( serNum, transferInProgress ); else sTransfers.remove( serNum ); } bool MessageProperty::transferInProgress( const KMMsgBase *msgBase ) { return transferInProgress( msgBase->getMsgSerNum() ); } void MessageProperty::setTransferInProgress( const KMMsgBase *msgBase, bool transfer, bool force ) { setTransferInProgress( msgBase->getMsgSerNum(), transfer, force ); } Q_UINT32 MessageProperty::serialCache( const KMMsgBase *msgBase ) { - if (sSerialCache.contains( msgBase )) - return sSerialCache[msgBase]; - return 0; + QMap::const_iterator it = sSerialCache.find( msgBase ); + return it == sSerialCache.constEnd() ? 0 : *it; } void MessageProperty::setSerialCache( const KMMsgBase *msgBase, Q_UINT32 serNum ) { if (serNum) - sSerialCache.replace( msgBase, serNum ); + sSerialCache.insert( msgBase, serNum ); else sSerialCache.remove( msgBase ); } +void MessageProperty::setKeepSerialNumber( Q_UINT32 serialNumber, bool keepForMoving ) +{ + if ( serialNumber ) { + if ( sKeepSerialNumber.contains( serialNumber ) ) + sKeepSerialNumber[ serialNumber ] = keepForMoving; + else + sKeepSerialNumber.insert( serialNumber, keepForMoving ); + } +} + +bool MessageProperty::keepSerialNumber( Q_UINT32 serialNumber ) +{ + if ( sKeepSerialNumber.contains( serialNumber ) ) + return sKeepSerialNumber[ serialNumber ]; + else + return false; +} + void MessageProperty::forget( const KMMsgBase *msgBase ) { Q_UINT32 serNum = serialCache( msgBase ); if (serNum) { Q_ASSERT( !transferInProgress( serNum ) ); sTransfers.remove( serNum ); sSerialCache.remove( msgBase ); + sKeepSerialNumber.remove( serNum ); } } #include "messageproperty.moc" diff --git a/kmail/messageproperty.h b/kmail/messageproperty.h index 1ffbdcc7b0..99fd4778e3 100644 --- a/kmail/messageproperty.h +++ b/kmail/messageproperty.h @@ -1,112 +1,133 @@ /* Message Property This file is part of KMail, the KDE mail client. Copyright (c) Don Sanders KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail 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 In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef messageproperty_h #define messageproperty_h #include "kmfilteraction.h" // for KMFilterAction::ReturnCode #include "kmfolder.h" #include #include #include class KMFilter; class KMFilterDlg; namespace KMail { class ActionScheduler; /* A place to store properties that some but not necessarily all messages have. These properties do not need to be stored persistantly on disk but rather only are required while KMail is running. Furthermore some properties, namely complete, transferInProgress, and serialCache should only exist during the lifetime of a particular KMMsgBase based instance. */ class MessageProperty : public QObject { Q_OBJECT public: /** If the message is being filtered */ static bool filtering( Q_UINT32 ); static void setFiltering( Q_UINT32, bool filtering ); static bool filtering( const KMMsgBase* ); static void setFiltering( const KMMsgBase*, bool filtering ); /** The folder this message is to be moved into once filtering is finished, or null if the message is not scheduled to be moved */ static KMFolder* filterFolder( Q_UINT32 ); static void setFilterFolder( Q_UINT32, KMFolder* folder ); static KMFolder* filterFolder( const KMMsgBase* ); static void setFilterFolder( const KMMsgBase*, KMFolder* folder ); /* Set the filterHandler for a message */ static ActionScheduler* filterHandler( Q_UINT32 ); static void setFilterHandler( Q_UINT32, ActionScheduler* filterHandler ); static ActionScheduler* filterHandler( const KMMsgBase* ); static void setFilterHandler( const KMMsgBase*, ActionScheduler* filterHandler ); /* Caches the serial number for a message, or more correctly for a KMMsgBase based instance representing a message. This property becomes invalid when the message is destructed or assigned a new value */ static void setSerialCache( const KMMsgBase*, Q_UINT32 ); static Q_UINT32 serialCache( const KMMsgBase* ); /* Set the transferInProgress for a message This property becomes invalid when the message is destructed or assigned a new value */ static void setTransferInProgress( const KMMsgBase*, bool, bool = false ); static bool transferInProgress( const KMMsgBase* ); static void setTransferInProgress( Q_UINT32, bool, bool = false ); static bool transferInProgress( Q_UINT32 ); + + /** + * Set this property to true if you want to keep the serial number when moving + * a message from a local folder to an online IMAP folder. + * Setting this to true will cause the ImapJob to save the meta data, like the + * serial number, of the message in a map, which is later read when the + * message arrives in the new location. Then the serial number is restored. + */ + static void setKeepSerialNumber( Q_UINT32 serialNumber, bool keepForMoving ); + static bool keepSerialNumber( Q_UINT32 serialNumber ); + /** Some properties, namely complete, transferInProgress, and serialCache must be forgotten when a message class instance is destructed or assigned a new value */ static void forget( const KMMsgBase* ); private: // The folder a message is to be moved into once filtering is finished if any static QMap > sFolders; + + // Whether the serial number of a message should be kept when moving it from + // a local folder to an online IMAP folder. This is currently only used by + // the action scheduler (in ActionScheduler::moveMessage()), to make the IMAP + // job aware that it should try to preserve the serial number when moving, see + // ImapJob::init(). + static QMap sKeepSerialNumber; + // The action scheduler currently processing a message if any static QMap > sHandlers; + // The transferInProgres state of a message if any. static QMap sTransfers; + // The cached serial number of a message if any. static QMap sSerialCache; }; } #endif /*messageproperty_h*/