messagingfw/msgsrvnstore/server/src/TMsvServerStoreManager.cpp
changeset 0 8e480a14352b
child 20 e4175d61d967
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 #include <e32wins.h>
       
    17 
       
    18 #include "TMsvServerStoreManager.h"
       
    19 #include "MSVUTILS.H"
       
    20 #include "MSVSERV.H"
       
    21 #include "MSVPANIC.H"
       
    22 #include "MSVAPI.H"
       
    23 #include "msvindexadapter.h"
       
    24 #include "msvpreferreddrivelist.h"
       
    25 
       
    26 TMsvServerStoreManager::TMsvServerStoreManager() : iMsvServer(NULL),iFs(NULL)
       
    27 	{
       
    28 	}
       
    29 
       
    30 void TMsvServerStoreManager::SetMsvServerAndFileSession(CMsvServer& aMsvServer,RFs& aFs)
       
    31 	{
       
    32 	iMsvServer = &aMsvServer;
       
    33 	iFs = &aFs;
       
    34 	}
       
    35 
       
    36 /** Gets the filepath for the storage of binary files associated with the context
       
    37 
       
    38 If the directory specified in the context does not exist, it is created.
       
    39 
       
    40 @param aEntryId index id of the entry whose filepath is requested
       
    41 @param aDirectory On return, contains the binary file directory path
       
    42 @return KErrNone - success;
       
    43 @return The server was unable to create the directory.- failure */
       
    44 TInt TMsvServerStoreManager::GetFilePath(TMsvId aEntryId, TFileName& aDirectory) const
       
    45 	{
       
    46 	__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
       
    47 
       
    48 	TMsvId owningService = KMsvNullIndexEntryId;
       
    49 	GetOwningServiceAndFilePath(aEntryId,aDirectory,owningService);
       
    50 
       
    51 	MsvUtils::ConstructEntryName(owningService, aEntryId, aDirectory, MsvUtils::EFolder);
       
    52 	TInt error = iMsvServer->FileSession().MkDirAll(aDirectory);
       
    53 	return (error==KErrAlreadyExists ? KErrNone : error);
       
    54 	}
       
    55 
       
    56 /** Gets the filestore name associated with the context
       
    57 
       
    58 @param aEntryId Index id of the entry whose store filename is requested
       
    59 @param aFileName On return, contains the store file name for the context
       
    60 */
       
    61 void TMsvServerStoreManager::GetStoreFileName(TMsvId aEntryId, TFileName& aFileName) const
       
    62 	{
       
    63 	__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
       
    64 
       
    65 	TMsvId owningService = KMsvNullIndexEntryId;
       
    66 	GetOwningServiceAndFilePath(aEntryId,aFileName,owningService);
       
    67 
       
    68 	MsvUtils::ConstructEntryName(owningService, aEntryId, aFileName, MsvUtils::EStore);
       
    69 	}
       
    70 
       
    71 void TMsvServerStoreManager::GetOwningServiceAndFilePath(TMsvId aEntryId,TDes& aFilePath,TMsvId& aOwningService) const
       
    72 	{
       
    73 	__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
       
    74 
       
    75 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
       
    76 	//TUint driveId = MsvUtils::GetDriveId(aEntryId);
       
    77 	TUint driveId = GetDriveId(aEntryId);
       
    78 	TDriveNumber driveNum = EDriveC;
       
    79 	CMsvPreferredDriveList::GetDriveList()->GetDriveNumber(driveId, driveNum);
       
    80 	aFilePath.Zero();
       
    81 	aFilePath.Append(TDriveUnit(driveNum).Name());
       
    82 	TParse parse;
       
    83 	parse.Set(iMsvServer->Context().MessageFolder(), NULL, NULL);
       
    84 	aFilePath.Append(parse.Path());
       
    85 #else
       
    86 	aFilePath = iMsvServer->Context().MessageFolder();
       
    87 #endif
       
    88 
       
    89 	iMsvServer->IndexAdapter().OwningService(aEntryId, aOwningService);
       
    90 	}
       
    91 
       
    92 /** Checks if the filename length is greater than KMaxFileName(256)
       
    93 
       
    94 If the filename is greater than KMaxFileName then it truncates the filename
       
    95 
       
    96 @param aFilePath file path where the file is being created.
       
    97 @param aFileName name of the file whose length if being checked.
       
    98 @return ETrue if the filename is changed.
       
    99 */
       
   100 TBool TMsvServerStoreManager::CheckFileNameLengthAndTrimL(const TDesC& aFilePath,TDes& aFileName)
       
   101 	{
       
   102 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   103 
       
   104  	TParsePtrC filenamePPtr(aFileName);
       
   105  	TPtrC fileExtension(filenamePPtr.Ext());
       
   106 
       
   107 #ifdef __WINS__
       
   108 	TFileName winsFileName;
       
   109 	TFileName mailStoreDrive;
       
   110 	TDriveUnit drive(MessageServer::CurrentDriveL(*iFs));
       
   111 	mailStoreDrive.Append(drive.Name());
       
   112 	mailStoreDrive.Append(KPathDelimiter);
       
   113 	MapEmulatedFileName(winsFileName, mailStoreDrive); // Ignoring return value
       
   114 	TInt KEpocBasePathLen = winsFileName.Length();
       
   115 	TInt maxFilenameLength = KMaxFileName-(aFilePath).Length()-fileExtension.Length()-KEpocBasePathLen;
       
   116 #else
       
   117 	TInt maxFilenameLength = KMaxFileName-(aFilePath).Length()-fileExtension.Length();
       
   118 #endif
       
   119 	TBool fileNameChanged = EFalse;
       
   120 	// Truncate filename if too long.
       
   121 	if (maxFilenameLength < aFileName.Length())
       
   122 		{
       
   123 		aFileName.SetLength(maxFilenameLength);
       
   124 		aFileName.Append(fileExtension);
       
   125 
       
   126 		fileNameChanged = ETrue;
       
   127 		}
       
   128 	return fileNameChanged;
       
   129 	}
       
   130 
       
   131 TBool TMsvServerStoreManager::GenerateFileNameIfExistsL(TDes& aFileName)
       
   132 	{
       
   133 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   134 
       
   135 	TParse fileParser;
       
   136 	User::LeaveIfError(fileParser.Set(aFileName, NULL, NULL));
       
   137 	TInt fileNameGenerator = 1;
       
   138 	TBool fileNameChanged = EFalse;
       
   139 	CDir* dir;
       
   140 	TInt error =  iFs->GetDir(fileParser.DriveAndPath(), KEntryAttNormal, ESortNone, dir);
       
   141 	if (error==KErrNone)
       
   142 		{
       
   143 		CleanupStack::PushL(dir);
       
   144 		TInt fileCount=dir->Count();
       
   145 		while(fileCount--)
       
   146 			{
       
   147 			TBool open;
       
   148 			TFileName filePath(aFileName);
       
   149 			TInt error = iFs->IsFileOpen(aFileName, open);
       
   150 			// file exists
       
   151 			if (error==KErrNone)
       
   152 				{
       
   153 				TFileName tempFileName(fileParser.DriveAndPath());
       
   154 				tempFileName.Append(fileParser.Name());
       
   155 				tempFileName.AppendNum(fileNameGenerator++);
       
   156 				tempFileName.Append(fileParser.Ext());
       
   157 				aFileName = tempFileName;
       
   158 				fileNameChanged = ETrue;
       
   159 				}
       
   160 			else if (error==KErrNotFound)
       
   161 				{
       
   162 				break;
       
   163 				}
       
   164 			else
       
   165 				{
       
   166 				User::Leave(error);
       
   167 				}
       
   168 			}
       
   169 		CleanupStack::PopAndDestroy(dir);
       
   170 		}
       
   171 	return fileNameChanged;
       
   172 	}
       
   173 
       
   174 // from MMsvStoreManager
       
   175 TBool TMsvServerStoreManager::CreateAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
       
   176 	{
       
   177 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   178 
       
   179 	return CreateAttachmentL(aEntryId, aFilename, aFile, *iFs);
       
   180 	}
       
   181 
       
   182 TBool TMsvServerStoreManager::CreateShareProtectedAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
       
   183 	{
       
   184 	RFs fs;
       
   185 	User::LeaveIfError(fs.Connect());
       
   186 	User::LeaveIfError(fs.ShareProtected());
       
   187 
       
   188 	return CreateAttachmentL(aEntryId, aFilename, aFile, fs, ETrue);
       
   189 	}
       
   190 
       
   191 TBool TMsvServerStoreManager::CreateAttachmentL(TMsvId aEntryId, TDes& aFilename, RFile& aFile, RFs& aFs,TBool aSharedAccess)
       
   192 	{
       
   193 	TFileName filePath;
       
   194 	GetFilePath(aEntryId,filePath);
       
   195 	TBool fileNameChanged = EFalse;
       
   196 
       
   197 	if(CheckFileNameLengthAndTrimL(filePath,(TDes&)aFilename))
       
   198 		{
       
   199 		fileNameChanged = ETrue;
       
   200 		}
       
   201 		
       
   202 	//for handling TBuf desc overflow
       
   203 	RBuf newFilePath;
       
   204 	TInt error = KErrNone;
       
   205  	newFilePath.CreateL(KMaxPath);
       
   206 	newFilePath.CleanupClosePushL(); 
       
   207 	newFilePath.Copy(filePath);
       
   208 	if(aFilename.Length()+filePath.Length()>KMaxFileName)
       
   209 		{
       
   210 	newFilePath.ReAllocL(aFilename.Length()+filePath.Length());	
       
   211 		}
       
   212 	newFilePath.Append(aFilename);
       
   213 	if (aSharedAccess)
       
   214 		{
       
   215 		//Shared access for reading and writing
       
   216 		error = aFile.Create(aFs,newFilePath,EFileShareAny|EFileWrite);		
       
   217 		}
       
   218 	else
       
   219 		{
       
   220 		error = aFile.Create(aFs,newFilePath,EFileWrite);	
       
   221 		}
       
   222 	
       
   223 	if(error == KErrAlreadyExists)
       
   224 		{
       
   225 		if(GenerateFileNameIfExistsL(newFilePath))
       
   226 			{			
       
   227 			fileNameChanged = ETrue;	
       
   228 			}
       
   229 			if (aSharedAccess)
       
   230 				{
       
   231 				//Shared access for reading and writing
       
   232 				User::LeaveIfError(aFile.Create(aFs,newFilePath, EFileShareAny|EFileWrite)); 
       
   233 				}
       
   234 			else
       
   235 				{
       
   236 			 	User::LeaveIfError(aFile.Create(aFs,newFilePath,EFileWrite));		
       
   237 				}
       
   238 			
       
   239 			aFilename.Copy(newFilePath);
       
   240 				
       
   241 		}
       
   242 	else 
       
   243 	   	{
       
   244 		User::LeaveIfError(error);
       
   245 		// return if error = KErrNone
       
   246 		aFilename.Copy(newFilePath);
       
   247 		}	
       
   248 	CleanupStack::PopAndDestroy(&newFilePath);//newFilePath destroy 
       
   249 	return fileNameChanged;
       
   250 	}
       
   251 
       
   252 void TMsvServerStoreManager::ReplaceAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
       
   253 	{
       
   254 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   255 
       
   256 	TFileName filePath;
       
   257 	GetFilePath(aEntryId, filePath);
       
   258 	TParsePtrC fileName(aFilename);
       
   259 	filePath.Append(fileName.NameAndExt());
       
   260 
       
   261 	User::LeaveIfError(aFile.Replace(*iFs, filePath, EFileWrite));
       
   262 
       
   263 	aFilename = filePath;
       
   264 	}
       
   265 
       
   266 void TMsvServerStoreManager::OpenAttachmentL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
   267 	{
       
   268 	__ASSERT_ALWAYS(iFs != NULL,PanicServer(EMsvFileSessionNotValid));
       
   269 
       
   270 	TFileName filePath;
       
   271 	GetFilePath(aEntryId,filePath);
       
   272 	TParsePtrC fileName(aFilePath);
       
   273 	filePath.Append(fileName.NameAndExt());
       
   274 
       
   275 	User::LeaveIfError(aFile.Open(*iFs,filePath,EFileRead|EFileShareReadersOnly));
       
   276 	}
       
   277 
       
   278 void TMsvServerStoreManager::OpenAttachmentForWriteL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
   279 	{
       
   280 	__ASSERT_ALWAYS(iFs != NULL,PanicServer(EMsvFileSessionNotValid));
       
   281 
       
   282 	TFileName filePath;
       
   283 	GetFilePath(aEntryId,filePath);
       
   284 	TParsePtrC fileName(aFilePath);
       
   285 	filePath.Append(fileName.NameAndExt());
       
   286 
       
   287 	User::LeaveIfError(aFile.Open(*iFs,filePath,EFileWrite));
       
   288 	}
       
   289 
       
   290 
       
   291 TInt TMsvServerStoreManager::DeleteAttachment(TMsvId aEntryId, const TDesC& aFilePath)
       
   292 	{
       
   293 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   294 
       
   295 	TFileName filePath;
       
   296 	GetFilePath(aEntryId,filePath);
       
   297 	TParsePtrC fileName(aFilePath);
       
   298 	filePath.Append(fileName.NameAndExt());
       
   299 
       
   300 	TInt error = iFs->Delete(filePath);
       
   301 
       
   302 	if(error == KErrNotFound || error == KErrPathNotFound)
       
   303 		return KErrNotFound;
       
   304 
       
   305 	return error;
       
   306 	}
       
   307 
       
   308 TInt TMsvServerStoreManager::RenameAttachment(TMsvId aEntryId, const TDesC& aOldFilePath, const TDesC& aNewName)
       
   309 	{
       
   310 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   311 
       
   312 	TFileName filePath;
       
   313 	TInt err = GetFilePath(aEntryId, filePath);
       
   314 
       
   315 	TParsePtrC fileToRename(aOldFilePath);
       
   316 	if(err==KErrNone)
       
   317 		{
       
   318 		filePath.Append(fileToRename.NameAndExt());
       
   319 		TParse newPath;
       
   320 		err = newPath.Set(aNewName, &fileToRename.FullName(), NULL);
       
   321 		if( err==KErrNone )
       
   322 			{
       
   323 			err = iFs->Rename(filePath, newPath.FullName());
       
   324 			}
       
   325 		}
       
   326 
       
   327 	return err;
       
   328 	}
       
   329 
       
   330 TBool TMsvServerStoreManager::FileExistsL(const TDesC& aFilePath)
       
   331 	{
       
   332 	// Use the Att method to check if file exists as it does change the
       
   333 	// file and is a light-weight call
       
   334 	TUint attValue = 0;
       
   335 	TInt err = iFs->Att(aFilePath, attValue);
       
   336 
       
   337 	TBool fileExists = EFalse;
       
   338 	if (err == KErrNotFound || err == KErrPathNotFound)
       
   339 		{
       
   340 		fileExists = EFalse;
       
   341 		}
       
   342 	else if (err == KErrNone)
       
   343 		{
       
   344 		fileExists = ETrue;
       
   345 		}
       
   346 	else
       
   347 		{
       
   348 		User::Leave(err);
       
   349 		}
       
   350 
       
   351 	return fileExists;
       
   352 	}
       
   353 
       
   354 void TMsvServerStoreManager::AttachmentFilePathL(TMsvId aEntryId, TDes& aFilePath)
       
   355 	{
       
   356 	TFileName filePath;
       
   357 	User::LeaveIfError(GetFilePath(aEntryId, filePath));
       
   358 
       
   359 	aFilePath = filePath;
       
   360 	}
       
   361 
       
   362 TInt TMsvServerStoreManager::OpenFileStoreForRead(TMsvId aEntryId, RFile& aFile)
       
   363 	{
       
   364 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   365 
       
   366 	TFileName filePathAndName;
       
   367 	GetStoreFileName(aEntryId,filePathAndName);
       
   368 
       
   369 	TInt error = aFile.Open(*iFs,filePathAndName,EFileRead|EFileShareAny);
       
   370 	if(error == KErrNotFound || error == KErrPathNotFound)
       
   371 		return KErrNotFound;
       
   372 
       
   373 	return error;
       
   374 	}
       
   375 
       
   376 void TMsvServerStoreManager::OpenTempStoreFileL(TMsvId aEntryId, RFile& aFile)
       
   377 	{
       
   378 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   379 
       
   380 	TFileName tempFilePathAndName;
       
   381 	GetStoreFileName(aEntryId,tempFilePathAndName);
       
   382 
       
   383 	tempFilePathAndName.Append(KMsvUtilsNewExtension);
       
   384 	TInt error = iFs->MkDirAll(tempFilePathAndName);
       
   385 	if(error == KErrNone || error == KErrAlreadyExists)
       
   386 		error = aFile.Replace(*iFs,tempFilePathAndName,EFileShareExclusive|EFileWrite);
       
   387 
       
   388 	User::LeaveIfError(error);
       
   389 	}
       
   390 
       
   391 void TMsvServerStoreManager::ReplaceFileStoreL(TMsvId aEntryId)
       
   392 	{
       
   393 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   394 
       
   395 	TFileName filePathAndName;
       
   396 	
       
   397 	GetStoreFileName(aEntryId,filePathAndName);
       
   398 	TFileName tempFilePathAndName(filePathAndName);
       
   399 	
       
   400 	tempFilePathAndName.Append(KMsvUtilsNewExtension);
       
   401 
       
   402 	TInt error = iFs->Replace(tempFilePathAndName,filePathAndName);
       
   403 	
       
   404 
       
   405 	if(error !=KErrNone)
       
   406 		{
       
   407 		iFs->Delete(tempFilePathAndName);
       
   408 		User::Leave(error);
       
   409 		}
       
   410 	}
       
   411 
       
   412 void TMsvServerStoreManager::DeleteFileStoreL(TMsvId aEntryId)
       
   413 	{
       
   414 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   415 
       
   416 	TFileName filePathAndName;
       
   417 	GetStoreFileName(aEntryId,filePathAndName);
       
   418 
       
   419 	TInt error = iFs->Delete(filePathAndName);
       
   420 	if(error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
       
   421 		User::Leave(error);
       
   422 
       
   423 	// Delete the temporary store file if it exists
       
   424 	filePathAndName.Append(KMsvUtilsNewExtension);
       
   425 	error = iFs->Delete(filePathAndName);
       
   426 	if(error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
       
   427 		User::Leave(error);
       
   428 	}
       
   429 
       
   430 TBool TMsvServerStoreManager::FileStoreExistsL(TMsvId aEntryId) const
       
   431 	{
       
   432 	__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
       
   433 
       
   434 	TMsvId owningService = KMsvNullIndexEntryId;
       
   435 	TFileName filePathAndName;
       
   436 	GetOwningServiceAndFilePath(aEntryId,filePathAndName,owningService);
       
   437 
       
   438 	return User::LeaveIfError(MsvUtils::HasStore(iMsvServer->FileSession(),filePathAndName,owningService, aEntryId));
       
   439 	}
       
   440 
       
   441 
       
   442 /**
       
   443 Gets the path for the file in message store for which the message Id is passed.
       
   444 @param aBodyTextId The Id of the body text for which the path is required.
       
   445 @param aFilepath The output parameter which contains filepath.
       
   446 @return none.
       
   447 */
       
   448 void TMsvServerStoreManager::BodyTextFilePathL(TMsvId aBodyTextId, TDes& aFilePath)
       
   449 	{
       
   450 	TFileName filePath;
       
   451 	User::LeaveIfError(GetFilePath(aBodyTextId, filePath));
       
   452 	aFilePath = filePath;
       
   453 	}
       
   454 
       
   455 /**
       
   456 Opens the RFile for which the aFilepath is passed in read mode.
       
   457 @param RFile   		Reference to RFile that needs to be opened.
       
   458 @param aBodyTextId 	The Id of the bodytext.
       
   459 @param aFilepath 	The path of the file to be opened.
       
   460 @return none.
       
   461 */
       
   462 void TMsvServerStoreManager::OpenBodyTextFileForReadL(RFile& aFile, TMsvId /*aBodyTextId*/, const TDesC& aFilePath)
       
   463 	{
       
   464 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   465 	
       
   466 	User::LeaveIfError(aFile.Open(*iFs, aFilePath, EFileRead));
       
   467 	}
       
   468 
       
   469 /**
       
   470 Creates the RFile in the aFilepath is passed.
       
   471 @param RFile     	Reference to RFile that will be created.
       
   472 @param aBodyTextId 	The Id of the bodytext.
       
   473 @return none.
       
   474 */
       
   475 void TMsvServerStoreManager::CreatePlainTextFileL(RFile& aFile, TMsvId aBodyTextId)
       
   476 	{
       
   477 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   478 	
       
   479 	TFileName filePathAndName;
       
   480 	GetFilePath(aBodyTextId, filePathAndName);
       
   481 	
       
   482 	TBuf<KFileNameFixedWidth> fileName;
       
   483 	
       
   484 	fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
       
   485 	filePathAndName.Append(fileName);
       
   486 	
       
   487 	TFileName tempFilePathAndName((filePathAndName));
       
   488 	tempFilePathAndName.Append(KMsvUtilsNewExtension);
       
   489 	User::LeaveIfError(aFile.Replace(*iFs, tempFilePathAndName, EFileShareExclusive|EFileWrite));
       
   490 	}
       
   491 
       
   492 /**
       
   493 Deletes the RFile in the aFilepath passed.
       
   494 @param aBodyTextId  The Id of the bodytext.
       
   495 @return none.
       
   496 */	
       
   497 void TMsvServerStoreManager::DeletePlainTextFileL(TMsvId aBodyTextId)
       
   498 	{
       
   499 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   500 	TFileName filePathAndName;
       
   501 	GetFilePath(aBodyTextId, filePathAndName);
       
   502 	
       
   503 	TBuf<KFileNameFixedWidth> fileName;
       
   504 	
       
   505 	fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
       
   506 	filePathAndName.Append(fileName);
       
   507 	
       
   508 	TFileName tempFilePathAndName((filePathAndName));
       
   509 	tempFilePathAndName.Append(KMsvUtilsNewExtension);
       
   510 	// Remove the temporary file if it is there.
       
   511 	TInt err = iFs->Delete(tempFilePathAndName);
       
   512 	
       
   513 	if (err != KErrNone && err != KErrNotFound)
       
   514 		{
       
   515 		User::Leave(err);
       
   516 		}
       
   517 	// There is no temporary file, delete the body text file.
       
   518 	if (err == KErrNotFound)
       
   519 		{
       
   520 		TInt error = iFs->Delete(filePathAndName);
       
   521 		if (error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
       
   522 			{
       
   523 			User::Leave(error);
       
   524 			}		
       
   525 		}
       
   526 	}
       
   527 
       
   528 /**
       
   529 Replaces a temporary RFile with a new RFile.
       
   530 @param aBodyTextId  The Id of the bodytext.
       
   531 @return none.
       
   532 */
       
   533 void TMsvServerStoreManager::ReplacePlainTextFileL(TMsvId aBodyTextId)
       
   534 	{
       
   535 	__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
       
   536 	TFileName filePathAndName;
       
   537 	GetFilePath(aBodyTextId, filePathAndName);
       
   538 	
       
   539 	TBuf<KFileNameFixedWidth> fileName;
       
   540 	
       
   541 	fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
       
   542 	filePathAndName.Append(fileName);
       
   543 	
       
   544 	TFileName tempFilePathAndName((filePathAndName));
       
   545 	tempFilePathAndName.Append(KMsvUtilsNewExtension);
       
   546 	TInt err = iFs->Replace(tempFilePathAndName,filePathAndName);
       
   547 	if(err != KErrNone)
       
   548 		{
       
   549 		iFs->Delete(tempFilePathAndName);
       
   550 		User::Leave(err);
       
   551 		}
       
   552 	}
       
   553 
       
   554 
       
   555 
       
   556 
       
   557 
       
   558 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
   559 /**
       
   560  * LoadHeaderL()
       
   561  * 
       
   562  * @param aMtmId : a MTM id.
       
   563  * @param aEntryId: Metadata entry Id of the message body.
       
   564  * @param iFieldPairList: Array of header fields.
       
   565  */
       
   566 
       
   567 void TMsvServerStoreManager::LoadHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, RPointerArray<CHeaderFields>& aFieldPairList)
       
   568 	{
       
   569 	iMsvServer->MessageDBAdapter().LoadHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
       
   570 	}
       
   571 	
       
   572 /**
       
   573  * DeleteHeaderL()
       
   574  *
       
   575  * 
       
   576  * @param aMtmId : a MTM id.
       
   577  * @param aEntryId: Metadata entry Id of the message body.
       
   578  */
       
   579 
       
   580 void TMsvServerStoreManager::DeleteHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId)
       
   581 	{
       
   582 	iMsvServer->MessageDBAdapter().DeleteHeaderEntryL(aMtmId,aEntryId);	
       
   583 	}
       
   584 
       
   585 
       
   586 /**
       
   587  * UpdateHeaderL()
       
   588  *
       
   589  * 
       
   590  * @param aMtmId : a MTM id.
       
   591  * @param aEntryId: Metadata entry Id of the message body.
       
   592  * @param iFieldPairList: Array of header fields.
       
   593  */
       
   594 
       
   595 void TMsvServerStoreManager::UpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
   596 	{
       
   597 	iMsvServer->MessageDBAdapter().UpdateHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
       
   598 	}
       
   599 
       
   600 /**
       
   601  * CreateHeaderEntryL()
       
   602  *
       
   603  * 
       
   604  * @param aMtmId : a MTM id.
       
   605  * @param aEntryId: Metadata entry Id of the message body.
       
   606  * @param iFieldPairList: Array of header fields.
       
   607  */
       
   608 
       
   609 void TMsvServerStoreManager::CreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
   610 	{
       
   611 	iMsvServer->MessageDBAdapter().CreateHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
       
   612 	}
       
   613 
       
   614 
       
   615 
       
   616 TBool TMsvServerStoreManager::DoesAnyStoreExists(TMsvId aId, TUid aMtmId)
       
   617 	{
       
   618 	TBool isStoreExists = EFalse;
       
   619 	TRAPD(err, isStoreExists = iMsvServer->MessageDBAdapter().DoesAnyStoreExistsL(aId, aMtmId));
       
   620 	if(err)
       
   621 		{
       
   622 		return EFalse;
       
   623 		}
       
   624 	else
       
   625 		{
       
   626 		return isStoreExists;
       
   627 		}
       
   628 
       
   629 	}
       
   630 
       
   631 TBool TMsvServerStoreManager::DoesHeaderTableExist(const TUid& aMtmId)
       
   632 	{
       
   633 	TBool doesTableExists = EFalse;
       
   634 	TRAPD(err, doesTableExists = iMsvServer->MessageDBAdapter().IsHeaderTableExistsL(aMtmId));
       
   635 	if(err)
       
   636 		{
       
   637 		return EFalse;
       
   638 		}
       
   639 	else
       
   640 		{
       
   641 		return doesTableExists;
       
   642 		}
       
   643 
       
   644 	}
       
   645 
       
   646 
       
   647 
       
   648 
       
   649 
       
   650 
       
   651 #endif			// #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)