|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cimapupdateflagoperation.h" |
|
20 #include "cimapfolder.h" |
|
21 #include "cimapsyncmanager.h" |
|
22 #include "cimapsessionconsts.h" |
|
23 #include "cimaplogger.h" |
|
24 #include "imappaniccodes.h" |
|
25 |
|
26 _LIT8(KImapAddFlags, "+FLAGS"); |
|
27 _LIT8(KStoreFlagsClearCommand, "-FLAGS"); |
|
28 _LIT8(KImapFlagSeen, "(\\Seen)"); |
|
29 |
|
30 |
|
31 CImapUpdateFlagOperation::CImapUpdateFlagOperation(CImapSyncManager& aSyncManager, |
|
32 CMsvServerEntry& aServerEntry, |
|
33 CImapSettings& aImapSettings) : |
|
34 CImapCompoundBase(aSyncManager, aServerEntry, aImapSettings) |
|
35 |
|
36 { |
|
37 |
|
38 } |
|
39 |
|
40 CImapUpdateFlagOperation::~CImapUpdateFlagOperation() |
|
41 { |
|
42 |
|
43 |
|
44 iMessageUids.Reset(); |
|
45 iFlagInfoResponseArray.Reset(); |
|
46 } |
|
47 |
|
48 CImapUpdateFlagOperation* CImapUpdateFlagOperation::NewL(CImapSyncManager& aSyncManager, |
|
49 CMsvServerEntry& aServerEntry, |
|
50 CImapSettings& aImapSettings) |
|
51 { |
|
52 CImapUpdateFlagOperation* self = new (ELeave) CImapUpdateFlagOperation(aSyncManager, |
|
53 aServerEntry, |
|
54 aImapSettings |
|
55 ); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 void CImapUpdateFlagOperation::ConstructL() |
|
63 { |
|
64 |
|
65 // Add to the active scheduler |
|
66 CActiveScheduler::Add(this); |
|
67 } |
|
68 |
|
69 void CImapUpdateFlagOperation::StartOperation(TRequestStatus& aStatus, CImapSession& aSession) |
|
70 //void CImapUpdateFlagOperation::StartOperation(TRequestStatus& aStatus) |
|
71 { |
|
72 iSession = &aSession; |
|
73 __LOG_TEXT(iSession->LogId(), "CImapUpdateFlagOperation::StartOperation()"); |
|
74 iNextStep = EUpdateFlag; |
|
75 Queue(aStatus); |
|
76 CompleteSelf(); |
|
77 } |
|
78 |
|
79 /** |
|
80 Handles the compound operation state machine |
|
81 |
|
82 @return ETrue if compound operation is completed, |
|
83 EFalse otherwise. |
|
84 */ |
|
85 TBool CImapUpdateFlagOperation::DoRunLoopL() |
|
86 { |
|
87 SetCurrentStep(); |
|
88 switch (iCurrentStep) |
|
89 { |
|
90 |
|
91 case EUpdateFlag: |
|
92 { |
|
93 TMsvEmailEntry entry = iServerEntry.Entry(); |
|
94 TUint id = entry.UID(); |
|
95 iMessageUids.AppendL(id); |
|
96 if(entry.Unread()) |
|
97 { |
|
98 entry.SetSeenIMAP4Flag(EFalse); |
|
99 } |
|
100 else |
|
101 { |
|
102 entry.SetSeenIMAP4Flag(ETrue); |
|
103 } |
|
104 |
|
105 |
|
106 User::LeaveIfError(iServerEntry.ChangeEntry(entry)); |
|
107 |
|
108 HBufC8* uidSeq = CImapSession::CreateSequenceSetLC(iMessageUids); |
|
109 |
|
110 // finished with the UID array. Clear it. |
|
111 iMessageUids.Reset(); |
|
112 if(entry.SeenIMAP4Flag()) |
|
113 { |
|
114 // issue the store command |
|
115 iSession->StoreL(iStatus, uidSeq->Des(), KImapAddFlags, KImapFlagSeen, ETrue, iFlagInfoResponseArray); |
|
116 |
|
117 } |
|
118 else |
|
119 { |
|
120 // issue the store command |
|
121 iSession->StoreL(iStatus, uidSeq->Des(), KStoreFlagsClearCommand, KImapFlagSeen, ETrue, iFlagInfoResponseArray); |
|
122 } |
|
123 |
|
124 iProgressState = TImap4GenericProgress::EBusy; |
|
125 CleanupStack::PopAndDestroy(uidSeq); |
|
126 iNextStep = EFinished; |
|
127 break; |
|
128 |
|
129 } |
|
130 |
|
131 |
|
132 case EFinished: |
|
133 { |
|
134 __LOG_TEXT(iSession->LogId(), "CImapUpdateFlagOperation::Completing OK"); |
|
135 iProgressState = TImap4GenericProgress::EIdle; |
|
136 Complete(KErrNone); |
|
137 return ETrue; |
|
138 } |
|
139 |
|
140 default: |
|
141 { |
|
142 __ASSERT_DEBUG(EFalse, |
|
143 TImapServerPanic::ImapPanic(TImapServerPanic::ECreateCompoundUnexpectedState)); |
|
144 // unexpected state - complete the request |
|
145 iProgressState = TImap4GenericProgress::EIdle; |
|
146 return ETrue; |
|
147 } |
|
148 } |
|
149 |
|
150 if (!IsActive()) |
|
151 { |
|
152 SetActive(); |
|
153 } |
|
154 return EFalse; |
|
155 } |
|
156 |
|
157 void CImapUpdateFlagOperation::DoCancel() |
|
158 { |
|
159 iProgressErrorCode = KErrCancel; |
|
160 |
|
161 switch (iCurrentStep) |
|
162 { |
|
163 case EUpdateFlag: |
|
164 { |
|
165 // outstanding request is on session |
|
166 iSession->Cancel(); |
|
167 break; |
|
168 } |
|
169 case EFinished: |
|
170 { |
|
171 // self-completed or no outstanding request. |
|
172 break; |
|
173 } |
|
174 |
|
175 default: |
|
176 { |
|
177 __ASSERT_DEBUG(EFalse, |
|
178 TImapServerPanic::ImapPanic(TImapServerPanic::ECreateCompoundCancelUnexpectedState)); |
|
179 break; |
|
180 } |
|
181 } // end switch (iCurrentStep) |
|
182 |
|
183 CMsgActive::DoCancel(); |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 void CImapUpdateFlagOperation::Progress(TImap4CompoundProgress& aCompoundProgress) |
|
190 { |
|
191 // Create does not set iOperation, it just sets iState to EBusy |
|
192 // when doing the creation |
|
193 aCompoundProgress.iGenericProgress.iState = iProgressState; |
|
194 |
|
195 |
|
196 // Put error into progress buffer |
|
197 if( aCompoundProgress.iGenericProgress.iErrorCode == KErrNone ) |
|
198 { |
|
199 aCompoundProgress.iGenericProgress.iErrorCode = iProgressErrorCode; |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 /** |
|
205 Handles NO/BAD responses according to current step. |
|
206 Negative server responses are not fatal - the error is reported in the |
|
207 progress report, and the operation completes. |
|
208 |
|
209 @return KErrNone if the error has been handled |
|
210 Completion error code otherwise. |
|
211 */ |
|
212 TInt CImapUpdateFlagOperation::ProcessNegativeServerResponse() |
|
213 { |
|
214 TInt err = iStatus.Int(); |
|
215 switch (iCurrentStep) |
|
216 { |
|
217 case EUpdateFlag: |
|
218 iNextStep = EFinished; |
|
219 break; |
|
220 case EFinished: |
|
221 default: |
|
222 { |
|
223 // positive error code not expected, |
|
224 // self-completed states or no outstanding request. |
|
225 TImapServerPanic::ImapPanic(TImapServerPanic::ECreateCompoundUnexpectedState); |
|
226 break; |
|
227 } |
|
228 |
|
229 } // end switch (iCurrentStep) |
|
230 iProgressErrorCode = err; |
|
231 return KErrNone; |
|
232 } |
|
233 |
|
234 /** |
|
235 Resume the operation following a bearer migration. |
|
236 */ |
|
237 void CImapUpdateFlagOperation::ResumeOperationL(TRequestStatus& aStatus, CImapSession& aSession) |
|
238 { |
|
239 iSession = &aSession; |
|
240 __LOG_TEXT(iSession->LogId(), "CImapUpdateFlagOperation::Resuming"); |
|
241 __ASSERT_DEBUG(iCurrentStep==ESuspendedForMigrate, TImapServerPanic::ImapPanic(TImapServerPanic::EUpdateCompoundUnexpectedState)); |
|
242 iStopForMigrate = EFalse; |
|
243 |
|
244 switch (iNextStep) |
|
245 { |
|
246 case EUpdateFlag: |
|
247 { |
|
248 // just return to the main state machine |
|
249 CompleteSelf(); |
|
250 break; |
|
251 } |
|
252 case EFinished: |
|
253 default: |
|
254 { |
|
255 __ASSERT_DEBUG(EFalse, TImapServerPanic::ImapPanic(TImapServerPanic::EUpdateCompoundUnexpectedState)); |
|
256 // abandon the compound operation |
|
257 iNextStep=EFinished; |
|
258 CompleteSelf(); |
|
259 break; |
|
260 } |
|
261 } |
|
262 Queue(aStatus); |
|
263 CompleteSelf(); |
|
264 } |
|
265 |