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