ipsservices/ipssosplugin/src/ipsplgsosbaseplugin.cpp
changeset 30 759dc5235cdb
parent 27 9ba4404ef423
child 44 c2d07d913565
equal deleted inserted replaced
27:9ba4404ef423 30:759dc5235cdb
    31 #define FREESTYLE_EMAIL_UI_SID 0x200255BA
    31 #define FREESTYLE_EMAIL_UI_SID 0x200255BA
    32 // </cmail> S60 UID update
    32 // </cmail> S60 UID update
    33 
    33 
    34 const TInt KOpGranularity = 2;
    34 const TInt KOpGranularity = 2;
    35 
    35 
    36 _LIT( KMimeTextCalRequest,  "text/calendar; method=REQUEST;" );
    36 // <qmail> remove unused literals
    37 _LIT( KMimeTextCalResponse, "text/calendar; method=RESPONSE;" );
       
    38 _LIT( KMimeTextCalCancel,   "text/calendar; method=CANCEL;" );
       
    39 _LIT8( KMethod, "method" );
       
    40 _LIT8( KRequest, "REQUEST" );
       
    41 _LIT8( KResponse, "RESPONSE" );
       
    42 _LIT8( KCancel, "CANCEL" );
       
    43 
    37 
    44 #ifdef __WINS__
    38 #ifdef __WINS__
    45 _LIT( KEmulatorIMEI, "123456789012345" );
    39 _LIT( KEmulatorIMEI, "123456789012345" );
    46 #endif // __WINS__
    40 #endif // __WINS__
    47 
    41 
   495             sel->AppendL( tEntry.Id() );
   489             sel->AppendL( tEntry.Id() );
   496             }
   490             }
   497         }
   491         }
   498     if( sel->Count() )
   492     if( sel->Count() )
   499         {
   493         {
   500         CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC();
   494         // <qmail> remove activeschedulerwait
       
   495         TMsvLocalOperationProgress progress;
   501         if( !aSourceFolderId.IsNullId() )
   496         if( !aSourceFolderId.IsNullId() )
   502             {
   497             {
   503             CMsvEntry* cEntry = iSession->GetEntryL( aSourceFolderId.Id() );
   498             CMsvEntry* cEntry = iSession->GetEntryL( aSourceFolderId.Id() );
   504             CleanupStack::PushL( cEntry );
   499             CleanupStack::PushL( cEntry );
   505             cEntry->MoveL(
   500             cEntry->MoveL( *sel, aDestinationFolderId.Id(), progress );
   506                 *sel,
       
   507                            aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
       
   508                            wait->iStatus );
       
   509 
       
   510             CleanupStack::PopAndDestroy( cEntry );
   501             CleanupStack::PopAndDestroy( cEntry );
   511             }
   502             }
   512         else
   503         else
   513             {
   504             {
   514             // Message is in editing state, we can't use parent as entry
   505             // Message is in editing state, we can't use parent as entry
   515             // because it's equal to destination.
   506             // because it's equal to destination.
   516             TMsvId parent = msgEntry->Entry().Parent();
   507             TMsvId parent = msgEntry->Entry().Parent();
   517             msgEntry->SetEntryL( parent );
   508             msgEntry->SetEntryL( parent );
   518             msgEntry->CopyL(
   509             msgEntry->CopyL( *sel, aDestinationFolderId.Id(), progress );
   519                 *sel,
   510             }
   520                              aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
   511         User::LeaveIfError( progress.iError );
   521                              wait->iStatus );
   512         // </qmail>
   522             }
       
   523         wait->Start();
       
   524         CleanupStack::PopAndDestroy( wait ); // wait
       
   525         }
   513         }
   526     CleanupStack::PopAndDestroy( 2, sel ); // msgEntry, sel
   514     CleanupStack::PopAndDestroy( 2, sel ); // msgEntry, sel
   527     }
   515     }
   528 
   516 
   529 // ----------------------------------------------------------------------------
   517 // ----------------------------------------------------------------------------
   808 	}
   796 	}
   809 
   797 
   810 // ----------------------------------------------------------------------------
   798 // ----------------------------------------------------------------------------
   811 // ----------------------------------------------------------------------------
   799 // ----------------------------------------------------------------------------
   812  CFSMailMessage* CIpsPlgSosBasePlugin::CreateMessageToSendL(
   800  CFSMailMessage* CIpsPlgSosBasePlugin::CreateMessageToSendL(
   813     const TFSMailMsgId& aMailBoxId )
   801     const TFSMailMsgId& /*aMailBoxId*/ )
   814 	{
   802 	{
   815     FUNC_LOG;
   803     // <qmail> not used any more
   816     CFSMailMessage* msg = iSmtpService->CreateNewSmtpMessageL( aMailBoxId );
   804     User::Leave(KErrFSMailPluginNotSupported);
   817 	return msg;
   805     return NULL; // prevents compiler warning
   818 	}
   806 	}
   819 
   807 
   820 // <qmail>
   808 // <qmail>
   821 // ----------------------------------------------------------------------------
   809 // ----------------------------------------------------------------------------
   822 // ----------------------------------------------------------------------------
   810 // ----------------------------------------------------------------------------
   849 // </qmail> 
   837 // </qmail> 
   850  
   838  
   851 // ----------------------------------------------------------------------------
   839 // ----------------------------------------------------------------------------
   852 // ----------------------------------------------------------------------------
   840 // ----------------------------------------------------------------------------
   853 CFSMailMessage* CIpsPlgSosBasePlugin::CreateForwardMessageL(
   841 CFSMailMessage* CIpsPlgSosBasePlugin::CreateForwardMessageL(
   854     const TFSMailMsgId& aMailBoxId,
   842     const TFSMailMsgId& /*aMailBoxId*/,
   855     const TFSMailMsgId& aOriginalMessageId,
   843     const TFSMailMsgId& /*aOriginalMessageId*/,
   856     const TDesC& aHeaderDescriptor )
   844     const TDesC& /*aHeaderDescriptor*/ )
   857     {
   845     {
   858     FUNC_LOG;
   846     // <qmail> not used any more
   859     CFSMailMessage* msg = iSmtpService->CreateForwardSmtpMessageL(
   847     User::Leave(KErrFSMailPluginNotSupported);
   860         aMailBoxId, aOriginalMessageId );
   848     return NULL; // prevents compiler warning
   861     
       
   862     if ( aHeaderDescriptor != KNullDesC )
       
   863         {
       
   864         // Ignoring trap as it is better to provide something in case of the
       
   865         // below fix method fails than nothing.
       
   866         TRAP_IGNORE( FixReplyForwardHeaderL( 
       
   867                         msg, 
       
   868                         aMailBoxId, 
       
   869                         aOriginalMessageId, 
       
   870                         aHeaderDescriptor ) );
       
   871         }
       
   872   
       
   873     return msg;
       
   874     }
   849     }
   875 
   850 
   876 // <qmail>
   851 // <qmail>
   877 // ----------------------------------------------------------------------------
   852 // ----------------------------------------------------------------------------
   878 // ----------------------------------------------------------------------------
   853 // ----------------------------------------------------------------------------
   927 // </qmail> 
   902 // </qmail> 
   928 
   903 
   929 // ----------------------------------------------------------------------------
   904 // ----------------------------------------------------------------------------
   930 // ---------------------------------------------------------------------------- 	
   905 // ---------------------------------------------------------------------------- 	
   931 CFSMailMessage* CIpsPlgSosBasePlugin::CreateReplyMessageL( 
   906 CFSMailMessage* CIpsPlgSosBasePlugin::CreateReplyMessageL( 
   932     const TFSMailMsgId& aMailBoxId,
   907     const TFSMailMsgId& /*aMailBoxId*/,
   933     const TFSMailMsgId& aOriginalMessageId,
   908     const TFSMailMsgId& /*aOriginalMessageId*/,
   934     const TBool aReplyToAll,
   909     const TBool /*aReplyToAll*/,
   935     const TDesC& aHeaderDescriptor )
   910     const TDesC& /*aHeaderDescriptor*/ )
   936     {
   911     {
   937     FUNC_LOG;
   912     // <qmail> not used any more
   938     CFSMailMessage* msg = iSmtpService->CreateReplySmtpMessageL(
   913     User::Leave(KErrFSMailPluginNotSupported);
   939         aMailBoxId, aOriginalMessageId, aReplyToAll );
   914     return NULL; // prevents compiler warning
   940 
       
   941     if ( aHeaderDescriptor != KNullDesC )
       
   942         {
       
   943         // Ignoring trap as it is better to provide something in case of the
       
   944         // below fix method fails than nothing.
       
   945         TRAP_IGNORE( FixReplyForwardHeaderL( 
       
   946                                 msg, 
       
   947                                 aMailBoxId, 
       
   948                                 aOriginalMessageId, 
       
   949                                 aHeaderDescriptor ) );
       
   950         }
       
   951 
       
   952     return msg;
       
   953     }
   915     }
   954 
   916 
   955 // <qmail>
   917 // <qmail>
   956 // ----------------------------------------------------------------------------
   918 // ----------------------------------------------------------------------------
   957 // ---------------------------------------------------------------------------- 	
   919 // ---------------------------------------------------------------------------- 	
  1149     }
  1111     }
  1150 
  1112 
  1151 // ----------------------------------------------------------------------------
  1113 // ----------------------------------------------------------------------------
  1152 // ----------------------------------------------------------------------------
  1114 // ----------------------------------------------------------------------------
  1153 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1115 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1154     const TFSMailMsgId& aMailBoxId,
  1116     const TFSMailMsgId& /*aMailBoxId*/,
  1155     const TFSMailMsgId& /* aParentFolderId */,
  1117     const TFSMailMsgId& /*aParentFolderId*/,
  1156     const TFSMailMsgId& aMessageId,
  1118     const TFSMailMsgId& /*aMessageId*/,
  1157     const TFSMailMsgId& /* aParentPartId */,
  1119     const TFSMailMsgId& /*aParentPartId*/,
  1158     const TDesC& aContentType,
  1120     const TDesC& /*aContentType*/,
  1159     const TDesC& aFilePath )
  1121     const TDesC& /*aFilePath*/ )
  1160     {
  1122     {
  1161     FUNC_LOG;
  1123     // <qmail> not used any more
  1162     CFSMailMessagePart* result ( NULL );
  1124     User::Leave(KErrFSMailPluginNotSupported);
  1163     CMsvEntry* cEntry( NULL );
  1125     return NULL; // prevents compiler warning
  1164     CImEmailMessage* message( NULL );
       
  1165     RFile file;
       
  1166     TInt fileSize( 0 );
       
  1167     TBool parentToMultipartAlternative( EFalse );
       
  1168 
       
  1169     // Read attachment size
       
  1170     User::LeaveIfError( file.Open( iSession->FileSession(), aFilePath, EFileShareReadersOnly ) );
       
  1171 
       
  1172     //in rare case that file has disappeared while sending
       
  1173     //we just won't get the size for it
       
  1174     file.Size( fileSize );
       
  1175     file.Close();
       
  1176 
       
  1177   // Take ownership of message entry objects since thanks to
       
  1178     // "clever" use of active scheduler waits we can re-enter 
       
  1179     // this function leading to crashes if somebody clears the cache
       
  1180     // while this iteration still needs them
       
  1181     TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
       
  1182 	
       
  1183     // Operation waiter needed to implement synchronous operation
       
  1184     // on the top of async API
       
  1185     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1186     CleanupStack::PushL( waiter );
       
  1187 
       
  1188     // Initialize CMsvAttachment instance for the attachment creation
       
  1189     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
  1190     CleanupStack::PushL( info );
       
  1191     info->SetAttachmentNameL( aFilePath );
       
  1192     info->SetSize( fileSize );
       
  1193 
       
  1194     // Start attachment creation
       
  1195     message->AttachmentManager().AddAttachmentL(
       
  1196         aFilePath, info, waiter->iStatus );
       
  1197     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1198 
       
  1199     waiter->Start();
       
  1200     CleanupStack::PopAndDestroy( waiter );
       
  1201     	
       
  1202     // Return message entry objects back to cache
       
  1203     CleanupStack::Pop( 2 ); // cEntry, message
       
  1204     ReturnMessageEntry( cEntry, message );
       
  1205 
       
  1206     // Dig out the entry ID of the new attachment (unbelievable that
       
  1207     // there seems to be no better way to do this)
       
  1208     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1209         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1210     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1211     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1212     attachmentIds->Sort( key );
       
  1213     if ( !attachmentIds->Count() )
       
  1214         {
       
  1215         User::Leave( KErrGeneral );
       
  1216         }
       
  1217     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1218     CleanupStack::PopAndDestroy( attachmentIds );
       
  1219 
       
  1220     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1221     CleanupStack::PushL( cAtta );
       
  1222 
       
  1223     // Set filename to iDetails
       
  1224     TMsvEntry tEntry = cAtta->Entry();
       
  1225     tEntry.iDetails.Set( aFilePath );
       
  1226     cAtta->ChangeL( tEntry );
       
  1227 
       
  1228     if( cAtta->HasStoreL() )
       
  1229         {
       
  1230         CMsvStore* store = cAtta->EditStoreL();
       
  1231         CleanupStack::PushL( store );
       
  1232         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1233 
       
  1234         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1235             {
       
  1236             mimeHeader->RestoreL( *store );
       
  1237             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1238             array.AppendL( KMethod );
       
  1239             parentToMultipartAlternative = ETrue;
       
  1240 
       
  1241             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1242                 {
       
  1243                 array.AppendL( KRequest );
       
  1244                 }
       
  1245             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1246                 {
       
  1247                 array.AppendL( KResponse );
       
  1248                 }
       
  1249             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1250                 {
       
  1251                 array.AppendL( KCancel );
       
  1252                 }
       
  1253             else
       
  1254                 {
       
  1255                 parentToMultipartAlternative = EFalse;
       
  1256                 }
       
  1257             mimeHeader->StoreWithoutCommitL( *store );
       
  1258             store->CommitL();
       
  1259             }
       
  1260 
       
  1261         CleanupStack::PopAndDestroy( 2, store );
       
  1262         }
       
  1263 
       
  1264     if( parentToMultipartAlternative &&
       
  1265         aFilePath.Find( _L(".ics")) != KErrNotFound )
       
  1266         {
       
  1267         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1268         TMsvId id = tAttaEntry.Parent();
       
  1269         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1270         CleanupStack::PushL( cParent );
       
  1271 
       
  1272         TMsvEmailEntry tEntry = cParent->Entry();
       
  1273         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1274         cParent->ChangeL( tEntry );
       
  1275 
       
  1276         CleanupStack::PopAndDestroy( cParent );
       
  1277         }
       
  1278     CleanupStack::PopAndDestroy( cAtta );
       
  1279 
       
  1280     // Delete the message entries to get all the changes to disk and
       
  1281     // possible store locks released
       
  1282     CleanCachedMessageEntries();
       
  1283 
       
  1284     // Create the FS message part object
       
  1285     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1286         aMessageId );
       
  1287 
       
  1288     return result;
       
  1289     }
  1126     }
  1290 
  1127 
  1291 // <qmail>
  1128 // <qmail>
  1292 // ----------------------------------------------------------------------------
       
  1293 // ----------------------------------------------------------------------------
       
  1294 // ----------------------------------------------------------------------------
  1129 // ----------------------------------------------------------------------------
  1295 // ----------------------------------------------------------------------------  
  1130 // ----------------------------------------------------------------------------  
  1296 void CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1131 void CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1297     const TFSMailMsgId& aMailBoxId,
  1132     const TFSMailMsgId& aMailBoxId,
  1298     const TFSMailMsgId& /* aParentFolderId */,
  1133     const TFSMailMsgId& /* aParentFolderId */,
  1319     watcher->SetOperation( op );
  1154     watcher->SetOperation( op );
  1320 
  1155 
  1321     iOperations.AppendL( watcher ); 
  1156     iOperations.AppendL( watcher ); 
  1322     CleanupStack::Pop( watcher );
  1157     CleanupStack::Pop( watcher );
  1323     }
  1158     }
  1324 
       
  1325 // </qmail> 
  1159 // </qmail> 
  1326 
  1160 
  1327 // ----------------------------------------------------------------------------
  1161 // ----------------------------------------------------------------------------
  1328 // ----------------------------------------------------------------------------  
  1162 // ----------------------------------------------------------------------------  
  1329 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1163 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1330     const TFSMailMsgId& aMailBoxId,
  1164     const TFSMailMsgId& /*aMailBoxId*/,
  1331     const TFSMailMsgId& /* aParentFolderId */,
  1165     const TFSMailMsgId& /*aParentFolderId*/,
  1332     const TFSMailMsgId& aMessageId,
  1166     const TFSMailMsgId& /*aMessageId*/,
  1333     const TFSMailMsgId& /* aParentPartId */,
  1167     const TFSMailMsgId& /*aParentPartId*/,
  1334     const TDesC& aContentType,
  1168     const TDesC& /*aContentType*/,
  1335     RFile& aFile )
  1169     RFile& /*aFile*/ )
  1336     {
  1170     {
  1337     FUNC_LOG;
  1171     // <qmail> not used any more
  1338 
  1172     User::Leave(KErrFSMailPluginNotSupported);
  1339     // Initialize helper variables
  1173     return NULL; // prevents compiler warning
  1340     CFSMailMessagePart* result ( NULL );
       
  1341     CMsvEntry* cEntry( NULL );
       
  1342     CImEmailMessage* message( NULL );
       
  1343     TInt fileSize( 0 );
       
  1344     TBuf<KMaxFileName> fileName;
       
  1345 
       
  1346  // Take ownership of message entry objects since thanks to
       
  1347     // "clever" use of active scheduler waits we can re-enter 
       
  1348     // this function leading to crashes if somebody clears the cache
       
  1349     // while this iteration still needs them
       
  1350     TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
       
  1351 
       
  1352     // Operation waiter needed to implement synchronous operation
       
  1353     // on the top of async API
       
  1354     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1355     CleanupStack::PushL( waiter );
       
  1356 
       
  1357     // Initialize CMsvAttachment instance for the attachment creation
       
  1358     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
  1359     CleanupStack::PushL( info );
       
  1360 
       
  1361     // Read attachment size
       
  1362     User::LeaveIfError( aFile.Size( fileSize ) );
       
  1363     info->SetSize( fileSize );
       
  1364 
       
  1365     // Read attachment filename
       
  1366     User::LeaveIfError( aFile.FullName( fileName ) );
       
  1367     info->SetAttachmentNameL( fileName );
       
  1368 
       
  1369     message->AttachmentManager().AddAttachmentL( aFile, info, waiter->iStatus );
       
  1370     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1371     
       
  1372     waiter->Start();
       
  1373     CleanupStack::PopAndDestroy( waiter );
       
  1374 
       
  1375  	// Return message entry objects back to cache
       
  1376  	CleanupStack::Pop( 2 ); // cEntry, message
       
  1377  	ReturnMessageEntry( cEntry, message );
       
  1378 
       
  1379     // Dig out the entry ID of the new attachment
       
  1380     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1381         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1382     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1383     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1384     attachmentIds->Sort( key );
       
  1385     if ( !attachmentIds->Count() )
       
  1386         {
       
  1387         User::Leave( KErrGeneral );
       
  1388         }
       
  1389     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1390     CleanupStack::PopAndDestroy( attachmentIds );
       
  1391 
       
  1392     // Meeting request related handling
       
  1393     TBool parentToMultipartAlternative( EFalse );
       
  1394     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1395     CleanupStack::PushL( cAtta );
       
  1396 
       
  1397     // Set filename to iDetails
       
  1398     TMsvEntry tEntry = cAtta->Entry();
       
  1399     tEntry.iDetails.Set( fileName );
       
  1400     cAtta->ChangeL( tEntry );
       
  1401 
       
  1402     if( cAtta->HasStoreL() )
       
  1403         {
       
  1404         CMsvStore* store = cAtta->EditStoreL();
       
  1405         CleanupStack::PushL( store );
       
  1406         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1407 
       
  1408         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1409             {
       
  1410             mimeHeader->RestoreL( *store );
       
  1411             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1412             array.AppendL( KMethod );
       
  1413             parentToMultipartAlternative = ETrue;
       
  1414 
       
  1415             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1416                 {
       
  1417                 array.AppendL( KRequest );
       
  1418                 }
       
  1419             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1420                 {
       
  1421                 array.AppendL( KResponse );
       
  1422                 }
       
  1423             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1424                 {
       
  1425                 array.AppendL( KCancel );
       
  1426                 }
       
  1427             else
       
  1428                 {
       
  1429                 parentToMultipartAlternative = EFalse;
       
  1430                 }
       
  1431             mimeHeader->StoreWithoutCommitL( *store );
       
  1432             store->CommitL();
       
  1433             }
       
  1434         CleanupStack::PopAndDestroy( 2, store );
       
  1435         }
       
  1436     if( parentToMultipartAlternative && fileName.Find( _L(".ics")) != KErrNotFound )
       
  1437         {
       
  1438         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1439         TMsvId id = tAttaEntry.Parent();
       
  1440         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1441         CleanupStack::PushL( cParent );
       
  1442 
       
  1443         TMsvEmailEntry tEntry = cParent->Entry();
       
  1444         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1445         cParent->ChangeL( tEntry );
       
  1446 
       
  1447         CleanupStack::PopAndDestroy( cParent );
       
  1448         }
       
  1449     CleanupStack::PopAndDestroy( cAtta );
       
  1450 
       
  1451     // Delete the message entries to get all the changes to disk and
       
  1452     // possible store locks released
       
  1453     CleanCachedMessageEntries();
       
  1454 
       
  1455     // Create the FS message part object and return it
       
  1456     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1457         aMessageId );
       
  1458     return result;
       
  1459     }
  1174     }
  1460 
  1175 
  1461 // ----------------------------------------------------------------------------
  1176 // ----------------------------------------------------------------------------
  1462 // ----------------------------------------------------------------------------
  1177 // ----------------------------------------------------------------------------
  1463 CFSMailMessagePart* CIpsPlgSosBasePlugin::CopyMessageAsChildPartL(
  1178 CFSMailMessagePart* CIpsPlgSosBasePlugin::CopyMessageAsChildPartL(
  1475 // Supports currently deletion of attachments and multipart structures
  1190 // Supports currently deletion of attachments and multipart structures
  1476 // which are represented as folders in Symbian store)
  1191 // which are represented as folders in Symbian store)
  1477 // ----------------------------------------------------------------------------
  1192 // ----------------------------------------------------------------------------
  1478 //
  1193 //
  1479 void CIpsPlgSosBasePlugin::RemoveChildPartL(
  1194 void CIpsPlgSosBasePlugin::RemoveChildPartL(
  1480     const TFSMailMsgId& /* aMailBoxId */,
  1195     const TFSMailMsgId& /*aMailBoxId*/,
  1481     const TFSMailMsgId& /* aParentFolderId */,
  1196     const TFSMailMsgId& /*aParentFolderId*/,
  1482     const TFSMailMsgId& aMessageId,
  1197     const TFSMailMsgId& /*aMessageId*/,
  1483     const TFSMailMsgId& /* aParentPartId */,
  1198     const TFSMailMsgId& /*aParentPartId*/,
  1484     const TFSMailMsgId& aPartId)
  1199     const TFSMailMsgId& /*aPartId*/)
  1485 	{
  1200 	{
  1486     FUNC_LOG;
  1201     // <qmail> not used any more
  1487     TInt status( KErrNone );
  1202     User::Leave(KErrFSMailPluginNotSupported);
  1488     CMsvEntry* cEntry( NULL );
       
  1489     TMsvEntry tEntry;
       
  1490     TMsvId serviceId;
       
  1491     status = iSession->GetEntry( aPartId.Id(), serviceId, tEntry );
       
  1492 
       
  1493     if ( ( status == KErrNone ) &&
       
  1494          ( tEntry.iType == KUidMsvAttachmentEntry ) )
       
  1495         {
       
  1496         CImEmailMessage* message( NULL );
       
  1497   
       
  1498         // We trust that the message ID really refers to a message
       
  1499         
       
  1500         // Take ownership of message entry objects since thanks to
       
  1501         // "clever" use of active scheduler waits we can re-enter 
       
  1502         // this function leading to crashes if somebody clears the cache
       
  1503         // while this iteration still needs them
       
  1504         TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
       
  1505 
       
  1506         MMsvAttachmentManager& attachmentMgr( message->AttachmentManager() );
       
  1507 
       
  1508         CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1509         CleanupStack::PushL( waiter );
       
  1510 
       
  1511         attachmentMgr.RemoveAttachmentL(
       
  1512             (TMsvAttachmentId) aPartId.Id(), waiter->iStatus );
       
  1513 
       
  1514         waiter->Start();
       
  1515         CleanupStack::PopAndDestroy( waiter );
       
  1516         	
       
  1517         // Return message entry objects to cache
       
  1518         CleanupStack::Pop( 2 ); // cEntry, message
       
  1519         ReturnMessageEntry( cEntry, message );
       
  1520         }
       
  1521     else if ( ( status == KErrNone ) &&
       
  1522               ( tEntry.iType == KUidMsvFolderEntry ) )
       
  1523         {
       
  1524         cEntry = iSession->GetEntryL( tEntry.Parent() );
       
  1525         CleanupStack::PushL( cEntry );
       
  1526         cEntry->DeleteL( tEntry.Id() );
       
  1527         CleanupStack::PopAndDestroy( cEntry );
       
  1528         }
       
  1529 	}
  1203 	}
  1530 
  1204 
  1531 // <qmail>
  1205 // <qmail>
  1532 // ----------------------------------------------------------------------------
  1206 // ----------------------------------------------------------------------------
  1533 // Supports currently deletion of attachments and multipart structures 
  1207 // Supports currently deletion of attachments and multipart structures 
  1771 	}
  1445 	}
  1772 
  1446 
  1773 // ----------------------------------------------------------------------------
  1447 // ----------------------------------------------------------------------------
  1774 // ----------------------------------------------------------------------------
  1448 // ----------------------------------------------------------------------------
  1775 void CIpsPlgSosBasePlugin::RemovePartContentL(
  1449 void CIpsPlgSosBasePlugin::RemovePartContentL(
  1776     const TFSMailMsgId& /* aMailBoxId */,
  1450     const TFSMailMsgId& /*aMailBoxId*/,
  1777     const TFSMailMsgId& /* aParentFolderId */,
  1451     const TFSMailMsgId& /*aParentFolderId*/,
  1778     const TFSMailMsgId& /* aMessageId */,
  1452     const TFSMailMsgId& /*aMessageId*/,
  1779     const RArray<TFSMailMsgId>& aPartIds )
  1453     const RArray<TFSMailMsgId>& /*aPartIds*/ )
  1780     {
  1454     {
  1781     TInt count( aPartIds.Count() );
  1455     // <qmail>
  1782 
  1456     User::Leave( KErrFSMailPluginNotSupported );
  1783     for( TInt i(0); i < count; i++ )
  1457     // </qmail>
  1784         {
       
  1785         CMsvEntry* cEntry = iSession->GetEntryL( aPartIds[i].Id() );
       
  1786         CleanupStack::PushL( cEntry );
       
  1787         CMsvStore* store = NULL;
       
  1788         TBool hasStore = cEntry->HasStoreL();
       
  1789         if ( hasStore )
       
  1790             {
       
  1791             store = cEntry->EditStoreL();
       
  1792             }
       
  1793 
       
  1794         if ( !store || !hasStore )
       
  1795             {
       
  1796             User::Leave( KErrNotFound );
       
  1797             }
       
  1798         CleanupStack::PushL( store );
       
  1799         MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
       
  1800 
       
  1801         // It is assumed that the attachment file is always in the index 0
       
  1802         if ( attachmentMgr.AttachmentCount() )
       
  1803             {
       
  1804             // delete attachment file
       
  1805             CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewLC();
       
  1806             attachmentMgr.RemoveAttachmentL( 0, waiter->iStatus );
       
  1807             waiter->Start();
       
  1808             CleanupStack::PopAndDestroy( waiter );
       
  1809             store->CommitL();
       
  1810 
       
  1811             // clear complete flag
       
  1812             TMsvEntry tEntry( cEntry->Entry() );
       
  1813             tEntry.SetComplete( EFalse );
       
  1814 
       
  1815             waiter = CIpsPlgOperationWait::NewLC();
       
  1816             CMsvOperation* ops = cEntry->ChangeL( tEntry, waiter->iStatus );
       
  1817             CleanupStack::PushL( ops );
       
  1818             waiter->Start();
       
  1819             CleanupStack::PopAndDestroy( 2, waiter );
       
  1820             }
       
  1821         else
       
  1822             {
       
  1823             User::Leave( KErrNotFound );
       
  1824             }
       
  1825         CleanupStack::PopAndDestroy( store );
       
  1826         CleanupStack::PopAndDestroy( cEntry );
       
  1827         }
       
  1828     }
  1458     }
  1829 
  1459 
  1830 // ----------------------------------------------------------------------------
  1460 // ----------------------------------------------------------------------------
  1831 // ----------------------------------------------------------------------------
  1461 // ----------------------------------------------------------------------------
  1832 void CIpsPlgSosBasePlugin::SetPartContentFromFileL(
  1462 void CIpsPlgSosBasePlugin::SetPartContentFromFileL(
  2069     CleanupStack::Pop( watcher );
  1699     CleanupStack::Pop( watcher );
  2070     //<qmail>
  1700     //<qmail>
  2071     CleanupStack::Pop( sel );
  1701     CleanupStack::Pop( sel );
  2072     //</qmail>
  1702     //</qmail>
  2073     }
  1703     }
       
  1704 
       
  1705 // <qmail>
       
  1706 // ----------------------------------------------------------------------------
       
  1707 // ----------------------------------------------------------------------------
       
  1708 void CIpsPlgSosBasePlugin::DeleteMessagesByUidL(
       
  1709     const TFSMailMsgId& /*aMailBoxId*/,
       
  1710     const TFSMailMsgId& /*aFolderId*/,
       
  1711 	const RArray<TFSMailMsgId>& aMessages,
       
  1712     MFSMailRequestObserver& aOperationObserver,
       
  1713     const TInt aRequestId)
       
  1714     {
       
  1715     FUNC_LOG;
       
  1716     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
       
  1717     CleanupStack::PushL(sel);
       
  1718 
       
  1719     TInt count = aMessages.Count();
       
  1720     TMsvEntry tEntry;
       
  1721     TMsvId service;
       
  1722     
       
  1723     for(TInt i=0; i<count; i++)
       
  1724         {
       
  1725         iSession->GetEntry( aMessages[i].Id(), service, tEntry );
       
  1726         //make sure that only messages get deleted.
       
  1727         if( tEntry.iType == KUidMsvMessageEntry )
       
  1728             {            
       
  1729             sel->AppendL( tEntry.Id() );
       
  1730             }
       
  1731         }
       
  1732         
       
  1733     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this );
       
  1734     CleanupStack::PushL( watcher );
       
  1735     CMsvOperation* op = CIpsPlgDeleteOperation::NewL( *iSession,
       
  1736         watcher->iStatus, sel, aOperationObserver, aRequestId );
       
  1737     watcher->SetOperation( op );
       
  1738     iOperations.AppendL( watcher );
       
  1739     CleanupStack::Pop( watcher );
       
  1740     CleanupStack::Pop( sel );
       
  1741     }
       
  1742 // </qmail>
  2074 
  1743 
  2075 // ----------------------------------------------------------------------------
  1744 // ----------------------------------------------------------------------------
  2076 // ----------------------------------------------------------------------------
  1745 // ----------------------------------------------------------------------------
  2077 void CIpsPlgSosBasePlugin::SubscribeMailboxEventsL(
  1746 void CIpsPlgSosBasePlugin::SubscribeMailboxEventsL(
  2078     const TFSMailMsgId& aMailboxId,
  1747     const TFSMailMsgId& aMailboxId,