|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
|
3 <title>TB10.1 Example Applications: examples/Messaging/Pop3Example/pop3Example.cpp Source File</title> |
|
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> |
|
5 <link href="tabs.css" rel="stylesheet" type="text/css"> |
|
6 </head><body> |
|
7 <!-- Generated by Doxygen 1.5.3 --> |
|
8 <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> |
|
9 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span> |
|
10 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span> |
|
11 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span> |
|
12 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span> |
|
13 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span> |
|
14 <a name="l00007"></a>00007 <span class="comment">//</span> |
|
15 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span> |
|
16 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span> |
|
17 <a name="l00010"></a>00010 <span class="comment">//</span> |
|
18 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span> |
|
19 <a name="l00012"></a>00012 <span class="comment">//</span> |
|
20 <a name="l00013"></a>00013 <span class="comment">// Description:</span> |
|
21 <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> |
|
22 <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> |
|
23 <a name="l00016"></a>00016 <span class="comment">//</span> |
|
24 <a name="l00017"></a>00017 |
|
25 <a name="l00018"></a>00018 |
|
26 <a name="l00019"></a>00019 |
|
27 <a name="l00023"></a>00023 <span class="preprocessor">#include "pop3Example.h"</span> |
|
28 <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> |
|
29 <a name="l00025"></a>00025 |
|
30 <a name="l00026"></a>00026 _LIT(KTextPressAKey, <span class="stringliteral">"\n\n Press any key to step through the example"</span>); |
|
31 <a name="l00027"></a>00027 _LIT(KExit,<span class="stringliteral">"\n\n Press any key to exit the application "</span>); |
|
32 <a name="l00028"></a>00028 _LIT(KCreateMtm,<span class="stringliteral">"\n\n Creating a Pop3 client MTM"</span>); |
|
33 <a name="l00029"></a>00029 _LIT(KKeyPress,<span class="stringliteral">"\n\n Press any key"</span>); |
|
34 <a name="l00030"></a>00030 _LIT(KTxtAccountName, <span class="stringliteral">"PopAccount"</span>); |
|
35 <a name="l00031"></a>00031 _LIT(KCreatePopAccount,<span class="stringliteral">"\n\n Creating a Pop account"</span>); |
|
36 <a name="l00032"></a>00032 _LIT(KCreateSmtpAccount,<span class="stringliteral">"\n\n Creating an Smtp account"</span>); |
|
37 <a name="l00033"></a>00033 _LIT(KSmtpServerAddress, <span class="stringliteral">"ban-sindhub01.intra"</span>); |
|
38 <a name="l00034"></a>00034 _LIT(KEmailAlias, <span class="stringliteral">"Messaging example"</span>); |
|
39 <a name="l00035"></a>00035 _LIT(KSmtpEmailAddress, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>); |
|
40 <a name="l00036"></a>00036 _LIT8(KFrom, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>); |
|
41 <a name="l00037"></a>00037 _LIT(KTo, <span class="stringliteral">"ban-sindhub01@ban-sindhub01.intra"</span>); |
|
42 <a name="l00038"></a>00038 _LIT(KSubject, <span class="stringliteral">"SimpleEmail"</span>); |
|
43 <a name="l00039"></a>00039 _LIT(KBodyContents, <span class="stringliteral">"This is a very simple mail"</span>); |
|
44 <a name="l00040"></a>00040 _LIT(KSendMail,<span class="stringliteral">"\n\n Sending the mail... please wait"</span>); |
|
45 <a name="l00041"></a>00041 _LIT(KPopServer, <span class="stringliteral">"ban-sindhub01.intra"</span>); |
|
46 <a name="l00042"></a>00042 _LIT8(KPopPassword,<span class="stringliteral">"ban-sindhub01"</span>); |
|
47 <a name="l00043"></a>00043 _LIT8(KPopLoginName,<span class="stringliteral">"ban-sindhub01"</span>); |
|
48 <a name="l00044"></a>00044 _LIT(KWait,<span class="stringliteral">"\n\n Connecting to pop3 server"</span>); |
|
49 <a name="l00045"></a>00045 _LIT(KDownload,<span class="stringliteral">"\n\n Downloading mail from the pop3 server"</span>); |
|
50 <a name="l00046"></a>00046 _LIT(KDisconnect,<span class="stringliteral">"\n\n Press any key to disconnect"</span>); |
|
51 <a name="l00047"></a>00047 |
|
52 <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>() |
|
53 <a name="l00053"></a>00053 { |
|
54 <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>(); |
|
55 <a name="l00055"></a>00055 CleanupStack::PushL(<span class="keyword">self</span>); |
|
56 <a name="l00056"></a>00056 <span class="keyword">self</span>->ConstructL(); |
|
57 <a name="l00057"></a>00057 CleanupStack::Pop(); |
|
58 <a name="l00058"></a>00058 <span class="keywordflow">return</span> <span class="keyword">self</span>; |
|
59 <a name="l00059"></a>00059 } |
|
60 <a name="l00063"></a>00063 CPop3Example::CPop3Example() |
|
61 <a name="l00064"></a>00064 { |
|
62 <a name="l00065"></a>00065 |
|
63 <a name="l00066"></a>00066 } |
|
64 <a name="l00067"></a>00067 |
|
65 <a name="l00068"></a>00068 <span class="keywordtype">void</span> CPop3Example::ConstructL() |
|
66 <a name="l00069"></a>00069 { |
|
67 <a name="l00070"></a>00070 iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen)); |
|
68 <a name="l00071"></a>00071 iConsole->Printf ( KTextPressAKey ); |
|
69 <a name="l00072"></a>00072 iConsole->Getch (); |
|
70 <a name="l00073"></a>00073 } |
|
71 <a name="l00074"></a>00074 |
|
72 <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>() |
|
73 <a name="l00079"></a>00079 { |
|
74 <a name="l00080"></a>00080 iConsole->Printf(KExit); |
|
75 <a name="l00081"></a>00081 iConsole->Getch(); |
|
76 <a name="l00082"></a>00082 <span class="keyword">delete</span> iMtm; |
|
77 <a name="l00083"></a>00083 iMtm = NULL; |
|
78 <a name="l00084"></a>00084 <span class="keyword">delete</span> iClientRegistry; |
|
79 <a name="l00085"></a>00085 iClientRegistry = NULL; |
|
80 <a name="l00086"></a>00086 <span class="keyword">delete</span> iSession; |
|
81 <a name="l00087"></a>00087 iSession = NULL; |
|
82 <a name="l00088"></a>00088 <span class="keyword">delete</span> iConsole; |
|
83 <a name="l00089"></a>00089 } |
|
84 <a name="l00090"></a>00090 |
|
85 <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>() |
|
86 <a name="l00097"></a>00097 { |
|
87 <a name="l00098"></a>00098 <span class="comment">// Create a message server session.</span> |
|
88 <a name="l00099"></a>00099 iSession = CMsvSession::OpenSyncL(*<span class="keyword">this</span>); |
|
89 <a name="l00100"></a>00100 CleanupStack::PushL(iSession); |
|
90 <a name="l00101"></a>00101 |
|
91 <a name="l00102"></a>00102 <span class="comment">// Create a client-side MTM registry.</span> |
|
92 <a name="l00103"></a>00103 iClientRegistry = CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32); |
|
93 <a name="l00104"></a>00104 <span class="keywordflow">if</span> (iClientRegistry != NULL && iClientRegistry->IsPresent(KUidMsgTypePOP3)) |
|
94 <a name="l00105"></a>00105 { |
|
95 <a name="l00106"></a>00106 CleanupStack::PushL(iClientRegistry); |
|
96 <a name="l00107"></a>00107 } |
|
97 <a name="l00108"></a>00108 <span class="comment">// Create a Client-side MTM object for the specified MTM UID.</span> |
|
98 <a name="l00109"></a>00109 iMtm = (CPop3ClientMtm*)iClientRegistry->NewMtmL(KUidMsgTypePOP3); |
|
99 <a name="l00110"></a>00110 iConsole->Printf(KCreateMtm); |
|
100 <a name="l00111"></a>00111 iConsole->Printf(KKeyPress); |
|
101 <a name="l00112"></a>00112 iConsole->Getch(); |
|
102 <a name="l00113"></a>00113 CleanupStack::Pop(2,iSession); <span class="comment">//iClientRegistry,iSession</span> |
|
103 <a name="l00114"></a>00114 |
|
104 <a name="l00115"></a>00115 } |
|
105 <a name="l00116"></a>00116 |
|
106 <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>() |
|
107 <a name="l00123"></a>00123 { |
|
108 <a name="l00124"></a>00124 CEmailAccounts* emailAccounts = CEmailAccounts::NewLC(); |
|
109 <a name="l00125"></a>00125 CImPop3Settings* settings = <span class="keyword">new</span>(ELeave) CImPop3Settings(); |
|
110 <a name="l00126"></a>00126 CleanupStack::PushL(settings); |
|
111 <a name="l00127"></a>00127 |
|
112 <a name="l00128"></a>00128 CImIAPPreferences* popIAP = CImIAPPreferences::NewLC(); |
|
113 <a name="l00129"></a>00129 |
|
114 <a name="l00130"></a>00130 <span class="comment">// Set the server address to system address</span> |
|
115 <a name="l00131"></a>00131 settings->SetServerAddressL(KPopServer); |
|
116 <a name="l00132"></a>00132 settings->SetLoginNameL(KPopLoginName); |
|
117 <a name="l00133"></a>00133 settings->SetPasswordL(KPopPassword); |
|
118 <a name="l00134"></a>00134 settings->SetPort(110); |
|
119 <a name="l00135"></a>00135 |
|
120 <a name="l00136"></a>00136 <span class="comment">// Create a Pop account</span> |
|
121 <a name="l00137"></a>00137 iConsole->Printf(KCreatePopAccount); |
|
122 <a name="l00138"></a>00138 iPopAccount = emailAccounts->CreatePopAccountL(KTxtAccountName, *settings,*popIAP,EFalse); |
|
123 <a name="l00139"></a>00139 |
|
124 <a name="l00140"></a>00140 CImSmtpSettings *smtpSettings = <span class="keyword">new</span> (ELeave) CImSmtpSettings(); |
|
125 <a name="l00141"></a>00141 CleanupStack::PushL(smtpSettings); |
|
126 <a name="l00142"></a>00142 |
|
127 <a name="l00143"></a>00143 emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *popIAP); |
|
128 <a name="l00144"></a>00144 |
|
129 <a name="l00145"></a>00145 <span class="comment">// Create an Smtp acoount</span> |
|
130 <a name="l00146"></a>00146 iConsole->Printf(KCreateSmtpAccount); |
|
131 <a name="l00147"></a>00147 iSmtpAccount = emailAccounts->CreateSmtpAccountL(iPopAccount, *smtpSettings, *popIAP, EFalse); |
|
132 <a name="l00148"></a>00148 |
|
133 <a name="l00149"></a>00149 emailAccounts->SetDefaultSmtpAccountL(iSmtpAccount); |
|
134 <a name="l00150"></a>00150 |
|
135 <a name="l00151"></a>00151 smtpSettings->SetServerAddressL(KSmtpServerAddress); |
|
136 <a name="l00152"></a>00152 smtpSettings->SetEmailAliasL(KEmailAlias); |
|
137 <a name="l00153"></a>00153 smtpSettings->SetEmailAddressL(KSmtpEmailAddress); |
|
138 <a name="l00154"></a>00154 smtpSettings->SetReplyToAddressL(KSmtpEmailAddress); |
|
139 <a name="l00155"></a>00155 smtpSettings->SetReceiptAddressL(KSmtpEmailAddress); |
|
140 <a name="l00156"></a>00156 smtpSettings->SetPort(25); |
|
141 <a name="l00157"></a>00157 |
|
142 <a name="l00158"></a>00158 <span class="comment">// Add IAP to the IAP preferences</span> |
|
143 <a name="l00159"></a>00159 CImIAPPreferences* prefs = CImIAPPreferences::NewLC(); |
|
144 <a name="l00160"></a>00160 TImIAPChoice iap; |
|
145 <a name="l00161"></a>00161 TInt iapID = 0; |
|
146 <a name="l00162"></a>00162 CMDBSession* dbSession = CMDBSession::NewL(KCDVersion1_1); |
|
147 <a name="l00163"></a>00163 CleanupStack::PushL(dbSession); |
|
148 <a name="l00164"></a>00164 CCDConnectionPrefsRecord *connPrefRecord = <span class="keyword">static_cast<</span>CCDConnectionPrefsRecord*<span class="keyword">></span>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
149 <a name="l00165"></a>00165 CleanupStack::PushL(connPrefRecord); |
|
150 <a name="l00166"></a>00166 |
|
151 <a name="l00167"></a>00167 <span class="comment">// Set the direction of connection</span> |
|
152 <a name="l00168"></a>00168 connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing; |
|
153 <a name="l00169"></a>00169 connPrefRecord->iRanking = 1; |
|
154 <a name="l00170"></a>00170 <span class="keywordflow">if</span>(!connPrefRecord->FindL(*dbSession)) |
|
155 <a name="l00171"></a>00171 { |
|
156 <a name="l00172"></a>00172 User::Leave(KErrNotFound); |
|
157 <a name="l00173"></a>00173 } |
|
158 <a name="l00174"></a>00174 iapID = connPrefRecord->iDefaultIAP; |
|
159 <a name="l00175"></a>00175 iap.iIAP = iapID; |
|
160 <a name="l00176"></a>00176 iap.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
161 <a name="l00177"></a>00177 prefs->AddIAPL(iap); |
|
162 <a name="l00178"></a>00178 |
|
163 <a name="l00179"></a>00179 emailAccounts->GetSmtpAccountL(iSmtpAccount.iSmtpService, iSmtpAccount); |
|
164 <a name="l00180"></a>00180 emailAccounts->SaveSmtpSettingsL(iSmtpAccount,*smtpSettings); |
|
165 <a name="l00181"></a>00181 emailAccounts->SaveSmtpIapSettingsL(iSmtpAccount, *prefs); |
|
166 <a name="l00182"></a>00182 |
|
167 <a name="l00183"></a>00183 CleanupStack::PopAndDestroy(7,emailAccounts); <span class="comment">//connPrefRecord,dbSession,prefs,smtpSettings,popIAP,settings,emailAccounts</span> |
|
168 <a name="l00184"></a>00184 } |
|
169 <a name="l00185"></a>00185 |
|
170 <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>() |
|
171 <a name="l00191"></a>00191 { |
|
172 <a name="l00192"></a>00192 |
|
173 <a name="l00193"></a>00193 TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId; |
|
174 <a name="l00194"></a>00194 |
|
175 <a name="l00195"></a>00195 <span class="comment">// Set the context to the folder in which message has to be created</span> |
|
176 <a name="l00196"></a>00196 CMsvEntry* entry = CMsvEntry::NewL(*iSession,outboxId,TMsvSelectionOrdering()); |
|
177 <a name="l00197"></a>00197 CleanupStack::PushL(entry); |
|
178 <a name="l00198"></a>00198 entry->SetEntryL(outboxId); |
|
179 <a name="l00199"></a>00199 |
|
180 <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>(); |
|
181 <a name="l00201"></a>00201 CleanupStack::PushL(waiter); |
|
182 <a name="l00202"></a>00202 |
|
183 <a name="l00203"></a>00203 TMsvEmailTypeList msvEmailTypeList = 0; |
|
184 <a name="l00204"></a>00204 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments); |
|
185 <a name="l00205"></a>00205 |
|
186 <a name="l00206"></a>00206 CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(waiter->iStatus, *iSession,KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP); |
|
187 <a name="l00207"></a>00207 CleanupStack::PushL(emailOperation); |
|
188 <a name="l00208"></a>00208 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>(); |
|
189 <a name="l00209"></a>00209 |
|
190 <a name="l00210"></a>00210 TMsvId temp; |
|
191 <a name="l00211"></a>00211 TPckgC<TMsvId> paramPack(temp); |
|
192 <a name="l00212"></a>00212 <span class="keyword">const</span> TDesC8& progBuf = emailOperation->ProgressL(); |
|
193 <a name="l00213"></a>00213 paramPack.Set(progBuf); |
|
194 <a name="l00214"></a>00214 TMsvId newMessageId; |
|
195 <a name="l00215"></a>00215 newMessageId = paramPack(); |
|
196 <a name="l00216"></a>00216 |
|
197 <a name="l00217"></a>00217 entry->SetEntryL(newMessageId); |
|
198 <a name="l00218"></a>00218 |
|
199 <a name="l00219"></a>00219 CMsvStore* store = entry->EditStoreL(); |
|
200 <a name="l00220"></a>00220 CleanupStack::PushL(store); |
|
201 <a name="l00221"></a>00221 CImHeader* emailEntry = CImHeader::NewLC(); |
|
202 <a name="l00222"></a>00222 emailEntry->RestoreL(*store); |
|
203 <a name="l00223"></a>00223 emailEntry->SetFromL((TDesC8&)KFrom); |
|
204 <a name="l00224"></a>00224 emailEntry->SetSubjectL((TDesC&)KSubject); |
|
205 <a name="l00225"></a>00225 emailEntry->ToRecipients().AppendL((TDesC&)KTo); |
|
206 <a name="l00226"></a>00226 |
|
207 <a name="l00227"></a>00227 <span class="comment">// Paragraph format layer for the rich text object </span> |
|
208 <a name="l00228"></a>00228 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
209 <a name="l00229"></a>00229 CleanupStack::PushL(paraFormatLayer); |
|
210 <a name="l00230"></a>00230 <span class="comment">// Character format layer for the rich text object</span> |
|
211 <a name="l00231"></a>00231 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
212 <a name="l00232"></a>00232 CleanupStack::PushL(charFormatLayer); |
|
213 <a name="l00233"></a>00233 |
|
214 <a name="l00234"></a>00234 CRichText* bodyText = CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256); |
|
215 <a name="l00235"></a>00235 CleanupStack::PushL(bodyText); |
|
216 <a name="l00236"></a>00236 |
|
217 <a name="l00237"></a>00237 <span class="comment">// Inserts the contents of a buffer into the document at specified position</span> |
|
218 <a name="l00238"></a>00238 bodyText->InsertL(0, KBodyContents); |
|
219 <a name="l00239"></a>00239 store->StoreBodyTextL(*bodyText); |
|
220 <a name="l00240"></a>00240 emailEntry->StoreL(*store); |
|
221 <a name="l00241"></a>00241 <span class="comment">// Store the changes permanently</span> |
|
222 <a name="l00242"></a>00242 store->CommitL(); |
|
223 <a name="l00243"></a>00243 |
|
224 <a name="l00244"></a>00244 CleanupStack::PopAndDestroy(8,entry); <span class="comment">// bodyText,charFormatLayer,paraFormatLayer,emailEntry,store,emailOperation,waiter,entry</span> |
|
225 <a name="l00245"></a>00245 |
|
226 <a name="l00246"></a>00246 } |
|
227 <a name="l00247"></a>00247 |
|
228 <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>() |
|
229 <a name="l00255"></a>00255 { |
|
230 <a name="l00256"></a>00256 CMsvEntry* entry = iSession->GetEntryL(iSmtpAccount.iSmtpService); |
|
231 <a name="l00257"></a>00257 CleanupStack::PushL(entry); |
|
232 <a name="l00258"></a>00258 |
|
233 <a name="l00259"></a>00259 TMsvId outboxId = KMsvGlobalOutBoxIndexEntryId; |
|
234 <a name="l00260"></a>00260 |
|
235 <a name="l00261"></a>00261 <span class="comment">// creating ChildrenSelection</span> |
|
236 <a name="l00262"></a>00262 TMsvSelectionOrdering order; |
|
237 <a name="l00263"></a>00263 order.SetShowInvisibleEntries(ETrue); |
|
238 <a name="l00264"></a>00264 entry->SetSortTypeL(order); |
|
239 <a name="l00265"></a>00265 |
|
240 <a name="l00266"></a>00266 entry->SetEntryL(outboxId); |
|
241 <a name="l00267"></a>00267 <span class="comment">// Get the selection containing the IDs of all the context children</span> |
|
242 <a name="l00268"></a>00268 CMsvEntrySelection* selection = entry->ChildrenL(); |
|
243 <a name="l00269"></a>00269 |
|
244 <a name="l00270"></a>00270 <span class="comment">// Fetch the Id of the first entry</span> |
|
245 <a name="l00271"></a>00271 TMsvId entryId = KMsvNullIndexEntryId; |
|
246 <a name="l00272"></a>00272 entryId = (*selection)[0]; |
|
247 <a name="l00273"></a>00273 |
|
248 <a name="l00274"></a>00274 <span class="keyword">delete</span> selection; |
|
249 <a name="l00275"></a>00275 |
|
250 <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>(); |
|
251 <a name="l00277"></a>00277 CleanupStack::PushL(waiter); |
|
252 <a name="l00278"></a>00278 |
|
253 <a name="l00279"></a>00279 iConsole->Printf(KSendMail); |
|
254 <a name="l00280"></a>00280 <span class="comment">// Create asynchronously, copies of children of the context </span> |
|
255 <a name="l00281"></a>00281 <span class="comment">// as new entries of targetId (smtpServiceId)</span> |
|
256 <a name="l00282"></a>00282 CMsvOperation* operation = entry->CopyL(entryId,iSmtpAccount.iSmtpService, waiter->iStatus); |
|
257 <a name="l00283"></a>00283 |
|
258 <a name="l00284"></a>00284 CleanupStack::PushL(operation); |
|
259 <a name="l00285"></a>00285 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>(); |
|
260 <a name="l00286"></a>00286 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>()); |
|
261 <a name="l00287"></a>00287 |
|
262 <a name="l00288"></a>00288 CleanupStack::PopAndDestroy(3, entry); <span class="comment">//operation,waiter,entry</span> |
|
263 <a name="l00289"></a>00289 } |
|
264 <a name="l00290"></a>00290 |
|
265 <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>() |
|
266 <a name="l00298"></a>00298 { |
|
267 <a name="l00299"></a>00299 |
|
268 <a name="l00300"></a>00300 <span class="comment">// Change the current context</span> |
|
269 <a name="l00301"></a>00301 iMtm->SwitchCurrentEntryL(iPopAccount.iPopService); |
|
270 <a name="l00302"></a>00302 |
|
271 <a name="l00303"></a>00303 CMsvEntrySelection* selection = <span class="keyword">new</span> (ELeave) CMsvEntrySelection; |
|
272 <a name="l00304"></a>00304 CleanupStack::PushL(selection); |
|
273 <a name="l00305"></a>00305 |
|
274 <a name="l00306"></a>00306 <span class="comment">// Append the popServiceId onto the end of the array</span> |
|
275 <a name="l00307"></a>00307 selection->AppendL(iPopAccount.iPopService); |
|
276 <a name="l00308"></a>00308 |
|
277 <a name="l00309"></a>00309 TBuf8<1> param; |
|
278 <a name="l00310"></a>00310 |
|
279 <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>(); |
|
280 <a name="l00312"></a>00312 CleanupStack::PushL(waiter); |
|
281 <a name="l00313"></a>00313 |
|
282 <a name="l00314"></a>00314 <span class="comment">// Attempts to connect to the Pop3 Service </span> |
|
283 <a name="l00315"></a>00315 iConsole->Printf(KWait); |
|
284 <a name="l00316"></a>00316 CMsvOperation* connectOperation = iMtm->InvokeAsyncFunctionL(KPOP3MTMConnect,*selection,param, waiter->iStatus); |
|
285 <a name="l00317"></a>00317 CleanupStack::PushL(connectOperation); |
|
286 <a name="l00318"></a>00318 |
|
287 <a name="l00319"></a>00319 <span class="comment">// Wait on the status</span> |
|
288 <a name="l00320"></a>00320 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>(); |
|
289 <a name="l00321"></a>00321 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>()); |
|
290 <a name="l00322"></a>00322 |
|
291 <a name="l00323"></a>00323 <span class="comment">// Populate the message</span> |
|
292 <a name="l00324"></a>00324 iConsole->Printf(KDownload); |
|
293 <a name="l00325"></a>00325 CMsvOperation* operationPop = iMtm->InvokeAsyncFunctionL(KPOP3MTMPopulate,*selection,param, waiter->iStatus); |
|
294 <a name="l00326"></a>00326 CleanupStack::PushL(operationPop); |
|
295 <a name="l00327"></a>00327 |
|
296 <a name="l00328"></a>00328 <span class="comment">// Wait on the status</span> |
|
297 <a name="l00329"></a>00329 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>(); |
|
298 <a name="l00330"></a>00330 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>()); |
|
299 <a name="l00331"></a>00331 |
|
300 <a name="l00332"></a>00332 <span class="comment">// Now disconnect from Pop3 service</span> |
|
301 <a name="l00333"></a>00333 CMsvOperation* operationDis = iMtm->InvokeAsyncFunctionL(KPOP3MTMDisconnect,*selection,param, waiter->iStatus); |
|
302 <a name="l00334"></a>00334 CleanupStack::PushL(operationDis); |
|
303 <a name="l00335"></a>00335 |
|
304 <a name="l00336"></a>00336 <span class="comment">// Wait on the status</span> |
|
305 <a name="l00337"></a>00337 waiter-><a class="code" href="class_c_mess_async_waiter.html#e976b71c3a09378e0cd9026732ed2438">StartAndWait</a>(); |
|
306 <a name="l00338"></a>00338 User::LeaveIfError(waiter-><a class="code" href="class_c_mess_async_waiter.html#35a7e4db06aa88a409176ddf7118bfce">Result</a>()); |
|
307 <a name="l00339"></a>00339 iConsole->Printf(KDisconnect); |
|
308 <a name="l00340"></a>00340 iConsole->Getch (); |
|
309 <a name="l00341"></a>00341 |
|
310 <a name="l00342"></a>00342 CleanupStack::PopAndDestroy(5,selection); <span class="comment">//operationDis,operationPop,connectOperation,waiter,selection</span> |
|
311 <a name="l00343"></a>00343 } |
|
312 <a name="l00344"></a>00344 |
|
313 <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>) |
|
314 <a name="l00355"></a>00355 {} |
|
315 <a name="l00356"></a>00356 |
|
316 <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>() |
|
317 <a name="l00358"></a>00358 { |
|
318 <a name="l00359"></a>00359 |
|
319 <a name="l00360"></a>00360 <span class="comment">// Create an Active Scheduler to handle asychronous calls</span> |
|
320 <a name="l00361"></a>00361 CActiveScheduler* scheduler = <span class="keyword">new</span> (ELeave) CActiveScheduler; |
|
321 <a name="l00362"></a>00362 <span class="comment">/*</span> |
|
322 <a name="l00363"></a>00363 <span class="comment"> If Active Scheduler has been created, install it .</span> |
|
323 <a name="l00364"></a>00364 <span class="comment"> As it is an asychronous call we need to install it explicitly.</span> |
|
324 <a name="l00365"></a>00365 <span class="comment"> */</span> |
|
325 <a name="l00366"></a>00366 CActiveScheduler::Install( scheduler ); |
|
326 <a name="l00367"></a>00367 |
|
327 <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>(); |
|
328 <a name="l00369"></a>00369 CleanupStack::PushL(app); |
|
329 <a name="l00370"></a>00370 |
|
330 <a name="l00371"></a>00371 <span class="comment">// Create a client registry.</span> |
|
331 <a name="l00372"></a>00372 app-><a class="code" href="class_c_pop3_example.html#071be1033b73bd98a19978d4bd90b7fb">CreateClientRegistryL</a>(); |
|
332 <a name="l00373"></a>00373 |
|
333 <a name="l00374"></a>00374 <span class="comment">// Create pop and smtp accounts.</span> |
|
334 <a name="l00375"></a>00375 app-><a class="code" href="class_c_pop3_example.html#e1b7a4e38a8771d202c637adb12302c2">CreatePopAndSmtpAccountL</a>(); |
|
335 <a name="l00376"></a>00376 |
|
336 <a name="l00377"></a>00377 <span class="comment">// Load the physical and logical device drivers.</span> |
|
337 <a name="l00378"></a>00378 <span class="comment">// Symbian platform will automatically append .PDD and .LDD</span> |
|
338 <a name="l00379"></a>00379 |
|
339 <a name="l00380"></a>00380 TInt err; |
|
340 <a name="l00381"></a>00381 err=User::LoadPhysicalDevice(PDD_NAME); |
|
341 <a name="l00382"></a>00382 <span class="keywordflow">if</span> (err!=KErrNone && err!=KErrAlreadyExists) |
|
342 <a name="l00383"></a>00383 User::Leave(err); |
|
343 <a name="l00384"></a>00384 err=User::LoadLogicalDevice(LDD_NAME); |
|
344 <a name="l00385"></a>00385 <span class="keywordflow">if</span> (err!=KErrNone && err!=KErrAlreadyExists) |
|
345 <a name="l00386"></a>00386 User::Leave(err); |
|
346 <a name="l00387"></a>00387 |
|
347 <a name="l00388"></a>00388 <span class="comment">// Create an Smtp mail to be sent. </span> |
|
348 <a name="l00389"></a>00389 app-><a class="code" href="class_c_pop3_example.html#4e14514a9a39eee71b372edc85a93b17">CreateSmtpMessageL</a>(); |
|
349 <a name="l00390"></a>00390 |
|
350 <a name="l00391"></a>00391 <span class="comment">// Send the mail created.</span> |
|
351 <a name="l00392"></a>00392 app-><a class="code" href="class_c_pop3_example.html#681d0b120db69c06587235560f1e3b34">SendSMTPMessageL</a>(); |
|
352 <a name="l00393"></a>00393 |
|
353 <a name="l00394"></a>00394 <span class="comment">// Connect to the pop3 server for downloading the mail and disconnect.</span> |
|
354 <a name="l00395"></a>00395 app-><a class="code" href="class_c_pop3_example.html#a6944f804b14759d3eaec2b791b78f0c">ConnectDownloadAndDisconnectPOPServerL</a>(); |
|
355 <a name="l00396"></a>00396 |
|
356 <a name="l00397"></a>00397 CleanupStack::PopAndDestroy(app); |
|
357 <a name="l00398"></a>00398 |
|
358 <a name="l00399"></a>00399 <span class="keyword">delete</span> scheduler; |
|
359 <a name="l00400"></a>00400 |
|
360 <a name="l00401"></a>00401 } |
|
361 <a name="l00402"></a>00402 |
|
362 <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>() |
|
363 <a name="l00404"></a>00404 { |
|
364 <a name="l00405"></a>00405 __UHEAP_MARK; |
|
365 <a name="l00406"></a>00406 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
366 <a name="l00407"></a>00407 <span class="keywordflow">if</span>(cleanup == NULL) |
|
367 <a name="l00408"></a>00408 { |
|
368 <a name="l00409"></a>00409 <span class="keywordflow">return</span> KErrNoMemory; |
|
369 <a name="l00410"></a>00410 } |
|
370 <a name="l00411"></a>00411 TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()); |
|
371 <a name="l00412"></a>00412 |
|
372 <a name="l00413"></a>00413 <span class="keywordflow">if</span>(err != KErrNone) |
|
373 <a name="l00414"></a>00414 { |
|
374 <a name="l00415"></a>00415 _LIT(KUserPanic,<span class="stringliteral">"Failed to complete"</span>); |
|
375 <a name="l00416"></a>00416 User::Panic(KUserPanic, err); |
|
376 <a name="l00417"></a>00417 } |
|
377 <a name="l00418"></a>00418 |
|
378 <a name="l00419"></a>00419 <span class="keyword">delete</span> cleanup; |
|
379 <a name="l00420"></a>00420 __UHEAP_MARKEND; |
|
380 <a name="l00421"></a>00421 <span class="keywordflow">return</span> KErrNone; |
|
381 <a name="l00422"></a>00422 } |
|
382 </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 |
|
383 <a href="http://www.doxygen.org/index.html"> |
|
384 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address> |
|
385 </body> |
|
386 </html> |