messagingfw/msgtestfw/TestActions/Email/Smtp/src/CMtfTestActionSmtpRemoveEntryAttachmentById.cpp
changeset 0 8e480a14352b
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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // SmtpRemoveEntryAttachmentById
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // AttachmentId	  <input>: Attachment Id of attachment to remove.
       
    21 // ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
       
    22 // leave if not KErrNone
       
    23 // [Action Description]
       
    24 // Removes the specified entry attachment by its attachment Id. The
       
    25 // attachment is first checked to to ensure that it is an entry attachment and 
       
    26 // then removes it. An additional check is done to ensure that the actual 
       
    27 // entry still remains in the message store.
       
    28 // [APIs Used]
       
    29 // CMsvSession::GetEntryL
       
    30 // CImEmailMessage::AttachmentManagerL
       
    31 // MMsvAttachmentManager::GetAttachmentInfoL
       
    32 // __ACTION_INFO_END__
       
    33 // 
       
    34 //
       
    35 
       
    36 
       
    37 #include "CMtfTestActionSmtpRemoveEntryAttachmentById.h"
       
    38 #include "CMtfAsyncWaiter.h"
       
    39 #include "CMtfTestCase.h"
       
    40 #include "CMtfTestActionParameters.h"
       
    41 #include "MtfTestActionUtilsUser.h"
       
    42 
       
    43 #include <miutset.h>
       
    44 #include <miutmsg.h>
       
    45 #include <mmsvattachmentmanager.h>
       
    46 #include <cmsvattachment.h>
       
    47 
       
    48 CMtfTestAction* CMtfTestActionSmtpRemoveEntryAttachmentById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50 	CMtfTestActionSmtpRemoveEntryAttachmentById* self = new(ELeave) CMtfTestActionSmtpRemoveEntryAttachmentById(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 
       
    58 CMtfTestActionSmtpRemoveEntryAttachmentById::CMtfTestActionSmtpRemoveEntryAttachmentById(CMtfTestCase& aTestCase)
       
    59 	: CMtfSynchronousTestAction(aTestCase)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 CMtfTestActionSmtpRemoveEntryAttachmentById::~CMtfTestActionSmtpRemoveEntryAttachmentById()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CMtfTestActionSmtpRemoveEntryAttachmentById::ExecuteActionL()
       
    69 	{
       
    70 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpRemoveEntryAttachmentById);
       
    71 	TRAPD(err, RunTestL());
       
    72 	
       
    73 	if( ActionParameters().Count() < 4 )
       
    74 		{
       
    75 		User::LeaveIfError(err);
       
    76 		}
       
    77 	else
       
    78 		{
       
    79 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
       
    80 		}
       
    81 		
       
    82 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpRemoveEntryAttachmentById);
       
    83 	TestCase().ActionCompletedL(*this);
       
    84 	}
       
    85 	
       
    86 void CMtfTestActionSmtpRemoveEntryAttachmentById::RunTestL()
       
    87 	{
       
    88 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    89 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    90 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2));
       
    91 
       
    92 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    93 	CleanupStack::PushL(entry);
       
    94 	
       
    95 	CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry);
       
    96 	CleanupStack::PushL(emailMsg);
       
    97 	
       
    98 	MMsvAttachmentManager& manager = emailMsg->AttachmentManager();
       
    99 	
       
   100 	CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId);
       
   101 	CleanupStack::PushL(attachInfo);
       
   102 	
       
   103 	// First ensure that the attachment is a file attachment
       
   104 	if( attachInfo->Type() != CMsvAttachment::EMsvMessageEntry )
       
   105 		{
       
   106 		User::Leave(KErrGeneral);
       
   107 		}
       
   108 		
       
   109 	// Get the linked file
       
   110 	TMsvId msgId = attachInfo->EntryAttachmentId();
       
   111 	CleanupStack::PopAndDestroy(attachInfo);
       
   112 		
       
   113 	// Remove the attachment
       
   114 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
   115 	CleanupStack::PushL(waiter);
       
   116 	manager.RemoveAttachmentL(attachId, waiter->iStatus);
       
   117 	waiter->StartAndWait();
       
   118 	User::LeaveIfError(waiter->Result());
       
   119 	CleanupStack::PopAndDestroy(waiter);	
       
   120 	
       
   121 	CleanupStack::PopAndDestroy(2, entry); // email msg, entry
       
   122 
       
   123 	// Ensure that the message entry still exists
       
   124 	CMsvEntry* checkEntry = paramSession->GetEntryL(msgId);
       
   125 	delete checkEntry;
       
   126 	checkEntry = NULL;
       
   127 	}