47
|
1 |
/*
|
|
2 |
* Copyright (c)2010 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: This file implements class CEmailFolder.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "emailfolder.h"
|
|
19 |
#include "emailmailbox.h"
|
|
20 |
#include "emailapiutils.h"
|
|
21 |
#include "messageiterator.h"
|
|
22 |
#include "emailsorting.h"
|
62
|
23 |
#include "CFSMailFolder.h"
|
|
24 |
#include "CFSMailPlugin.h"
|
47
|
25 |
#include "emailclientapi.hrh"
|
|
26 |
#include "emailclientapiimpldefs.h"
|
|
27 |
|
|
28 |
// -----------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
// -----------------------------------------------------------------------------
|
|
31 |
CEmailFolder* CEmailFolder::NewLC(
|
|
32 |
CPluginData& aPluginData,
|
|
33 |
const TFolderId& aFolderId,
|
|
34 |
CFSMailFolder *aFolder )
|
|
35 |
{
|
|
36 |
CEmailFolder* self = new ( ELeave )
|
|
37 |
CEmailFolder( aPluginData, aFolderId, aFolder );
|
|
38 |
CleanupStack::PushL( self );
|
|
39 |
self->ConstructL();
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
//
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
CEmailFolder* CEmailFolder::NewL(
|
|
47 |
CPluginData& aPluginData,
|
|
48 |
const TFolderId& aFolderId,
|
|
49 |
CFSMailFolder *aFolder )
|
|
50 |
{
|
|
51 |
CEmailFolder* self = CEmailFolder::NewLC( aPluginData, aFolderId, aFolder);
|
|
52 |
CleanupStack::Pop( self );
|
|
53 |
return self;
|
|
54 |
}
|
|
55 |
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
CEmailFolder::CEmailFolder(
|
|
60 |
CPluginData& aPluginData,
|
|
61 |
const TFolderId& aFolderId,
|
|
62 |
CFSMailFolder* aFolder) :
|
|
63 |
iPluginData( aPluginData ),
|
|
64 |
iFolderType( EOther ),
|
|
65 |
iFolderId( aFolderId ),
|
|
66 |
iFolder( aFolder )
|
|
67 |
{
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
void CEmailFolder::ConstructL()
|
|
75 |
{
|
|
76 |
iPlugin = iPluginData.ClaimInstance();
|
|
77 |
|
|
78 |
User::LeaveIfNull( iFolder );
|
|
79 |
|
|
80 |
const TFSFolderType fsType = iFolder->GetFolderType();
|
|
81 |
switch ( fsType )
|
|
82 |
{
|
|
83 |
case EFSInbox:
|
|
84 |
iFolderType = EInbox;
|
|
85 |
break;
|
|
86 |
case EFSOutbox:
|
|
87 |
iFolderType = EOutbox;
|
|
88 |
break;
|
|
89 |
case EFSDraftsFolder:
|
|
90 |
iFolderType = EDrafts;
|
|
91 |
break;
|
|
92 |
case EFSSentFolder:
|
|
93 |
iFolderType = ESent;
|
|
94 |
break;
|
|
95 |
case EFSDeleted:
|
|
96 |
iFolderType = EDeleted;
|
|
97 |
break;
|
|
98 |
case EFSOther:
|
|
99 |
default:
|
|
100 |
iFolderType = EOther;
|
|
101 |
break;
|
|
102 |
}
|
|
103 |
iParentId = TFolderId(
|
|
104 |
iFolder->GetParentFolderId().Id(),
|
|
105 |
iFolderId.iMailboxId );
|
|
106 |
}
|
|
107 |
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
CEmailFolder::~CEmailFolder()
|
|
112 |
{
|
|
113 |
iPluginData.ReleaseInstance();
|
|
114 |
delete iFolder;
|
|
115 |
}
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
// -----------------------------------------------------------------------------
|
|
120 |
TEmailTypeId CEmailFolder::InterfaceId() const
|
|
121 |
{
|
|
122 |
return KEmailIFUidFolder;
|
|
123 |
}
|
|
124 |
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
// -----------------------------------------------------------------------------
|
|
128 |
void CEmailFolder::Release()
|
|
129 |
{
|
|
130 |
delete this;
|
|
131 |
}
|
|
132 |
|
|
133 |
// -----------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
TFolderId CEmailFolder::FolderId() const
|
|
137 |
{
|
|
138 |
return iFolderId;
|
|
139 |
}
|
|
140 |
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
//
|
|
143 |
// -----------------------------------------------------------------------------
|
|
144 |
TFolderId CEmailFolder::ParentFolderId() const
|
|
145 |
{
|
|
146 |
return iParentId;
|
|
147 |
}
|
|
148 |
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
TFolderType CEmailFolder::FolderType() const
|
|
153 |
{
|
|
154 |
return iFolderType;
|
|
155 |
}
|
|
156 |
|
|
157 |
// -----------------------------------------------------------------------------
|
|
158 |
//
|
|
159 |
// -----------------------------------------------------------------------------
|
|
160 |
TPtrC CEmailFolder::Name() const
|
|
161 |
{
|
|
162 |
if ( !iFolder )
|
|
163 |
return KNullDesC();
|
|
164 |
return TPtrC ( iFolder->GetFolderName() );
|
|
165 |
}
|
|
166 |
|
|
167 |
// -----------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
TInt CEmailFolder::GetSubfoldersL( RFolderArray& aSubfolders ) const
|
|
171 |
{
|
|
172 |
User::LeaveIfNull( iFolder );
|
|
173 |
|
|
174 |
RPointerArray<CFSMailFolder> folders;
|
|
175 |
CleanupResetAndDestroy<RPointerArray<CFSMailFolder> >::PushL( folders );
|
|
176 |
|
|
177 |
iFolder->GetSubFoldersL( folders );
|
|
178 |
|
|
179 |
TInt res( folders.Count() );
|
|
180 |
|
|
181 |
for ( TInt i = 0; i < res; i++ )
|
|
182 |
{
|
|
183 |
const CFSMailFolder* fsfolder = folders[i];
|
|
184 |
const TEntryId id = fsfolder->GetFolderId().Id();
|
|
185 |
const TFolderId folderId( id, iFolderId.iMailboxId.iId );
|
|
186 |
MEmailFolder* folder = CEmailFolder::NewL( iPluginData, folderId, folders[i] );
|
76
|
187 |
CleanupStack::PushL(folder);
|
47
|
188 |
aSubfolders.AppendL( folder );
|
76
|
189 |
CleanupStack::Pop(folder);
|
47
|
190 |
}
|
|
191 |
CleanupStack::Pop( &folders );
|
|
192 |
folders.Close();
|
|
193 |
return res;
|
|
194 |
}
|
|
195 |
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
// CEmailFolder::MessagesL
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
MMessageIterator* CEmailFolder::MessagesL(
|
|
200 |
const RSortCriteriaArray& aCriteria )
|
|
201 |
{
|
|
202 |
RArray<TFSMailSortCriteria> sortCriterias;
|
|
203 |
CleanupClosePushL( sortCriterias );
|
|
204 |
CEmailFolder::ToFsSortCriteriaL( aCriteria, sortCriterias );
|
|
205 |
|
|
206 |
MFSMailIterator* fsIter = iFolder->ListMessagesL( EFSMsgDataEnvelope, sortCriterias );
|
|
207 |
TUint count = iFolder->GetMessageCount();
|
|
208 |
|
|
209 |
CleanupStack::PopAndDestroy( &sortCriterias );
|
|
210 |
CMessageIterator* iter = CMessageIterator::NewL(
|
|
211 |
fsIter, iPluginData, count );
|
|
212 |
|
|
213 |
return iter;
|
|
214 |
}
|
|
215 |
|
|
216 |
// -----------------------------------------------------------------------------
|
|
217 |
//
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
void CEmailFolder::DeleteMessagesL( const REmailMessageIdArray& aMessageIds )
|
|
220 |
{
|
|
221 |
RArray<TFSMailMsgId> fsArray;
|
|
222 |
CleanupClosePushL( fsArray );
|
|
223 |
const TInt count( aMessageIds.Count() );
|
|
224 |
for ( TInt i = 0; i < count; i++ )
|
|
225 |
{
|
|
226 |
TMessageId msgId = aMessageIds[i];
|
|
227 |
if ( iFolderId != msgId.iFolderId )
|
|
228 |
{
|
|
229 |
// not all messages in the same folder, plugin API doesn't accept this.
|
|
230 |
User::Leave( KErrArgument );
|
|
231 |
}
|
|
232 |
fsArray.AppendL( FsMsgId( iPluginData, msgId ) );
|
|
233 |
}
|
|
234 |
iPlugin->DeleteMessagesByUidL(
|
|
235 |
FsMsgId( iPluginData, iFolderId.iMailboxId ),
|
|
236 |
FsMsgId( iPluginData, iFolderId ),
|
|
237 |
fsArray );
|
|
238 |
CleanupStack::PopAndDestroy( &fsArray );
|
|
239 |
}
|
|
240 |
|
|
241 |
// -----------------------------------------------------------------------------
|
|
242 |
// Maps email api sort criteria to sort criteria type that protocol plugin
|
|
243 |
// accepts.
|
|
244 |
// -----------------------------------------------------------------------------
|
|
245 |
void CEmailFolder::ToFsSortCriteriaL(
|
|
246 |
const RSortCriteriaArray& aSortCriteria,
|
|
247 |
RArray<TFSMailSortCriteria>& aFsCriteria )
|
|
248 |
{
|
|
249 |
const TFSMailSortField fieldValues[] = {
|
|
250 |
EFSMailDontCare,
|
|
251 |
EFSMailSortByDate,
|
|
252 |
EFSMailSortBySender,
|
|
253 |
EFSMailSortByRecipient,
|
|
254 |
EFSMailSortBySubject,
|
|
255 |
EFSMailSortByPriority,
|
|
256 |
EFSMailSortByFlagStatus,
|
|
257 |
EFSMailSortByUnread,
|
|
258 |
EFSMailSortBySize,
|
|
259 |
EFSMailSortByAttachment };
|
|
260 |
|
|
261 |
for ( TInt i=0; i < aSortCriteria.Count(); i++ )
|
|
262 |
{
|
|
263 |
const TEmailSortCriteria& criteria = aSortCriteria[i];
|
|
264 |
__ASSERT_ALWAYS( criteria.iField < sizeof( fieldValues ) / sizeof (fieldValues [i] ),
|
|
265 |
Panic( EMailPanicSortMapIndexOutOfBounds ) );
|
|
266 |
TFSMailSortCriteria fsCriteria;
|
|
267 |
fsCriteria.iField = fieldValues[ criteria.iField ];
|
|
268 |
if ( criteria.iAscending )
|
|
269 |
{
|
|
270 |
fsCriteria.iOrder = EFSMailAscending;
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
fsCriteria.iOrder = EFSMailDescending;
|
|
275 |
}
|
|
276 |
aFsCriteria.AppendL( fsCriteria );
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
// End of file
|