Blob Blame History Raw
Index: kmail/kmfoldercachedimap.cpp
===================================================================
--- kmail/kmfoldercachedimap.cpp	(Revision 935084)
+++ kmail/kmfoldercachedimap.cpp	(Revision 935085)
@@ -202,7 +202,8 @@
     /*mHoldSyncs( false ),*/
     mFolderRemoved( false ),
     mRecurse( true ),
-    mStatusChangedLocally( false ), mAnnotationFolderTypeChanged( false ),
+    mStatusChangedLocally( false ),
+    mAnnotationFolderTypeChanged( false ),
     mIncidencesForChanged( false ), mPersonalNamespacesCheckDone( true ),
     mQuotaInfo(), mAlarmsBlocked( false ),
     mRescueCommandCount( 0 ),
@@ -303,18 +304,22 @@
   KMFolderMaildir::readConfig();
 
   mStatusChangedLocally = group.readEntry( "StatusChangedLocally", false );
+  QStringList uidsChanged = group.readEntry( "UIDStatusChangedLocally", QStringList() );
+  foreach( const QString &uid, uidsChanged ) {
+    mUIDsOfLocallyChangedStatuses.append( uid.toUInt() );
+  }
   mAnnotationFolderTypeChanged = group.readEntry( "AnnotationFolderTypeChanged", false );
   mIncidencesForChanged = group.readEntry( "IncidencesForChanged", false );
   if ( mImapPath.isEmpty() ) {
     mImapPathCreation = group.readEntry("ImapPathCreation");
   }
 
-  QStringList uids = group.readEntry( "UIDSDeletedSinceLastSync", QStringList() );
+  QStringList delUids = group.readEntry( "UIDSDeletedSinceLastSync" , QStringList() );
 #if MAIL_LOSS_DEBUGGING
   kDebug( 5006 ) << "READING IN UIDSDeletedSinceLastSync: " << folder()->prettyUrl() << endl << uids;
 #endif
-  for ( QStringList::iterator it = uids.begin(); it != uids.end(); ++it ) {
-      mDeletedUIDsSinceLastSync.insert( (*it).toULong(), 0);
+  for ( QStringList::iterator it = delUids.begin(); it != delUids.end(); it++ ) {
+    mDeletedUIDsSinceLastSync.insert( (*it).toULong(), 0);
   }
 }
 
@@ -331,7 +336,14 @@
   configGroup.writeEntry( "NoContent", mNoContent );
   configGroup.writeEntry( "ReadOnly", mReadOnly );
   configGroup.writeEntry( "FolderAttributes", mFolderAttributes );
-  configGroup.writeEntry( "StatusChangedLocally", mStatusChangedLocally );
+
+  // StatusChangedLocally is always false, as we use UIDStatusChangedLocally now
+  configGroup.writeEntry( "StatusChangedLocally", false );
+  QStringList uidsToWrite;
+  foreach( const ulong uid, mUIDsOfLocallyChangedStatuses ) {
+    uidsToWrite.append( QString::number( uid ) );
+  }
+  configGroup.writeEntry( "UIDStatusChangedLocally", uidsToWrite );
   if ( !mImapPathCreation.isEmpty() ) {
     if ( mImapPath.isEmpty() ) {
       configGroup.writeEntry( "ImapPathCreation", mImapPathCreation );
@@ -953,12 +965,13 @@
       // Upload flags, unless we know from the ACL that we're not allowed
       // to do that or they did not change locally
       if ( mUserRights <= 0 || ( mUserRights & KMail::ACLJobs::WriteFlags ) ) {
-        if ( mStatusChangedLocally ) {
+        if ( !mUIDsOfLocallyChangedStatuses.isEmpty() || mStatusChangedLocally ) {
           uploadFlags();
           break;
         }
-      } else if ( mUserRights & KMail::ACLJobs::WriteSeenFlag ) {
-        if ( mStatusChangedLocally ) {
+      }
+      else if ( mUserRights & KMail::ACLJobs::WriteSeenFlag ) {
+        if ( !mUIDsOfLocallyChangedStatuses.isEmpty() || mStatusChangedLocally ) {
           uploadSeenFlags();
           break;
         }
@@ -1425,6 +1438,10 @@
         // Either not a valid message or not one that is on the server yet
         continue;
       }
+      if ( mUIDsOfLocallyChangedStatuses.indexOf( msg->UID() ) < 0 && !mStatusChangedLocally ) {
+        // This message has not had its status changed locally
+        continue;
+      }
 
       QString flags = KMFolderImap::statusToFlags( msg->status(), mPermanentFlags );
       // Collect uids for each typem of flags.
@@ -1468,6 +1485,11 @@
         // Either not a valid message or not one that is on the server yet
         continue;
 
+      if ( mUIDsOfLocallyChangedStatuses.indexOf( msg->UID() ) < 0 && !mStatusChangedLocally ) {
+        // This message has not had its status changed locally
+        continue;
+      }
+
       if ( msg->status().isOld() || msg->status().isRead() )
         seenUids.append( msg->UID() );
       else
@@ -1525,13 +1547,21 @@
 void KMFolderCachedImap::setStatus( int idx, const MessageStatus &status, bool toggle )
 {
   KMFolderMaildir::setStatus( idx, status, toggle );
-  mStatusChangedLocally = true;
+  const KMMsgBase *msg = getMsgBase( idx );
+  Q_ASSERT( msg );
+  if ( msg )
+    mUIDsOfLocallyChangedStatuses.append( msg->UID() );
 }
 
 void KMFolderCachedImap::setStatus( QList<int> &ids, const MessageStatus &status, bool toggle )
 {
   KMFolderMaildir::setStatus( ids, status, toggle );
-  mStatusChangedLocally = true;
+  foreach( const int id, ids ) {
+    const KMMsgBase *msg = getMsgBase( id );
+    Q_ASSERT( msg );
+    if ( msg )
+      mUIDsOfLocallyChangedStatuses.append( msg->UID() );
+  }
 }
 
 /* Upload new folders to server */
@@ -1888,7 +1918,8 @@
   } else {
     if ( lastSet ) { // always true here (this comes from online-imap...)
       mContentState = imapFinished;
-      mStatusChangedLocally = false; // we are up to date again
+      mUIDsOfLocallyChangedStatuses.clear(); // we are up to date again
+      mStatusChangedLocally = false;
     }
   }
   serverSyncInternal();
Index: kmail/kmfoldercachedimap.h
===================================================================
--- kmail/kmfoldercachedimap.h	(Revision 935084)
+++ kmail/kmfoldercachedimap.h	(Revision 935085)
@@ -627,12 +627,18 @@
     bool mFolderRemoved;
     bool mRecurse;
 
+   /**
+    * UIDs added by setStatus. Indicates that the client has changed
+    * the status of those mails. The mail flags for changed mails will be
+    * uploaded to the server, overwriting the server's notion of the status
+    * of the mails in this folder.
+    */
+    QList<ulong> mUIDsOfLocallyChangedStatuses;
+
     /**
-      Set to true by setStatus. Indicates that the client has changed
-      the status of at least one mail. The mail flags will therefore be
-      uploaded to the server, overwriting the server's notion of the status
-      of the mails in this folder.
-    */
+     * Same as above, but uploads the flags of all mails, even if not all changed.
+     * Only still here for config compatibility.
+     */
     bool mStatusChangedLocally;
 
     /**