|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // User includes |
|
17 #include <t_utilscentralrepository.h> |
|
18 |
|
19 // epoc includes |
|
20 #include <msvids.h> |
|
21 |
|
22 /** |
|
23 CT_MsgUtilsCentralRepository() |
|
24 Constructor |
|
25 */ |
|
26 EXPORT_C CT_MsgUtilsCentralRepository::CT_MsgUtilsCentralRepository() |
|
27 { |
|
28 } |
|
29 |
|
30 |
|
31 /** |
|
32 ~CT_MsgUtilsCentralRepository() |
|
33 Destructor |
|
34 */ |
|
35 CT_MsgUtilsCentralRepository::~CT_MsgUtilsCentralRepository() |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 GetDefaultSmtpServiceIdL() |
|
42 This function return the default Smtp Service Id. This method requires that a |
|
43 related IMAP4 or POP3 account has been previously created in the central |
|
44 repository - this is because SMTP accounts do not exist independently but only |
|
45 as part of an IMAP4 or POP3 account |
|
46 |
|
47 @return |
|
48 Entry ID of the default SMTP service entry |
|
49 */ |
|
50 EXPORT_C TMsvId CT_MsgUtilsCentralRepository::GetDefaultSmtpServiceIdL() |
|
51 { |
|
52 CEmailAccounts* emailAccounts = CEmailAccounts::NewLC(); |
|
53 |
|
54 TSmtpAccount smtpAccount; |
|
55 smtpAccount.iSmtpService = KMsvNullIndexEntryId; |
|
56 User::LeaveIfError(emailAccounts->DefaultSmtpAccountL(smtpAccount)); |
|
57 |
|
58 CleanupStack::PopAndDestroy(emailAccounts); |
|
59 |
|
60 return smtpAccount.iSmtpService; |
|
61 } |
|
62 |
|
63 |
|
64 /** |
|
65 GetImapServiceIdL() |
|
66 This function returns the Service Id of the IMAP account with the specified name |
|
67 |
|
68 @param aName |
|
69 The Imap account name |
|
70 |
|
71 @return |
|
72 It returns entry Id of an IMAP service |
|
73 */ |
|
74 EXPORT_C TMsvId CT_MsgUtilsCentralRepository::GetImapServiceIdL(TDes& aName) |
|
75 { |
|
76 TImapAccount imapAccount; |
|
77 TMsvId imapServiceId = KMsvNullIndexEntryId; |
|
78 |
|
79 TBool returnValue = GetImapAccountL( aName, imapAccount ); |
|
80 |
|
81 if ( returnValue ) |
|
82 { |
|
83 imapServiceId = imapAccount.iImapService; |
|
84 } |
|
85 return imapServiceId; |
|
86 } |
|
87 |
|
88 |
|
89 /** |
|
90 GetPopServiceIdL() |
|
91 This function returns the Service Id of the POP account with the specified name |
|
92 |
|
93 @param aName |
|
94 The Pop account name |
|
95 |
|
96 @return |
|
97 Returns entry Id of an POP service |
|
98 */ |
|
99 EXPORT_C TMsvId CT_MsgUtilsCentralRepository::GetPopServiceIdL(TDes& aName) |
|
100 { |
|
101 TPopAccount popAccount; |
|
102 TMsvId popServiceId = KMsvNullIndexEntryId; |
|
103 |
|
104 TBool returnValue = GetPopAccountL( aName, popAccount ); |
|
105 |
|
106 if ( returnValue ) |
|
107 { |
|
108 popServiceId = popAccount.iPopService; |
|
109 } |
|
110 return popServiceId; |
|
111 } |
|
112 |
|
113 /** |
|
114 GetSmtpServiceIdL() |
|
115 This function returns the Service Id of the SMTP account with the specified name |
|
116 |
|
117 @param aName |
|
118 The Smtp account name |
|
119 |
|
120 @return |
|
121 Returns entry Id of an SMTP service |
|
122 */ |
|
123 EXPORT_C TMsvId CT_MsgUtilsCentralRepository::GetSmtpServiceIdL(TDes& aName) |
|
124 { |
|
125 TSmtpAccount smtpAccount; |
|
126 TMsvId smtpServiceId = KMsvNullIndexEntryId; |
|
127 |
|
128 TBool returnValue = GetSmtpAccountL(aName, smtpAccount); |
|
129 |
|
130 if (returnValue) |
|
131 { |
|
132 smtpServiceId = smtpAccount.iSmtpService; |
|
133 } |
|
134 return smtpServiceId; |
|
135 } |
|
136 |
|
137 /** |
|
138 GetImapAccountL() |
|
139 Searches the IMAP account with the specified name and |
|
140 returns the TImapAccount oject associted to it. |
|
141 |
|
142 @param aName |
|
143 The Imap account name |
|
144 |
|
145 @param aImapAccount |
|
146 An object of type TImapAccount |
|
147 |
|
148 @leave KErrNotFound |
|
149 Leaves if no account found with the supplied name. |
|
150 |
|
151 @return |
|
152 ETrue if the account is found, else EFalse |
|
153 */ |
|
154 EXPORT_C TBool CT_MsgUtilsCentralRepository::GetImapAccountL(TDes& aName, TImapAccount& aImapAccount ) |
|
155 { |
|
156 TImapAccount imapAccount; |
|
157 imapAccount.iImapService = KMsvNullIndexEntryId; |
|
158 |
|
159 // Get the list of IMAP accounts |
|
160 RArray<TImapAccount> accountIds; |
|
161 |
|
162 CEmailAccounts *emailAccounts = CEmailAccounts::NewLC(); |
|
163 emailAccounts->GetImapAccountsL(accountIds); |
|
164 |
|
165 // Search for the account with the given name in the list of IMAP accounts |
|
166 TBool accountFound = EFalse; |
|
167 for( TInt index = 0; index < accountIds.Count(); index++) |
|
168 { |
|
169 TImapAccount tempAccount = accountIds[index]; |
|
170 TPtrC accountPtr( tempAccount.iImapAccountName ); |
|
171 |
|
172 if( accountPtr.Compare(aName) == 0 ) |
|
173 { |
|
174 aImapAccount = tempAccount; |
|
175 accountFound = ETrue; |
|
176 break; |
|
177 } |
|
178 } |
|
179 if(!accountFound) |
|
180 { |
|
181 User::Leave(KErrNotFound); |
|
182 } |
|
183 CleanupStack::PopAndDestroy(emailAccounts); |
|
184 accountIds.Reset(); |
|
185 |
|
186 return accountFound; |
|
187 } |
|
188 |
|
189 |
|
190 /** |
|
191 GetPopAccountL() |
|
192 Searches the POP account with the specified name and |
|
193 returns the TPopAccount oject associted to it. |
|
194 |
|
195 @param aName |
|
196 The Imap account name |
|
197 |
|
198 @param aPopAccount |
|
199 An object of type TPopAccount |
|
200 |
|
201 @leave KErrNotFound |
|
202 Leaves if no account found with the supplied name. |
|
203 |
|
204 @return |
|
205 ETrue if the account is found, else EFalse |
|
206 */ |
|
207 EXPORT_C TBool CT_MsgUtilsCentralRepository::GetPopAccountL(TDes& aName, TPopAccount& aPopAccount ) |
|
208 { |
|
209 TPopAccount popAccount; |
|
210 popAccount.iPopService = KMsvNullIndexEntryId; |
|
211 |
|
212 // Get the list of POP accounts |
|
213 RArray<TPopAccount> accountIds; |
|
214 |
|
215 CEmailAccounts *emailAccounts = CEmailAccounts::NewLC(); |
|
216 emailAccounts->GetPopAccountsL(accountIds); |
|
217 |
|
218 // Search for the account with the given name in the list of POP accounts |
|
219 TBool accountFound = EFalse; |
|
220 for( TInt index = 0; index < accountIds.Count(); index++) |
|
221 { |
|
222 TPopAccount tempAccount = accountIds[index]; |
|
223 TPtrC accountPtr( tempAccount.iPopAccountName ); |
|
224 |
|
225 if( accountPtr.Compare(aName) == 0 ) |
|
226 { |
|
227 aPopAccount = tempAccount; |
|
228 accountFound = ETrue; |
|
229 break; |
|
230 } |
|
231 } |
|
232 if(!accountFound) |
|
233 { |
|
234 User::Leave(KErrNotFound); |
|
235 } |
|
236 CleanupStack::PopAndDestroy(emailAccounts); |
|
237 accountIds.Reset(); |
|
238 |
|
239 return accountFound; |
|
240 } |
|
241 |
|
242 /** |
|
243 GetSmtpAccountL() |
|
244 Searches the SMTP account with the specified name and |
|
245 returns the TSmtpAccount oject associted to it. |
|
246 |
|
247 @param aName |
|
248 The Smtp account name |
|
249 |
|
250 @param aSmtpAccount |
|
251 An object of type TSmtpAccount |
|
252 |
|
253 @leave KErrNotFound |
|
254 Leaves if no account found with the supplied name. |
|
255 |
|
256 @return |
|
257 ETrue if the account is found, else EFalse |
|
258 */ |
|
259 EXPORT_C TBool CT_MsgUtilsCentralRepository::GetSmtpAccountL(TDes& aName, TSmtpAccount& aSmtpAccount) |
|
260 { |
|
261 TSmtpAccount smtpAccount; |
|
262 smtpAccount.iSmtpService = KMsvNullIndexEntryId; |
|
263 |
|
264 // Get the list of SMTP accounts |
|
265 RArray<TSmtpAccount> accountIds; |
|
266 |
|
267 CEmailAccounts *emailAccounts = CEmailAccounts::NewLC(); |
|
268 emailAccounts->GetSmtpAccountsL(accountIds); |
|
269 |
|
270 // Search for the account with the given name in the list of SMTP accounts |
|
271 TBool accountFound = EFalse; |
|
272 for( TInt index = 0; index < accountIds.Count(); index++) |
|
273 { |
|
274 TSmtpAccount tempAccount = accountIds[index]; |
|
275 TPtrC accountPtr( tempAccount.iSmtpAccountName ); |
|
276 |
|
277 if( accountPtr.Compare(aName) == 0 ) |
|
278 { |
|
279 aSmtpAccount = tempAccount; |
|
280 accountFound = ETrue; |
|
281 break; |
|
282 } |
|
283 } |
|
284 if(!accountFound) |
|
285 { |
|
286 User::Leave(KErrNotFound); |
|
287 } |
|
288 CleanupStack::PopAndDestroy(emailAccounts); |
|
289 accountIds.Reset(); |
|
290 |
|
291 return accountFound; |
|
292 } |