messagingfw/sendas/client/src/rsendasmessage.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 <rsendasmessage.h>
       
    17 
       
    18 #include <s32mem.h>
       
    19 #include <txtrich.h>
       
    20 
       
    21 #include "sendasserverdefs.h"
       
    22 
       
    23 // Large enough to pass an sms message across in one transfer.
       
    24 const TInt KSendAs2BodyChunkSize = 512;
       
    25 
       
    26 /**
       
    27 Create a new message in the Drafts folder.
       
    28 
       
    29 The message type is implied by the type of the account used.
       
    30 The message can be modified or deleted by this object at any
       
    31 time up until the message is sent, deleted or opened in an editor.
       
    32 
       
    33 @param	aSendAs
       
    34 The connection to the SendAs server.  This RSendAs object must be
       
    35 connected.
       
    36 
       
    37 @param	aAccount
       
    38 An account obtained from the CSendAsAccounts helper class.
       
    39 */
       
    40 EXPORT_C void RSendAsMessage::CreateL(RSendAs& aSendAs, TSendAsAccount aAccount)
       
    41 	{
       
    42 	// create subsession with server.
       
    43 	User::LeaveIfError(CreateSubSession((RSessionBase&)aSendAs, ESASCreateSubSession));
       
    44 	
       
    45 	TPckgBuf<TSendAsAccount> buf(aAccount);
       
    46 	TInt createStatus = SendReceive(ESAMCreateForAccount, TIpcArgs(&buf));
       
    47 	if (createStatus != KErrNone)
       
    48 		{
       
    49 		CloseSubSession(ESAMDestroySubSession);
       
    50 		User::Leave(createStatus);
       
    51 		}
       
    52 	}
       
    53 	
       
    54 /**
       
    55 Create a new message in the Drafts folder.
       
    56 
       
    57 The message type is specified.
       
    58 The message can be modified or deleted by this object at any
       
    59 time up until the message is sent, deleted or opened in an editor.
       
    60 
       
    61 @param aSendAs
       
    62 The connection to the SendAs server.  This RSendAs object must be
       
    63 connected.
       
    64 
       
    65 @param aMessageType
       
    66 A message type obtained from the CSendAsMessageTypes helper class.
       
    67 */
       
    68 EXPORT_C void RSendAsMessage::CreateL(RSendAs& aSendAs, TUid aMessageType)
       
    69 	{
       
    70 	// create subsession with server
       
    71 	User::LeaveIfError(CreateSubSession((RSessionBase&)aSendAs, ESASCreateSubSession));
       
    72 	
       
    73 	TPckgBuf<TUid> buf(aMessageType);
       
    74 	TInt createStatus = SendReceive(ESAMCreateByType, TIpcArgs(&buf));
       
    75 	if (createStatus != KErrNone)
       
    76 		{
       
    77 		CloseSubSession(ESAMDestroySubSession);
       
    78 		User::Leave(createStatus);
       
    79 		}
       
    80 	}
       
    81 
       
    82 /**
       
    83 Close an open message and save it in the Drafts folder.
       
    84 */
       
    85 EXPORT_C void RSendAsMessage::SaveMessageAndCloseL()
       
    86 	{
       
    87 	User::LeaveIfError(SendReceive(ESAMSaveMessage, TIpcArgs()));
       
    88 	CloseSubSession(ESAMDestroySubSession);
       
    89 	}
       
    90 
       
    91 /**
       
    92 Close an open message and delete it from the Drafts folder.
       
    93 */
       
    94 EXPORT_C void RSendAsMessage::Close()
       
    95 	{
       
    96 	if (SubSessionHandle() != KNullHandle)
       
    97 		{
       
    98 		// don't attempt deletion if no subsession present (ie already closed/never opened)
       
    99 		SendReceive(ESAMDelete, TIpcArgs());
       
   100 		}
       
   101 	CloseSubSession(ESAMDestroySubSession);
       
   102 	}
       
   103 	
       
   104 /**
       
   105 Set the body text of this message using a CRichText object.
       
   106 The object must have an open message to use this method.
       
   107 
       
   108 @param aBody
       
   109 A CRichText object containing the body to add to the message being constructed.
       
   110 */
       
   111 EXPORT_C void RSendAsMessage::SetBodyTextL(const CRichText& aBody)
       
   112 	{
       
   113 	TInt textLength = aBody.DocumentLength();
       
   114 	TInt textPos = 0;
       
   115 
       
   116 	HBufC* bodyBuf = HBufC::NewLC(KSendAs2BodyChunkSize);
       
   117 	TPtr bodyPtr(bodyBuf->Des());
       
   118 	while (textPos < textLength)
       
   119 		{
       
   120 		aBody.Extract(bodyPtr, textPos, KSendAs2BodyChunkSize);
       
   121 		User::LeaveIfError(SendReceive(
       
   122 			textPos == 0 ? ESAMSetBodyFirst : ESAMSetBodyNext, TIpcArgs(&bodyPtr)));
       
   123 		textPos	+= KSendAs2BodyChunkSize;
       
   124 		}
       
   125 		CleanupStack::PopAndDestroy(bodyBuf);
       
   126 	}
       
   127 	
       
   128 /**
       
   129 Set the body text of this message using a plain descriptor.
       
   130 The object must have an open message to use this method.
       
   131 
       
   132 @param aBody
       
   133 A descriptor containing the body to add to the message being constructed.
       
   134 */
       
   135 EXPORT_C void RSendAsMessage::SetBodyTextL(const TDesC& aBody)
       
   136 	{
       
   137 	TInt textLength = aBody.Length();
       
   138 	TInt textPos = 0;
       
   139 
       
   140 	while (textPos < textLength)
       
   141 		{
       
   142 		TInt sizeLeft = textLength - textPos;
       
   143 		TPtrC bodyPtr(aBody.Mid(textPos, 
       
   144 			(KSendAs2BodyChunkSize >= sizeLeft) ? sizeLeft : KSendAs2BodyChunkSize));
       
   145 		User::LeaveIfError(SendReceive(
       
   146 			textPos == 0 ? ESAMSetBodyFirst : ESAMSetBodyNext, TIpcArgs(&bodyPtr)));
       
   147 
       
   148 		textPos	+= KSendAs2BodyChunkSize;
       
   149 		}
       
   150 	}
       
   151 	
       
   152 /**
       
   153 Set the subject of this message using a plain descriptor.
       
   154 The object must have an open message to use this method.
       
   155 
       
   156 @param aSubject
       
   157 A descriptor containing the subject for the message.
       
   158 */
       
   159 EXPORT_C void RSendAsMessage::SetSubjectL(const TDesC& aSubject)
       
   160 	{
       
   161 	User::LeaveIfError(SendReceive(ESAMSetSubject, TIpcArgs(&aSubject)));
       
   162 	}
       
   163 	
       
   164 /**
       
   165 Set the BIO type of this message.
       
   166 The object must have an open message to use this method.
       
   167 
       
   168 @param aBioType
       
   169 The biotype for this message.
       
   170 */
       
   171 EXPORT_C void RSendAsMessage::SetBioTypeL(TUid aBioType)
       
   172 	{
       
   173 	TPckgBuf<TUid> pckg(aBioType);
       
   174 	User::LeaveIfError(SendReceive(ESAMSetBioType, TIpcArgs(&pckg)));
       
   175 	}
       
   176 	
       
   177 /**
       
   178 Add a recipient to this message.
       
   179 The recipient's address is held in a descriptor, and is in the correct format for the
       
   180 message type.
       
   181 
       
   182 The recipient type is one of the TSendAsRecipientType constants, currently one of:
       
   183 ESendAsRecipientTo	-	The recipient goes in the 'To' field.
       
   184 ESendAsRecipientCc	-	The recipient goes in the 'Cc' field.
       
   185 ESendAsRecipientBcc	-	The recipient goes in the 'Bcc' field.
       
   186 
       
   187 If the 'Cc' field is not supported, the recipient will instead be added to the 'To'
       
   188 field since these are functionally equivalent.
       
   189 If the 'Bcc' field is not supported, this method will return KErrNotSupported.
       
   190 
       
   191 @param aAddress
       
   192 A descriptor holding the address of the recipient to add.
       
   193 
       
   194 @param aRecipientType
       
   195 The recipient type of the address being added. See above.
       
   196 */
       
   197 EXPORT_C void RSendAsMessage::AddRecipientL(const TDesC& aAddress, TSendAsRecipientType aRecipientType)
       
   198 	{
       
   199 	TPckgBuf<TSendAsRecipientType> pckg(aRecipientType);
       
   200 	User::LeaveIfError(SendReceive(ESAMAddRecipient, TIpcArgs(&aAddress, &pckg)));
       
   201 	}
       
   202 	
       
   203 /**
       
   204 Add a recipient with an alias to this message.
       
   205 The recipient's address is held in a descriptor, and is in the correct format for the
       
   206 message type.
       
   207 The alias is the displayed recipient name.
       
   208 
       
   209 The recipient type is one of the TSendAsRecipientType constants, currently one of:
       
   210 ESendAsRecipientTo	-	The recipient goes in the 'To' field.
       
   211 ESendAsRecipientCc	-	The recipient goes in the 'Cc' field.
       
   212 ESendAsRecipientBcc	-	The recipient goes in the 'Bcc' field.
       
   213 
       
   214 If the 'Cc' field is not supported, the recipient will instead be added to the 'To'
       
   215 field since these are functionally equivalent.
       
   216 If the 'Bcc' field is not supported, this method will return KErrNotSupported.
       
   217 
       
   218 @param aAddress
       
   219 A descriptor holding the address of the recipient to add.
       
   220 
       
   221 @param aAlias
       
   222 A descriptor holding the address alias of the recipient to add.
       
   223 
       
   224 @param aRecipientType
       
   225 The recipient type of the address being added. See above.
       
   226 */
       
   227 EXPORT_C void RSendAsMessage::AddRecipientL(const TDesC& aAddress, const TDesC& aAlias, TSendAsRecipientType aRecipientType)
       
   228 	{
       
   229 	TPckgBuf<TSendAsRecipientType> pckg(aRecipientType);
       
   230 	User::LeaveIfError(SendReceive(ESAMAddRecipientWithAlias, TIpcArgs(&aAddress, &aAlias, &pckg)));
       
   231 	}
       
   232 
       
   233 /**
       
   234 Add an attachment to this message asynchronously.
       
   235 
       
   236 A copy of the specified file is attached to message.
       
   237 
       
   238 @param aAttachmentFile
       
   239 The file being added to the message as an attachment.
       
   240 The file is closed if attached successfully. Ownership is transferred .The caller must close the file handle.
       
   241 
       
   242 @param aMimeType
       
   243 The mime type for this attachment.
       
   244 
       
   245 @param aCharset
       
   246 The charset for this attachment. The value is a standard IANA charset.
       
   247 
       
   248 @param aStatus
       
   249 Asynchronous status object (TRequestStatus) that is signalled when the
       
   250 operation completes. aStatus should be checked by the caller to ensure that the
       
   251 operation was successful.
       
   252 */
       
   253 EXPORT_C void RSendAsMessage::AddAttachment(RFile& aAttachmentFile, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus)
       
   254 	{
       
   255 	TInt err;
       
   256 	TIpcArgs args;
       
   257 	err = aAttachmentFile.TransferToServer(args, 0, 1);
       
   258 	if (err != KErrNone)
       
   259 		{
       
   260 		TRequestStatus* p = &aStatus;
       
   261 		User::RequestComplete(p, err);
       
   262 		}
       
   263 	else
       
   264 		{
       
   265 		// Perform synchronous operation to allow server to take ownership of the RFile.
       
   266 		err = SendReceive(ESAMTransferAttachmentFile, args);
       
   267 		if  (err != KErrNone)
       
   268 			{
       
   269 			TRequestStatus* p = &aStatus;
       
   270 			User::RequestComplete(p, err);
       
   271 			}
       
   272 		else
       
   273 			{
       
   274 			// Now it's safe to close the file.
       
   275 			aAttachmentFile.Close();
       
   276 			TIpcArgs args2;
       
   277 			// reuse the args
       
   278 			args2.Set(0, &aMimeType);	
       
   279 			args2.Set(1, aCharset); 	
       
   280 				
       
   281 			// Now perform async adding of transfered attachment
       
   282 			SendReceive(ESAMAddAttachmentWithType, args2, aStatus);
       
   283 			}
       
   284 		}
       
   285 	}
       
   286 	
       
   287 /**
       
   288 Add an attachment to this message asynchronously.
       
   289 
       
   290 A copy of the specified file is attached to message.
       
   291 
       
   292 @param aAttachmentFile
       
   293 The file being added to the message as an attachment. Ownership is transferred .The caller must close the file handle.
       
   294 
       
   295 
       
   296 @param aMimeType
       
   297 The mime type for this attachment.
       
   298 
       
   299 @param aStatus
       
   300 Asynchronous status object (TRequestStatus) that is signalled when the
       
   301 operation completes. aStatus should be checked by the caller to ensure that the
       
   302 operation was successful.
       
   303 */
       
   304 EXPORT_C void RSendAsMessage::AddAttachment(RFile& aAttachmentFile, const TDesC8& aMimeType, TRequestStatus& aStatus)
       
   305 	{
       
   306 	AddAttachment(aAttachmentFile, aMimeType, 0, aStatus);
       
   307 	}
       
   308 	
       
   309 /**
       
   310 Add an attachment to this message.
       
   311 The attachment is copied into the message store from the supplied file.
       
   312 
       
   313 @param aAttachmentFile
       
   314 The file being added to the message as an attachment. Ownership is transferred .The caller must close the file handle. 
       
   315 
       
   316 @param aStatus
       
   317 Asynchronous status object (TRequestStatus) that is signalled when the
       
   318 operation completes. aStatus should be checked by the caller to ensure that the
       
   319 operation was successful.
       
   320 */
       
   321 EXPORT_C void RSendAsMessage::AddAttachment(RFile& aAttachmentFile, TRequestStatus& aStatus)
       
   322 	{
       
   323 	TInt err;
       
   324 	TIpcArgs args;
       
   325 	err = aAttachmentFile.TransferToServer(args, 0, 1);
       
   326 	if (err != KErrNone)
       
   327 		{
       
   328 		TRequestStatus* p = &aStatus;
       
   329 		User::RequestComplete(p, err);
       
   330 		}
       
   331 	else
       
   332 		{
       
   333 		// Perform synchronous operation to allow server to take ownership of the RFile.
       
   334 		err = SendReceive(ESAMTransferAttachmentFile, args);
       
   335 		if  (err != KErrNone)
       
   336 			{
       
   337 			TRequestStatus* p = &aStatus;
       
   338 			User::RequestComplete(p, err);
       
   339 			}
       
   340 		else
       
   341 			{
       
   342 			// Now it's safe to close the file.
       
   343 			aAttachmentFile.Close();
       
   344 			// Now perform async adding of transfered attachment
       
   345 			SendReceive(ESAMAddAttachment, args, aStatus);
       
   346 			}
       
   347 		}
       
   348 	}
       
   349 
       
   350 /**
       
   351 Add an attachment to this message asynchronously.
       
   352 
       
   353 A copy of the specified file is attached to message.
       
   354 
       
   355 @param aAttachmentFilePath
       
   356 The file name and path for the file being added to the message as an attachment.
       
   357 
       
   358 @param aMimeType
       
   359 The mime type for this attachment.
       
   360 
       
   361 @param aCharset
       
   362 The charset for this attachment. The value is a standard IANA charset.
       
   363 
       
   364 @param aStatus
       
   365 Asynchronous status object (TRequestStatus) that is signalled when the
       
   366 operation completes. aStatus should be checked by the caller to ensure that the
       
   367 operation was successful.
       
   368 */	
       
   369 EXPORT_C void RSendAsMessage::AddAttachment(const TDesC& aAttachmentFilePath, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus)
       
   370 	{
       
   371 	TInt err;
       
   372 	RFs fs;
       
   373 	RFile file;
       
   374 
       
   375 	err = fs.Connect();
       
   376 	if (err == KErrNone)
       
   377 		{
       
   378 		err = fs.ShareProtected();
       
   379 		if (err == KErrNone)
       
   380 			{
       
   381 			err = file.Open(fs, aAttachmentFilePath, EFileRead | EFileShareReadersOnly);
       
   382 			if (err == KErrNone)
       
   383 				{
       
   384 				AddAttachment(file, aMimeType, aCharset, aStatus);
       
   385 				}
       
   386 			}
       
   387 		}
       
   388 	// On successful adding of an attachment, ownership of the file is
       
   389 	// transfered. Otherwise clean up must happen here.
       
   390 	if (err != KErrNone)
       
   391 		{
       
   392 		TRequestStatus* p = &aStatus;
       
   393 		file.Close();
       
   394 		User::RequestComplete(p, err);
       
   395 		}
       
   396 	fs.Close();
       
   397 	}
       
   398 
       
   399 /**
       
   400 Add an attachment to this message asynchronously.
       
   401 
       
   402 A copy of the specified file is attached to message.
       
   403 
       
   404 @param aAttachmentFilePath
       
   405 The file name and path for the file being added to the message as an attachment.
       
   406 
       
   407 @param aMimeType
       
   408 The mime type for this attachment.
       
   409 
       
   410 @param aStatus
       
   411 Asynchronous status object (TRequestStatus) that is signalled when the
       
   412 operation completes. aStatus should be checked by the caller to ensure that the
       
   413 operation was successful.
       
   414 */	
       
   415 EXPORT_C void RSendAsMessage::AddAttachment(const TDesC& aAttachmentFilePath, const TDesC8& aMimeType, TRequestStatus& aStatus)
       
   416 	{
       
   417 	AddAttachment(aAttachmentFilePath, aMimeType, 0, aStatus);
       
   418 	}
       
   419 
       
   420 /**
       
   421 Add an attachment to this message.
       
   422 The attachment is copied into the message store from the supplied filename.
       
   423 
       
   424 @param aAttachmentFilePath
       
   425 The file name and path for the file being added to the message as an attachment.
       
   426 
       
   427 @param aStatus
       
   428 Asynchronous status object (TRequestStatus) that is signalled when the
       
   429 operation completes. aStatus should be checked by the caller to ensure that the
       
   430 operation was successful.
       
   431 */
       
   432 EXPORT_C void RSendAsMessage::AddAttachment(const TDesC& aAttachmentFilePath, TRequestStatus& aStatus)
       
   433 	{
       
   434 	TInt err;
       
   435 	RFs fs;
       
   436 	RFile file;
       
   437 
       
   438 	err = fs.Connect();
       
   439 	if (err == KErrNone)
       
   440 		{
       
   441 		err = fs.ShareProtected();
       
   442 		if (err == KErrNone)
       
   443 			{
       
   444 			err = file.Open(fs, aAttachmentFilePath, EFileRead | EFileShareReadersOnly);
       
   445 			if (err == KErrNone)
       
   446 				{
       
   447 				AddAttachment(file, aStatus);
       
   448 				}
       
   449 			}
       
   450 		}
       
   451 	// On successful adding of an attachment, ownership of the file is
       
   452 	// transfered. Otherwise clean up must happen here.
       
   453 	if (err != KErrNone)
       
   454 		{
       
   455 		TRequestStatus* p = &aStatus;
       
   456 		file.Close();
       
   457 		User::RequestComplete(p, err);
       
   458 		}
       
   459 	fs.Close();
       
   460 	}
       
   461 
       
   462 /**
       
   463 Add an attachment to this message.
       
   464 The attachment is linked to the message from the supplied filename.  This file must be present
       
   465 when the message is sent.
       
   466 
       
   467 @param aLinkedAttachmentFile
       
   468 The file name and path for the file being added to the message as a linked attachment.
       
   469 
       
   470 @param aMimeType
       
   471 The mime type for this attachment.
       
   472 
       
   473 @param aCharset
       
   474 The charset for this attachment. The value is a standard IANA charset.
       
   475 
       
   476 @param aStatus
       
   477 Asynchronous status object (TRequestStatus) that is signalled when the
       
   478 operation completes. aStatus should be checked by the caller to ensure that the
       
   479 operation was successful.
       
   480 */
       
   481 EXPORT_C void RSendAsMessage::AddLinkedAttachment(const TDesC& aLinkedAttachmentFile, const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus)
       
   482 	{
       
   483 	SendReceive(ESAMAddLinkedAttachmentWithType, TIpcArgs(&aLinkedAttachmentFile, &aMimeType, aCharset), aStatus);
       
   484 	}
       
   485 	
       
   486 /**
       
   487 Add an attachment to this message asynchronously.
       
   488 
       
   489 The attachment is linked to the message from the supplied filename. This file must be present
       
   490 when the message is sent.
       
   491 
       
   492 @param aLinkedAttachmentFile
       
   493 The file name and path for the file being added to the message as a linked attachment.
       
   494 
       
   495 @param aMimeType
       
   496 The mime type for this attachment.
       
   497 
       
   498 @param aStatus
       
   499 Asynchronous status object (TRequestStatus) that is signalled when the
       
   500 operation completes. aStatus should be checked by the caller to ensure that the
       
   501 operation was successful.
       
   502 */
       
   503 EXPORT_C void RSendAsMessage::AddLinkedAttachment(const TDesC& aLinkedAttachmentFile, const TDesC8& aMimeType, TRequestStatus& aStatus)
       
   504 	{
       
   505 	AddLinkedAttachment(aLinkedAttachmentFile, aMimeType, 0, aStatus);
       
   506 	}
       
   507 	
       
   508 /**
       
   509 Add an attachment to this message asynchronously.
       
   510 
       
   511 The attachment is linked to the message from the supplied filename. This file must be present
       
   512 when the message is sent.
       
   513 
       
   514 @param aLinkedAttachmentFile
       
   515 The file name and path for the file being added to the message as a linked attachment.
       
   516 
       
   517 @param aStatus
       
   518 Asynchronous status object (TRequestStatus) that is signalled when the
       
   519 operation completes. aStatus should be checked by the caller to ensure that the
       
   520 operation was successful.
       
   521 */
       
   522 EXPORT_C void RSendAsMessage::AddLinkedAttachment(const TDesC& aLinkedAttachmentFile, TRequestStatus& aStatus)
       
   523 	{
       
   524 	SendReceive(ESAMAddLinkedAttachment, TIpcArgs(&aLinkedAttachmentFile), aStatus);
       
   525 	}
       
   526 
       
   527 /**
       
   528 Create an attachment to this message.
       
   529 The RFile object should not be open when this method is called.
       
   530 On return, the supplied RFile is able to write into the file.
       
   531 
       
   532 @param aFileName
       
   533 The filename to assign to the newly create attachment file. 
       
   534 
       
   535 @param aAttachmentFile
       
   536 The RFile which on return will be opened on the newly created attachment. Ownership is transferred .The caller must close the file handle. 
       
   537 @param aMimeType
       
   538 The mime type for this attachment.
       
   539 
       
   540 @param aCharset
       
   541 The charset for this attachment. The value is a standard IANA charset.
       
   542 */
       
   543 EXPORT_C void RSendAsMessage::CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, const TDesC8& aMimeType, TUint aCharset)
       
   544 	{
       
   545 	TIpcArgs args;
       
   546 	TPckgBuf<TInt> fileHandle;	
       
   547 	
       
   548 	User::LeaveIfError(SendReceive(ESAMCharSetInfoForAttachment, TIpcArgs(aCharset)));
       
   549 		
       
   550 	args.Set(0, &fileHandle);
       
   551 	args.Set(1, &aFileName);
       
   552 	args.Set(2, &aMimeType);
       
   553 
       
   554 	// session handle (RFs)received from TransferToClient() in server
       
   555 	TInt fileServerHandle = User::LeaveIfError(SendReceive(ESAMCreateAttachmentWithType, args));
       
   556 
       
   557 	// Retrieve the RFile handle from the server
       
   558 	// Take ownership of the new file from server
       
   559 	User::LeaveIfError(aAttachmentFile.AdoptFromServer(fileServerHandle, fileHandle()));
       
   560 	}
       
   561 	
       
   562 /**
       
   563 Create an attachment to this message.
       
   564 The RFile object should not be open when this method is called.
       
   565 On return, the supplied RFile is able to write into the file.
       
   566 
       
   567 @param aFileName
       
   568 The filename to assign to the newly create attachment file. 
       
   569 
       
   570 @param aAttachmentFile
       
   571 The RFile which on return will be opened on the newly created attachment.Ownership is transferred . The caller must close the file handle.
       
   572 
       
   573 @param aMimeType
       
   574 The mime type for this attachment.
       
   575 */
       
   576 EXPORT_C void RSendAsMessage::CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, const TDesC8& aMimeType)
       
   577 	{
       
   578 	CreateAttachmentL(aFileName, aAttachmentFile, aMimeType, 0);
       
   579 	}
       
   580 	
       
   581 /**
       
   582 Create an attachment to this message.
       
   583 The RFile object should not be open when this method is called.
       
   584 On return, the supplied RFile is able to write into the file.
       
   585 
       
   586 @param aFileName
       
   587 The filename to assign to the newly create attachment file. 
       
   588 
       
   589 @param aAttachmentFile
       
   590 The RFile which on return will be opened on the newly created attachment.Ownership is transferred .The caller must close the file handle.
       
   591 
       
   592 */
       
   593 EXPORT_C void RSendAsMessage::CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile)
       
   594 	{
       
   595 	TIpcArgs args;
       
   596 	TPckgBuf<TInt> fileHandle;
       
   597 	
       
   598 	args.Set(0, &fileHandle);
       
   599 	args.Set(1, &aFileName);
       
   600 
       
   601 	// session handle (RFs)received from TransferToClient() in server
       
   602 	TInt fileServerHandle = User::LeaveIfError(SendReceive(ESAMCreateAttachment, args));
       
   603 
       
   604 	// Retrieve the RFile handle from the server
       
   605 	// Take ownership of the new file from server
       
   606 	User::LeaveIfError(aAttachmentFile.AdoptFromServer(fileServerHandle, fileHandle()));
       
   607 	}
       
   608 	
       
   609 /**
       
   610 Asynchronously send this message.
       
   611 This method requests that the SendAs server send the message without prompting the
       
   612 user.  This will only be allowed to happen if the caller holds sufficient capabilities
       
   613 to perform this action. If the caller does not hold these capabilities, then the
       
   614 message send will be automatically demoted to a confirmed send.
       
   615 The RSendAsMessage API cannot modify the message if this method fails.
       
   616 
       
   617 @param aStatus
       
   618 Asynchronous status object (TRequestStatus) that is signalled when the
       
   619 operation completes. aStatus should be checked by the caller to ensure that the
       
   620 operation was successful.
       
   621 */
       
   622 EXPORT_C void RSendAsMessage::SendMessage(TRequestStatus& aStatus)
       
   623 	{
       
   624 	SendReceive(ESAMSendMessage, aStatus);
       
   625 	}
       
   626 	
       
   627 /**
       
   628 Asynchronously send this message.
       
   629 This method requests that the SendAs server send the message, prompting the user
       
   630 for confirmation.  This functionality must be supported by the UI MTM for the selected
       
   631 message type.
       
   632 The RSendAsMessage API cannot modify the message if this method fails.
       
   633 
       
   634 @param aStatus
       
   635 Asynchronous status object (TRequestStatus) that is signalled when the
       
   636 operation completes. aStatus should be checked by the caller to ensure that the
       
   637 operation was successful.
       
   638 */
       
   639 EXPORT_C void RSendAsMessage::SendMessageConfirmed(TRequestStatus& aStatus)
       
   640 	{
       
   641 	SendReceive(ESAMSendMessageConfirmed, aStatus);	
       
   642 	}
       
   643 	
       
   644 /**
       
   645 Sends this message in the background without confirmation and close the handle.
       
   646 This is a synchronous operation. This will only be allowed to happen if the
       
   647 caller holds sufficient capabilities to perform this action.  If the caller does
       
   648 not hold these capabilities, then the message send will be automatically demoted
       
   649 to a confirmed send. The RSendAsMessage API cannot modify or resend the message
       
   650 if this method fails. No progress information is available after calling this API.
       
   651 */
       
   652 EXPORT_C void RSendAsMessage::SendMessageAndCloseL()
       
   653 	{
       
   654 	// close message
       
   655 	User::LeaveIfError(SendReceive(ESAMSendMessageBackground));
       
   656 	CloseSubSession(ESAMDestroySubSession);
       
   657 	}
       
   658 	
       
   659 /**
       
   660 Sends this message in the background and close the handle to it. This is a 
       
   661 synchronous operation. This method requests that the SendAs server send the
       
   662 message, prompting the user for confirmation.  This functionality must be
       
   663 supported by the UI MTM for the selected message type.
       
   664 The RSendAsMessage API cannot modify or resend the message if this method fails.
       
   665 */
       
   666 EXPORT_C void RSendAsMessage::SendMessageConfirmedAndCloseL()
       
   667 	{
       
   668 	// close message
       
   669 	User::LeaveIfError(SendReceive(ESAMSendMessageConfirmedBackground));
       
   670 	CloseSubSession(ESAMDestroySubSession);
       
   671 	}
       
   672 	
       
   673 /**
       
   674 Retrieve the progress information for this message.
       
   675 This method can be called at any time after message creation.
       
   676 
       
   677 @param aProgress
       
   678 Progress information on current asynchronous operation.
       
   679 */
       
   680 EXPORT_C void RSendAsMessage::ProgressL(TSendAsProgress& aProgress)
       
   681 	{
       
   682 	if (SubSessionHandle() == KNullHandle)
       
   683 		{
       
   684 		User::Leave(KErrAbort);
       
   685 		}
       
   686 	TPckgBuf<TSendAsProgress> buf;
       
   687 	User::LeaveIfError(SendReceive(ESAMGetProgress, TIpcArgs(&buf)));
       
   688 	aProgress = buf();
       
   689 	}
       
   690 	
       
   691 /**
       
   692 Cancels any asynchronous request.
       
   693 
       
   694 Only a single asynchronous request is supported at any one time. This method
       
   695 cancels the current requests if any.
       
   696 */
       
   697 EXPORT_C void RSendAsMessage::Cancel()
       
   698 	{
       
   699 	SendReceive(ESAMCancel);
       
   700 	}
       
   701 	
       
   702 /**
       
   703 Opens the message in the associated message editor for the message type. 
       
   704 The RSendAsMessage handle is closed, so that the message cannot be 
       
   705 futher accessed through the object.
       
   706 */
       
   707 EXPORT_C void RSendAsMessage::LaunchEditorAndCloseL()
       
   708 	{
       
   709 	// close message
       
   710 	User::LeaveIfError(SendReceive(ESAMLaunchEditor));
       
   711 	CloseSubSession(ESAMDestroySubSession);
       
   712 	}
       
   713 
       
   714 /** 
       
   715 Sets the character encoding value. The character encoding value options are 7-bit,
       
   716 8-bit and 16-Bit Unicode.
       
   717 If this functionality is not supported by the sending MTM (currently for SMS it is supported), 
       
   718 it will leave with KErrExtensionNotSupported
       
   719 @param aCharset 					TUint, indicating the enocding value.
       
   720 @leave KErrExtensionNotSupported 	If the message is other than SMS.
       
   721 @leave Other 			 			Standard system-wide error codes.
       
   722 @return void
       
   723 */
       
   724    
       
   725 EXPORT_C void RSendAsMessage::SetCharacterSetL(const TUint aCharset)
       
   726 	{
       
   727 	TPckgBuf<TInt> pckg;
       
   728 	User::LeaveIfError(SendReceive(ESAMSetCharacterSet,TIpcArgs(aCharset, &pckg)));
       
   729 	User::LeaveIfError(pckg());
       
   730 	}