emailservices/emailframework/src/CFSMailClient.cpp
changeset 59 16ed8d08d0b1
parent 54 997a02608b3a
child 65 478bc57ad291
--- a/emailservices/emailframework/src/CFSMailClient.cpp	Tue Jul 06 14:04:34 2010 +0300
+++ b/emailservices/emailframework/src/CFSMailClient.cpp	Wed Aug 18 09:37:47 2010 +0300
@@ -37,24 +37,28 @@
 {
     NM_FUNCTION;
 
-	CFSMailClient* client = Instance();
-	if(!client)
-	{
-		client = new (ELeave) CFSMailClient();
-		CleanupStack:: PushL(client);
-		client->ConstructL(aConfiguration);
-		TInt err = Dll::SetTls(static_cast<TAny*>(client));
-		User::LeaveIfError(err);
-		}
-	else
-		{
-		CleanupStack:: PushL(client);
-		}
+    CFSMailClient* client = Instance();
+    if( !client )
+        {
+        client = new (ELeave) CFSMailClient();
+        // The new client needs to be deleted rather than closed, up until
+        // the TLS has been set properly.
+        CleanupStack::PushL( client );
+        client->ConstructL( aConfiguration );
+        TInt err = Dll::SetTls( static_cast<TAny*>( client ));
+        User::LeaveIfError( err );
+        // Now that the TLS has been set, we no longer want the new client
+        // to be deleted if there's a problem, so pop it off the cleanup
+        // stack (it will be pushed back on for closing below).
+        CleanupStack::Pop( client );
+        }
 
-	client->IncReferenceCount();
-	
-	return client;
-
+    // Increment reference count before calling CleanupClosePushL so that
+    // the reference count is correct if CleanupClosePushL leaves.
+    client->IncReferenceCount();
+    CleanupClosePushL( *client );
+    
+    return client;
 } 
 
 // -----------------------------------------------------------------------------
@@ -138,6 +142,19 @@
 }
 
 // -----------------------------------------------------------------------------
+// CFSMailClient::GetMailBoxByUidLC
+// -----------------------------------------------------------------------------
+EXPORT_C CFSMailBox* CFSMailClient::GetMailBoxByUidLC(const TFSMailMsgId aMailBoxId)
+{
+    NM_FUNCTION;
+    CFSMailBox* mailBox = GetMailBoxByUidL( aMailBoxId );
+    CleanupStack::PushL( mailBox );
+    return mailBox;
+}
+
+
+
+// -----------------------------------------------------------------------------
 // CFSMailClient::GetFolderByUidL
 // -----------------------------------------------------------------------------
 EXPORT_C CFSMailFolder* CFSMailClient::GetFolderByUidL( const TFSMailMsgId aMailBoxId,
@@ -254,7 +271,7 @@
                         mailBox = plugin->GetMailBoxByUidL(mailBoxList[ii]) );
 				    if ( mailBox )
     				    {
-                        aMailBoxes.Append( mailBox );
+                        err = aMailBoxes.Append( mailBox );
                         }
 				// </cmail>
 					if(err != KErrNone)
@@ -294,7 +311,7 @@
                         mailBox = plugin->GetMailBoxByUidL(mailBoxList[i]) );
                     if ( mailBox )
                         {
-                        aMailBoxes.Append( mailBox );
+                        err = aMailBoxes.Append( mailBox );
                         }
                 // </cmail>				
 				if(err != KErrNone)
@@ -559,7 +576,23 @@
 		plugin->SetMailboxName( aMailboxId, aMailboxName );
 		}
 	}
-	
+
+// -----------------------------------------------------------------------------
+// CFSMailClient::PrepareMrDescriptionL
+// -----------------------------------------------------------------------------
+EXPORT_C void CFSMailClient::PrepareMrDescriptionL(  const TFSMailMsgId& aMailBoxId,
+                                                     const TFSMailMsgId& aMessageId )
+    {
+    NM_FUNCTION;
+    // select plugin
+    CFSMailPlugin* plugin = iFWImplementation->GetPluginManager().GetPluginByUid( aMessageId );
+    if ( plugin )
+        {
+        // set MR description from the plugin
+        plugin->PrepareMrDescriptionL( aMailBoxId, aMessageId );
+        }  
+    }
+
 // -----------------------------------------------------------------------------
 // CFSMailClient::Close
 // -----------------------------------------------------------------------------