email/pop3andsmtpmtm/imapservermtm/src/FLDINDEX.CPP
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // IMAP Folder indexing
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "fldindex.h"
       
    19 #include "impspan.h"
       
    20 
       
    21 // Illegal UID we use for marker
       
    22 const TUint KIllegalUID	= 0xffffffff;
       
    23 
       
    24 CImImap4IndexEntry::CImImap4IndexEntry()
       
    25 	{
       
    26 	// Default values
       
    27 	iUid=0;
       
    28 	iMsvId=-1;
       
    29 	}
       
    30 
       
    31 CImImap4IndexEntry::CImImap4IndexEntry(CImImap4IndexEntry& aFrom)
       
    32 	{
       
    33 	// Copy entry
       
    34 	iUid=aFrom.iUid;
       
    35 	iMsvId=aFrom.iMsvId;
       
    36 	}
       
    37 
       
    38 CImImap4IndexEntry& CImImap4IndexEntry::operator=(CImImap4IndexEntry& aFrom)
       
    39 	{
       
    40 	// Copy entry
       
    41 	iUid=aFrom.iUid;
       
    42 	iMsvId=aFrom.iMsvId;
       
    43 	return(*this);
       
    44 	}
       
    45 
       
    46 CImImap4FolderIndex::CImImap4FolderIndex()
       
    47 	{
       
    48 	__DECLARE_NAME(_S("CImImap4FolderIndex"));
       
    49 	}
       
    50 
       
    51 CImImap4FolderIndex::~CImImap4FolderIndex()
       
    52 	{
       
    53 	// Dispose of index
       
    54 	delete iIndex;
       
    55 	}
       
    56 
       
    57 void CImImap4FolderIndex::Reset()
       
    58 	{
       
    59 	// Dispose of index
       
    60 	delete iIndex;
       
    61 	iIndex=NULL;
       
    62 	iSize=0;
       
    63 	}
       
    64 
       
    65 void CImImap4FolderIndex::SetSizeL(const TUint aEntries)
       
    66 	{
       
    67 	// Set number of entries
       
    68 	if (!iIndex)
       
    69 		{
       
    70 		// Create new array (granularity 8 entries)
       
    71 		iIndex=new (ELeave) CArrayFixFlat<CImImap4IndexEntry>(8);
       
    72 		}
       
    73 
       
    74 	// Alter size, filling unused entries with 0xffffffff
       
    75 	CImImap4IndexEntry blank;
       
    76 	blank.iUid=KIllegalUID;
       
    77 	blank.iMsvId=0;
       
    78 	iIndex->ResizeL(aEntries,blank);
       
    79 
       
    80 	// Save new size
       
    81 	iSize=aEntries;
       
    82 	}
       
    83 
       
    84 TInt CImImap4FolderIndex::Size()
       
    85 	{
       
    86 	// Return current size
       
    87 	return(iSize);
       
    88 	}
       
    89 
       
    90 void CImImap4FolderIndex::SetUid(const TUint aMsgNr, const TUint aMsgUid)
       
    91 	{
       
    92 	__ASSERT_ALWAYS(aMsgNr<=TUint(iSize),gPanic(EMsgnrOutOfRange));
       
    93 
       
    94 	// Is UID already set?
       
    95 	if ((*iIndex)[aMsgNr-1].iUid!=KIllegalUID && (*iIndex)[aMsgNr-1].iUid!=aMsgUid)
       
    96 		{
       
    97 		// CHANGING a UID? No way!
       
    98 		gPanic(ECantChangeUID);
       
    99 		}
       
   100 
       
   101 	// Set a UID for a message number
       
   102 	(*iIndex)[aMsgNr-1].iUid=aMsgUid;
       
   103 	}
       
   104 
       
   105 void CImImap4FolderIndex::SetMsvId(const TUint aMsgNr, const TMsvId aMsvId)
       
   106 	{
       
   107 	__ASSERT_ALWAYS(aMsgNr<=TUint(iSize),gPanic(EMsgnrOutOfRange));
       
   108 
       
   109 	// Is MsvId already set?
       
   110 	if ((*iIndex)[aMsgNr-1].iMsvId!=0 && (*iIndex)[aMsgNr-1].iMsvId!=aMsvId)
       
   111 		{
       
   112 		// CHANGING a MsvId? No way!
       
   113 		gPanic(ECantChangeMsvId);
       
   114 		}
       
   115 
       
   116 	// Set a MsvId for a message number
       
   117 	(*iIndex)[aMsgNr-1].iMsvId=aMsvId;
       
   118 	}
       
   119 
       
   120 void CImImap4FolderIndex::Expunge(const TUint aMsgNr)
       
   121 	{
       
   122 	__ASSERT_ALWAYS(aMsgNr<=TUint(iSize),gPanic(EMsgnrOutOfRange));
       
   123 
       
   124 	// Remove entry from index
       
   125 	iIndex->Delete(aMsgNr-1);
       
   126 	iSize--;
       
   127 	}
       
   128 
       
   129 TUint CImImap4FolderIndex::FindMsg(const TUint aMsgUid)
       
   130 	{
       
   131 	__ASSERT_ALWAYS(iSize>0,gPanic(EIndexEmpty));
       
   132 
       
   133 	// Replace this with a binary search...
       
   134 	TInt i=0;
       
   135 	do
       
   136 		{
       
   137 		// UID match?
       
   138 		if ((*iIndex)[i].iUid==aMsgUid)
       
   139 			return(i+1);
       
   140 
       
   141 		i++;
       
   142 		}
       
   143 	while(i<iSize);
       
   144 
       
   145 	// Failure (0 not a legal message number)
       
   146 	return(0);
       
   147 	}
       
   148 
       
   149 // Access entry directly
       
   150 CImImap4IndexEntry& CImImap4FolderIndex::operator[] (const TInt aIndex)
       
   151 	{
       
   152 	return((*iIndex)[aIndex]);
       
   153 	}
       
   154 
       
   155 // Sort index by UID
       
   156 void CImImap4FolderIndex::Sort()
       
   157 	{
       
   158 	// Sorting object
       
   159 	TKeyArrayFix uidKey(_FOFF(CImImap4IndexEntry,iUid),ECmpTUint32);
       
   160 
       
   161 	// Perform the sort
       
   162 	iIndex->Sort(uidKey);
       
   163 	}