Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/pop3_example_8cpp-source.html
Week 12 contribution of SDK documentation_content. See release notes for details. Fixes Bug 1892, Bug 1522, Bug 1520, Bug 394, Bug 1319, Bug 344, Bug 1897
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/Messaging/Pop3Example/pop3Example.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/Messaging/Pop3Example/pop3Example.cpp</h1><a href="pop3_example_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// This is a simple example code that demonstrates the usage of the POP3 protocol to retrieve emails.</span>
<a name="l00015"></a>00015 <span class="comment">// The code creates a simple SMTP mail, sends it and then retrieves the same using POP. </span>
<a name="l00016"></a>00016 <span class="comment">//</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018
<a name="l00019"></a>00019
<a name="l00023"></a>00023 <span class="preprocessor">#include "pop3Example.h"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="_pop3_example_2_m_async_waiter_8h.html">MAsyncWaiter.h</a>"</span>
<a name="l00025"></a>00025
<a name="l00026"></a>00026 _LIT(KTextPressAKey, <span class="stringliteral">"\n\n Press any key to step through the example"</span>);
<a name="l00027"></a>00027 _LIT(KExit,<span class="stringliteral">"\n\n Press any key to exit the application "</span>);
<a name="l00028"></a>00028 _LIT(KCreateMtm,<span class="stringliteral">"\n\n Creating a Pop3 client MTM"</span>);
<a name="l00029"></a>00029 _LIT(KKeyPress,<span class="stringliteral">"\n\n Press any key"</span>);
<a name="l00030"></a>00030 _LIT(KTxtAccountName, <span class="stringliteral">"PopAccount"</span>);
<a name="l00031"></a>00031 _LIT(KCreatePopAccount,<span class="stringliteral">"\n\n Creating a Pop account"</span>);
<a name="l00032"></a>00032 _LIT(KCreateSmtpAccount,<span class="stringliteral">"\n\n Creating an Smtp account"</span>);
<a name="l00033"></a>00033 _LIT(KSmtpServerAddress, <span class="stringliteral">"ban-sindhub01.intra"</span>);
<a name="l00034"></a>00034 _LIT(KEmailAlias, <span class="stringliteral">"Messaging example"</span>);
<a name="l00035"></a>00035 _LIT(KSmtpEmailAddress, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00036"></a>00036 _LIT8(KFrom, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00037"></a>00037 _LIT(KTo, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00038"></a>00038 _LIT(KSubject, <span class="stringliteral">"SimpleEmail"</span>);
<a name="l00039"></a>00039 _LIT(KBodyContents, <span class="stringliteral">"This is a very simple mail"</span>);
<a name="l00040"></a>00040 _LIT(KSendMail,<span class="stringliteral">"\n\n Sending the mail... please wait"</span>);
<a name="l00041"></a>00041 _LIT(KPopServer, <span class="stringliteral">"ban-sindhub01.intra"</span>);
<a name="l00042"></a>00042 _LIT8(KPopPassword,<span class="stringliteral">"ban-sindhub01"</span>);
<a name="l00043"></a>00043 _LIT8(KPopLoginName,<span class="stringliteral">"ban-sindhub01"</span>);
<a name="l00044"></a>00044 _LIT(KWait,<span class="stringliteral">"\n\n Connecting to pop3 server"</span>);
<a name="l00045"></a>00045 _LIT(KDownload,<span class="stringliteral">"\n\n Downloading mail from the pop3 server"</span>);
<a name="l00046"></a>00046 _LIT(KDisconnect,<span class="stringliteral">"\n\n Press any key to disconnect"</span>);
<a name="l00047"></a>00047
<a name="l00052"></a><a class="code" href="class_c_pop3_example.html#b349920e1fdb72d5dbf6186c52d319b6">00052</a> <a class="code" href="class_c_pop3_example.html">CPop3Example</a>* <a class="code" href="class_c_pop3_example.html#b349920e1fdb72d5dbf6186c52d319b6">CPop3Example::NewL</a>()
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054 <a class="code" href="class_c_pop3_example.html">CPop3Example</a>* <span class="keyword">self</span> = <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_pop3_example.html">CPop3Example</a>();
<a name="l00055"></a>00055 CleanupStack::PushL(<span class="keyword">self</span>);
<a name="l00056"></a>00056 <span class="keyword">self</span>->ConstructL();
<a name="l00057"></a>00057 CleanupStack::Pop();
<a name="l00058"></a>00058 <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00059"></a>00059 }
<a name="l00063"></a>00063 CPop3Example::CPop3Example()
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00068"></a>00068 <span class="keywordtype">void</span> CPop3Example::ConstructL()
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00071"></a>00071 iConsole->Printf ( KTextPressAKey );
<a name="l00072"></a>00072 iConsole->Getch ();
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074
<a name="l00078"></a><a class="code" href="class_c_pop3_example.html#401645654f38c3e601b09ff84d6fd033">00078</a> <a class="code" href="class_c_pop3_example.html#401645654f38c3e601b09ff84d6fd033">CPop3Example::~CPop3Example</a>()
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080 iConsole->Printf(KExit);
<a name="l00081"></a>00081 iConsole->Getch();
<a name="l00082"></a>00082 <span class="keyword">delete</span> iMtm;
<a name="l00083"></a>00083 iMtm = NULL;
<a name="l00084"></a>00084 <span class="keyword">delete</span> iClientRegistry;
<a name="l00085"></a>00085 iClientRegistry = NULL;
<a name="l00086"></a>00086 <span class="keyword">delete</span> iSession;
<a name="l00087"></a>00087 iSession = NULL;
<a name="l00088"></a>00088 <span class="keyword">delete</span> iConsole;
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090
<a name="l00096"></a><a class="code" href="class_c_pop3_example.html#071be1033b73bd98a19978d4bd90b7fb">00096</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#071be1033b73bd98a19978d4bd90b7fb">CPop3Example::CreateClientRegistryL</a>()
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098 <span class="comment">// Create a message server session.</span>
<a name="l00099"></a>00099 iSession = CMsvSession::OpenSyncL(*<span class="keyword">this</span>);
<a name="l00100"></a>00100 CleanupStack::PushL(iSession);
<a name="l00101"></a>00101
<a name="l00102"></a>00102 <span class="comment">// Create a client-side MTM registry.</span>
<a name="l00103"></a>00103 iClientRegistry = CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32);
<a name="l00104"></a>00104 <span class="keywordflow">if</span> (iClientRegistry != NULL && iClientRegistry->IsPresent(KUidMsgTypePOP3))
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 CleanupStack::PushL(iClientRegistry);
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 <span class="comment">// Create a Client-side MTM object for the specified MTM UID.</span>
<a name="l00109"></a>00109 iMtm = (CPop3ClientMtm*)iClientRegistry->NewMtmL(KUidMsgTypePOP3);
<a name="l00110"></a>00110 iConsole->Printf(KCreateMtm);
<a name="l00111"></a>00111 iConsole->Printf(KKeyPress);
<a name="l00112"></a>00112 iConsole->Getch();
<a name="l00113"></a>00113 CleanupStack::Pop(2,iSession); <span class="comment">//iClientRegistry,iSession</span>
<a name="l00114"></a>00114
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116
<a name="l00122"></a><a class="code" href="class_c_pop3_example.html#e1b7a4e38a8771d202c637adb12302c2">00122</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#e1b7a4e38a8771d202c637adb12302c2">CPop3Example::CreatePopAndSmtpAccountL</a>()
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124 CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
<a name="l00125"></a>00125 CImPop3Settings* settings = <span class="keyword">new</span>(ELeave) CImPop3Settings();
<a name="l00126"></a>00126 CleanupStack::PushL(settings);
<a name="l00127"></a>00127
<a name="l00128"></a>00128 CImIAPPreferences* popIAP = CImIAPPreferences::NewLC();
<a name="l00129"></a>00129
<a name="l00130"></a>00130 <span class="comment">// Set the server address to system address</span>
<a name="l00131"></a>00131 settings->SetServerAddressL(KPopServer);
<a name="l00132"></a>00132 settings->SetLoginNameL(KPopLoginName);
<a name="l00133"></a>00133 settings->SetPasswordL(KPopPassword);
<a name="l00134"></a>00134 settings->SetPort(110);
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <span class="comment">// Create a Pop account</span>
<a name="l00137"></a>00137 iConsole->Printf(KCreatePopAccount);
<a name="l00138"></a>00138 iPopAccount = emailAccounts->CreatePopAccountL(KTxtAccountName, *settings,*popIAP,EFalse);
<a name="l00139"></a>00139
<a name="l00140"></a>00140 CImSmtpSettings *smtpSettings = <span class="keyword">new</span> (ELeave) CImSmtpSettings();
<a name="l00141"></a>00141 CleanupStack::PushL(smtpSettings);
<a name="l00142"></a>00142
<a name="l00143"></a>00143 emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *popIAP);
<a name="l00144"></a>00144
<a name="l00145"></a>00145 <span class="comment">// Create an Smtp acoount</span>
<a name="l00146"></a>00146 iConsole->Printf(KCreateSmtpAccount);
<a name="l00147"></a>00147 iSmtpAccount = emailAccounts->CreateSmtpAccountL(iPopAccount, *smtpSettings, *popIAP, EFalse);
<a name="l00148"></a>00148
<a name="l00149"></a>00149 emailAccounts->SetDefaultSmtpAccountL(iSmtpAccount);
<a name="l00150"></a>00150
<a name="l00151"></a>00151 smtpSettings->SetServerAddressL(KSmtpServerAddress);
<a name="l00152"></a>00152 smtpSettings->SetEmailAliasL(KEmailAlias);
<a name="l00153"></a>00153 smtpSettings->SetEmailAddressL(KSmtpEmailAddress);
<a name="l00154"></a>00154 smtpSettings->SetReplyToAddressL(KSmtpEmailAddress);
<a name="l00155"></a>00155 smtpSettings->SetReceiptAddressL(KSmtpEmailAddress);
<a name="l00156"></a>00156 smtpSettings->SetPort(25);
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="comment">// Add IAP to the IAP preferences</span>
<a name="l00159"></a>00159 CImIAPPreferences* prefs = CImIAPPreferences::NewLC();
<a name="l00160"></a>00160 TImIAPChoice iap;
<a name="l00161"></a>00161 TInt iapID = 0;
<a name="l00162"></a>00162 CMDBSession* dbSession = CMDBSession::NewL(KCDVersion1_1);
<a name="l00163"></a>00163 CleanupStack::PushL(dbSession);
<a name="l00164"></a>00164 CCDConnectionPrefsRecord *connPrefRecord = <span class="keyword">static_cast<</span>CCDConnectionPrefsRecord*<span class="keyword">></span>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord));
<a name="l00165"></a>00165 CleanupStack::PushL(connPrefRecord);
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="comment">// Set the direction of connection</span>
<a name="l00168"></a>00168 connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing;
<a name="l00169"></a>00169 connPrefRecord->iRanking = 1;
<a name="l00170"></a>00170 <span class="keywordflow">if</span>(!connPrefRecord->FindL(*dbSession))
<a name="l00171"></a>00171 {
<a name="l00172"></a>00172 User::Leave(KErrNotFound);
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 iapID = connPrefRecord->iDefaultIAP;
<a name="l00175"></a>00175 iap.iIAP = iapID;
<a name="l00176"></a>00176 iap.iDialogPref = ECommDbDialogPrefDoNotPrompt;
<a name="l00177"></a>00177 prefs->AddIAPL(iap);
<a name="l00178"></a>00178
<a name="l00179"></a>00179 emailAccounts->GetSmtpAccountL(iSmtpAccount.iSmtpService, iSmtpAccount);
<a name="l00180"></a>00180 emailAccounts->SaveSmtpSettingsL(iSmtpAccount,*smtpSettings);
<a name="l00181"></a>00181 emailAccounts->SaveSmtpIapSettingsL(iSmtpAccount, *prefs);
<a name="l00182"></a>00182
<a name="l00183"></a>00183 CleanupStack::PopAndDestroy(7,emailAccounts); <span class="comment">//connPrefRecord,dbSession,prefs,smtpSettings,popIAP,settings,emailAccounts</span>
<a name="l00184"></a>00184 }
<a name="l00185"></a>00185
<a name="l00190"></a><a class="code" href="class_c_pop3_example.html#4e14514a9a39eee71b372edc85a93b17">00190</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#4e14514a9a39eee71b372edc85a93b17">CPop3Example::CreateSmtpMessageL</a>()
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192
<a name="l00193"></a>00193 TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId;
<a name="l00194"></a>00194
<a name="l00195"></a>00195 <span class="comment">// Set the context to the folder in which message has to be created</span>
<a name="l00196"></a>00196 CMsvEntry* entry = CMsvEntry::NewL(*iSession,outboxId,TMsvSelectionOrdering());
<a name="l00197"></a>00197 CleanupStack::PushL(entry);
<a name="l00198"></a>00198 entry->SetEntryL(outboxId);
<a name="l00199"></a>00199
<a name="l00200"></a>00200 <a class="code" href="class_c_mess_async_waiter.html">CMessAsyncWaiter</a>* waiter = <a class="code" href="class_c_mess_async_waiter.html#fcb5bdc70a5f6a134afdaf7af207a038">CMessAsyncWaiter::NewL</a>();
<a name="l00201"></a>00201 CleanupStack::PushL(waiter);
<a name="l00202"></a>00202
<a name="l00203"></a>00203 TMsvEmailTypeList msvEmailTypeList = 0;
<a name="l00204"></a>00204 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments);
<a name="l00205"></a>00205
<a name="l00206"></a>00206 CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(waiter->iStatus, *iSession,KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP);
<a name="l00207"></a>00207 CleanupStack::PushL(emailOperation);
<a name="l00208"></a>00208 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00209"></a>00209
<a name="l00210"></a>00210 TMsvId temp;
<a name="l00211"></a>00211 TPckgC<TMsvId> paramPack(temp);
<a name="l00212"></a>00212 <span class="keyword">const</span> TDesC8& progBuf = emailOperation->ProgressL();
<a name="l00213"></a>00213 paramPack.Set(progBuf);
<a name="l00214"></a>00214 TMsvId newMessageId;
<a name="l00215"></a>00215 newMessageId = paramPack();
<a name="l00216"></a>00216
<a name="l00217"></a>00217 entry->SetEntryL(newMessageId);
<a name="l00218"></a>00218
<a name="l00219"></a>00219 CMsvStore* store = entry->EditStoreL();
<a name="l00220"></a>00220 CleanupStack::PushL(store);
<a name="l00221"></a>00221 CImHeader* emailEntry = CImHeader::NewLC();
<a name="l00222"></a>00222 emailEntry->RestoreL(*store);
<a name="l00223"></a>00223 emailEntry->SetFromL((TDesC8&)KFrom);
<a name="l00224"></a>00224 emailEntry->SetSubjectL((TDesC&)KSubject);
<a name="l00225"></a>00225 emailEntry->ToRecipients().AppendL((TDesC&)KTo);
<a name="l00226"></a>00226
<a name="l00227"></a>00227 <span class="comment">// Paragraph format layer for the rich text object </span>
<a name="l00228"></a>00228 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
<a name="l00229"></a>00229 CleanupStack::PushL(paraFormatLayer);
<a name="l00230"></a>00230 <span class="comment">// Character format layer for the rich text object</span>
<a name="l00231"></a>00231 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
<a name="l00232"></a>00232 CleanupStack::PushL(charFormatLayer);
<a name="l00233"></a>00233
<a name="l00234"></a>00234 CRichText* bodyText = CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256);
<a name="l00235"></a>00235 CleanupStack::PushL(bodyText);
<a name="l00236"></a>00236
<a name="l00237"></a>00237 <span class="comment">// Inserts the contents of a buffer into the document at specified position</span>
<a name="l00238"></a>00238 bodyText->InsertL(0, KBodyContents);
<a name="l00239"></a>00239 store->StoreBodyTextL(*bodyText);
<a name="l00240"></a>00240 emailEntry->StoreL(*store);
<a name="l00241"></a>00241 <span class="comment">// Store the changes permanently</span>
<a name="l00242"></a>00242 store->CommitL();
<a name="l00243"></a>00243
<a name="l00244"></a>00244 CleanupStack::PopAndDestroy(8,entry); <span class="comment">// bodyText,charFormatLayer,paraFormatLayer,emailEntry,store,emailOperation,waiter,entry</span>
<a name="l00245"></a>00245
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247
<a name="l00254"></a><a class="code" href="class_c_pop3_example.html#681d0b120db69c06587235560f1e3b34">00254</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#681d0b120db69c06587235560f1e3b34">CPop3Example::SendSMTPMessageL</a>()
<a name="l00255"></a>00255 {
<a name="l00256"></a>00256 CMsvEntry* entry = iSession->GetEntryL(iSmtpAccount.iSmtpService);
<a name="l00257"></a>00257 CleanupStack::PushL(entry);
<a name="l00258"></a>00258
<a name="l00259"></a>00259 TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId;
<a name="l00260"></a>00260
<a name="l00261"></a>00261 <span class="comment">// creating ChildrenSelection</span>
<a name="l00262"></a>00262 TMsvSelectionOrdering order;
<a name="l00263"></a>00263 order.SetShowInvisibleEntries(ETrue);
<a name="l00264"></a>00264 entry->SetSortTypeL(order);
<a name="l00265"></a>00265
<a name="l00266"></a>00266 entry->SetEntryL(outboxId);
<a name="l00267"></a>00267 <span class="comment">// Get the selection containing the IDs of all the context children</span>
<a name="l00268"></a>00268 CMsvEntrySelection* selection = entry->ChildrenL();
<a name="l00269"></a>00269
<a name="l00270"></a>00270 <span class="comment">// Fetch the Id of the first entry</span>
<a name="l00271"></a>00271 TMsvId entryId = KMsvNullIndexEntryId;
<a name="l00272"></a>00272 entryId = (*selection)[0];
<a name="l00273"></a>00273
<a name="l00274"></a>00274 <span class="keyword">delete</span> selection;
<a name="l00275"></a>00275
<a name="l00276"></a>00276 <a class="code" href="class_c_mess_async_waiter.html">CMessAsyncWaiter</a>* waiter = <a class="code" href="class_c_mess_async_waiter.html#fcb5bdc70a5f6a134afdaf7af207a038">CMessAsyncWaiter::NewL</a>();
<a name="l00277"></a>00277 CleanupStack::PushL(waiter);
<a name="l00278"></a>00278
<a name="l00279"></a>00279 iConsole->Printf(KSendMail);
<a name="l00280"></a>00280 <span class="comment">// Create asynchronously, copies of children of the context </span>
<a name="l00281"></a>00281 <span class="comment">// as new entries of targetId (smtpServiceId)</span>
<a name="l00282"></a>00282 CMsvOperation* operation = entry->CopyL(entryId,iSmtpAccount.iSmtpService, waiter->iStatus);
<a name="l00283"></a>00283
<a name="l00284"></a>00284 CleanupStack::PushL(operation);
<a name="l00285"></a>00285 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00286"></a>00286 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00287"></a>00287
<a name="l00288"></a>00288 CleanupStack::PopAndDestroy(3, entry); <span class="comment">//operation,waiter,entry</span>
<a name="l00289"></a>00289 }
<a name="l00290"></a>00290
<a name="l00297"></a><a class="code" href="class_c_pop3_example.html#a6944f804b14759d3eaec2b791b78f0c">00297</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#a6944f804b14759d3eaec2b791b78f0c">CPop3Example::ConnectDownloadAndDisconnectPOPServerL</a>()
<a name="l00298"></a>00298 {
<a name="l00299"></a>00299
<a name="l00300"></a>00300 <span class="comment">// Change the current context</span>
<a name="l00301"></a>00301 iMtm->SwitchCurrentEntryL(iPopAccount.iPopService);
<a name="l00302"></a>00302
<a name="l00303"></a>00303 CMsvEntrySelection* selection = <span class="keyword">new</span> (ELeave) CMsvEntrySelection;
<a name="l00304"></a>00304 CleanupStack::PushL(selection);
<a name="l00305"></a>00305
<a name="l00306"></a>00306 <span class="comment">// Append the popServiceId onto the end of the array</span>
<a name="l00307"></a>00307 selection->AppendL(iPopAccount.iPopService);
<a name="l00308"></a>00308
<a name="l00309"></a>00309 TBuf8<1> param;
<a name="l00310"></a>00310
<a name="l00311"></a>00311 <a class="code" href="class_c_mess_async_waiter.html">CMessAsyncWaiter</a>* waiter = <a class="code" href="class_c_mess_async_waiter.html#fcb5bdc70a5f6a134afdaf7af207a038">CMessAsyncWaiter::NewL</a>();
<a name="l00312"></a>00312 CleanupStack::PushL(waiter);
<a name="l00313"></a>00313
<a name="l00314"></a>00314 <span class="comment">// Attempts to connect to the Pop3 Service </span>
<a name="l00315"></a>00315 iConsole->Printf(KWait);
<a name="l00316"></a>00316 CMsvOperation* connectOperation = iMtm->InvokeAsyncFunctionL(KPOP3MTMConnect,*selection,param, waiter->iStatus);
<a name="l00317"></a>00317 CleanupStack::PushL(connectOperation);
<a name="l00318"></a>00318
<a name="l00319"></a>00319 <span class="comment">// Wait on the status</span>
<a name="l00320"></a>00320 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00321"></a>00321 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00322"></a>00322
<a name="l00323"></a>00323 <span class="comment">// Populate the message</span>
<a name="l00324"></a>00324 iConsole->Printf(KDownload);
<a name="l00325"></a>00325 CMsvOperation* operationPop = iMtm->InvokeAsyncFunctionL(KPOP3MTMPopulate,*selection,param, waiter->iStatus);
<a name="l00326"></a>00326 CleanupStack::PushL(operationPop);
<a name="l00327"></a>00327
<a name="l00328"></a>00328 <span class="comment">// Wait on the status</span>
<a name="l00329"></a>00329 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00330"></a>00330 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00331"></a>00331
<a name="l00332"></a>00332 <span class="comment">// Now disconnect from Pop3 service</span>
<a name="l00333"></a>00333 CMsvOperation* operationDis = iMtm->InvokeAsyncFunctionL(KPOP3MTMDisconnect,*selection,param, waiter->iStatus);
<a name="l00334"></a>00334 CleanupStack::PushL(operationDis);
<a name="l00335"></a>00335
<a name="l00336"></a>00336 <span class="comment">// Wait on the status</span>
<a name="l00337"></a>00337 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00338"></a>00338 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00339"></a>00339 iConsole->Printf(KDisconnect);
<a name="l00340"></a>00340 iConsole->Getch ();
<a name="l00341"></a>00341
<a name="l00342"></a>00342 CleanupStack::PopAndDestroy(5,selection); <span class="comment">//operationDis,operationPop,connectOperation,waiter,selection</span>
<a name="l00343"></a>00343 }
<a name="l00344"></a>00344
<a name="l00354"></a><a class="code" href="class_c_pop3_example.html#e48622bc95aeac93981f58a7418258f9">00354</a> <span class="keywordtype">void</span> <a class="code" href="class_c_pop3_example.html#e48622bc95aeac93981f58a7418258f9">CPop3Example::HandleSessionEventL</a>(TMsvSessionEvent <span class="comment">/*aEvent*/</span>, TAny* <span class="comment">/*aArg1*/</span>, TAny* <span class="comment">/*aArg2*/</span>, TAny* <span class="comment">/*aArg3*/</span>)
<a name="l00355"></a>00355 {}
<a name="l00356"></a>00356
<a name="l00357"></a><a class="code" href="pop3_example_8cpp.html#689e0bf9aa924a1d7dc108665d44736c">00357</a> LOCAL_C <span class="keywordtype">void</span> <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()
<a name="l00358"></a>00358 {
<a name="l00359"></a>00359
<a name="l00360"></a>00360 <span class="comment">// Create an Active Scheduler to handle asychronous calls</span>
<a name="l00361"></a>00361 CActiveScheduler* scheduler = <span class="keyword">new</span> (ELeave) CActiveScheduler;
<a name="l00362"></a>00362 <span class="comment">/*</span>
<a name="l00363"></a>00363 <span class="comment"> If Active Scheduler has been created, install it .</span>
<a name="l00364"></a>00364 <span class="comment"> As it is an asychronous call we need to install it explicitly.</span>
<a name="l00365"></a>00365 <span class="comment"> */</span>
<a name="l00366"></a>00366 CActiveScheduler::Install( scheduler );
<a name="l00367"></a>00367
<a name="l00368"></a>00368 <a class="code" href="class_c_pop3_example.html">CPop3Example</a>* app = <a class="code" href="class_c_pop3_example.html#b349920e1fdb72d5dbf6186c52d319b6">CPop3Example::NewL</a>();
<a name="l00369"></a>00369 CleanupStack::PushL(app);
<a name="l00370"></a>00370
<a name="l00371"></a>00371 <span class="comment">// Create a client registry.</span>
<a name="l00372"></a>00372 app-><a class="code" href="class_c_pop3_example.html#071be1033b73bd98a19978d4bd90b7fb">CreateClientRegistryL</a>();
<a name="l00373"></a>00373
<a name="l00374"></a>00374 <span class="comment">// Create pop and smtp accounts.</span>
<a name="l00375"></a>00375 app-><a class="code" href="class_c_pop3_example.html#e1b7a4e38a8771d202c637adb12302c2">CreatePopAndSmtpAccountL</a>();
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <span class="comment">// Load the physical and logical device drivers.</span>
<a name="l00378"></a>00378 <span class="comment">// Symbian platform will automatically append .PDD and .LDD</span>
<a name="l00379"></a>00379
<a name="l00380"></a>00380 TInt err;
<a name="l00381"></a>00381 err=User::LoadPhysicalDevice(PDD_NAME);
<a name="l00382"></a>00382 <span class="keywordflow">if</span> (err!=KErrNone && err!=KErrAlreadyExists)
<a name="l00383"></a>00383 User::Leave(err);
<a name="l00384"></a>00384 err=User::LoadLogicalDevice(LDD_NAME);
<a name="l00385"></a>00385 <span class="keywordflow">if</span> (err!=KErrNone && err!=KErrAlreadyExists)
<a name="l00386"></a>00386 User::Leave(err);
<a name="l00387"></a>00387
<a name="l00388"></a>00388 <span class="comment">// Create an Smtp mail to be sent. </span>
<a name="l00389"></a>00389 app-><a class="code" href="class_c_pop3_example.html#4e14514a9a39eee71b372edc85a93b17">CreateSmtpMessageL</a>();
<a name="l00390"></a>00390
<a name="l00391"></a>00391 <span class="comment">// Send the mail created.</span>
<a name="l00392"></a>00392 app-><a class="code" href="class_c_pop3_example.html#681d0b120db69c06587235560f1e3b34">SendSMTPMessageL</a>();
<a name="l00393"></a>00393
<a name="l00394"></a>00394 <span class="comment">// Connect to the pop3 server for downloading the mail and disconnect.</span>
<a name="l00395"></a>00395 app-><a class="code" href="class_c_pop3_example.html#a6944f804b14759d3eaec2b791b78f0c">ConnectDownloadAndDisconnectPOPServerL</a>();
<a name="l00396"></a>00396
<a name="l00397"></a>00397 CleanupStack::PopAndDestroy(app);
<a name="l00398"></a>00398
<a name="l00399"></a>00399 <span class="keyword">delete</span> scheduler;
<a name="l00400"></a>00400
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402
<a name="l00403"></a><a class="code" href="pop3_example_8cpp.html#0f358e9c4355138f629b8c4f37310295">00403</a> GLDEF_C TInt <a class="code" href="dbllist_8cpp.html#0f358e9c4355138f629b8c4f37310295">E32Main</a>()
<a name="l00404"></a>00404 {
<a name="l00405"></a>00405 __UHEAP_MARK;
<a name="l00406"></a>00406 CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00407"></a>00407 <span class="keywordflow">if</span>(cleanup == NULL)
<a name="l00408"></a>00408 {
<a name="l00409"></a>00409 <span class="keywordflow">return</span> KErrNoMemory;
<a name="l00410"></a>00410 }
<a name="l00411"></a>00411 TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>());
<a name="l00412"></a>00412
<a name="l00413"></a>00413 <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00414"></a>00414 {
<a name="l00415"></a>00415 _LIT(KUserPanic,<span class="stringliteral">"Failed to complete"</span>);
<a name="l00416"></a>00416 User::Panic(KUserPanic, err);
<a name="l00417"></a>00417 }
<a name="l00418"></a>00418
<a name="l00419"></a>00419 <span class="keyword">delete</span> cleanup;
<a name="l00420"></a>00420 __UHEAP_MARKEND;
<a name="l00421"></a>00421 <span class="keywordflow">return</span> KErrNone;
<a name="l00422"></a>00422 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:58 2010 for TB10.1 Example Applications by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>