|
1 /* |
|
2 * Copyright (c) 2007-2008 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: common email folder object |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //<cmail> |
|
20 #include "emailtrace.h" |
|
21 #include "cfsmailfolder.h" |
|
22 #include "cfsmailplugin.h" |
|
23 //</cmail> |
|
24 |
|
25 #include "cfsmailiterator.h" |
|
26 #include "cfsmailrequestobserver.h" |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ========================================== |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CFSMailFolder::NewLC |
|
31 // ----------------------------------------------------------------------------- |
|
32 EXPORT_C CFSMailFolder* CFSMailFolder::NewLC( TFSMailMsgId aFolderId ) |
|
33 { |
|
34 FUNC_LOG; |
|
35 CFSMailFolder* api = new (ELeave) CFSMailFolder(); |
|
36 CleanupStack:: PushL(api); |
|
37 api->ConstructL( aFolderId ); |
|
38 return api; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CFSMailFolder::NewL |
|
43 // ----------------------------------------------------------------------------- |
|
44 EXPORT_C CFSMailFolder* CFSMailFolder::NewL( TFSMailMsgId aFolderId ) |
|
45 { |
|
46 FUNC_LOG; |
|
47 CFSMailFolder* api = CFSMailFolder::NewLC( aFolderId ); |
|
48 CleanupStack:: Pop(api); |
|
49 return api; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CFSMailFolder::CFSMailFolder |
|
54 // ----------------------------------------------------------------------------- |
|
55 CFSMailFolder::CFSMailFolder() |
|
56 { |
|
57 FUNC_LOG; |
|
58 |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CFSMailFolder::ConstructL |
|
63 // ----------------------------------------------------------------------------- |
|
64 void CFSMailFolder::ConstructL( TFSMailMsgId aFolderId ) |
|
65 { |
|
66 FUNC_LOG; |
|
67 // get requesthandler pointer |
|
68 iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls()); |
|
69 |
|
70 // set folder id |
|
71 iFolderId = aFolderId; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CFSMailFolder::~CFSMailFolder |
|
76 // ----------------------------------------------------------------------------- |
|
77 EXPORT_C CFSMailFolder::~CFSMailFolder() |
|
78 { |
|
79 FUNC_LOG; |
|
80 |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CFSMailFolder::ListMessagesL |
|
85 // ----------------------------------------------------------------------------- |
|
86 EXPORT_C MFSMailIterator* CFSMailFolder::ListMessagesL( const TFSMailDetails aDetails, |
|
87 const RArray<TFSMailSortCriteria>& aSorting) |
|
88 { |
|
89 FUNC_LOG; |
|
90 |
|
91 CFSMailIterator* iterator = NULL; |
|
92 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId())) |
|
93 { |
|
94 MFSMailIterator* pluginIterator = |
|
95 plugin->ListMessagesL(GetMailBoxId(),GetFolderId(),aDetails,aSorting); |
|
96 if(pluginIterator) |
|
97 { |
|
98 iterator = CFSMailIterator::NewL(*pluginIterator,iRequestHandler ); |
|
99 } |
|
100 } |
|
101 return iterator; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CFSMailFolder::FetchMessagesL |
|
106 // ----------------------------------------------------------------------------- |
|
107 EXPORT_C TInt CFSMailFolder::FetchMessagesL( const RArray<TFSMailMsgId>& aMessageIds, |
|
108 TFSMailDetails aDetails, |
|
109 MFSMailRequestObserver& aObserver ) |
|
110 { |
|
111 FUNC_LOG; |
|
112 // init asynchronous request |
|
113 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()); |
|
114 TFSPendingRequest request = |
|
115 iRequestHandler->InitAsyncRequestL( GetFolderId().PluginId(), aObserver ); |
|
116 |
|
117 TInt err = KErrNone; |
|
118 |
|
119 if (plugin) |
|
120 { |
|
121 MFSMailRequestObserver* observer = request.iObserver; |
|
122 TRAP(err,plugin->FetchMessagesL( GetMailBoxId(), |
|
123 GetFolderId(), |
|
124 aMessageIds, |
|
125 aDetails, |
|
126 *observer, |
|
127 request.iRequestId)); |
|
128 } |
|
129 else |
|
130 { |
|
131 err = KErrNotFound; |
|
132 } |
|
133 |
|
134 if(err != KErrNone) |
|
135 { |
|
136 iRequestHandler->CompleteRequest(request.iRequestId); |
|
137 User::Leave(err); |
|
138 } |
|
139 return request.iRequestId; |
|
140 |
|
141 } |
|
142 |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CFSMailFolder::GetSubFoldersL |
|
146 // ----------------------------------------------------------------------------- |
|
147 EXPORT_C void CFSMailFolder::GetSubFoldersL(RPointerArray<CFSMailFolder>& aSubFolders) |
|
148 { |
|
149 FUNC_LOG; |
|
150 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId())) |
|
151 { |
|
152 TRAPD(err,plugin->ListFoldersL( GetMailBoxId(), GetFolderId(), aSubFolders)); |
|
153 if(err != KErrNone) |
|
154 { |
|
155 aSubFolders.ResetAndDestroy(); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CFSMailFolder::RemoveMessageL |
|
162 // ----------------------------------------------------------------------------- |
|
163 EXPORT_C void CFSMailFolder::RemoveMessageL(TFSMailMsgId aMessage) |
|
164 { |
|
165 FUNC_LOG; |
|
166 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId())) |
|
167 { |
|
168 RArray<TFSMailMsgId> messages; |
|
169 messages.Reset(); |
|
170 messages.Append(aMessage); |
|
171 plugin->DeleteMessagesByUidL(GetMailBoxId(),GetFolderId(),messages); |
|
172 messages.Close(); |
|
173 } |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CFSMailFolder::SupportsCopyFromL |
|
178 // ----------------------------------------------------------------------------- |
|
179 EXPORT_C TBool CFSMailFolder::SupportsCopyFromL( TFSFolderType aFolderType ) |
|
180 { |
|
181 FUNC_LOG; |
|
182 |
|
183 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId())) |
|
184 { |
|
185 TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId()); |
|
186 if(onlineStatus == EFSMailBoxOnline) |
|
187 { |
|
188 for(TInt i=0;i<iCopyOnlineBlocked.Count();i++) |
|
189 { |
|
190 if(iCopyOnlineBlocked[i] == aFolderType) |
|
191 { |
|
192 return EFalse; |
|
193 } |
|
194 } |
|
195 } |
|
196 else if(onlineStatus == EFSMailBoxOffline) |
|
197 { |
|
198 for(TInt i=0;i<iCopyOfflineBlocked.Count();i++) |
|
199 { |
|
200 if(iCopyOfflineBlocked[i] == aFolderType) |
|
201 { |
|
202 return EFalse; |
|
203 } |
|
204 } |
|
205 } |
|
206 } |
|
207 return ETrue; |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CFSMailFolder::SupportsMoveFromL |
|
212 // ----------------------------------------------------------------------------- |
|
213 EXPORT_C TBool CFSMailFolder::SupportsMoveFromL( TFSFolderType aFolderType ) |
|
214 { |
|
215 FUNC_LOG; |
|
216 |
|
217 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId())) |
|
218 { |
|
219 TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId()); |
|
220 if(onlineStatus == EFSMailBoxOnline) |
|
221 { |
|
222 for(TInt i=0;i<iMoveOnlineBlocked.Count();i++) |
|
223 { |
|
224 if(iMoveOnlineBlocked[i] == aFolderType) |
|
225 { |
|
226 return EFalse; |
|
227 } |
|
228 } |
|
229 } |
|
230 else if(onlineStatus == EFSMailBoxOffline) |
|
231 { |
|
232 for(TInt i=0;i<iMoveOfflineBlocked.Count();i++) |
|
233 { |
|
234 if(iMoveOfflineBlocked[i] == aFolderType) |
|
235 { |
|
236 return EFalse; |
|
237 } |
|
238 } |
|
239 } |
|
240 } |
|
241 return ETrue; |
|
242 |
|
243 } |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CFSMailFolder::RemoveDownLoadedAttachmentsL |
|
246 // ----------------------------------------------------------------------------- |
|
247 EXPORT_C void CFSMailFolder::RemoveDownLoadedAttachmentsL() |
|
248 { |
|
249 FUNC_LOG; |
|
250 |
|
251 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()); |
|
252 if(plugin != NULL) |
|
253 { |
|
254 MFSMailIterator* iterator = NULL; |
|
255 |
|
256 // select message details to be listed |
|
257 TFSMailDetails details(EFSMsgDataEnvelope); |
|
258 |
|
259 // sorting is free, give empty array |
|
260 RArray<TFSMailSortCriteria> sorting; |
|
261 sorting.Reset(); |
|
262 iterator = plugin->ListMessagesL( GetMailBoxId(), |
|
263 GetFolderId(), |
|
264 details, |
|
265 sorting ); |
|
266 if(iterator) |
|
267 { |
|
268 TFSMailMsgId nullId; |
|
269 RPointerArray<CFSMailMessage> messages; |
|
270 messages.Reset(); |
|
271 iterator->NextL(nullId,GetMessageCount(),messages); |
|
272 for(TInt i=0;i<messages.Count();i++) |
|
273 { |
|
274 if(messages[i]->IsFlagSet(EFSMsgFlag_Attachments)) |
|
275 { |
|
276 messages[i]->RemoveDownLoadedAttachmentsL(); |
|
277 } |
|
278 } |
|
279 messages.ResetAndDestroy(); |
|
280 delete iterator; |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CFSMailFolder::ReleaseExtension |
|
287 // ----------------------------------------------------------------------------- |
|
288 EXPORT_C void CFSMailFolder::ReleaseExtension( CEmailExtension* aExtension ) |
|
289 { |
|
290 FUNC_LOG; |
|
291 // no specialized behaviour, call base class |
|
292 CExtendableEmail::ReleaseExtension( aExtension ); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CFSMailFolder::ExtensionL |
|
297 // ----------------------------------------------------------------------------- |
|
298 EXPORT_C CEmailExtension* CFSMailFolder::ExtensionL( const TUid& aInterfaceUid ) |
|
299 { |
|
300 FUNC_LOG; |
|
301 return CExtendableEmail::ExtensionL( aInterfaceUid ); |
|
302 } |
|
303 |