messagingfw/msgtestfw/TestActions/Email/Smtp/src/CMtfTestActionSmtpRemoveFileAttachmentById.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 // SmtpRemoveFileAttachmentById
       
    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 file attachment by its attachment Id. The attachment
       
    25 // is first checked to to ensure that it is a file attachment and then
       
    26 // removes it.
       
    27 // [APIs Used]
       
    28 // CMsvSession::GetEntryL
       
    29 // CImEmailMessage::AttachmentManagerL
       
    30 // __ACTION_INFO_END__
       
    31 // 
       
    32 //
       
    33 
       
    34 
       
    35 #include "CMtfTestActionSmtpRemoveFileAttachmentById.h"
       
    36 #include "CMtfAsyncWaiter.h"
       
    37 #include "CMtfTestCase.h"
       
    38 #include "CMtfTestActionParameters.h"
       
    39 #include "MtfTestActionUtilsUser.h"
       
    40 
       
    41 #include <miutset.h>
       
    42 #include <mmsvattachmentmanager.h>
       
    43 #include <cmsvattachment.h>
       
    44 #include <miutmsg.h>
       
    45 
       
    46 CMtfTestAction* CMtfTestActionSmtpRemoveFileAttachmentById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    47 	{
       
    48 	CMtfTestActionSmtpRemoveFileAttachmentById* self = new(ELeave) CMtfTestActionSmtpRemoveFileAttachmentById(aTestCase);
       
    49 	CleanupStack::PushL(self);
       
    50 	self->ConstructL(aActionParameters);
       
    51 	CleanupStack::Pop();
       
    52 	return self;
       
    53 	}
       
    54 	
       
    55 
       
    56 CMtfTestActionSmtpRemoveFileAttachmentById::CMtfTestActionSmtpRemoveFileAttachmentById(CMtfTestCase& aTestCase)
       
    57 	: CMtfSynchronousTestAction(aTestCase)
       
    58 	{
       
    59 	}
       
    60 
       
    61 
       
    62 CMtfTestActionSmtpRemoveFileAttachmentById::~CMtfTestActionSmtpRemoveFileAttachmentById()
       
    63 	{
       
    64 	}
       
    65 
       
    66 void CMtfTestActionSmtpRemoveFileAttachmentById::ExecuteActionL()
       
    67 	{
       
    68 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpRemoveFileAttachmentById);
       
    69 	TRAPD(err, RunTestL());
       
    70 	
       
    71 	if( ActionParameters().Count() < 4 )
       
    72 		{
       
    73 		User::LeaveIfError(err);
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
       
    78 		}
       
    79 		
       
    80 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpRemoveFileAttachmentById);
       
    81 	TestCase().ActionCompletedL(*this); 
       
    82 	}
       
    83 
       
    84 void CMtfTestActionSmtpRemoveFileAttachmentById::RunTestL()
       
    85 	{
       
    86 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    87 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    88 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2));
       
    89 
       
    90 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    91 	CleanupStack::PushL(entry);
       
    92 	
       
    93 	CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry);
       
    94 	CleanupStack::PushL(emailMsg);
       
    95 	
       
    96 	MMsvAttachmentManager& manager = emailMsg->AttachmentManager();
       
    97 	
       
    98 	CMsvAttachment* attachmentInfo = manager.GetAttachmentInfoL(attachId);
       
    99 	CleanupStack::PushL(attachmentInfo);
       
   100 	
       
   101 	// First ensure that the attachment is a file attachment
       
   102 	if( attachmentInfo->Type() != CMsvAttachment::EMsvFile )
       
   103 		{
       
   104 		User::Leave(KErrGeneral);
       
   105 		}
       
   106 	
       
   107 	CleanupStack::PopAndDestroy(attachmentInfo);
       
   108 	
       
   109 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
   110 	CleanupStack::PushL(waiter);
       
   111 	
       
   112 	manager.RemoveAttachmentL(attachId, waiter->iStatus);
       
   113 	
       
   114 	waiter->StartAndWait();
       
   115 	User::LeaveIfError(waiter->Result());
       
   116 	
       
   117 	CleanupStack::PopAndDestroy(waiter);
       
   118 	
       
   119 	CleanupStack::PopAndDestroy(2, entry); // emailMsg, entry
       
   120 	}