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