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