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 #include "nmframeworkadapterheaders.h" |
|
19 |
|
20 NmFwaCheckOutboxOperation::NmFwaCheckOutboxOperation( |
|
21 const NmId &mailboxId, |
|
22 CFSMailClient &mailClient) : |
|
23 mMailboxId(mailboxId), |
|
24 mMailClient(mailClient), |
|
25 mFound(false), |
|
26 mMessageId(0) |
|
27 { |
|
28 } |
|
29 |
|
30 NmFwaCheckOutboxOperation::~NmFwaCheckOutboxOperation() |
|
31 { |
|
32 } |
|
33 |
|
34 void NmFwaCheckOutboxOperation::doRunAsyncOperation() |
|
35 { |
|
36 TRAPD(err, doRunAsyncOperationL()); |
|
37 |
|
38 if (err) { |
|
39 completeOperation(NmGeneralError); |
|
40 } |
|
41 } |
|
42 |
|
43 /*! |
|
44 Gets the id of the message with index '0' in the Outbox . |
|
45 |
|
46 \return true if there is a message in Outbox. |
|
47 */ |
|
48 bool NmFwaCheckOutboxOperation::getMessageId(NmId &messageId) const |
|
49 { |
|
50 messageId = mMessageId; |
|
51 return mFound; |
|
52 } |
|
53 |
|
54 void NmFwaCheckOutboxOperation::doRunAsyncOperationL() |
|
55 { |
|
56 int err = NmNotFoundError; |
|
57 |
|
58 TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32()); |
|
59 |
|
60 CFSMailBox *mailbox = mMailClient.GetMailBoxByUidL(mailboxId); |
|
61 |
|
62 if (mailbox) { |
|
63 CleanupStack::PushL(mailbox); |
|
64 |
|
65 TFSMailMsgId folderId = mailbox->GetStandardFolderId(EFSOutbox); |
|
66 |
|
67 CFSMailFolder *folder = |
|
68 mMailClient.GetFolderByUidL(mailboxId, folderId); |
|
69 |
|
70 if (folder) { |
|
71 CleanupStack::PushL(folder); |
|
72 |
|
73 TFSMailSortCriteria sortCriteria; |
|
74 sortCriteria.iField = EFSMailSortByDate; |
|
75 sortCriteria.iOrder = EFSMailDescending; |
|
76 |
|
77 RArray<TFSMailSortCriteria> sortArray; |
|
78 CleanupClosePushL(sortArray); |
|
79 sortArray.AppendL(sortCriteria); |
|
80 |
|
81 MFSMailIterator *iter = folder->ListMessagesL( |
|
82 EFSMsgDataIdOnly, sortArray); |
|
83 |
|
84 CleanupStack::PopAndDestroy(); // sortArray |
|
85 |
|
86 if (iter) { |
|
87 CleanupDeletePushL(iter); |
|
88 |
|
89 TFSMailMsgId nullId; |
|
90 TInt numberOfItems = 1; |
|
91 RPointerArray<CFSMailMessage> messages; |
|
92 |
|
93 CleanupClosePushL(messages); |
|
94 TBool unused = iter->NextL(nullId, numberOfItems, messages); |
|
95 |
|
96 if (messages.Count() > 0) { |
|
97 mMessageId = messages[0]->GetMessageId().GetNmId(); |
|
98 mFound = true; |
|
99 } |
|
100 |
|
101 messages.ResetAndDestroy(); |
|
102 CleanupStack::PopAndDestroy(); // messages |
|
103 |
|
104 CleanupStack::PopAndDestroy(iter); |
|
105 |
|
106 err = NmNoError; |
|
107 } |
|
108 CleanupStack::PopAndDestroy(folder); |
|
109 } |
|
110 CleanupStack::PopAndDestroy(mailbox); |
|
111 } |
|
112 |
|
113 completeOperation(err); |
|
114 } |
|
115 |
|