64
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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: ESMR FS mailbox utilities implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "cesmrfsmailboxutils.h"
|
|
20 |
|
|
21 |
#include "esmrhelper.h"
|
|
22 |
#include "esmrinternaluid.h"
|
|
23 |
|
|
24 |
#include "cfsmailclient.h"
|
|
25 |
#include "cfsmailbox.h"
|
|
26 |
#include "cmrcalendarinfo.h"
|
|
27 |
|
|
28 |
#include <calentry.h>
|
|
29 |
#include <caluser.h>
|
|
30 |
#include <ct/rcpointerarray.h>
|
|
31 |
|
|
32 |
#include "emailtrace.h"
|
|
33 |
|
|
34 |
// Unnamed namespace for local definitions
|
|
35 |
namespace {
|
|
36 |
|
|
37 |
// Definition for email address comparison
|
|
38 |
const TInt KEqualEmailAddress( 0 );
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Listes all FS mailboxes. On return aMailboxes contains FS mailboxes
|
|
42 |
* @param aMailClient FS mail client
|
|
43 |
* @aMailboxes Reference to mailboxes
|
|
44 |
*/
|
|
45 |
void ListMailBoxesL(
|
|
46 |
CFSMailClient& aMailClient,
|
|
47 |
RPointerArray<CFSMailBox>& aMailboxes )
|
|
48 |
{
|
|
49 |
TFSMailMsgId msgId;
|
|
50 |
aMailClient.ListMailBoxes(
|
|
51 |
msgId,
|
|
52 |
aMailboxes );
|
|
53 |
}
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Helper class for Email extension cleanup
|
|
57 |
*/
|
|
58 |
class TExtensionCleanup
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
|
|
62 |
TExtensionCleanup(
|
|
63 |
CFSMailBox* aMailbox,
|
|
64 |
CEmailExtension* aExtension )
|
|
65 |
: iMailbox( aMailbox ),
|
|
66 |
iExtension( aExtension )
|
|
67 |
{
|
|
68 |
}
|
|
69 |
|
|
70 |
void Close()
|
|
71 |
{
|
|
72 |
iMailbox->ReleaseExtension( iExtension );
|
|
73 |
}
|
|
74 |
|
|
75 |
private:
|
|
76 |
/// Not own: mailbox
|
|
77 |
CFSMailBox* iMailbox;
|
|
78 |
// Not own: mailbox extension
|
|
79 |
CEmailExtension* iExtension;
|
|
80 |
};
|
|
81 |
|
|
82 |
|
|
83 |
}
|
|
84 |
|
|
85 |
// ======== MEMBER FUNCTIONS ========
|
|
86 |
|
|
87 |
// ---------------------------------------------------------------------------
|
|
88 |
// CESMRFsMailboxUtils::CESMRFsMailboxUtils
|
|
89 |
// ---------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
inline CESMRFsMailboxUtils::CESMRFsMailboxUtils(
|
|
92 |
CMRMailboxUtils& aMailboxUtils )
|
|
93 |
: iMRMailboxUtils( aMailboxUtils )
|
|
94 |
{
|
|
95 |
FUNC_LOG;
|
|
96 |
}
|
|
97 |
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
// CESMRFsMailboxUtils::~CESMRFsMailboxUtils
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
EXPORT_C CESMRFsMailboxUtils::~CESMRFsMailboxUtils()
|
|
103 |
{
|
|
104 |
FUNC_LOG;
|
|
105 |
if ( iMailClient )
|
|
106 |
{
|
|
107 |
iMailClient->Close();
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
// ---------------------------------------------------------------------------
|
|
112 |
// CESMRFsMailboxUtils::NewL
|
|
113 |
// ---------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
EXPORT_C CESMRFsMailboxUtils* CESMRFsMailboxUtils::NewL(
|
|
116 |
CMRMailboxUtils& aMailboxUtils )
|
|
117 |
{
|
|
118 |
FUNC_LOG;
|
|
119 |
CESMRFsMailboxUtils* self =
|
|
120 |
new (ELeave) CESMRFsMailboxUtils( aMailboxUtils );
|
|
121 |
CleanupStack::PushL( self );
|
|
122 |
self->ConstructL();
|
|
123 |
CleanupStack::Pop( self );
|
|
124 |
return self;
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
// CESMRFsMailboxUtils::ConstructL
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
void CESMRFsMailboxUtils::ConstructL()
|
|
132 |
{
|
|
133 |
FUNC_LOG;
|
|
134 |
// Do nothing
|
|
135 |
}
|
|
136 |
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
// CESMRFsMailboxUtils::SetPhoneOwnerL
|
|
139 |
// ---------------------------------------------------------------------------
|
|
140 |
//
|
|
141 |
EXPORT_C TInt CESMRFsMailboxUtils::SetPhoneOwnerL(
|
|
142 |
CCalEntry& aCalEntry,
|
|
143 |
TMsvId aPrimaryBox )
|
|
144 |
{
|
|
145 |
FUNC_LOG;
|
|
146 |
TInt err( iMRMailboxUtils.SetPhoneOwnerL( aCalEntry, aPrimaryBox ) );
|
|
147 |
|
|
148 |
// Check that phone owner was set correctly
|
|
149 |
if ( err == KErrNotFound )
|
|
150 |
{
|
|
151 |
// Check if phone owner can be set using FS mailboxes
|
|
152 |
// Loop throug all mailboxes in this plug-in
|
|
153 |
RCPointerArray<CFSMailBox> mailboxes;
|
|
154 |
CleanupClosePushL( mailboxes );
|
|
155 |
|
|
156 |
ListMailBoxesL(
|
|
157 |
MailClientL(),
|
|
158 |
mailboxes );
|
|
159 |
|
|
160 |
TInt dummyIndex( -1 ); // don't care
|
|
161 |
CCalUser* phoneOwner = PhoneOwnerL( aCalEntry, mailboxes, dummyIndex );
|
|
162 |
|
|
163 |
if ( phoneOwner )
|
|
164 |
{
|
|
165 |
aCalEntry.SetPhoneOwnerL( phoneOwner );
|
|
166 |
err = KErrNone;
|
|
167 |
}
|
|
168 |
|
|
169 |
CleanupStack::PopAndDestroy( &mailboxes );
|
|
170 |
}
|
|
171 |
return err;
|
|
172 |
}
|
|
173 |
|
|
174 |
// ----------------------------------------------------------------------------
|
|
175 |
// CESMRFsMailboxUtils::SetPhoneOwnerL
|
|
176 |
// ----------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
EXPORT_C TInt CESMRFsMailboxUtils::SetPhoneOwnerL(
|
|
179 |
CCalEntry& aCalEntry,
|
|
180 |
CFSMailClient& aMailClient,
|
|
181 |
CFSMailMessage& aMailMessage )
|
|
182 |
{
|
|
183 |
FUNC_LOG;
|
|
184 |
TInt err( KErrNotFound );
|
|
185 |
|
|
186 |
TFSMailMsgId mailboxId( aMailMessage.GetMailBoxId() );
|
|
187 |
CFSMailBox* mailbox = aMailClient.GetMailBoxByUidL( mailboxId );
|
|
188 |
|
|
189 |
if ( !mailbox )
|
|
190 |
{
|
|
191 |
return KErrNotFound;
|
|
192 |
}
|
|
193 |
|
|
194 |
CleanupStack::PushL( mailbox );
|
|
195 |
|
|
196 |
TPtrC mailboxOwnerAddName(
|
|
197 |
mailbox->OwnMailAddress().GetEmailAddress() );
|
|
198 |
|
|
199 |
CCalUser* po = NULL;
|
|
200 |
CCalUser* organizer = aCalEntry.OrganizerL();
|
|
201 |
|
|
202 |
if ( organizer &&
|
|
203 |
KEqualEmailAddress == organizer->Address().CompareF(mailboxOwnerAddName) )
|
|
204 |
{
|
|
205 |
po = organizer;
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
RPointerArray<CCalAttendee>& attendees = aCalEntry.AttendeesL();
|
|
210 |
TInt attendeeCount( attendees.Count() );
|
|
211 |
|
|
212 |
for( TInt i(0); i < attendeeCount && !po; ++i )
|
|
213 |
{
|
|
214 |
CCalAttendee* attendee = attendees[i];
|
|
215 |
TPtrC attendeeAddr( attendee->Address() );
|
|
216 |
if ( KEqualEmailAddress == attendeeAddr.CompareF(mailboxOwnerAddName) )
|
|
217 |
{
|
|
218 |
po = attendee;
|
|
219 |
}
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
if ( po )
|
|
224 |
{
|
|
225 |
aCalEntry.SetPhoneOwnerL( po );
|
|
226 |
err = KErrNone;
|
|
227 |
}
|
|
228 |
|
|
229 |
CleanupStack::PopAndDestroy( mailbox );
|
|
230 |
|
|
231 |
return err;
|
|
232 |
}
|
|
233 |
|
|
234 |
// ----------------------------------------------------------------------------
|
|
235 |
// CESMRFsMailboxUtils::FSEmailPluginForEntryL
|
|
236 |
// ----------------------------------------------------------------------------
|
|
237 |
//
|
|
238 |
EXPORT_C TESMRMailPlugin CESMRFsMailboxUtils::FSEmailPluginForEntryL(
|
|
239 |
const CCalEntry& aEntry )
|
|
240 |
{
|
|
241 |
FUNC_LOG;
|
|
242 |
RCPointerArray<CFSMailBox> mailboxes;
|
|
243 |
CleanupClosePushL( mailboxes );
|
|
244 |
|
|
245 |
ListMailBoxesL(
|
|
246 |
MailClientL(),
|
|
247 |
mailboxes );
|
|
248 |
|
|
249 |
CCalUser* phoneOwner = aEntry.PhoneOwnerL();
|
|
250 |
TPtrC poMailAddress( phoneOwner->Address() );
|
|
251 |
|
|
252 |
CFSMailBox* fsEmailMailbox = NULL;
|
|
253 |
TInt mailboxCount( mailboxes.Count() );
|
|
254 |
for (TInt j(0); j < mailboxCount && !fsEmailMailbox; ++j )
|
|
255 |
{
|
|
256 |
TPtrC mailboxOwnerAddName(
|
|
257 |
mailboxes[j]->OwnMailAddress().GetEmailAddress() );
|
|
258 |
|
|
259 |
if ( KEqualEmailAddress == mailboxOwnerAddName.CompareF(poMailAddress) )
|
|
260 |
{
|
|
261 |
// Correct mailbox is found
|
|
262 |
fsEmailMailbox = mailboxes[j];
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
TESMRMailPlugin plugin( EESMRUnknownPlugin );
|
|
267 |
|
|
268 |
if ( fsEmailMailbox )
|
|
269 |
{
|
|
270 |
// Mailbox was found --> We need to resolve mailboxes plug-in
|
|
271 |
TFSMailMsgId mailboxId( fsEmailMailbox->GetId( ) );
|
|
272 |
TUid pluginId( mailboxId.PluginId() );
|
|
273 |
|
|
274 |
if ( TUid::Uid( KEasFreestylePlugin ) == pluginId )
|
|
275 |
{
|
|
276 |
plugin = EESMRActiveSync;
|
|
277 |
}
|
|
278 |
else if ( TUid::Uid( KIntellisync ) == pluginId )
|
|
279 |
{
|
|
280 |
plugin = EESMRIntelliSync;
|
|
281 |
}
|
|
282 |
else if ( TUid::Uid( KFSEmailPop3 ) == pluginId ||
|
|
283 |
TUid::Uid( KFSEmailImap4 ) == pluginId )
|
|
284 |
{
|
|
285 |
plugin = EESMRImapPop;
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
CleanupStack::PopAndDestroy( &mailboxes );
|
|
290 |
return plugin;
|
|
291 |
}
|
|
292 |
|
|
293 |
// ----------------------------------------------------------------------------
|
|
294 |
// CESMRFsMailboxUtils::DefaultMailboxSupportCapabilityL
|
|
295 |
// ----------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
EXPORT_C TBool CESMRFsMailboxUtils::DefaultMailboxSupportCapabilityL(
|
|
298 |
CESMRFsMailboxUtils::TMRMailboxCapability aCapability )
|
|
299 |
{
|
|
300 |
FUNC_LOG;
|
|
301 |
|
|
302 |
TBool retValue( EFalse );
|
|
303 |
|
|
304 |
CFSMailBox* defaultMailbox = DefaultMailboxL();
|
|
305 |
CleanupStack::PushL( defaultMailbox );
|
|
306 |
ASSERT( defaultMailbox );
|
|
307 |
|
|
308 |
switch ( aCapability )
|
|
309 |
{
|
|
310 |
case CESMRFsMailboxUtils::EMRCapabilityAttachment:
|
|
311 |
{
|
|
312 |
retValue = defaultMailbox->HasCapability(
|
|
313 |
EFSMboxCapaSupportsAttahmentsInMR );
|
|
314 |
}
|
|
315 |
break;
|
|
316 |
}
|
|
317 |
|
|
318 |
CleanupStack::PopAndDestroy( defaultMailbox );
|
|
319 |
|
|
320 |
return retValue;
|
|
321 |
}
|
|
322 |
|
|
323 |
// ----------------------------------------------------------------------------
|
|
324 |
// CESMRFsMailboxUtils::GetCalendarDatabaseIdL
|
|
325 |
// ----------------------------------------------------------------------------
|
|
326 |
//
|
|
327 |
void CESMRFsMailboxUtils::GetCalendarDatabaseIdL(
|
|
328 |
TESMRMailPlugin aPlugin,
|
|
329 |
TCalFileId& aDbId )
|
|
330 |
{
|
|
331 |
FUNC_LOG;
|
|
332 |
|
|
333 |
TUid pluginUid( TUid::Null() );
|
|
334 |
aDbId = KNullFileId;
|
|
335 |
|
|
336 |
switch ( aPlugin )
|
|
337 |
{
|
|
338 |
case EESMRActiveSync:
|
|
339 |
{
|
|
340 |
pluginUid = TUid::Uid( KEasFreestylePlugin );
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
case EESMRIntelliSync:
|
|
344 |
{
|
|
345 |
pluginUid = TUid::Uid( KIntellisync );
|
|
346 |
break;
|
|
347 |
}
|
|
348 |
default:
|
|
349 |
{
|
|
350 |
break;
|
|
351 |
}
|
|
352 |
}
|
|
353 |
|
|
354 |
if ( pluginUid != TUid::Null() )
|
|
355 |
{
|
|
356 |
RCPointerArray<CFSMailBox> mailboxes;
|
|
357 |
CleanupClosePushL( mailboxes );
|
|
358 |
|
|
359 |
ListMailBoxesL(
|
|
360 |
MailClientL(),
|
|
361 |
mailboxes );
|
|
362 |
|
|
363 |
for ( TInt i = 0; i < mailboxes.Count(); ++i )
|
|
364 |
{
|
|
365 |
CFSMailBox* mailbox = mailboxes[ i ];
|
|
366 |
if ( mailbox->GetId().PluginId() == pluginUid )
|
|
367 |
{
|
|
368 |
// Resolve database id using mailbox extension
|
|
369 |
CEmailExtension* extension =
|
|
370 |
mailbox->ExtensionL( KMailboxExtMrCalInfo );
|
|
371 |
|
|
372 |
TExtensionCleanup cleanup( mailbox, extension );
|
|
373 |
CleanupClosePushL( cleanup );
|
|
374 |
|
|
375 |
CMRCalendarInfo* calInfo =
|
|
376 |
static_cast< CMRCalendarInfo* >( extension );
|
|
377 |
|
|
378 |
if ( calInfo )
|
|
379 |
{
|
|
380 |
calInfo->GetCalendarDatabaseIdL( aDbId );
|
|
381 |
}
|
|
382 |
|
|
383 |
CleanupStack::PopAndDestroy( &cleanup ); // Release extension
|
|
384 |
break;
|
|
385 |
}
|
|
386 |
}
|
|
387 |
|
|
388 |
CleanupStack::PopAndDestroy( &mailboxes );
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
// ----------------------------------------------------------------------------
|
|
393 |
// CESMRFsMailboxUtils::PhoneOwnerL
|
|
394 |
// ----------------------------------------------------------------------------
|
|
395 |
//
|
|
396 |
CCalUser* CESMRFsMailboxUtils::PhoneOwnerL(
|
|
397 |
const CCalEntry& aCalEntry,
|
|
398 |
const RPointerArray<CFSMailBox>& aMailBoxes,
|
|
399 |
TInt& aMatchIndex )
|
|
400 |
{
|
|
401 |
FUNC_LOG;
|
|
402 |
aMatchIndex = -1; // no match yet
|
|
403 |
|
|
404 |
// 1. test if phone owner is organizer:
|
|
405 |
CCalUser* organizer = aCalEntry.OrganizerL(); // ownership not transf.
|
|
406 |
if ( organizer )
|
|
407 |
{
|
|
408 |
if ( IsPhoneOwnerL( *organizer, aMailBoxes, aMatchIndex ) )
|
|
409 |
{
|
|
410 |
return organizer;
|
|
411 |
}
|
|
412 |
}
|
|
413 |
|
|
414 |
// 2. test if phone owner is attendee:
|
|
415 |
RPointerArray<CCalAttendee>& attendees = aCalEntry.AttendeesL();
|
|
416 |
TInt attCount( attendees.Count() );
|
|
417 |
for ( TInt i( 0 );i < attCount; ++i )
|
|
418 |
{
|
|
419 |
CCalUser* att = static_cast<CCalUser*>(attendees[i]);
|
|
420 |
if ( IsPhoneOwnerL( *att, aMailBoxes, aMatchIndex ) )
|
|
421 |
{
|
|
422 |
return att;
|
|
423 |
}
|
|
424 |
}
|
|
425 |
|
|
426 |
// Matching attendee was not found:
|
|
427 |
return NULL;
|
|
428 |
}
|
|
429 |
|
|
430 |
// ----------------------------------------------------------------------------
|
|
431 |
// CESMRFsMailboxUtils::IsPhoneOwnerL
|
|
432 |
// ----------------------------------------------------------------------------
|
|
433 |
//
|
|
434 |
TBool CESMRFsMailboxUtils::IsPhoneOwnerL(
|
|
435 |
const CCalUser& aUser,
|
|
436 |
const RPointerArray<CFSMailBox>& aMailBoxes,
|
|
437 |
TInt& aMatchIndex )
|
|
438 |
{
|
|
439 |
FUNC_LOG;
|
|
440 |
TPtrC addr = ESMRHelper::AddressWithoutMailtoPrefix( aUser.Address() );
|
|
441 |
aMatchIndex = -1; // no match yet
|
|
442 |
TInt boxCount( aMailBoxes.Count() );
|
|
443 |
for ( TInt i( 0 ); i < boxCount; ++i )
|
|
444 |
{
|
|
445 |
TPtrC mailboxOwnerAddName(
|
|
446 |
aMailBoxes[i]->OwnMailAddress().GetEmailAddress() );
|
|
447 |
|
|
448 |
if ( addr.CompareF( mailboxOwnerAddName ) == KEqualEmailAddress )
|
|
449 |
{
|
|
450 |
// first match is enough:
|
|
451 |
aMatchIndex = i;
|
|
452 |
return ETrue;
|
|
453 |
}
|
|
454 |
}
|
|
455 |
return EFalse; // no match
|
|
456 |
}
|
|
457 |
|
|
458 |
// ----------------------------------------------------------------------------
|
|
459 |
// CESMRFsMailboxUtils::MailClientL
|
|
460 |
// ----------------------------------------------------------------------------
|
|
461 |
//
|
|
462 |
CFSMailClient& CESMRFsMailboxUtils::MailClientL()
|
|
463 |
{
|
|
464 |
FUNC_LOG;
|
|
465 |
if ( !iMailClient )
|
|
466 |
{
|
|
467 |
iMailClient = CFSMailClient::NewL();
|
|
468 |
}
|
|
469 |
return *iMailClient;
|
|
470 |
}
|
|
471 |
|
|
472 |
// ----------------------------------------------------------------------------
|
|
473 |
// CESMRFsMailboxUtils::DefaultMailboxL
|
|
474 |
// ----------------------------------------------------------------------------
|
|
475 |
//
|
|
476 |
CFSMailBox* CESMRFsMailboxUtils::DefaultMailboxL()
|
|
477 |
{
|
|
478 |
FUNC_LOG;
|
|
479 |
|
|
480 |
CFSMailBox* defaultMailbox( NULL );
|
|
481 |
|
|
482 |
CMRMailboxUtils::TMailboxInfo mailboxInfo;
|
|
483 |
TInt err = iMRMailboxUtils.GetDefaultMRMailBoxL( mailboxInfo );
|
|
484 |
|
|
485 |
if ( KErrNone == err )
|
|
486 |
{
|
|
487 |
RCPointerArray<CFSMailBox> mailboxes;
|
|
488 |
CleanupClosePushL( mailboxes );
|
|
489 |
|
|
490 |
ListMailBoxesL( MailClientL(), mailboxes );
|
|
491 |
|
|
492 |
TInt mailboxCount( mailboxes.Count() );
|
|
493 |
for (TInt j(0); j < mailboxCount && !defaultMailbox; ++j )
|
|
494 |
{
|
|
495 |
TPtrC mailboxOwnerAddName(
|
|
496 |
mailboxes[j]->OwnMailAddress().GetEmailAddress() );
|
|
497 |
|
|
498 |
if ( KEqualEmailAddress ==
|
|
499 |
mailboxOwnerAddName.CompareF( mailboxInfo.iEmailAddress) )
|
|
500 |
{
|
|
501 |
// Default mailbox is found
|
|
502 |
defaultMailbox = mailboxes[j];
|
|
503 |
mailboxes.Remove( j );
|
|
504 |
}
|
|
505 |
}
|
|
506 |
|
|
507 |
CleanupStack::PopAndDestroy( &mailboxes );
|
|
508 |
}
|
|
509 |
|
|
510 |
return defaultMailbox;
|
|
511 |
}
|
|
512 |
|
|
513 |
// EOF
|
|
514 |
|