1 /* |
1 /* |
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 #include "cesmrfsmailboxutils.h" |
20 #include "cesmrfsmailboxutils.h" |
21 #include "esmrhelper.h" |
21 #include "esmrhelper.h" |
22 #include "esmrinternaluid.h" |
22 #include "esmrinternaluid.h" |
23 |
23 |
24 #include <calentry.h> |
24 #include <calentry.h> |
25 #include "cfsmailclient.h" |
25 //<cmail> |
26 #include "cfsmailbox.h" |
26 #include "CFSMailClient.h" |
|
27 #include "CFSMailBox.h" |
|
28 //</cmail> |
27 #include <caluser.h> |
29 #include <caluser.h> |
|
30 #include <ct/rcpointerarray.h> |
28 |
31 |
29 // Unnamed namespace for local definitions |
32 // Unnamed namespace for local definitions |
30 namespace { |
33 namespace { |
31 |
34 |
32 // Definition for email address comparison |
35 // Definition for email address comparison |
33 const TInt KEqualEmailAddress( 0 ); |
36 const TInt KEqualEmailAddress( 0 ); |
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Cleanup operation for RPointerArray. |
|
37 // @param aArray Pointer to RPointerArray. |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void MailboxPointerArrayCleanup( TAny* aArray ) |
|
41 { |
|
42 RPointerArray<CFSMailBox>* entryArray = |
|
43 static_cast<RPointerArray<CFSMailBox>*>( aArray ); |
|
44 |
|
45 entryArray->ResetAndDestroy(); |
|
46 entryArray->Close(); |
|
47 } |
|
48 |
37 |
49 /** |
38 /** |
50 * Listes all FS mailboxes. On return aMailboxes contains FS mailboxes |
39 * Listes all FS mailboxes. On return aMailboxes contains FS mailboxes |
51 * @param aMailClient FS mail client |
40 * @param aMailClient FS mail client |
52 * @aMailboxes Reference to mailboxes |
41 * @aMailboxes Reference to mailboxes |
90 |
79 |
91 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
92 // CESMRFsMailboxUtils::NewL |
81 // CESMRFsMailboxUtils::NewL |
93 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
94 // |
83 // |
95 CESMRFsMailboxUtils* CESMRFsMailboxUtils::NewL( |
84 EXPORT_C CESMRFsMailboxUtils* CESMRFsMailboxUtils::NewL( |
96 CMRMailboxUtils& aMailboxUtils ) |
85 CMRMailboxUtils& aMailboxUtils ) |
97 { |
86 { |
98 FUNC_LOG; |
87 FUNC_LOG; |
99 CESMRFsMailboxUtils* self = |
88 CESMRFsMailboxUtils* self = |
100 new (ELeave) CESMRFsMailboxUtils( aMailboxUtils ); |
89 new (ELeave) CESMRFsMailboxUtils( aMailboxUtils ); |
116 |
105 |
117 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
118 // CESMRFsMailboxUtils::SetPhoneOwnerL |
107 // CESMRFsMailboxUtils::SetPhoneOwnerL |
119 // --------------------------------------------------------------------------- |
108 // --------------------------------------------------------------------------- |
120 // |
109 // |
121 TInt CESMRFsMailboxUtils::SetPhoneOwnerL( |
110 EXPORT_C TInt CESMRFsMailboxUtils::SetPhoneOwnerL( |
122 CCalEntry& aCalEntry, |
111 CCalEntry& aCalEntry, |
123 TMsvId aPrimaryBox ) |
112 TMsvId aPrimaryBox ) |
124 { |
113 { |
125 FUNC_LOG; |
114 FUNC_LOG; |
126 TInt err( iMRMailboxUtils.SetPhoneOwnerL( aCalEntry, aPrimaryBox ) ); |
115 TInt err( iMRMailboxUtils.SetPhoneOwnerL( aCalEntry, aPrimaryBox ) ); |
128 // Check that phone owner was set correctly |
117 // Check that phone owner was set correctly |
129 if ( err == KErrNotFound ) |
118 if ( err == KErrNotFound ) |
130 { |
119 { |
131 // Check if phone owner can be set using FS mailboxes |
120 // Check if phone owner can be set using FS mailboxes |
132 // Loop throug all mailboxes in this plug-in |
121 // Loop throug all mailboxes in this plug-in |
133 RPointerArray<CFSMailBox> mailboxes; |
122 RCPointerArray<CFSMailBox> mailboxes; |
134 CleanupStack::PushL( |
123 CleanupClosePushL( mailboxes ); |
135 TCleanupItem( |
|
136 MailboxPointerArrayCleanup, |
|
137 &mailboxes ) ); |
|
138 |
124 |
139 ListMailBoxesL( |
125 ListMailBoxesL( |
140 MailClientL(), |
126 MailClientL(), |
141 mailboxes ); |
127 mailboxes ); |
142 |
128 |
146 if ( phoneOwner ) |
132 if ( phoneOwner ) |
147 { |
133 { |
148 aCalEntry.SetPhoneOwnerL( phoneOwner ); |
134 aCalEntry.SetPhoneOwnerL( phoneOwner ); |
149 err = KErrNone; |
135 err = KErrNone; |
150 } |
136 } |
|
137 |
151 CleanupStack::PopAndDestroy( &mailboxes ); |
138 CleanupStack::PopAndDestroy( &mailboxes ); |
152 } |
139 } |
153 return err; |
140 return err; |
154 } |
141 } |
155 |
142 |
156 // ---------------------------------------------------------------------------- |
143 // ---------------------------------------------------------------------------- |
157 // CESMRFsMailboxUtils::SetPhoneOwnerL |
144 // CESMRFsMailboxUtils::SetPhoneOwnerL |
158 // ---------------------------------------------------------------------------- |
145 // ---------------------------------------------------------------------------- |
159 // |
146 // |
160 TInt CESMRFsMailboxUtils::SetPhoneOwnerL( |
147 EXPORT_C TInt CESMRFsMailboxUtils::SetPhoneOwnerL( |
161 CCalEntry& aCalEntry, |
148 CCalEntry& aCalEntry, |
162 CFSMailClient& aMailClient, |
149 CFSMailClient& aMailClient, |
163 CFSMailMessage& aMailMessage ) |
150 CFSMailMessage& aMailMessage ) |
164 { |
151 { |
165 FUNC_LOG; |
152 FUNC_LOG; |
166 TInt err( KErrNotFound ); |
153 TInt err( KErrNotFound ); |
167 |
154 |
168 TFSMailMsgId mailboxId( aMailMessage.GetMailBoxId() ); |
155 TFSMailMsgId mailboxId( aMailMessage.GetMailBoxId() ); |
169 CFSMailBox* mailbox = aMailClient.GetMailBoxByUidL( mailboxId ); |
156 CFSMailBox* mailbox = aMailClient.GetMailBoxByUidL( mailboxId ); |
170 |
157 |
171 if ( !mailbox ) |
158 if ( !mailbox ) |
172 { |
159 { |
173 return KErrNotFound; |
160 return KErrNotFound; |
174 } |
161 } |
175 |
162 |
176 CleanupStack::PushL( mailbox ); |
163 CleanupStack::PushL( mailbox ); |
177 |
164 |
178 TPtrC mailboxOwnerAddName( |
165 TPtrC mailboxOwnerAddName( |
179 mailbox->OwnMailAddress().GetEmailAddress() ); |
166 mailbox->OwnMailAddress().GetEmailAddress() ); |
180 |
167 |
181 CCalUser* po = NULL; |
168 CCalUser* po = NULL; |
182 CCalUser* organizer = aCalEntry.OrganizerL(); |
169 CCalUser* organizer = aCalEntry.OrganizerL(); |
183 |
170 |
184 if ( organizer && |
171 if ( organizer && |
185 KEqualEmailAddress == organizer->Address().CompareF(mailboxOwnerAddName) ) |
172 KEqualEmailAddress == organizer->Address().CompareF(mailboxOwnerAddName) ) |
186 { |
173 { |
187 po = organizer; |
174 po = organizer; |
188 } |
175 } |
189 else |
176 else |
198 if ( KEqualEmailAddress == attendeeAddr.CompareF(mailboxOwnerAddName) ) |
185 if ( KEqualEmailAddress == attendeeAddr.CompareF(mailboxOwnerAddName) ) |
199 { |
186 { |
200 po = attendee; |
187 po = attendee; |
201 } |
188 } |
202 } |
189 } |
203 } |
190 } |
204 |
191 |
205 if ( po ) |
192 if ( po ) |
206 { |
193 { |
207 aCalEntry.SetPhoneOwnerL( po ); |
194 aCalEntry.SetPhoneOwnerL( po ); |
208 err = KErrNone; |
195 err = KErrNone; |
209 } |
196 } |
210 |
197 |
211 CleanupStack::PopAndDestroy( mailbox ); |
198 CleanupStack::PopAndDestroy( mailbox ); |
212 |
199 |
213 return err; |
200 return err; |
214 } |
201 } |
215 |
202 |
216 // ---------------------------------------------------------------------------- |
203 // ---------------------------------------------------------------------------- |
217 // CESMRFsMailboxUtils::FSEmailPluginForEntryL |
204 // CESMRFsMailboxUtils::FSEmailPluginForEntryL |
218 // ---------------------------------------------------------------------------- |
205 // ---------------------------------------------------------------------------- |
219 // |
206 // |
220 TESMRMailPlugin CESMRFsMailboxUtils::FSEmailPluginForEntryL( |
207 EXPORT_C TESMRMailPlugin CESMRFsMailboxUtils::FSEmailPluginForEntryL( |
221 const CCalEntry& aEntry ) |
208 const CCalEntry& aEntry ) |
222 { |
209 { |
223 FUNC_LOG; |
210 FUNC_LOG; |
224 RPointerArray<CFSMailBox> mailboxes; |
211 RCPointerArray<CFSMailBox> mailboxes; |
225 CleanupStack::PushL( |
212 CleanupClosePushL( mailboxes ); |
226 TCleanupItem( |
|
227 MailboxPointerArrayCleanup, |
|
228 &mailboxes ) ); |
|
229 |
213 |
230 ListMailBoxesL( |
214 ListMailBoxesL( |
231 MailClientL(), |
215 MailClientL(), |
232 mailboxes ); |
216 mailboxes ); |
233 |
217 |
234 CCalUser* phoneOwner = aEntry.PhoneOwnerL(); |
218 CCalUser* phoneOwner = aEntry.PhoneOwnerL(); |
235 TPtrC poMailAddress( phoneOwner->Address() ); |
219 TPtrC poMailAddress( phoneOwner->Address() ); |
236 |
220 |
237 CFSMailBox* fsEmailMailbox = NULL; |
221 CFSMailBox* fsEmailMailbox = NULL; |
238 TInt mailboxCount( mailboxes.Count() ); |
222 TInt mailboxCount( mailboxes.Count() ); |
239 for (TInt j(0); j < mailboxCount && !fsEmailMailbox; ++j ) |
223 for (TInt j(0); j < mailboxCount && !fsEmailMailbox; ++j ) |
240 { |
224 { |
241 TPtrC mailboxOwnerAddName( |
225 TPtrC mailboxOwnerAddName( |
242 mailboxes[j]->OwnMailAddress().GetEmailAddress() ); |
226 mailboxes[j]->OwnMailAddress().GetEmailAddress() ); |
243 |
227 |
244 if ( KEqualEmailAddress == mailboxOwnerAddName.CompareF(poMailAddress) ) |
228 if ( KEqualEmailAddress == mailboxOwnerAddName.CompareF(poMailAddress) ) |
245 { |
229 { |
246 // Correct mailbox is found |
230 // Correct mailbox is found |
247 fsEmailMailbox = mailboxes[j]; |
231 fsEmailMailbox = mailboxes[j]; |
248 } |
232 } |
249 } |
233 } |
250 |
234 |
251 TESMRMailPlugin plugin( EESMRUnknownPlugin ); |
235 TESMRMailPlugin plugin( EESMRUnknownPlugin ); |
252 |
236 |
253 if ( fsEmailMailbox ) |
237 if ( fsEmailMailbox ) |
254 { |
238 { |
255 // Mailbox was found --> We need to resolve mailboxes plug-in |
239 // Mailbox was found --> We need to resolve mailboxes plug-in |
256 TFSMailMsgId mailboxId( fsEmailMailbox->GetId( ) ); |
240 TFSMailMsgId mailboxId( fsEmailMailbox->GetId( ) ); |
257 TUid pluginId( mailboxId.PluginId() ); |
241 TUid pluginId( mailboxId.PluginId() ); |
266 } |
250 } |
267 else if ( TUid::Uid( KFSEmailPop3 ) == pluginId || |
251 else if ( TUid::Uid( KFSEmailPop3 ) == pluginId || |
268 TUid::Uid( KFSEmailImap4 ) == pluginId ) |
252 TUid::Uid( KFSEmailImap4 ) == pluginId ) |
269 { |
253 { |
270 plugin = EESMRImapPop; |
254 plugin = EESMRImapPop; |
271 } |
255 } |
272 } |
256 } |
273 |
257 |
274 CleanupStack::PopAndDestroy( &mailboxes ); |
258 CleanupStack::PopAndDestroy( &mailboxes ); |
275 return plugin; |
259 return plugin; |
276 } |
260 } |
277 |
261 |
278 // ---------------------------------------------------------------------------- |
262 // ---------------------------------------------------------------------------- |
279 // CESMRFsMailboxUtils::FSEmailMailBoxForEntryL |
263 // CESMRFsMailboxUtils::DefaultMailboxSupportCapabilityL |
280 // ---------------------------------------------------------------------------- |
264 // ---------------------------------------------------------------------------- |
281 // |
265 // |
282 TFSMailMsgId CESMRFsMailboxUtils::FSEmailMailBoxForEntryL( |
266 EXPORT_C TBool CESMRFsMailboxUtils::DefaultMailboxSupportCapabilityL( |
283 const CCalEntry& aEntry ) |
267 CESMRFsMailboxUtils::TMRMailboxCapability aCapability ) |
284 { |
268 { |
285 FUNC_LOG; |
269 FUNC_LOG; |
286 RPointerArray<CFSMailBox> mailboxes; |
270 |
287 CleanupStack::PushL( |
271 TBool retValue( EFalse ); |
288 TCleanupItem( MailboxPointerArrayCleanup, &mailboxes ) ); |
272 |
289 |
273 CFSMailBox* defaultMailbox = DefaultMailboxL(); |
290 ListMailBoxesL( MailClientL(), mailboxes ); |
274 CleanupStack::PushL( defaultMailbox ); |
291 |
275 ASSERT( defaultMailbox ); |
292 CCalUser* phoneOwner = aEntry.PhoneOwnerL(); |
276 |
293 TPtrC poMailAddress( phoneOwner->Address() ); |
277 switch ( aCapability ) |
294 |
278 { |
295 CFSMailBox* fsEmailMailbox = NULL; |
279 case CESMRFsMailboxUtils::EMRCapabilityAttachment: |
296 TInt mailboxCount( mailboxes.Count() ); |
280 { |
297 for (TInt j(0); j < mailboxCount && !fsEmailMailbox; ++j ) |
281 retValue = defaultMailbox->HasCapability( |
298 { |
282 EFSMboxCapaSupportsAttahmentsInMR ); |
299 TPtrC mailboxOwnerAddName( |
283 } |
300 mailboxes[j]->OwnMailAddress().GetEmailAddress() ); |
284 break; |
301 |
285 } |
302 if ( KEqualEmailAddress == |
286 |
303 mailboxOwnerAddName.CompareF( poMailAddress ) ) |
287 CleanupStack::PopAndDestroy( defaultMailbox ); |
304 { |
288 |
305 // Correct mailbox is found |
289 return retValue; |
306 fsEmailMailbox = mailboxes[j]; |
|
307 } |
|
308 } |
|
309 |
|
310 TFSMailMsgId retVal; // default ctor constructs a null id. |
|
311 |
|
312 if ( fsEmailMailbox ) |
|
313 { |
|
314 retVal = fsEmailMailbox->GetId(); |
|
315 } |
|
316 |
|
317 CleanupStack::PopAndDestroy( &mailboxes ); |
|
318 return retVal; |
|
319 } |
290 } |
320 |
291 |
321 // ---------------------------------------------------------------------------- |
292 // ---------------------------------------------------------------------------- |
322 // CESMRFsMailboxUtils::PhoneOwnerL |
293 // CESMRFsMailboxUtils::PhoneOwnerL |
323 // ---------------------------------------------------------------------------- |
294 // ---------------------------------------------------------------------------- |
396 iMailClient = CFSMailClient::NewL(); |
367 iMailClient = CFSMailClient::NewL(); |
397 } |
368 } |
398 return *iMailClient; |
369 return *iMailClient; |
399 } |
370 } |
400 |
371 |
|
372 // ---------------------------------------------------------------------------- |
|
373 // CESMRFsMailboxUtils::DefaultMailboxL |
|
374 // ---------------------------------------------------------------------------- |
|
375 // |
|
376 CFSMailBox* CESMRFsMailboxUtils::DefaultMailboxL() |
|
377 { |
|
378 FUNC_LOG; |
|
379 |
|
380 CFSMailBox* defaultMailbox( NULL ); |
|
381 |
|
382 CMRMailboxUtils::TMailboxInfo mailboxInfo; |
|
383 TInt err = iMRMailboxUtils.GetDefaultMRMailBoxL( mailboxInfo ); |
|
384 |
|
385 if ( KErrNone == err ) |
|
386 { |
|
387 RCPointerArray<CFSMailBox> mailboxes; |
|
388 CleanupClosePushL( mailboxes ); |
|
389 |
|
390 ListMailBoxesL( MailClientL(), mailboxes ); |
|
391 |
|
392 TInt mailboxCount( mailboxes.Count() ); |
|
393 for (TInt j(0); j < mailboxCount && !defaultMailbox; ++j ) |
|
394 { |
|
395 TPtrC mailboxOwnerAddName( |
|
396 mailboxes[j]->OwnMailAddress().GetEmailAddress() ); |
|
397 |
|
398 if ( KEqualEmailAddress == |
|
399 mailboxOwnerAddName.CompareF( mailboxInfo.iEmailAddress) ) |
|
400 { |
|
401 // Default mailbox is found |
|
402 defaultMailbox = mailboxes[j]; |
|
403 mailboxes.Remove( j ); |
|
404 } |
|
405 } |
|
406 |
|
407 CleanupStack::PopAndDestroy( &mailboxes ); |
|
408 } |
|
409 |
|
410 return defaultMailbox; |
|
411 } |
|
412 |
401 // EOF |
413 // EOF |
402 |
414 |