email/pop3andsmtpmtm/clientmtms/src/cmsvsmtpsendoperation.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 //
       
    15 
       
    16 #include "cmsvsmtpsendoperation.h"
       
    17 #include "SMTPSET.H"
       
    18 
       
    19 CMsvSmtpProgressOperation* CMsvSmtpProgressOperation::NewL(CMsvSession& aMsvSession, 
       
    20 										const CMsvEntrySelection& aSelection, TInt aFunctionId, 
       
    21 										TDes8& aParameter, TRequestStatus& aObserverRequestStatus)
       
    22 	{
       
    23 	CMsvSmtpProgressOperation* self = new(ELeave) CMsvSmtpProgressOperation(aMsvSession, aObserverRequestStatus);
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL(aSelection, aFunctionId, aParameter);
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CMsvSmtpProgressOperation::CMsvSmtpProgressOperation(CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus) :
       
    31 	CMsvSendOperation(aMsvSession, aObserverRequestStatus)
       
    32 	{
       
    33 	}
       
    34 
       
    35 CMsvSmtpProgressOperation::~CMsvSmtpProgressOperation()
       
    36 	{
       
    37 	delete iSelection;
       
    38 	}
       
    39 
       
    40 void CMsvSmtpProgressOperation::ConstructL(const CMsvEntrySelection& aSelection, TInt aFunctionId, TDes8& aParameter)
       
    41 	{
       
    42 	iSelection = new (ELeave) CMsvEntrySelection;
       
    43 	
       
    44 	// Get the service ID for the message being sent and set as first entry in 
       
    45 	// selection. Append the rest of the entry IDs to the selection.
       
    46 	TMsvId notUsed;
       
    47 	TMsvEntry entry;
       
    48 	User::LeaveIfError(iMsvSession.GetEntry(aSelection.At(0), notUsed, entry));
       
    49 	
       
    50 	iSelection->AppendL(entry.iServiceId);
       
    51 	TInt count = aSelection.Count();
       
    52 	for( TInt i=0; i < count; ++i )
       
    53 		{
       
    54 		iSelection->AppendL(aSelection.At(i));
       
    55 		}
       
    56 
       
    57 	iOperation = iMsvSession.TransferCommandL(*iSelection, aFunctionId, aParameter, iStatus);
       
    58 	// assigns iMtm, iService and sets active
       
    59 	Start(iOperation);
       
    60 	}
       
    61 	
       
    62 const TDesC8& CMsvSmtpProgressOperation::TranslateProgress(const TDesC8& aProgress)
       
    63 	{
       
    64 	// convert SMTP progress into standard progress
       
    65 	TImSmtpProgress smtpProgress;
       
    66 	TPckg<TImSmtpProgress> smtpProgressBuf(smtpProgress);
       
    67 	smtpProgressBuf.Copy(aProgress);
       
    68 
       
    69 	// default progress info
       
    70 	iProgress().iProgressMax = 0;
       
    71 	iProgress().iProgress = 0;
       
    72 	
       
    73 	// translate state into send state
       
    74 	switch (smtpProgress.Status())
       
    75 		{
       
    76 		case EMsgOutboxProgressWaiting:
       
    77 			iProgress().iState = ESendStateWaitingToSend;
       
    78 			break;
       
    79 		case EMsgOutboxProgressConnecting:
       
    80 			iProgress().iState = ESendStateConnecting;
       
    81 			break;
       
    82 		case EMsgOutboxProgressSending:
       
    83 			iProgress().iState = ESendStateSending;
       
    84 			if (smtpProgress.iSendFileProgress.iSessionState == ESendingImail)
       
    85 				{
       
    86 				// get total bytes to send
       
    87 				iProgress().iProgressMax = smtpProgress.iSendFileProgress.iBytesToSend;
       
    88 				// get bytes sent
       
    89 				iProgress().iProgress = smtpProgress.iSendFileProgress.iBytesSent;
       
    90 				}
       
    91 			break;
       
    92 		case EMsgOutboxProgressDone:
       
    93 			iProgress().iState = ESendStateDone;
       
    94 			break;
       
    95 		}
       
    96 	// get error
       
    97 	iProgress().iError = smtpProgress.Error();
       
    98 
       
    99 	return iProgress;
       
   100 	}