Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/imap4example_8cpp-source.html
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Tue, 30 Mar 2010 11:42:04 +0100
changeset 4 4816d766a08a
parent 1 25a17d01db0c
permissions -rw-r--r--
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/Imap4Example/imap4example.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/Imap4Example/imap4example.cpp</h1><a href="imap4example_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 code example that demonstrates the use of </span>
<a name="l00015"></a>00015 <span class="comment">// the IMAP4 protocol to retrieve emails. </span>
<a name="l00016"></a>00016 <span class="comment">// The code creates a simple SMTP mail, sends it </span>
<a name="l00017"></a>00017 <span class="comment">// and then retrieves the same using IMAP4.</span>
<a name="l00018"></a>00018 <span class="comment">//</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00026"></a>00026 <span class="preprocessor">#include "imap4example.h"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="_messaging_2_imap4_example_2asyncwaiter_8h.html">asyncwaiter.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;e32cons.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "imapset.h"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include "impcmtm.h"</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;mtclbase.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;iapprefs.h&gt;</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 _LIT(KTitle, <span class="stringliteral">"Imap4example"</span>);
<a name="l00035"></a>00035 _LIT(KTextPressAKey, <span class="stringliteral">"\n\n Press any key to step through the example"</span>);
<a name="l00036"></a>00036 _LIT(KExit,<span class="stringliteral">"\n\n Press any key to exit the application "</span>);
<a name="l00037"></a>00037 _LIT(KCreateMtm,<span class="stringliteral">"\n\n Creating an IMAP4 client MTM"</span>);
<a name="l00038"></a>00038 _LIT(KTxtAccountName, <span class="stringliteral">"ImapAccount"</span>);
<a name="l00039"></a>00039 _LIT(KCreateAccounts,<span class="stringliteral">"\n\n Creating IMAP and SMTP acoounts"</span>);
<a name="l00040"></a>00040 _LIT(KSmtpServerAddress, <span class="stringliteral">"ban-sindhub01.intra"</span>);
<a name="l00041"></a>00041 _LIT(KEmailAlias, <span class="stringliteral">"Messaging example"</span>);
<a name="l00042"></a>00042 _LIT(KSmtpEmailAddress, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00043"></a>00043 _LIT8(KFrom, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00044"></a>00044 _LIT(KTo, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>);
<a name="l00045"></a>00045 _LIT(KSubject, <span class="stringliteral">"SimpleEmail"</span>);
<a name="l00046"></a>00046 _LIT(KBodyContents, <span class="stringliteral">"This is a very simple mail"</span>);
<a name="l00047"></a>00047 _LIT(KSendMail,<span class="stringliteral">"\n\n Sending the mail ... please wait"</span>);
<a name="l00048"></a>00048 _LIT(KImapServer, <span class="stringliteral">"ban-sindhub01.intra"</span>);
<a name="l00049"></a>00049 _LIT8(KImapPassword,<span class="stringliteral">"ban-sindhub01"</span>);
<a name="l00050"></a>00050 _LIT8(KImapLoginName,<span class="stringliteral">"ban-sindhub01"</span>);
<a name="l00051"></a>00051 _LIT(KWait,<span class="stringliteral">"\n\n Connecting to the IMAP server"</span>);
<a name="l00052"></a>00052 _LIT(KPopulate,<span class="stringliteral">"\n\n Downloading........"</span>);
<a name="l00053"></a>00053 _LIT(KDisconnect,<span class="stringliteral">"\n\n Disconnecting from the IMAP server"</span>);
<a name="l00054"></a>00054 
<a name="l00059"></a><a class="code" href="class_c_imap4_example.html#f2fa3514a5efc6a92577823ec3508615">00059</a> <a class="code" href="class_c_imap4_example.html">CImap4Example</a>* <a class="code" href="class_c_imap4_example.html#f2fa3514a5efc6a92577823ec3508615">CImap4Example::NewL</a>()
<a name="l00060"></a>00060         {
<a name="l00061"></a>00061         <a class="code" href="class_c_imap4_example.html">CImap4Example</a>* <span class="keyword">self</span>= <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_imap4_example.html">CImap4Example</a>();
<a name="l00062"></a>00062         CleanupStack::PushL(<span class="keyword">self</span>);
<a name="l00063"></a>00063         <span class="keyword">self</span>-&gt;ConstructL();
<a name="l00064"></a>00064         CleanupStack::Pop();
<a name="l00065"></a>00065         <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00071"></a>00071 CImap4Example::CImap4Example()
<a name="l00072"></a>00072         {}
<a name="l00073"></a>00073 
<a name="l00077"></a>00077 <span class="keywordtype">void</span> CImap4Example::ConstructL()
<a name="l00078"></a>00078         {
<a name="l00079"></a>00079         iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00080"></a>00080 
<a name="l00081"></a>00081         iConsole-&gt;Printf ( KTextPressAKey );
<a name="l00082"></a>00082         iConsole-&gt;Getch ();
<a name="l00083"></a>00083         }
<a name="l00084"></a>00084 
<a name="l00088"></a><a class="code" href="class_c_imap4_example.html#0fd7f78ad3b9350a9fc556090441e033">00088</a> <a class="code" href="class_c_imap4_example.html#0fd7f78ad3b9350a9fc556090441e033">CImap4Example::~CImap4Example</a>()
<a name="l00089"></a>00089         {
<a name="l00090"></a>00090         iConsole-&gt;Printf(KExit);
<a name="l00091"></a>00091         iConsole-&gt;Getch();
<a name="l00092"></a>00092         <span class="keyword">delete</span> iMtm;
<a name="l00093"></a>00093         <span class="keyword">delete</span> iClientRegistry;
<a name="l00094"></a>00094         <span class="keyword">delete</span> iSession;
<a name="l00095"></a>00095         <span class="keyword">delete</span> iConsole;
<a name="l00096"></a>00096         }
<a name="l00097"></a>00097 
<a name="l00105"></a><a class="code" href="class_c_imap4_example.html#9a2e08f3d32825f33ab77ec067139823">00105</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#9a2e08f3d32825f33ab77ec067139823">CImap4Example::CreateClientRegistryL</a>()
<a name="l00106"></a>00106         {
<a name="l00107"></a>00107         <span class="comment">// Create a message server session</span>
<a name="l00108"></a>00108         iSession=CMsvSession::OpenSyncL(*<span class="keyword">this</span>);
<a name="l00109"></a>00109         CleanupStack::PushL(iSession);
<a name="l00110"></a>00110 
<a name="l00111"></a>00111         <span class="comment">// Create a client-side MTM registry</span>
<a name="l00112"></a>00112         iClientRegistry=CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32);
<a name="l00113"></a>00113         <span class="keywordflow">if</span> (iClientRegistry != NULL &amp;&amp; iClientRegistry-&gt;IsPresent(KUidMsgTypeIMAP4))
<a name="l00114"></a>00114                 {
<a name="l00115"></a>00115                 CleanupStack::PushL(iClientRegistry);
<a name="l00116"></a>00116                 }
<a name="l00117"></a>00117         <span class="comment">// Create a client-side MTM object for the specified MTM UID.</span>
<a name="l00118"></a>00118         iMtm=(CImap4ClientMtm*)iClientRegistry-&gt;NewMtmL(KUidMsgTypeIMAP4); 
<a name="l00119"></a>00119         iConsole-&gt;Printf(KCreateMtm);
<a name="l00120"></a>00120         CleanupStack::Pop(2,iSession); <span class="comment">// iClientRegistry,iSession</span>
<a name="l00121"></a>00121         }
<a name="l00122"></a>00122 
<a name="l00128"></a><a class="code" href="class_c_imap4_example.html#dca622be43042650b3618371431d2c84">00128</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#dca622be43042650b3618371431d2c84">CImap4Example::CreateImapAndSmtpAccountL</a>()
<a name="l00129"></a>00129         {
<a name="l00130"></a>00130         CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
<a name="l00131"></a>00131         CImImap4Settings *imap4Settings = <span class="keyword">new</span>(ELeave)CImImap4Settings;
<a name="l00132"></a>00132         CleanupStack::PushL(imap4Settings);
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         <span class="comment">// Add IAP to the IAP preferences</span>
<a name="l00135"></a>00135         CImIAPPreferences* prefs = CImIAPPreferences::NewLC();
<a name="l00136"></a>00136         TImIAPChoice iap;
<a name="l00137"></a>00137         TInt iapID = 0;
<a name="l00138"></a>00138         CMDBSession* dbSession = CMDBSession::NewL(KCDVersion1_1);
<a name="l00139"></a>00139         CleanupStack::PushL(dbSession);
<a name="l00140"></a>00140         CCDConnectionPrefsRecord *connPrefRecord = <span class="keyword">static_cast&lt;</span>CCDConnectionPrefsRecord*<span class="keyword">&gt;</span>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord));
<a name="l00141"></a>00141         CleanupStack::PushL(connPrefRecord);
<a name="l00142"></a>00142 
<a name="l00143"></a>00143         <span class="comment">// Set the direction of connection</span>
<a name="l00144"></a>00144         connPrefRecord-&gt;iDirection = ECommDbConnectionDirectionOutgoing;
<a name="l00145"></a>00145         connPrefRecord-&gt;iRanking = 1;
<a name="l00146"></a>00146         <span class="keywordflow">if</span>(!connPrefRecord-&gt;FindL(*dbSession))
<a name="l00147"></a>00147                 {
<a name="l00148"></a>00148                 User::Leave(KErrNotFound);
<a name="l00149"></a>00149                 }
<a name="l00150"></a>00150         iapID = connPrefRecord-&gt;iDefaultIAP;
<a name="l00151"></a>00151         iap.iIAP = iapID;
<a name="l00152"></a>00152         iap.iDialogPref = ECommDbDialogPrefDoNotPrompt;
<a name="l00153"></a>00153         prefs-&gt;AddIAPL(iap);
<a name="l00154"></a>00154 
<a name="l00155"></a>00155         emailAccounts-&gt;PopulateDefaultImapSettingsL(*imap4Settings, *prefs);
<a name="l00156"></a>00156 
<a name="l00157"></a>00157         <span class="comment">// Set the server address to system address</span>
<a name="l00158"></a>00158         imap4Settings-&gt;SetServerAddressL(KImapServer);
<a name="l00159"></a>00159         imap4Settings-&gt;SetLoginNameL(KImapLoginName); 
<a name="l00160"></a>00160         imap4Settings-&gt;SetPasswordL(KImapPassword);
<a name="l00161"></a>00161         imap4Settings-&gt;SetPort(143);
<a name="l00162"></a>00162 
<a name="l00163"></a>00163         <span class="comment">// Create an IMAP account</span>
<a name="l00164"></a>00164         iImapAccount = emailAccounts-&gt;CreateImapAccountL(KTxtAccountName, *imap4Settings,*prefs,EFalse);
<a name="l00165"></a>00165 
<a name="l00166"></a>00166         CImSmtpSettings *smtpSettings = <span class="keyword">new</span> (ELeave) CImSmtpSettings();
<a name="l00167"></a>00167         CleanupStack::PushL(smtpSettings);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         emailAccounts-&gt;PopulateDefaultSmtpSettingsL(*smtpSettings, *prefs);
<a name="l00170"></a>00170 
<a name="l00171"></a>00171         <span class="comment">// Create an SMTP acoount</span>
<a name="l00172"></a>00172         iConsole-&gt;Printf(KCreateAccounts);
<a name="l00173"></a>00173         iSmtpAccount= emailAccounts-&gt;CreateSmtpAccountL(iImapAccount, *smtpSettings, *prefs, EFalse);
<a name="l00174"></a>00174 
<a name="l00175"></a>00175         emailAccounts-&gt;SetDefaultSmtpAccountL(iSmtpAccount);
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         smtpSettings-&gt;SetServerAddressL(KSmtpServerAddress);
<a name="l00178"></a>00178         smtpSettings-&gt;SetEmailAliasL(KEmailAlias);
<a name="l00179"></a>00179         smtpSettings-&gt;SetEmailAddressL(KSmtpEmailAddress);
<a name="l00180"></a>00180         smtpSettings-&gt;SetReplyToAddressL(KSmtpEmailAddress);
<a name="l00181"></a>00181         smtpSettings-&gt;SetReceiptAddressL(KSmtpEmailAddress);
<a name="l00182"></a>00182         smtpSettings-&gt;SetPort(25);
<a name="l00183"></a>00183 
<a name="l00184"></a>00184         emailAccounts-&gt;GetSmtpAccountL(iSmtpAccount.iSmtpService, iSmtpAccount);
<a name="l00185"></a>00185         emailAccounts-&gt;SaveSmtpSettingsL(iSmtpAccount,*smtpSettings);
<a name="l00186"></a>00186         emailAccounts-&gt;SaveSmtpIapSettingsL(iSmtpAccount, *prefs);
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         CleanupStack::PopAndDestroy(6,emailAccounts); <span class="comment">//smtpSettings, connPrefRecord, dbSession, prefs, imap4Settings, emailAccounts</span>
<a name="l00189"></a>00189         }
<a name="l00190"></a>00190 
<a name="l00198"></a><a class="code" href="class_c_imap4_example.html#41fb083255e0596cff88bbf3ddefe3ed">00198</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#41fb083255e0596cff88bbf3ddefe3ed">CImap4Example::CreateSmtpMessageL</a>() 
<a name="l00199"></a>00199         {
<a name="l00200"></a>00200         TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId; 
<a name="l00201"></a>00201 
<a name="l00202"></a>00202         <span class="comment">// Set the context to the folder in which message has to be created</span>
<a name="l00203"></a>00203         CMsvEntry* entry = CMsvEntry::NewL(*iSession,outboxId,TMsvSelectionOrdering());
<a name="l00204"></a>00204         CleanupStack::PushL(entry);
<a name="l00205"></a>00205         entry-&gt;SetEntryL(outboxId);
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         <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="l00208"></a>00208         CleanupStack::PushL(waiter);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         TMsvEmailTypeList msvEmailTypeList = 0;
<a name="l00211"></a>00211         TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments);
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(waiter-&gt;iStatus, *iSession,KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP);
<a name="l00214"></a>00214         CleanupStack::PushL(emailOperation);
<a name="l00215"></a>00215         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00216"></a>00216 
<a name="l00217"></a>00217         TMsvId temp;
<a name="l00218"></a>00218         TPckgC&lt;TMsvId&gt; paramPack(temp);
<a name="l00219"></a>00219         <span class="keyword">const</span> TDesC8&amp; progBuf = emailOperation-&gt;ProgressL();
<a name="l00220"></a>00220         paramPack.Set(progBuf);
<a name="l00221"></a>00221         TMsvId newMessageId;
<a name="l00222"></a>00222         newMessageId = paramPack();
<a name="l00223"></a>00223 
<a name="l00224"></a>00224         entry-&gt;SetEntryL(newMessageId);
<a name="l00225"></a>00225 
<a name="l00226"></a>00226         CMsvStore* store = entry-&gt;EditStoreL();
<a name="l00227"></a>00227         CleanupStack::PushL(store);
<a name="l00228"></a>00228         CImHeader* emailEntry = CImHeader::NewLC();
<a name="l00229"></a>00229         emailEntry-&gt;RestoreL(*store);
<a name="l00230"></a>00230         emailEntry-&gt;SetFromL((TDesC8&amp;)KFrom);
<a name="l00231"></a>00231         emailEntry-&gt;SetSubjectL((TDesC&amp;)KSubject);
<a name="l00232"></a>00232         emailEntry-&gt;ToRecipients().AppendL((TDesC&amp;)KTo);
<a name="l00233"></a>00233 
<a name="l00234"></a>00234         <span class="comment">// Paragraph format layer for the rich text object </span>
<a name="l00235"></a>00235         CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
<a name="l00236"></a>00236         CleanupStack::PushL(paraFormatLayer);
<a name="l00237"></a>00237         <span class="comment">// Character format layer for the rich text object</span>
<a name="l00238"></a>00238         CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); 
<a name="l00239"></a>00239         CleanupStack::PushL(charFormatLayer);
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         CRichText* bodyText = CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256);
<a name="l00242"></a>00242         CleanupStack::PushL(bodyText);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244         <span class="comment">// Insert the contents of a buffer into the document at specified position</span>
<a name="l00245"></a>00245         bodyText-&gt;InsertL(0, KBodyContents);
<a name="l00246"></a>00246         store-&gt;StoreBodyTextL(*bodyText);
<a name="l00247"></a>00247         emailEntry-&gt;StoreL(*store);
<a name="l00248"></a>00248         <span class="comment">// Store the changes permanently</span>
<a name="l00249"></a>00249         store-&gt;CommitL();
<a name="l00250"></a>00250 
<a name="l00251"></a>00251         CleanupStack::PopAndDestroy(8,entry); <span class="comment">// bodyText,charFormatLayer,paraFormatLayer,emailEntry,store,emailOperation,waiter,entry</span>
<a name="l00252"></a>00252         }
<a name="l00253"></a>00253 
<a name="l00261"></a><a class="code" href="class_c_imap4_example.html#25bd92dfb54191201da4fdb34bdad2a7">00261</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#25bd92dfb54191201da4fdb34bdad2a7">CImap4Example::SendSMTPMessageL</a>()
<a name="l00262"></a>00262         {
<a name="l00263"></a>00263         CMsvEntry* entry = iSession-&gt;GetEntryL(iSmtpAccount.iSmtpService);
<a name="l00264"></a>00264         CleanupStack::PushL(entry);
<a name="l00265"></a>00265 
<a name="l00266"></a>00266         TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId;
<a name="l00267"></a>00267 
<a name="l00268"></a>00268         <span class="comment">// Create children selection</span>
<a name="l00269"></a>00269         TMsvSelectionOrdering order;
<a name="l00270"></a>00270         order.SetShowInvisibleEntries(ETrue);
<a name="l00271"></a>00271         entry-&gt;SetSortTypeL(order);
<a name="l00272"></a>00272 
<a name="l00273"></a>00273         entry-&gt;SetEntryL(outboxId);
<a name="l00274"></a>00274         <span class="comment">// Get the  selection containing the IDs of all the context children</span>
<a name="l00275"></a>00275         CMsvEntrySelection* selection = entry-&gt;ChildrenL();
<a name="l00276"></a>00276 
<a name="l00277"></a>00277         <span class="comment">// Fetch the ID of the first entry</span>
<a name="l00278"></a>00278         TMsvId entryId = KMsvNullIndexEntryId;
<a name="l00279"></a>00279         entryId = (*selection)[0];
<a name="l00280"></a>00280 
<a name="l00281"></a>00281         <span class="keyword">delete</span> selection;
<a name="l00282"></a>00282 
<a name="l00283"></a>00283         <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="l00284"></a>00284         CleanupStack::PushL(waiter);
<a name="l00285"></a>00285 
<a name="l00286"></a>00286         iConsole-&gt;Printf(KSendMail);
<a name="l00287"></a>00287         <span class="comment">// Create asynchronously copies of children of the context</span>
<a name="l00288"></a>00288         <span class="comment">// as new entries of targetId (smtpServiceId)</span>
<a name="l00289"></a>00289         CMsvOperation* operation = entry-&gt;CopyL(entryId,iSmtpAccount.iSmtpService, waiter-&gt;iStatus);
<a name="l00290"></a>00290 
<a name="l00291"></a>00291         CleanupStack::PushL(operation);
<a name="l00292"></a>00292         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00293"></a>00293         User::LeaveIfError(waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00294"></a>00294 
<a name="l00295"></a>00295         CleanupStack::PopAndDestroy(3, entry); <span class="comment">// operation,waiter,entry</span>
<a name="l00296"></a>00296         }
<a name="l00297"></a>00297 
<a name="l00308"></a><a class="code" href="class_c_imap4_example.html#bbeb6d452e3c8579f6a40517e318279c">00308</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#bbeb6d452e3c8579f6a40517e318279c">CImap4Example::ConnectAndCopyAllMailAndDisconnectL</a>()
<a name="l00309"></a>00309         {
<a name="l00310"></a>00310         <span class="comment">// Change the current context</span>
<a name="l00311"></a>00311         iMtm-&gt;SwitchCurrentEntryL(iImapAccount.iImapService);
<a name="l00312"></a>00312         CMsvEntrySelection* selection = <span class="keyword">new</span> (ELeave) CMsvEntrySelection;
<a name="l00313"></a>00313         CleanupStack::PushL(selection);
<a name="l00314"></a>00314 
<a name="l00315"></a>00315         <span class="comment">// Append the imapServiceId onto the end of the array</span>
<a name="l00316"></a>00316         selection-&gt;AppendL(iImapAccount.iImapService);
<a name="l00317"></a>00317 
<a name="l00318"></a>00318         TImImap4GetMailInfo imap4GetMailInfo;
<a name="l00319"></a>00319         imap4GetMailInfo.iMaxEmailSize = KMaxTInt;
<a name="l00320"></a>00320         imap4GetMailInfo.iDestinationFolder = iImapAccount.iImapService+1; <span class="comment">// remote inbox</span>
<a name="l00321"></a>00321         imap4GetMailInfo.iGetMailBodyParts = EGetImap4EmailBodyText;
<a name="l00322"></a>00322 
<a name="l00323"></a>00323         TPckgBuf&lt;TImImap4GetMailInfo&gt; package(imap4GetMailInfo);
<a name="l00324"></a>00324 
<a name="l00325"></a>00325         <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="l00326"></a>00326         CleanupStack::PushL(waiter);
<a name="l00327"></a>00327 
<a name="l00328"></a>00328         <span class="comment">// Connect to the server</span>
<a name="l00329"></a>00329         iConsole-&gt;Printf (KWait);
<a name="l00330"></a>00330         CMsvOperation* operationConnect = iMtm-&gt;InvokeAsyncFunctionL(KIMAP4MTMConnect,*selection,package, waiter-&gt;iStatus);
<a name="l00331"></a>00331         CleanupStack::PushL(operationConnect);
<a name="l00332"></a>00332 
<a name="l00333"></a>00333         <span class="comment">// Wait on the status</span>
<a name="l00334"></a>00334         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00335"></a>00335         User::LeaveIfError(waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00336"></a>00336 
<a name="l00337"></a>00337         CMsvOperation* operationSync = iMtm-&gt;InvokeAsyncFunctionL(KIMAP4MTMFullSync ,*selection,package, waiter-&gt;iStatus);
<a name="l00338"></a>00338         CleanupStack::PushL(operationSync);
<a name="l00339"></a>00339 
<a name="l00340"></a>00340         <span class="comment">// Wait on the status</span>
<a name="l00341"></a>00341         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00342"></a>00342         User::LeaveIfError(waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00343"></a>00343 
<a name="l00344"></a>00344         CMsvEntry* entry = iSession-&gt;GetEntryL(iImapAccount.iImapService);
<a name="l00345"></a>00345         CMsvEntrySelection* childrenSelection = entry-&gt;ChildrenL();
<a name="l00346"></a>00346         TMsvId <span class="keywordtype">id</span> = (*childrenSelection)[0];
<a name="l00347"></a>00347         selection-&gt;AppendL(<span class="keywordtype">id</span>);
<a name="l00348"></a>00348 
<a name="l00349"></a>00349         <span class="comment">// Copy the meassage when already connected</span>
<a name="l00350"></a>00350         iConsole-&gt;Printf (KPopulate);
<a name="l00351"></a>00351         CMsvOperation* operationCopy = iMtm-&gt;InvokeAsyncFunctionL(KIMAP4MTMPopulateAllMailWhenAlreadyConnected ,*selection,package, waiter-&gt;iStatus);
<a name="l00352"></a>00352         CleanupStack::PushL(operationCopy);
<a name="l00353"></a>00353 
<a name="l00354"></a>00354         <span class="comment">// Wait on the status</span>
<a name="l00355"></a>00355         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00356"></a>00356 
<a name="l00357"></a>00357         User::LeaveIfError(waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00358"></a>00358 
<a name="l00359"></a>00359         <span class="comment">// Now disconnect from Imap4 service</span>
<a name="l00360"></a>00360         iConsole-&gt;Printf (KDisconnect);
<a name="l00361"></a>00361         CMsvOperation* operationDis = iMtm-&gt;InvokeAsyncFunctionL(KIMAP4MTMDisconnect,*selection,package, waiter-&gt;iStatus);
<a name="l00362"></a>00362         CleanupStack::PushL(operationDis);
<a name="l00363"></a>00363 
<a name="l00364"></a>00364         <span class="comment">// Wait on the status</span>
<a name="l00365"></a>00365         waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>();
<a name="l00366"></a>00366         User::LeaveIfError(waiter-&gt;<a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>());
<a name="l00367"></a>00367         <span class="keyword">delete</span> entry;
<a name="l00368"></a>00368         <span class="keyword">delete</span> childrenSelection;
<a name="l00369"></a>00369 
<a name="l00370"></a>00370         CleanupStack::PopAndDestroy(6,selection); <span class="comment">// operationDis,operationCopy,operationSync,operationConnect,waiter,selection </span>
<a name="l00371"></a>00371         }
<a name="l00372"></a>00372 
<a name="l00383"></a><a class="code" href="class_c_imap4_example.html#e6a09d8d3f27ac93aa98147605516278">00383</a> <span class="keywordtype">void</span> <a class="code" href="class_c_imap4_example.html#e6a09d8d3f27ac93aa98147605516278">CImap4Example::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="l00384"></a>00384         {}
<a name="l00385"></a>00385 
<a name="l00386"></a><a class="code" href="imap4example_8cpp.html#689e0bf9aa924a1d7dc108665d44736c">00386</a> LOCAL_C <span class="keywordtype">void</span> <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()
<a name="l00387"></a>00387         {
<a name="l00388"></a>00388         <span class="comment">// Create an Active Scheduler to handle asychronous calls</span>
<a name="l00389"></a>00389         CActiveScheduler* scheduler = <span class="keyword">new</span> (ELeave) CActiveScheduler;
<a name="l00390"></a>00390 
<a name="l00391"></a>00391         <span class="comment">// If Active Scheduler has been created, install it.</span>
<a name="l00392"></a>00392         <span class="comment">// As it is an asychronous call we need to install it explicitly.</span>
<a name="l00393"></a>00393         CActiveScheduler::Install( scheduler );
<a name="l00394"></a>00394 
<a name="l00395"></a>00395         <a class="code" href="class_c_imap4_example.html">CImap4Example</a>* app = <a class="code" href="class_c_imap4_example.html#f2fa3514a5efc6a92577823ec3508615">CImap4Example::NewL</a>();
<a name="l00396"></a>00396         CleanupStack::PushL(app);
<a name="l00397"></a>00397 
<a name="l00398"></a>00398         <span class="comment">// Create a client registry</span>
<a name="l00399"></a>00399         app-&gt;<a class="code" href="class_c_imap4_example.html#9a2e08f3d32825f33ab77ec067139823">CreateClientRegistryL</a>();
<a name="l00400"></a>00400 
<a name="l00401"></a>00401         <span class="comment">// Create IMAP and SMTP accounts</span>
<a name="l00402"></a>00402         app-&gt;<a class="code" href="class_c_imap4_example.html#dca622be43042650b3618371431d2c84">CreateImapAndSmtpAccountL</a>();
<a name="l00403"></a>00403 
<a name="l00404"></a>00404         <span class="comment">// Load the physical and logical device drivers.</span>
<a name="l00405"></a>00405         <span class="comment">// Symbian platform will automatically append .PDD and .LDD</span>
<a name="l00406"></a>00406         TInt err;
<a name="l00407"></a>00407         err=User::LoadPhysicalDevice(PDD_NAME);
<a name="l00408"></a>00408         <span class="keywordflow">if</span> (err!=KErrNone &amp;&amp; err!=KErrAlreadyExists)
<a name="l00409"></a>00409                 User::Leave(err);
<a name="l00410"></a>00410         err=User::LoadLogicalDevice(LDD_NAME);
<a name="l00411"></a>00411         <span class="keywordflow">if</span> (err!=KErrNone &amp;&amp; err!=KErrAlreadyExists)
<a name="l00412"></a>00412                 User::Leave(err);
<a name="l00413"></a>00413 
<a name="l00414"></a>00414         <span class="comment">// Create an SMTP mail to be sent</span>
<a name="l00415"></a>00415         app-&gt;<a class="code" href="class_c_imap4_example.html#41fb083255e0596cff88bbf3ddefe3ed">CreateSmtpMessageL</a>();
<a name="l00416"></a>00416 
<a name="l00417"></a>00417         <span class="comment">// Send the mail created.</span>
<a name="l00418"></a>00418         app-&gt;<a class="code" href="class_c_imap4_example.html#25bd92dfb54191201da4fdb34bdad2a7">SendSMTPMessageL</a>();
<a name="l00419"></a>00419 
<a name="l00420"></a>00420         <span class="comment">// Connect, download and disconnect from the IMAP server</span>
<a name="l00421"></a>00421         app-&gt;<a class="code" href="class_c_imap4_example.html#bbeb6d452e3c8579f6a40517e318279c">ConnectAndCopyAllMailAndDisconnectL</a>();
<a name="l00422"></a>00422 
<a name="l00423"></a>00423         CleanupStack::PopAndDestroy(app);
<a name="l00424"></a>00424 
<a name="l00425"></a>00425         <span class="keyword">delete</span> scheduler;
<a name="l00426"></a>00426         }
<a name="l00427"></a>00427 
<a name="l00428"></a><a class="code" href="imap4example_8cpp.html#0f358e9c4355138f629b8c4f37310295">00428</a> GLDEF_C TInt <a class="code" href="dbllist_8cpp.html#0f358e9c4355138f629b8c4f37310295">E32Main</a>()
<a name="l00429"></a>00429         {
<a name="l00430"></a>00430         __UHEAP_MARK;
<a name="l00431"></a>00431         CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00432"></a>00432         <span class="keywordflow">if</span>(cleanup == NULL)
<a name="l00433"></a>00433                 {
<a name="l00434"></a>00434                 <span class="keywordflow">return</span> KErrNoMemory;
<a name="l00435"></a>00435                 }
<a name="l00436"></a>00436         TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>());
<a name="l00437"></a>00437         <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00438"></a>00438                 {
<a name="l00439"></a>00439                 User::Panic(_L(<span class="stringliteral">"Failed to complete"</span>),err);
<a name="l00440"></a>00440                 }
<a name="l00441"></a>00441 
<a name="l00442"></a>00442         <span class="keyword">delete</span> cleanup;
<a name="l00443"></a>00443         __UHEAP_MARKEND;
<a name="l00444"></a>00444         <span class="keywordflow">return</span> KErrNone;
<a name="l00445"></a>00445         }
</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&nbsp;
<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>