|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Populates imap4 folders using current populate settings. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <impcmtm.h> // CImap4ClientMtm |
|
21 #include <SenduiMtmUids.h> |
|
22 #include "AlwaysOnlineEmailPluginLogging.h" |
|
23 #include "AlwaysOnlineEmailLoggingTools.h" |
|
24 #include "AlwaysOnlineImap4FolderPopulate.h" |
|
25 |
|
26 |
|
27 |
|
28 //-------------------------------- |
|
29 // CAlwaysOnlineImap4Agent() |
|
30 //-------------------------------- |
|
31 CAlwaysOnlineImap4FolderPopulate::CAlwaysOnlineImap4FolderPopulate( |
|
32 CMsvSession& aMsvSession, |
|
33 CImap4ClientMtm& aImap4ClientMtm, |
|
34 TMsvId aServiceId, |
|
35 TMsvId aInboxId, |
|
36 TImImap4GetPartialMailInfo& aPartialInfo, |
|
37 TRequestStatus& aObserverRequestStatus ) |
|
38 : |
|
39 CMsvOperation( |
|
40 aMsvSession, |
|
41 CActive::EPriorityStandard, |
|
42 aObserverRequestStatus), |
|
43 iServiceId( aServiceId ), |
|
44 iPartialInfo( aPartialInfo), |
|
45 iImap4ClientMtm( aImap4ClientMtm ), |
|
46 iInboxId( aInboxId ) |
|
47 { |
|
48 CActiveScheduler::Add(this); |
|
49 iMtm = KSenduiMtmImap4Uid; |
|
50 } |
|
51 |
|
52 //-------------------------------- |
|
53 // NewL |
|
54 //-------------------------------- |
|
55 CAlwaysOnlineImap4FolderPopulate* CAlwaysOnlineImap4FolderPopulate::NewL( |
|
56 CMsvSession& aMsvSession, |
|
57 CImap4ClientMtm& aImap4ClientMtm, |
|
58 TMsvId aServiceId, |
|
59 TMsvId aInboxId, |
|
60 TImImap4GetPartialMailInfo& aPartialInfo, |
|
61 const CMsvEntrySelection* aSelection, // folder ids |
|
62 TRequestStatus& aObserverRequestStatus ) |
|
63 { |
|
64 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::NewL" ); |
|
65 CAlwaysOnlineImap4FolderPopulate* self=new (ELeave) CAlwaysOnlineImap4FolderPopulate( |
|
66 aMsvSession, |
|
67 aImap4ClientMtm, |
|
68 aServiceId, |
|
69 aInboxId, |
|
70 aPartialInfo, |
|
71 aObserverRequestStatus ); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(aSelection); |
|
74 CleanupStack::Pop(self); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 //-------------------------------- |
|
80 // ConstructL() |
|
81 //-------------------------------- |
|
82 |
|
83 void CAlwaysOnlineImap4FolderPopulate::ConstructL( const CMsvEntrySelection* aSelection) |
|
84 { |
|
85 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::ConstructL" ); |
|
86 iFolderSelection = aSelection->CopyL(); |
|
87 |
|
88 // if selection is empty, following just completes |
|
89 StartNextFolderPopulateOperation(); |
|
90 } |
|
91 |
|
92 |
|
93 //-------------------------------- |
|
94 // ~CAlwaysOnlineImap4Agent() |
|
95 //-------------------------------- |
|
96 |
|
97 CAlwaysOnlineImap4FolderPopulate::~CAlwaysOnlineImap4FolderPopulate() |
|
98 { |
|
99 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::~CAlwaysOnlineImap4FolderPopulate" ); |
|
100 Cancel(); |
|
101 delete iOperation; |
|
102 delete iFolderSelection; |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------- |
|
106 // CAlwaysOnlineImap4FolderPopulate::StartNextFolderPopulateOperation |
|
107 // ---------------------------------------------------- |
|
108 void CAlwaysOnlineImap4FolderPopulate::StartNextFolderPopulateOperation() |
|
109 { |
|
110 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::StartNextFolderPopulateOperation" ); |
|
111 delete iOperation; |
|
112 iOperation = NULL; |
|
113 TInt err = KErrNotFound; // if folder selection is empty, operation is completed with this error |
|
114 if ( iFolderSelection->Count() ) |
|
115 { |
|
116 TRAP(err, DoNewFolderPopulateOperationL()); |
|
117 // whether error or not, remove the data for this operation |
|
118 iFolderSelection->Delete(0); |
|
119 } |
|
120 // and set active |
|
121 iStatus=KRequestPending; |
|
122 SetActive(); |
|
123 // if error, then complete this pass with the error code |
|
124 if (err) |
|
125 { |
|
126 TRequestStatus* status = &iStatus; |
|
127 User::RequestComplete(status, err); |
|
128 } |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------- |
|
132 // CAlwaysOnlineImap4FolderPopulate::DoNewFolderPopulateOperationL |
|
133 // ---------------------------------------------------- |
|
134 void CAlwaysOnlineImap4FolderPopulate::DoNewFolderPopulateOperationL() |
|
135 { |
|
136 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::DoNewFolderPopulateOperationL" ); |
|
137 KAOEMAIL_LOGGER_FN1("CAlwaysOnlineImap4FolderPopulate::DoNewFolderPopulateOperationL"); |
|
138 if ( HasFolderNewMailL( (*iFolderSelection)[0] ) ) |
|
139 { |
|
140 // here do folder populate operation |
|
141 CMsvEntrySelection* selection=new(ELeave) CMsvEntrySelection; |
|
142 CleanupStack::PushL(selection); |
|
143 selection->AppendL( iServiceId ); |
|
144 selection->AppendL( (*iFolderSelection)[0] ); |
|
145 |
|
146 TPckg<TImImap4GetPartialMailInfo> param( iPartialInfo ); |
|
147 |
|
148 iOperation = iImap4ClientMtm.InvokeAsyncFunctionL( |
|
149 KIMAP4MTMPopulateNewMailWhenAlreadyConnected, |
|
150 *selection, |
|
151 param, |
|
152 iStatus); |
|
153 KAOEMAIL_LOGGER_WRITE_FORMAT("Started populate folder 0x%x", (*selection)[1]); // CSI: 2 # 2 items added above |
|
154 |
|
155 CleanupStack::PopAndDestroy( selection ); |
|
156 } |
|
157 else |
|
158 { |
|
159 // no new mail found, just complete |
|
160 KAOEMAIL_LOGGER_WRITE_FORMAT("No new mail found if folder 0x%x, just complete", (*iFolderSelection)[0]); |
|
161 iOperation = CMsvCompletedOperation::NewL( |
|
162 iMsvSession, |
|
163 KSenduiMtmImap4Uid, |
|
164 KNullDesC8, |
|
165 KMsvLocalServiceIndexEntryId, |
|
166 iStatus, |
|
167 KErrCancel); |
|
168 } |
|
169 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderPopulate::DoNewFolderPopulateOperationL"); |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------- |
|
173 // CAlwaysOnlineImap4FolderPopulate::DoCancel |
|
174 // ---------------------------------------------------- |
|
175 void CAlwaysOnlineImap4FolderPopulate::DoCancel() |
|
176 { |
|
177 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::DoCancel" ); |
|
178 if (iOperation) |
|
179 { |
|
180 iOperation->Cancel(); |
|
181 } |
|
182 TRequestStatus* status = &iObserverRequestStatus; |
|
183 User::RequestComplete(status, iStatus.Int()); |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------- |
|
187 // CAlwaysOnlineImap4FolderPopulate::RunL |
|
188 // ---------------------------------------------------- |
|
189 void CAlwaysOnlineImap4FolderPopulate::RunL() |
|
190 { |
|
191 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::RunL" ); |
|
192 KAOEMAIL_LOGGER_WRITE_FORMAT("CAlwaysOnlineImap4FolderPopulate::RunL iStatus %d", iStatus.Int() ); |
|
193 if (iFolderSelection->Count()==0) |
|
194 { |
|
195 // nothing left to process, so complete the observer |
|
196 TRequestStatus* status = &iObserverRequestStatus; |
|
197 User::RequestComplete(status, iStatus.Int()); |
|
198 } |
|
199 else |
|
200 { |
|
201 // start the next pass |
|
202 StartNextFolderPopulateOperation(); |
|
203 } |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------- |
|
207 // CAlwaysOnlineImap4FolderPopulate::ProgressL |
|
208 // ---------------------------------------------------- |
|
209 const TDesC8& CAlwaysOnlineImap4FolderPopulate::ProgressL() |
|
210 { |
|
211 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::ProgressL" ); |
|
212 if (iOperation) |
|
213 { |
|
214 return iOperation->ProgressL(); |
|
215 } |
|
216 return KNullDesC8(); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------- |
|
220 // CAlwaysOnlineImap4FolderPopulate::SelectInbox |
|
221 // ---------------------------------------------------- |
|
222 void CAlwaysOnlineImap4FolderPopulate::SelectInbox() |
|
223 { |
|
224 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::SelectInbox" ); |
|
225 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderPopulate::SelectInbox"); |
|
226 delete iOperation; |
|
227 iOperation = NULL; |
|
228 TRAPD(err, DoSelectInboxL()); |
|
229 // and set active |
|
230 iStatus=KRequestPending; |
|
231 SetActive(); |
|
232 // if error, then complete this pass with the error code |
|
233 if (err) |
|
234 { |
|
235 TRequestStatus* status = &iStatus; |
|
236 User::RequestComplete(status, err); |
|
237 } |
|
238 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderPopulate::SelectInbox"); |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------- |
|
242 // CAlwaysOnlineImap4FolderPopulate::DoSelectInboxL |
|
243 // ---------------------------------------------------- |
|
244 void CAlwaysOnlineImap4FolderPopulate::DoSelectInboxL() |
|
245 { |
|
246 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::DoSelectInboxL" ); |
|
247 KAOEMAIL_LOGGER_FN1("CAlwaysOnlineImap4FolderPopulate::DoSelectInboxL"); |
|
248 // here do folder populate operation |
|
249 CMsvEntrySelection* selection=new(ELeave) CMsvEntrySelection; |
|
250 CleanupStack::PushL(selection); |
|
251 selection->AppendL( iInboxId ); |
|
252 |
|
253 TBuf8<1> dummyParams; |
|
254 dummyParams.Zero(); |
|
255 |
|
256 iOperation = iImap4ClientMtm.InvokeAsyncFunctionL( |
|
257 //KIMAP4MTMPopulateAllMailWhenAlreadyConnected, |
|
258 KIMAP4MTMInboxNewSync, |
|
259 //KIMAP4MTMSelect, |
|
260 *selection, |
|
261 dummyParams, |
|
262 iStatus); |
|
263 KAOEMAIL_LOGGER_WRITE_FORMAT("Started inbox select 0x%x", iInboxId); |
|
264 |
|
265 iInboxId = -1; |
|
266 |
|
267 CleanupStack::PopAndDestroy( selection ); |
|
268 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderPopulate::DoSelectInboxL"); |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------- |
|
272 // CAlwaysOnlineImap4FolderPopulate::HasFolderNewMailL |
|
273 // ---------------------------------------------------- |
|
274 TBool CAlwaysOnlineImap4FolderPopulate::HasFolderNewMailL( TMsvId aFolderId ) |
|
275 { |
|
276 AOLOG_IN( "CAlwaysOnlineImap4FolderPopulate::HasFolderNewMailL" ); |
|
277 KAOEMAIL_LOGGER_FN1("CAlwaysOnlineImap4FolderPopulate::HasFolderNewMailL"); |
|
278 TInt count = 0; // number of NEW mails in this folder |
|
279 CMsvEntry* folderEntry = iMsvSession.GetEntryL( aFolderId ); |
|
280 CleanupStack::PushL( folderEntry ); |
|
281 const TInt entryCount = folderEntry->Count(); |
|
282 TInt i=0; |
|
283 for (i=0; i < entryCount && count == 0 ; i++) |
|
284 { |
|
285 if ( (*folderEntry)[i].New() ) |
|
286 { |
|
287 count++; |
|
288 } |
|
289 } |
|
290 CleanupStack::PopAndDestroy( folderEntry ); |
|
291 KAOEMAIL_LOGGER_WRITE_FORMAT("New mail count %d", count); |
|
292 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderPopulate::HasFolderNewMailL"); |
|
293 return (count>0); |
|
294 } |
|
295 |
|
296 //EOF |