|
1 /* |
|
2 * Copyright (c) 2006 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: IMASAccountControl.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <SendUiConsts.h> |
|
22 #include <centralrepository.h> |
|
23 |
|
24 #include "IMASAccountControl.h" |
|
25 #include "EmailUtils.H" |
|
26 #include "ImumPrivateCRKeys.h" // Predefined mailbox keys |
|
27 #include "ImumPanic.h" |
|
28 #include "ImumUtilsLogging.h" |
|
29 |
|
30 // EXTERNAL DATA STRUCTURES |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 // CONSTANTS |
|
33 enum TIACErrors |
|
34 { |
|
35 EIACNoError = 0, |
|
36 EIACMboxToAccIdMtmError, |
|
37 EIACAccIdToExtIdMtmError, |
|
38 EIACExtIdToAccIdMtmError |
|
39 }; |
|
40 |
|
41 // Account Id conversion to Extension Id |
|
42 enum TIACKeyShifts |
|
43 { |
|
44 EIACKeyShiftImap4 = 0, |
|
45 EIACKeyShiftPop3 = 8 |
|
46 }; |
|
47 |
|
48 const TInt KImasShiftAccountId = 8; |
|
49 |
|
50 // MACROS |
|
51 // LOCAL CONSTANTS AND MACROS |
|
52 // MODULE DATA STRUCTURES |
|
53 // LOCAL FUNCTION PROTOTYPES |
|
54 // FORWARD DECLARATIONS |
|
55 |
|
56 // ============================ MEMBER FUNCTIONS =============================== |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // IMASAccountControl::CreateBaseKeyFromAccountId() |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 TUint32 IMASAccountControl::CreateBaseKeyFromAccountId( |
|
63 const TUint32 aAccountId, |
|
64 const TUid& aProtocol ) |
|
65 { |
|
66 IMUM_STATIC_CONTEXT( IMASAccountControl::CreateBaseKeyFromAccountId, 0, utils, KLogData ); |
|
67 |
|
68 TUint32 extendedAccountId = |
|
69 AccountIdToExtendedAccountId( aAccountId, aProtocol ); |
|
70 return ( extendedAccountId << KImasShiftAccountId ); |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // IMASAccountControl::CreateBaseKeyFromExtendedAccountId() |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 TUint32 IMASAccountControl::CreateBaseKeyFromExtendedAccountId( |
|
78 const TUint32 aExtendedAccountId ) |
|
79 { |
|
80 IMUM_STATIC_CONTEXT( IMASAccountControl::CreateBaseKeyFromExtendedAccountId, 0, utils, KLogData ); |
|
81 |
|
82 return ( aExtendedAccountId << KImasShiftAccountId ); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // IMASAccountControl::MailboxIdToAccountIdL() |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 TUint32 IMASAccountControl::MailboxIdToAccountIdL( |
|
90 const TMsvId aMailboxId, |
|
91 const TUid& aMtmId ) |
|
92 { |
|
93 IMUM_STATIC_CONTEXT( IMASAccountControl::MailboxIdToAccountIdL, 0, utils, KLogData ); |
|
94 |
|
95 TUint32 accountId = 0; |
|
96 |
|
97 switch ( aMtmId.iUid ) |
|
98 { |
|
99 case KSenduiMtmSmtpUidValue: |
|
100 accountId = IMASAccountControl::GetSmtpAccountIdL( |
|
101 aMailboxId ).iSmtpAccountId; |
|
102 break; |
|
103 |
|
104 case KSenduiMtmPop3UidValue: |
|
105 accountId = IMASAccountControl::GetPopAccountIdL( |
|
106 aMailboxId ).iPopAccountId; |
|
107 break; |
|
108 |
|
109 case KSenduiMtmImap4UidValue: |
|
110 accountId = IMASAccountControl::GetImapAccountIdL( |
|
111 aMailboxId ).iImapAccountId; |
|
112 break; |
|
113 |
|
114 default: |
|
115 __ASSERT_DEBUG( EFalse, User::Panic( |
|
116 KIMASAccountControlPanic, EIACMboxToAccIdMtmError ) ); |
|
117 User::Leave( KErrNotSupported ); |
|
118 break; |
|
119 } |
|
120 |
|
121 return accountId; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // IMASAccountControl::AccountIdToMailboxId() |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 TMsvId IMASAccountControl::AccountIdToMailboxId( |
|
129 CEmailAccounts& aAccounts, |
|
130 const TUint32 aAccountId, |
|
131 const TUid& aMtmId ) |
|
132 { |
|
133 IMUM_STATIC_CONTEXT( IMASAccountControl::AccountIdToMailboxId, 0, utils, KLogData ); |
|
134 |
|
135 TMsvId mailboxId = KErrNotFound; |
|
136 |
|
137 // Get the correct accounts according to the protocol |
|
138 if ( aMtmId.iUid == KSenduiMtmImap4UidValue ) |
|
139 { |
|
140 // IMAP4 |
|
141 TImapAccount imapAccount; |
|
142 RArray<TImapAccount> accountArray; |
|
143 TRAPD( error, aAccounts.GetImapAccountsL( accountArray ) ); |
|
144 |
|
145 TInt account = ( error == KErrNone ) ? |
|
146 accountArray.Count() : KErrNotFound; |
|
147 |
|
148 while ( mailboxId < 0 && --account >= 0 ) |
|
149 { |
|
150 imapAccount = accountArray[account]; |
|
151 |
|
152 // Check if the id's match |
|
153 if ( imapAccount.iImapAccountId == aAccountId ) |
|
154 { |
|
155 mailboxId = imapAccount.iImapService; |
|
156 } |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // POP3 |
|
162 TPopAccount popAccount; |
|
163 RArray<TPopAccount> accountArray; |
|
164 TRAPD( error, aAccounts.GetPopAccountsL( accountArray ) ); |
|
165 |
|
166 TInt account = ( error == KErrNone ) ? |
|
167 accountArray.Count() : KErrNotFound; |
|
168 |
|
169 while ( mailboxId < 0 && --account >= 0 ) |
|
170 { |
|
171 popAccount = accountArray[account]; |
|
172 |
|
173 // Check if the id's match |
|
174 if ( popAccount.iPopAccountId == aAccountId ) |
|
175 { |
|
176 mailboxId = popAccount.iPopService; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 return mailboxId; |
|
182 } |
|
183 |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // IMASAccountControl::AccountIdToExtendedAccountId() |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 TUint32 IMASAccountControl::AccountIdToExtendedAccountId( |
|
190 const TUint32 aAccountId, |
|
191 const TUid& aMtmId ) |
|
192 { |
|
193 IMUM_STATIC_CONTEXT( IMASAccountControl::AccountIdToExtendedAccountId, 0, utils, KLogData ); |
|
194 |
|
195 // Imap4 accounts are 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 |
|
196 if ( aMtmId == KSenduiMtmImap4Uid ) |
|
197 { |
|
198 return ( aAccountId << EIACKeyShiftImap4 ); |
|
199 } |
|
200 // Pop3 accounts are 0x100, 0x200, 0x300, 0x400, 0x500, 0x600 |
|
201 else if ( aMtmId == KSenduiMtmPop3Uid ) |
|
202 { |
|
203 return ( aAccountId << EIACKeyShiftPop3 ); |
|
204 } |
|
205 else |
|
206 { |
|
207 __ASSERT_DEBUG( EFalse, User::Panic( |
|
208 KIMASAccountControlPanic, EIACAccIdToExtIdMtmError ) ); |
|
209 } |
|
210 |
|
211 return 0; |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // IMASAccountControl::ExtendedAccountIdToAccountId() |
|
216 // ---------------------------------------------------------------------------- |
|
217 // |
|
218 TUint32 IMASAccountControl::ExtendedAccountIdToAccountId( |
|
219 const TUint32 aExtendedAccountId, |
|
220 const TUid& aMtmId ) |
|
221 { |
|
222 IMUM_STATIC_CONTEXT( IMASAccountControl::ExtendedAccountIdToAccountId, 0, utils, KLogData ); |
|
223 |
|
224 // Imap4 accounts are 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 |
|
225 if ( aMtmId == KSenduiMtmImap4Uid ) |
|
226 { |
|
227 return ( aExtendedAccountId >> EIACKeyShiftImap4 ); |
|
228 } |
|
229 // Pop3 accounts are 0x100, 0x200, 0x300, 0x400, 0x500, 0x600 |
|
230 else if ( aMtmId == KSenduiMtmPop3Uid ) |
|
231 { |
|
232 return ( aExtendedAccountId >> EIACKeyShiftPop3 ); |
|
233 } |
|
234 else |
|
235 { |
|
236 __ASSERT_DEBUG( EFalse, User::Panic( |
|
237 KIMASAccountControlPanic, EIACExtIdToAccIdMtmError ) ); |
|
238 } |
|
239 |
|
240 return 0; |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // IMASAccountControl::GetPopAccountIdL() |
|
245 // ---------------------------------------------------------------------------- |
|
246 // |
|
247 TPopAccount IMASAccountControl::GetPopAccountIdL( |
|
248 const TMsvId aPopMailboxId ) |
|
249 { |
|
250 IMUM_STATIC_CONTEXT( IMASAccountControl::GetPopAccountIdL, 0, utils, KLogData ); |
|
251 |
|
252 CEmailAccounts* account = CEmailAccounts::NewLC(); |
|
253 |
|
254 TPopAccount popAccountId; |
|
255 account->GetPopAccountL( aPopMailboxId, popAccountId ); |
|
256 |
|
257 CleanupStack::PopAndDestroy( account ); |
|
258 account = NULL; |
|
259 |
|
260 return popAccountId; |
|
261 } |
|
262 |
|
263 // ---------------------------------------------------------------------------- |
|
264 // IMASAccountControl::GetImapAccountIdL() |
|
265 // ---------------------------------------------------------------------------- |
|
266 // |
|
267 TImapAccount IMASAccountControl::GetImapAccountIdL( |
|
268 const TMsvId aImapMailboxId ) |
|
269 { |
|
270 IMUM_STATIC_CONTEXT( IMASAccountControl::GetImapAccountIdL, 0, utils, KLogData ); |
|
271 |
|
272 CEmailAccounts* account = CEmailAccounts::NewLC(); |
|
273 |
|
274 TImapAccount imapAccountId; |
|
275 account->GetImapAccountL( aImapMailboxId, imapAccountId ); |
|
276 |
|
277 CleanupStack::PopAndDestroy( account ); |
|
278 account = NULL; |
|
279 |
|
280 return imapAccountId; |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // IMASAccountControl::GetSmtpAccountIdL() |
|
285 // ---------------------------------------------------------------------------- |
|
286 // |
|
287 TSmtpAccount IMASAccountControl::GetSmtpAccountIdL( |
|
288 const TMsvId aSmtpMailboxId ) |
|
289 { |
|
290 IMUM_STATIC_CONTEXT( IMASAccountControl::GetSmtpAccountIdL, 0, utils, KLogData ); |
|
291 |
|
292 CEmailAccounts* account = CEmailAccounts::NewLC(); |
|
293 |
|
294 TSmtpAccount smtpAccountId; |
|
295 account->GetSmtpAccountL( aSmtpMailboxId, smtpAccountId ); |
|
296 |
|
297 CleanupStack::PopAndDestroy( account ); |
|
298 account = NULL; |
|
299 |
|
300 return smtpAccountId; |
|
301 } |
|
302 |
|
303 // ---------------------------------------------------------------------------- |
|
304 // IMASAccountControl::CreateSettingKey() |
|
305 // ---------------------------------------------------------------------------- |
|
306 // |
|
307 TUint32 IMASAccountControl::CreateSettingKey( |
|
308 const TUint32 aAccountId, |
|
309 const TUint32 aSetting, |
|
310 const TUid& aMtmId ) |
|
311 { |
|
312 IMUM_STATIC_CONTEXT( IMASAccountControl::CreateSettingKey, 0, utils, KLogData ); |
|
313 |
|
314 return CreateBaseKeyFromAccountId( aAccountId, aMtmId ) + aSetting; |
|
315 } |
|
316 |
|
317 // End of File |