00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00037 #include "SendAs2Example.h"
00038
00039 _LIT(KBodyText, "You are limited only by your fears. Remember it is attitude, more than aptitude,that determines your altitude");
00040 _LIT(KAddress1, "ban-sindhub01@ban-sindhub01.intra");
00041 _LIT(KAddress3, "ban-sindhub01@ban-sindhub01.intra");
00042 _LIT(KAddress4, "test1@nokia.com");
00043 _LIT(KAlias1, "Alias1");
00044 _LIT(KAlias2, "Alias2");
00045 _LIT(KAccount1, " \n SendAs Account1 \n");
00046 _LIT(KAccount2, " \n SendAs Account2 \n");
00047 _LIT(KAccount3, " \n SendAs Account3 \n");
00048 _LIT(KAccountNames,"\n The list of accounts present are: \n");
00049 _LIT(KTextWelcome, " SendAs2 Example \n");
00050 _LIT(KTextStartApp, "\n Starting the SendAs2 Example application .... \n");
00051 _LIT(KTextPressAKey, "\n Press any key to step through the example .... \n");
00052 _LIT(KTextConn, "\n Connecting to sendAs server .... \n");
00053 _LIT(KTextErrInn, "\n Connection is successful\n");
00054 _LIT(KTextErrOut, "\n\n Connection has failed\n");
00055 _LIT(KTextCreate, "\n Creating a SendAs message .... \n");
00056 _LIT(KTextSend, "\n Sending the sendAs message .... \n");
00057 _LIT(KTextClose, "\n The SendAs message has been sent \n");
00058 _LIT(KPressAnyKey, "\n Press any key.... \n");
00059 _LIT(KExitKey, "\n Press any key to exit the application.... \n");
00060 _LIT(KSmsClient, "SMS Client");
00061
00066 CSendAs2Example* CSendAs2Example::NewL()
00067 {
00068 CSendAs2Example* self = new (ELeave) CSendAs2Example();
00069 CleanupStack::PushL(self);
00070 self->ConstructL();
00071 CleanupStack::Pop();
00072 return self;
00073 }
00074
00078 CSendAs2Example::CSendAs2Example()
00079 {
00080
00081 }
00082
00086 void CSendAs2Example::ConstructL()
00087 {
00088 iConsole = Console::NewL(KTextWelcome,TSize(KConsFullScreen,KConsFullScreen));
00089 iConsole->Printf ( KTextStartApp );
00090 iConsole->Printf ( KTextPressAKey );
00091 iConsole->Getch ();
00092 }
00093
00100 CSendAs2Example::~CSendAs2Example()
00101 {
00102 delete iSelection;
00103 iSelection = NULL;
00104
00105 delete iEntry;
00106 iEntry = NULL;
00107
00108 delete iSession;
00109 iSession = NULL;
00110
00111 delete iObserver;
00112 iObserver = NULL;
00113
00114 iSendAs.Close();
00115 delete iConsole;
00116 }
00117
00124 void CSendAs2Example::StartL()
00125 {
00126 iObserver = new(ELeave) CDummyObserver;
00127 iSession = CMsvSession::OpenSyncL(*iObserver);
00128
00129 TMsvId aFolderId = KMsvDraftEntryId;
00130 iEntry = CMsvEntry::NewL(*iSession, aFolderId,
00131 TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00132
00133 iSelection = iEntry->ChildrenL();
00134
00135 Connect();
00136 RSendAsMessage message;
00137 CleanMessageFolderL();
00138 CreateL(message);
00139 DisplayAccountL();
00140 CapabilityFilterL();
00141 SendL(message);
00142 }
00143
00150 void CSendAs2Example::Connect()
00151 {
00152 iConsole->Printf ( KTextConn );
00153 TInt err = iSendAs.Connect(KSendAsDefaultMessageSlots);
00154 if ( err == KErrNone)
00155 {
00156 iConsole->Printf ( KTextErrInn );
00157 }
00158 else
00159 {
00160 iConsole->Printf ( KTextErrOut );
00161 }
00162 }
00163
00167 void CSendAs2Example::CleanMessageFolderL()
00168 {
00169 TMsvLocalOperationProgress progress;
00170 if (iSelection->Count() > 0)
00171 {
00172 iEntry->DeleteL(*iSelection, progress);
00173 }
00174 }
00175
00180 void CSendAs2Example::CreateL( RSendAsMessage& aMessage)
00181 {
00182
00183 CSendAsMessageTypes* messageTypes = CSendAsMessageTypes::NewL();
00184 CleanupStack::PushL(messageTypes);
00185
00186
00187
00188 iSendAs.FilteredMessageTypesL(*messageTypes);
00189
00190 TUid sendAsMtmUid;
00191
00192
00193
00194
00195 sendAsMtmUid = messageTypes->UidFromNameL(KSmsClient);
00196
00197 CleanupStack::PopAndDestroy(messageTypes);
00198 iConsole->Printf ( KTextCreate );
00199
00200
00201 iEntry->SetEntryL(KMsvDraftEntryId);
00202
00203 aMessage.CreateL(iSendAs, sendAsMtmUid);
00204
00205
00206 aMessage.SetBodyTextL(KBodyText);
00207
00208 aMessage.AddRecipientL(KAddress1, KAlias1, RSendAsMessage::ESendAsRecipientTo);
00209 aMessage.AddRecipientL(KAddress3, RSendAsMessage::ESendAsRecipientCc);
00210 aMessage.AddRecipientL(KAddress4, KAlias2, RSendAsMessage::ESendAsRecipientCc);
00211
00212 CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvDraftEntryId,
00213 TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00214 CleanupStack::PushL(entry);
00215
00216
00217 entry->SetEntryL(KMsvDraftEntryId);
00218 if(iSelection->Count() >= 1)
00219 {
00220 entry->SetEntryL((*iSelection)[0]);
00221 };
00222
00223 CleanupStack::PopAndDestroy(entry);
00224 }
00225
00230 void CSendAs2Example::DisplayAccountL()
00231 {
00232 CSendAsAccounts* accounts = CSendAsAccounts::NewL();
00233 CleanupStack::PushL(accounts);
00234
00235
00236 if(accounts->Count()==0)
00237 {
00238 accounts->AppendAccountL(KAccount1, 0xaaaaaaaa);
00239 }
00240
00241 if(accounts->Count()==1)
00242 {
00243 accounts->AppendAccountL(KAccount2, 0x55555555);
00244 }
00245
00246 if(accounts->Count()==2)
00247 {
00248 accounts->AppendAccountL(KAccount3, 0x22222222);
00249 }
00250 iConsole->Printf( KAccountNames );
00251 iConsole->Printf ( KPressAnyKey );
00252 iConsole->Getch ();
00253
00254
00255 for(TInt i = 0; i < 3; i++)
00256 {
00257 TPtrC array = accounts->AccountNames().MdcaPoint(i);
00258 iConsole->Printf( array );
00259 }
00260
00261 CleanupStack::PopAndDestroy(accounts);
00262
00263 }
00264
00270 void CSendAs2Example::CapabilityFilterL()
00271 {
00272
00273
00274
00275 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQuerySupportAttachments));
00276 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQueryMaxBodySize, 0x10, RSendAs::ESendAsGreaterThan));
00277 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQuerySupportedBody, KMtm16BitBody, RSendAs::ESendAsBitwiseAnd));
00278 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQuerySupportedBody, KMtm16BitBody, RSendAs::ESendAsBitwiseAnd));
00279 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQuerySupportSubject));
00280 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQuerySupportsFolder));
00281 User::LeaveIfError(iSendAs.FilterAgainstCapability(KUidMtmQueryMaxRecipientCount));
00282 }
00283
00288 void CSendAs2Example::SendL(RSendAsMessage& aMessage)
00289 {
00290 iConsole->Printf ( KTextSend );
00291 iConsole->Printf ( KPressAnyKey );
00292 iConsole->Getch ();
00293
00294 CMsvOperationWait* wait = CMsvOperationWait::NewLC();
00295 wait->iStatus = KRequestPending;
00296 wait->Start();
00297
00298
00299
00300
00301
00302 aMessage.SendMessage(wait->iStatus);
00303
00304 CleanupStack::PopAndDestroy(wait);
00305 iConsole->Printf ( KTextClose );
00306 iConsole->Printf ( KExitKey );
00307 iConsole->Getch ();
00308 }
00309
00310 LOCAL_C void MainL()
00311 {
00312
00313 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00314
00315
00316
00317
00318 CActiveScheduler::Install( scheduler );
00319
00320 CSendAs2Example* app = CSendAs2Example::NewL();
00321 CleanupStack::PushL(app);
00322
00323 app->StartL();
00324 CleanupStack::PopAndDestroy(app);
00325
00326 delete scheduler;
00327 }
00328
00329 GLDEF_C TInt E32Main()
00330 {
00331 __UHEAP_MARK;
00332 CTrapCleanup* cleanup = CTrapCleanup::New();
00333 if(cleanup == NULL)
00334 {
00335 return KErrNoMemory;
00336 }
00337 TRAPD(err, MainL());
00338 if(err != KErrNone)
00339 {
00340 User::Panic(_L("failed to complete"),err);
00341 }
00342
00343 delete cleanup;
00344 __UHEAP_MARKEND;
00345 return KErrNone;
00346 }