Buggy code:
public class IMAPFolder extends RemoteFolder { private ImapItem item ; private Object aktMessageUid ; private ColumbaMessage aktMessage ; private boolean mailcheck = false ; private IMAPStore store ; protected HeaderList headerList ; protected RemoteHeaderCache cache ; protected boolean existsOnServer ; public IMAPFolder ( FolderItem folderItem ) { } public Object [ ] searchMessages ( Filter filter , Object [ ] uids ) throws Exception { } public Object [ ] searchMessages ( Filter filter ) throws Exception { } public void removeFolder ( ) throws Exception { } public boolean renameFolder ( String name ) throws Exception { } public FolderTreeNode getRootFolder ( ) { } public IMAPStore getStore ( ) { } public HeaderList getHeaderList ( ) throws Exception { } protected void updateFlags ( Flags [ ] flagsList ) { } public void save ( ) throws Exception { } public List synchronize ( HeaderList headerList , List newList ) throws Exception { } protected boolean existsRemotely ( String uid , int startIndex , List uidList ) throws Exception { } protected boolean existsLocally ( String uid , HeaderList list ) throws Exception { } public MimeTree getMimePartTree ( Object uid ) throws Exception { } public MimePart getMimePart ( Object uid , Integer [ ] address ) throws Exception { } public void innerCopy ( MailboxInterface destFolder , Object [ ] uids ) throws Exception { } public Object addMessage ( ColumbaMessage message ) throws Exception { } public Object addMessage ( String source ) throws Exception { } public boolean exists ( Object uid ) throws Exception { } protected void markMessage ( Object uid , int variant ) throws Exception { ColumbaHeader h = ( ( ColumbaHeader ) ( cache . getHeaderList ( ) . get ( uid ) ) ) ; Flags flags = getFlags ( uid ) ; switch ( variant ) { case MarkMessageCommand . MARK_AS_READ : { if ( flags . getRecent ( ) ) getMessageFolderInfo ( ) . decRecent ( ) ; <START_BUG> if ( flags . getSeen ( ) ) <END_BUG> getMessageFolderInfo ( ) . decUnseen ( ) ; flags . setSeen ( true ) ; flags . setRecent ( false ) ; break ; } case MarkMessageCommand . MARK_AS_UNREAD : { flags . setSeen ( false ) ; getMessageFolderInfo ( ) . incUnseen ( ) ; break ; } case MarkMessageCommand . MARK_AS_FLAGGED : { flags . setFlagged ( true ) ; break ; } case MarkMessageCommand . MARK_AS_UNFLAGGED : { flags . setFlagged ( false ) ; break ; } case MarkMessageCommand . MARK_AS_EXPUNGED : { if ( flags . getSeen ( ) ) getMessageFolderInfo ( ) . decUnseen ( ) ; flags . setSeen ( true ) ; flags . setRecent ( false ) ; flags . setExpunged ( true ) ; break ; } case MarkMessageCommand . MARK_AS_UNEXPUNGED : { flags . setExpunged ( false ) ; break ; } case MarkMessageCommand . MARK_AS_ANSWERED : { flags . setAnswered ( true ) ; break ; } case MarkMessageCommand . MARK_AS_SPAM : { setAttribute ( uid , "columba.spam" , Boolean . TRUE ) ; break ; } case MarkMessageCommand . MARK_AS_NOTSPAM : { setAttribute ( uid , "columba.spam" , Boolean . FALSE ) ; break ; } } } public void markMessage ( Object [ ] uids , int variant ) throws Exception { } public void removeMessage ( Object uid ) throws Exception { } public Object [ ] getUids ( ) throws Exception { } public void expungeFolder ( ) throws Exception { } public String getMessageSource ( Object uid ) throws Exception { } public ColumbaHeader getMessageHeader ( Object uid ) throws Exception { } public ColumbaMessage getMessage ( Object uid ) throws Exception { } protected String getImapPath ( ) throws Exception { } public static XmlElement getDefaultProperties ( ) { } public boolean tryToGetLock ( Object locker ) { } public void releaseLock ( Object locker ) { } public IMAPFolder ( String name , String type ) throws Exception { } public void addSubfolder ( FolderTreeNode child ) throws Exception { } public StatusObservable getObservable ( ) { } public Object addMessage ( InputStream in ) throws Exception { } public Object getAttribute ( Object uid , String key ) throws Exception { } public Flags getFlags ( Object uid ) throws Exception { } public Header getHeaderFields ( Object uid , String [ ] keys ) throws Exception { } public InputStream getMessageSourceStream ( Object uid ) throws Exception { } public InputStream getMimePartSourceStream ( Object uid , Integer [ ] address ) throws Exception { } public InputStream getMimePartBodyStream ( Object uid , Integer [ ] address ) throws Exception { } public boolean isInboxFolder ( ) { } public boolean isTrashFolder ( ) { } public void setAttribute ( Object uid , String key , Object value ) throws Exception { } }

Fix:
if ( ! ( flags . getSeen ( ) ) )