emailservices/emailframework/commonlib/src/CFSMailMessagePart.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
--- a/emailservices/emailframework/commonlib/src/CFSMailMessagePart.cpp	Wed Sep 15 11:52:37 2010 +0300
+++ b/emailservices/emailframework/commonlib/src/CFSMailMessagePart.cpp	Wed Oct 13 14:11:15 2010 +0300
@@ -985,88 +985,99 @@
 // -----------------------------------------------------------------------------
 // CFSMailMessagePart::FindBodyPartL
 // -----------------------------------------------------------------------------
-EXPORT_C CFSMailMessagePart* CFSMailMessagePart::FindBodyPartL(const TDesC& aContentType)
-{
+EXPORT_C CFSMailMessagePart* CFSMailMessagePart::FindBodyPartL(
+        const TDesC& aContentType )
+    {
     FUNC_LOG;
 
-	TBuf<KMaxDataTypeLength> ptr;
-	if ( iContentType )
-    {
-		ptr.Copy(iContentType->Des());
-		TInt length = ptr.Locate(';');
-		if(length >= 0)
-			{
-			ptr.SetLength(length);
-			}
-		
-		if( !ptr.CompareF(aContentType) )
+    TBuf<KMaxDataTypeLength> ptr;
+    if ( iContentType )
+        {
+        ptr.Copy( iContentType->Des() );
+        TInt length = ptr.Locate(';');
+        if( length >= 0 )
+            {
+            ptr.SetLength( length );
+            }
+        if( !ptr.CompareF( aContentType ) )
+            {
+            return this;
+            }
+        }
+
+    CFSMailMessagePart* messagePart = NULL;	
+    CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetMessageId() );
+    if( plugin )
 		{
-			return this;
-		}
-    }
-
-	CFSMailMessagePart* messagePart = NULL;	
-
-	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
-		{
-		if(iReadMessageParts)
-			{
-			plugin->ChildPartsL(GetMailBoxId(),GetFolderId(),GetMessageId(),GetPartId(),iMessageParts);	
-			iReadMessageParts = EFalse;
-			}
-		if(iMessageParts.Count())
-		{
-			if( !ptr.CompareF(KFSMailContentTypeMultipartAlternative) )
+		if( iReadMessageParts )
 			{
-				// multipart / alternative
-				for(TInt i=0;i<iMessageParts.Count();i++)
-				{
-					ptr.Copy(iMessageParts[i]->GetContentType());
-					TInt length = ptr.Locate(';');
-					if(length >= 0)
-					{
-						ptr.SetLength(length);
-					}
-					if(!ptr.CompareF(aContentType) )
-					{
-						messagePart = iMessageParts[i];
-						// remove part from table
-						iMessageParts.Remove(i);
-						break;
-					}
-					else if(!ptr.CompareF(KFSMailContentTypeMultipartRelated) ||
-					   	 	!ptr.CompareF(KFSMailContentTypeMultipartMixed) ||
-							!ptr.CompareF(KFSMailContentTypeMultipartAlternative) ||
-							!ptr.CompareF(KFSMailContentTypeMultipartDigest) ||
-							!ptr.CompareF(KFSMailContentTypeMultipartParallel))
-					{
-						// multipart, check child parts
-						messagePart = iMessageParts[i];
-						// remove part from table
-						messagePart = messagePart->FindBodyPartL(aContentType);
-						if(messagePart && messagePart->GetPartId() == iMessageParts[0]->GetPartId())
-							{
-							iMessageParts.Remove(i);
-							}
-						break;
-					}					
-				}
+			plugin->ChildPartsL( GetMailBoxId(),
+			                     GetFolderId(),
+			                     GetMessageId(),
+			                     GetPartId(),
+			                     iMessageParts );	
+            iReadMessageParts = EFalse;
 			}
-			else
-			{
-				// all other cases
-				messagePart = iMessageParts[0];
-				// remove part from table
-				messagePart = messagePart->FindBodyPartL(aContentType);
-				if(messagePart && messagePart->GetPartId() == iMessageParts[0]->GetPartId())
-					{
-					iMessageParts.Remove(0);
-					}
-			}
+		if( iMessageParts.Count() )
+		    {
+            if( !ptr.CompareF( KFSMailContentTypeMultipartAlternative ) )
+                {
+                // multipart / alternative
+                for( TInt i=0; i<iMessageParts.Count(); i++ )
+                    {
+                    ptr.Copy( iMessageParts[i]->GetContentType() );
+                    TInt length = ptr.Locate(';');
+                    if( length >= 0 )
+                        {
+                        ptr.SetLength( length );
+                        }
+                    if( !ptr.CompareF( aContentType ) )
+                        {
+                        messagePart = iMessageParts[i];
+                        // remove part from table
+                        iMessageParts.Remove( i );
+                        break;
+                        }
+                    else if( !ptr.CompareF( KFSMailContentTypeMultipartRelated ) ||
+                             !ptr.CompareF( KFSMailContentTypeMultipartMixed ) ||
+                             !ptr.CompareF( KFSMailContentTypeMultipartAlternative ) ||
+                             !ptr.CompareF( KFSMailContentTypeMultipartDigest ) ||
+                             !ptr.CompareF( KFSMailContentTypeMultipartParallel ) )
+                        {
+                        // multipart, check child parts
+                        messagePart = iMessageParts[i];
+                        // remove part from table
+                        messagePart = 
+                                messagePart->FindBodyPartL( aContentType );
+                        if( messagePart && messagePart->GetPartId() == 
+                                    iMessageParts[i]->GetPartId() )
+                            {
+                            iMessageParts.Remove( i );
+                            }
+                        break;
+                        }					
+                    }
+                }
+            else
+                {
+                // all other cases
+                const TInt count = iMessageParts.Count();
+                for ( TInt i = 0; i < count && !messagePart; i++ )
+                    {
+                    messagePart = iMessageParts[i];
+                    // remove part from table
+                    messagePart = messagePart->FindBodyPartL( aContentType );
+                    if( messagePart && messagePart->GetPartId() == 
+                            iMessageParts[i]->GetPartId() )
+                        {
+                        iMessageParts.Remove( i );
+                        }
+                    }
+                }
+		    }
 		}
-	}
     return messagePart;
-}
+    }
 
 
 // -----------------------------------------------------------------------------