mobilemessaging/unieditor/utils/src/UniAddressHandler.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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 *       Defines implementation of CUniAddressHandler class methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ========== INCLUDE FILES ================================
       
    22 
       
    23 #include "UniAddressHandler.h"
       
    24 
       
    25 // MSV
       
    26 #include <cmsvrecipientlist.h>  
       
    27 #include <mtclbase.h>
       
    28 
       
    29 // MMS Engine
       
    30 #include <mmsgenutils.h>
       
    31 
       
    32 // Base Editor
       
    33 #include <MsgAddressControl.h>      // for CMsgAddressControl
       
    34 #include <MsgRecipientItem.h>       // for CMsgRecipientItem
       
    35 #include <MsgCheckNames.h>          // for CMsgCheckNames
       
    36 #include <contactmatcher.h>
       
    37 #include <MVPbkStoreContact.h>
       
    38 
       
    39 // MUIU
       
    40 #include <MuiuMsvUiServiceUtilities.h>
       
    41 #include <muiumsvuiserviceutilitiesinternal.h>
       
    42 
       
    43 #include <centralrepository.h>    // link against centralrepository.lib
       
    44 #include <telconfigcrkeys.h> // for Central Repository keys
       
    45 
       
    46 // AVKON
       
    47 #include <AknUtils.h>
       
    48 #include <aknnotewrappers.h>
       
    49 #include <akninputblock.h>
       
    50 
       
    51 // Common Components
       
    52 #include <StringLoader.h>           // for StringLoader (load and foramt strings from resources)
       
    53 #include <commonphoneparser.h>      // Common phone number validity checker
       
    54 #include <data_caging_path_literals.hrh> 
       
    55 
       
    56 #include <bautils.h>                        // NearestLanguageFile
       
    57 
       
    58 #include <UniUtils.rsg>           // resources
       
    59 
       
    60 #include "UniUtils.h"
       
    61 
       
    62 // ========== EXTERNAL DATA STRUCTURES =====================
       
    63 
       
    64 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    65 
       
    66 // ========== CONSTANTS ====================================
       
    67 
       
    68 const TInt KMaxDetailsLength = 64;   // Copy max this many chars to TMsvEntry iDetails
       
    69 const TInt KDefaultCompareLength = 7;
       
    70 
       
    71 _LIT( KAddressSeparator, ";" );
       
    72 
       
    73 // ========== MACROS =======================================
       
    74 
       
    75 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    76 
       
    77 // ========== MODULE DATA STRUCTURES =======================
       
    78 
       
    79 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
    80 
       
    81 // ========== LOCAL FUNCTIONS ==============================
       
    82 
       
    83 // ========== MEMBER FUNCTIONS =============================
       
    84 
       
    85 // ---------------------------------------------------------
       
    86 // CUniAddressHandler::CUniAddressHandler
       
    87 //
       
    88 // C++ constructor.
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 CUniAddressHandler::CUniAddressHandler( CBaseMtm& aMtm,
       
    92                                         CMsgAddressControl& aControl,
       
    93                                         CCoeEnv& aCoeEnv ) :
       
    94     iMtm( aMtm ),
       
    95     iControl( aControl ),
       
    96     iCoeEnv( aCoeEnv ),
       
    97     iValidAddressType( CMsgCheckNames::EMsgTypeMms ),
       
    98     iResourceLoader( iCoeEnv )
       
    99     {
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // CUniAddressHandler::ConstructL
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 void CUniAddressHandler::ConstructL()
       
   107     {
       
   108     if ( !iCoeEnv.IsResourceAvailableL( R_UNUT_INFO_FAIL_RECIPIENT_NO_ALIAS ) )
       
   109         {
       
   110         TParse parse;
       
   111         User::LeaveIfError( parse.Set( KUniUtilsResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL ) );
       
   112         TFileName fileName( parse.FullName() );
       
   113         iResourceLoader.OpenL( fileName );                 
       
   114         }
       
   115         iCheckNames = CMsgCheckNames::NewL();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CUniAddressHandler::NewL
       
   120 //
       
   121 // Factory method.
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 EXPORT_C CUniAddressHandler* CUniAddressHandler::NewL( CBaseMtm& aMtm,
       
   125                                                        CMsgAddressControl& aControl,
       
   126                                                        CCoeEnv& aCoeEnv )
       
   127     {
       
   128     CUniAddressHandler* self = new ( ELeave ) CUniAddressHandler( aMtm, aControl, aCoeEnv );
       
   129 
       
   130     CleanupStack::PushL( self );
       
   131     self->ConstructL();
       
   132     CleanupStack::Pop( self );
       
   133 
       
   134     return self;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CUniAddressHandler::~CUniAddressHandler
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 CUniAddressHandler::~CUniAddressHandler()
       
   142     {
       
   143     iResourceLoader.Close();
       
   144     
       
   145     delete iCheckNames;
       
   146     delete iInvalidRecipients;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CUniAddressHandler::RemoveAddressesFromMtmL
       
   151 //
       
   152 // Resets address list in MTM
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CUniAddressHandler::RemoveAddressesFromMtmL( TMsvRecipientTypeValues aRecipientType)
       
   156     {
       
   157     const CMsvRecipientList& addresses = iMtm.AddresseeList();
       
   158 
       
   159     for ( TInt i = iMtm.AddresseeList().Count(); --i >=  0; )
       
   160         {
       
   161         if ( addresses.Type( i ) == aRecipientType )
       
   162             {
       
   163             iMtm.RemoveAddressee( i );
       
   164             }
       
   165         }
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // CUniAddressHandler::CopyAddressesToMtmL
       
   170 //
       
   171 // Resets address list in MTM and insert addresses from 
       
   172 // address control to MTM
       
   173 // ---------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CUniAddressHandler::CopyAddressesToMtmL( TMsvRecipientTypeValues aRecipientType )
       
   176     {
       
   177     RemoveAddressesFromMtmL( aRecipientType );
       
   178     AppendAddressesToMtmL( aRecipientType );
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CUniAddressHandler::AppendAddressesToMtmL
       
   183 //
       
   184 // Inserts addresses from control to MTM.
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 EXPORT_C void CUniAddressHandler::AppendAddressesToMtmL( TMsvRecipientTypeValues aRecipientType)
       
   188 
       
   189     {
       
   190     const TInt KMaxContactLength = 100;
       
   191     const CMsgRecipientArray* recipients = iControl.GetRecipientsL(); // Not owned
       
   192     
       
   193     HBufC* contactname = HBufC::NewL( KMaxContactLength );
       
   194     CleanupStack::PushL( contactname ); 
       
   195     TPtr aliPtr ( contactname->Des() );
       
   196     TInt addrCnt = recipients->Count();
       
   197     
       
   198     for ( TInt i = 0; i < addrCnt ; i++ )
       
   199         {
       
   200         CMsgRecipientItem* addrItem = recipients->At( i );
       
   201 
       
   202         TPtr realAddress = addrItem->Address()->Des();
       
   203         TPtr alias = addrItem->Name()->Des();
       
   204 
       
   205         // Check that neither string contains illegal characters.
       
   206         // If they does strip illegal chars away and save
       
   207         RemoveIllegalChars( realAddress );
       
   208         
       
   209         if ( alias.Length() > 0 )
       
   210             {
       
   211             RemoveIllegalChars( alias );
       
   212             iMtm.AddAddresseeL( aRecipientType, realAddress, alias );
       
   213             }
       
   214         else
       
   215             {               
       
   216             iCheckNames->GetAliasL(realAddress,aliPtr,KMaxContactLength);             
       
   217             if(contactname->Des().Length() > 0 )
       
   218                 {
       
   219                 RemoveIllegalChars( aliPtr );
       
   220                 }            
       
   221             iMtm.AddAddresseeL( aRecipientType, realAddress, aliPtr );
       
   222             }                              
       
   223         }
       
   224         CleanupStack::PopAndDestroy( contactname );           
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CUniAddressHandler::CopyAddressesFromMtmL
       
   229 //
       
   230 // Inserts addresses from MTM to address control. aAddInvalid
       
   231 // parameter is used to determine whether invalid addresses
       
   232 // should be added to the control or to special list that can
       
   233 // be used later on to show invalid address notes.
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 EXPORT_C void CUniAddressHandler::CopyAddressesFromMtmL( TMsvRecipientTypeValues aRecipientType,
       
   237                                                          TBool aAddInvalid )
       
   238     {
       
   239     const CMsvRecipientList& addresses = iMtm.AddresseeList();
       
   240 
       
   241     CMsgRecipientList* recipients = CMsgRecipientList::NewL();
       
   242     CleanupStack::PushL( recipients );
       
   243         
       
   244     TInt addrCnt = addresses.Count();        
       
   245     for ( TInt i = 0; i < addrCnt; i++ )
       
   246         {          
       
   247         if ( addresses.Type( i ) == aRecipientType )
       
   248             {
       
   249             TPtrC address = TMmsGenUtils::PureAddress( addresses[i] );
       
   250             if ( address.Length() > 0 )
       
   251                 {
       
   252                 TPtrC alias   = TMmsGenUtils::Alias( addresses[i] );
       
   253                 if ( address.Compare( alias ) == 0 )
       
   254                     {
       
   255                     // Both alias and address are the same -> drop the alias as this is most likely reply to 
       
   256                     // SMS and SMS client MTM sets both alias and address to be the same.
       
   257                     alias.Set( KNullDesC );
       
   258                     }
       
   259                 
       
   260                 CMsgRecipientItem* item = CMsgRecipientItem::NewLC( alias, address );
       
   261                 item->SetVerified( alias.Length() > 0 ? ETrue : EFalse );
       
   262                 
       
   263                 HBufC16* convertBuffer = NumberConversionLC( address, EFalse );
       
   264                 
       
   265             	if ( aAddInvalid || CheckSingleAddressL( *convertBuffer ) )
       
   266                     {    
       
   267                     recipients->AppendL( item );
       
   268                     }
       
   269                 else
       
   270                     {
       
   271                     if ( !iInvalidRecipients )
       
   272                         {
       
   273                         iInvalidRecipients = CMsgRecipientList::NewL();
       
   274                         }
       
   275                     iInvalidRecipients->AppendL( item );
       
   276                     }
       
   277                 
       
   278                 CleanupStack::PopAndDestroy( convertBuffer );    
       
   279                 CleanupStack::Pop( item );
       
   280                 }
       
   281             }
       
   282         }
       
   283 
       
   284     if ( recipients->Count() > 0 )
       
   285         {
       
   286         iControl.AddRecipientsL( *recipients );
       
   287         iControl.SetModified( EFalse );
       
   288         }
       
   289         
       
   290     CleanupStack::PopAndDestroy( recipients );
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------
       
   294 // CUniAddressHandler::VerifyAddressesL
       
   295 //
       
   296 // Walks thru addresses in addresscontrol and counts errors. 
       
   297 // If unverified address is valid, marks it validated (verified now). 
       
   298 // Stops to first error.
       
   299 // ---------------------------------------------------------
       
   300 //
       
   301 EXPORT_C TBool CUniAddressHandler::VerifyAddressesL( TBool& aModified )
       
   302     {
       
   303     CAknInputBlock::NewLC();  
       
   304 
       
   305     aModified = EFalse;
       
   306 
       
   307     CMsgRecipientArray* recipients = iControl.GetRecipientsL(); // Not owned
       
   308 
       
   309     TInt addrCnt = recipients->Count();
       
   310     
       
   311     // First verify unverified addresses in control.
       
   312     for ( TInt i = 0; i < addrCnt; i++ )
       
   313         {
       
   314         CMsgRecipientItem* addrItem = recipients->At( i );
       
   315 
       
   316         if ( !addrItem->IsVerified() || 
       
   317              !addrItem->IsValidated() )
       
   318             {
       
   319             // Must check
       
   320             // Just check the addresses here. Don't modify them yet.
       
   321             if ( CheckSingleAddressL( *( addrItem->Address() ) ) )
       
   322                 {
       
   323                 addrItem->SetValidated( ETrue );
       
   324                 }
       
   325             else 
       
   326                 {
       
   327                 // Address not OK, but maybe it's an alias from Phonebook...
       
   328                 TBool addressOK = EFalse;
       
   329                 
       
   330                 // Search for matches
       
   331                 if ( !iCheckNames )
       
   332                     {
       
   333                     iCheckNames = CMsgCheckNames::NewL();
       
   334                     }
       
   335                     
       
   336                 if ( iCheckNames->FindAndCheckByNameL( *addrItem->Address(), 
       
   337                                                        iValidAddressType, 
       
   338                                                        *recipients, 
       
   339                                                        i ) ) 
       
   340                     { 
       
   341                     //  Determine how many new entries
       
   342                     addressOK = ETrue;
       
   343                     aModified = ETrue;
       
   344 
       
   345                     TInt newEntries = recipients->Count() - addrCnt;
       
   346                     TInt checkedEntry = i;
       
   347                     i = i + newEntries;
       
   348                     
       
   349                     // Check that found entry's/entries number is valid
       
   350                     while ( checkedEntry <= i )
       
   351                         {
       
   352                         addrItem = recipients->At( checkedEntry );
       
   353                         if ( CheckSingleAddressL( *( addrItem->Address() ) ) )
       
   354                             {
       
   355                             addrItem->SetValidated( ETrue );
       
   356                             addrItem->SetVerified( ETrue );
       
   357                             }
       
   358                         else 
       
   359                             { 
       
   360                             // Address not OK
       
   361                             addressOK = EFalse;
       
   362                             break;
       
   363                             }
       
   364                             
       
   365                         checkedEntry++;
       
   366                         }
       
   367                     }
       
   368                     
       
   369                 if ( !addressOK )
       
   370                     {
       
   371                     // Save the address & alias name. Those will be
       
   372                     // lost if slide is changed.
       
   373                     HBufC* address = addrItem->Address()->AllocLC();
       
   374                     HBufC* name = addrItem->Name()->AllocLC();
       
   375                     
       
   376                     iControl.RefreshL( *recipients ); 
       
   377                     
       
   378                     // Address is not OK.
       
   379                     ShowAddressInfoNoteL( *address, *name );
       
   380                     
       
   381                     CleanupStack::PopAndDestroy( 3 ); //address, name, CAknInputBlock
       
   382                     
       
   383                     iControl.HighlightUnvalidatedStringL(); 
       
   384                     return EFalse;
       
   385                     }
       
   386                 }
       
   387             }
       
   388         }
       
   389 
       
   390 
       
   391     // Addresses are all ok. Now parse not allowed chars away before giving it to MTM.
       
   392     addrCnt = recipients->Count();
       
   393     for ( TInt ii = 0; ii < addrCnt; ii++ )
       
   394         {
       
   395         // Note: This is just to parse spaces etc away from phonenumbers.
       
   396         //       Ignore EFalse returned for email addresses. 
       
   397         TPtr tempPtr = recipients->At( ii )->Address()->Des();
       
   398         CommonPhoneParser::ParsePhoneNumber( tempPtr, 
       
   399                                              CommonPhoneParser::ESMSNumber );
       
   400         }
       
   401 
       
   402     iControl.RefreshL( *recipients ); // returns always KErrNone!
       
   403     
       
   404     CleanupStack::PopAndDestroy(); // CAknInputBlock
       
   405     return ETrue;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CUniAddressHandler::RemoveDuplicateAddressesL
       
   410 //
       
   411 // Should be called when sending and after 
       
   412 // all addresses are validated i.e. no more error corrections
       
   413 // from user i.e. user is not going to edit addr control 
       
   414 // after this because Addresscontrol is not updated to show 
       
   415 // removed entries.
       
   416 // ---------------------------------------------------------
       
   417 //
       
   418 EXPORT_C TBool CUniAddressHandler::RemoveDuplicateAddressesL( 
       
   419     CArrayPtrFlat<CMsgAddressControl>& aAddressControls )
       
   420     {
       
   421     TBool retVal = EFalse;
       
   422     
       
   423     TInt controlCount = aAddressControls.Count();
       
   424     if ( controlCount == 0 )
       
   425         {
       
   426         return retVal;
       
   427         }
       
   428 
       
   429     // Initialize internal recipient info array.
       
   430     // Needed for tracking modifications of the recipient lists.
       
   431     // Possible modifications are "committed" back to address
       
   432     // controls only once after all the checks have been performed.
       
   433     CArrayFixFlat<TRecipientsInfo>* recipientInfos = 
       
   434                                     new ( ELeave ) CArrayFixFlat<TRecipientsInfo>( controlCount );
       
   435     CleanupStack::PushL( recipientInfos );
       
   436     
       
   437     for ( TInt init = 0; init < controlCount; init++ )
       
   438         {
       
   439         TRecipientsInfo info;
       
   440         info.iRecipients = aAddressControls.At( init )->GetRecipientsL();
       
   441         info.iOriginalCount = info.iRecipients->Count();
       
   442         info.iModified = EFalse;
       
   443         recipientInfos->AppendL( info );
       
   444         }
       
   445 
       
   446     TInt compareLength( KDefaultCompareLength );
       
   447     
       
   448     CRepository* repository = CRepository::NewL( KCRUidTelConfiguration );
       
   449     
       
   450     repository->Get( KTelMatchDigits, compareLength );
       
   451     
       
   452     delete repository;   
       
   453    
       
   454     CMsgRecipientItem* addrItem1 = NULL;
       
   455     CMsgRecipientItem* addrItem2 = NULL;
       
   456     CMsgRecipientArray* recipients1 = NULL;
       
   457     CMsgRecipientArray* recipients2 = NULL;
       
   458     
       
   459     for ( TInt i = 0; i < controlCount; i++ )
       
   460         {
       
   461         recipients1 = recipientInfos->At( i ).iRecipients;
       
   462         
       
   463         for ( TInt j = 0; j < recipients1->Count(); j++ )
       
   464             {
       
   465             addrItem1 = recipients1->At( j );
       
   466             
       
   467             for ( TInt k = i; k < controlCount; k++ )
       
   468                 {
       
   469                 recipients2 = recipientInfos->At( k ).iRecipients;
       
   470                 TInt l( 0 );
       
   471                 if ( recipients2 == recipients1 )
       
   472                     {
       
   473                     // No need to check earlier items of "recipients1"
       
   474                     l = j + 1;
       
   475                     }
       
   476                 for ( ; l < recipients2->Count(); l++ )
       
   477                     {
       
   478                     addrItem2 = recipients2->At( l );
       
   479 
       
   480                     if ( addrItem1->Address() && addrItem2->Address() )
       
   481                         {
       
   482                         // Check for equal phone numbers
       
   483                         TBool equal = MsvUiServiceUtilitiesInternal::ComparePhoneNumberL( *( addrItem1->Address() ), 
       
   484                                                                                           *( addrItem2->Address() ), 
       
   485                                                                                           compareLength );
       
   486                         if ( !equal )
       
   487                             {
       
   488                             // Check for equal mail addresses
       
   489                             equal = addrItem1->Address()->CompareF( *(addrItem2->Address() ) ) == 0;
       
   490                             }
       
   491                         
       
   492                         // If email address check or phone number check returns that addresses are 
       
   493                         // equal then remove either one of them.
       
   494                         if ( equal )
       
   495                             {
       
   496                             if( addrItem1->Name()->Length() && addrItem2->Name()->Length() )
       
   497                                 { // Both recipients have alias
       
   498                                 if ( addrItem1->Name()->Compare( *(addrItem2->Name()) ) != 0 )
       
   499                                     {
       
   500                                     // if aliases don't match clear alias.
       
   501                                     addrItem1->SetNameL( KNullDesC() );
       
   502                                     addrItem1->SetVerified( EFalse );
       
   503                                     recipientInfos->At( i ).iModified = ETrue;
       
   504                                     }
       
   505                                 // if they match -> leave it as it is
       
   506                                 }
       
   507                             else if( addrItem1->Name()->Length() || addrItem2->Name()->Length() )
       
   508                                 { // only one of them has an alias
       
   509                                 if( addrItem2->Name()->Length() )
       
   510                                     { // addrItem2 has it
       
   511                                     addrItem1->SetNameL( *addrItem2->Name( ) );
       
   512                                     addrItem1->SetVerified( ETrue );
       
   513                                     recipientInfos->At( i ).iModified = ETrue;
       
   514                                     }
       
   515                                 // else addrItem1 has it so it's already set in the Name field
       
   516                                 }
       
   517                             recipients2->Delete( l );
       
   518                             delete addrItem2;
       
   519                             addrItem2 = NULL;
       
   520                             l--;
       
   521                             retVal = ETrue;
       
   522                             }
       
   523                         }
       
   524                     }
       
   525                 }
       
   526             }
       
   527         }
       
   528 
       
   529     // Check whether recipients have changed and refresh if needed.
       
   530     for ( TInt final = 0; final < controlCount; final++ )
       
   531         {
       
   532         if ( recipientInfos->At( final ).iModified ||
       
   533             ( recipientInfos->At( final ).iOriginalCount !=
       
   534               recipientInfos->At( final ).iRecipients->Count() ) )
       
   535             {
       
   536             aAddressControls.At( final )->RefreshL( *recipientInfos->At( final ).iRecipients );
       
   537             }
       
   538         }
       
   539     CleanupStack::PopAndDestroy( recipientInfos );
       
   540     return retVal;
       
   541     }
       
   542 
       
   543 // ----------------------------------------------------
       
   544 // CUniAddressHandler::AddRecipientL
       
   545 //
       
   546 // Performs address(es) fetch operation.
       
   547 // ----------------------------------------------------
       
   548 //
       
   549 EXPORT_C TBool CUniAddressHandler::AddRecipientL( TBool& aInvalid )
       
   550     {
       
   551     TBool addressesAdded( EFalse );
       
   552     aInvalid = EFalse;
       
   553     
       
   554     CMsgRecipientList* recipientList = CMsgRecipientList::NewL();
       
   555     CleanupStack::PushL( recipientList );
       
   556 
       
   557     CMsgRecipientArray* recipients = new ( ELeave ) CMsgRecipientArray( 10 );
       
   558     CleanupStack::PushL( TCleanupItem( CleanupRecipientArray, recipients ) );
       
   559     
       
   560     // Multiple entry fetch to get the contact    
       
   561     if ( !iCheckNames )
       
   562         {
       
   563         iCheckNames = CMsgCheckNames::NewL();
       
   564         }
       
   565         
       
   566     iCheckNames->FetchRecipientsL( *recipients, iValidAddressType );
       
   567     
       
   568     // Contacts now fetched, verify that valid address is given for every contact
       
   569     while ( recipients->Count() > 0 )
       
   570         {
       
   571         CMsgRecipientItem* recipient = recipients->At( 0 );
       
   572         
       
   573         TPtrC namePtr = recipient->Name()->Des();
       
   574         TPtrC addressPtr = recipient->Address()->Des();
       
   575 
       
   576         // Don't parse away chars here so this is consistent with 
       
   577         // addresses that user writes "-()" are saved to draft
       
   578         // but removed when sending
       
   579         if ( CheckSingleAddressL( addressPtr ) )
       
   580             {
       
   581             //  add it to the list of valid addresses
       
   582             recipient->SetValidated( ETrue );
       
   583             recipient->SetVerified( ( namePtr.Length() > 0 ? ETrue : EFalse ) );
       
   584             recipientList->AppendL( recipient );
       
   585             }
       
   586         else
       
   587             {
       
   588             aInvalid = ETrue;
       
   589             ShowAddressInfoNoteL( addressPtr, namePtr );
       
   590             delete recipient;
       
   591             }
       
   592         
       
   593         recipients->Delete( 0 );
       
   594         }
       
   595     
       
   596     if ( recipientList->Count() > 0 )
       
   597         {
       
   598         iControl.AddRecipientsL( *recipientList );
       
   599         addressesAdded = ETrue;
       
   600         }
       
   601  
       
   602     CleanupStack::PopAndDestroy( 2, recipientList );//recipients
       
   603     
       
   604     return addressesAdded;
       
   605     }
       
   606     
       
   607 // ---------------------------------------------------------
       
   608 // CUniAddressHandler::CheckSingleAddressL
       
   609 // ---------------------------------------------------------
       
   610 //
       
   611 EXPORT_C TBool CUniAddressHandler::CheckSingleAddressL( const TDesC& aAddress )
       
   612     {
       
   613     if ( iValidAddressType != CMsgCheckNames::EMsgTypeMail &&
       
   614          CommonPhoneParser::IsValidPhoneNumber( aAddress, CommonPhoneParser::ESMSNumber ) )
       
   615         {
       
   616         return ETrue;
       
   617         }
       
   618         
       
   619     if ( iValidAddressType != CMsgCheckNames::EMsgTypeSms && 
       
   620          MsvUiServiceUtilities::IsValidEmailAddressL( aAddress ) )
       
   621         {
       
   622         return ETrue;
       
   623         }
       
   624         
       
   625     return EFalse;
       
   626     }
       
   627 
       
   628 // ---------------------------------------------------------
       
   629 // CUniAddressHandler::MakeDetailsL
       
   630 // ---------------------------------------------------------
       
   631 //
       
   632 EXPORT_C void CUniAddressHandler::MakeDetailsL( TDes& aDetails )
       
   633     {
       
   634     // This very same code can be found in MMSPlugin. 
       
   635     // They should be put in common location some day...
       
   636     const CMsvRecipientList& addresses = iMtm.AddresseeList();
       
   637     TInt addrCnt = addresses.Count();
       
   638 
       
   639     TPtrC stringToAdd;
       
   640     for ( TInt i = 0; i < addrCnt; i++)
       
   641         {
       
   642         // Only address is converted to western. 
       
   643         // There may numbers in contact name - they must not be converted 
       
   644         TPtrC alias = TMmsGenUtils::Alias( addresses[i] );
       
   645         HBufC* addressBuf = NULL;
       
   646         
       
   647         if ( alias.Length() != 0 )
       
   648             {
       
   649             stringToAdd.Set( alias );
       
   650             }
       
   651         else
       
   652             {
       
   653             TPtrC address = TMmsGenUtils::PureAddress( addresses[i] );
       
   654             addressBuf = HBufC::NewLC( address.Length() );
       
   655             TPtr addressPtr = addressBuf->Des();
       
   656             addressPtr.Copy( address );
       
   657             stringToAdd.Set( addressPtr );
       
   658 
       
   659             // Internal data structures always holds the address data in western format.
       
   660             // UI is responsible of doing language specific conversions.    
       
   661             AknTextUtils::ConvertDigitsTo( addressPtr, EDigitTypeWestern );      
       
   662             }
       
   663         
       
   664         if ( ( aDetails.Length() != 0 ) &&   // Not a first address
       
   665              ( aDetails.Length() + KAddressSeparator().Length() < KMaxDetailsLength ) )
       
   666             {
       
   667             // Add separator
       
   668             aDetails.Append( KAddressSeparator() );
       
   669             }
       
   670 
       
   671         if ( aDetails.Length() + stringToAdd.Length() < KMaxDetailsLength ) 
       
   672             {
       
   673             // whole string fits. Add it.
       
   674             aDetails.Append( stringToAdd );
       
   675             if ( addressBuf )
       
   676                 {
       
   677                 CleanupStack::PopAndDestroy( addressBuf );
       
   678                 }
       
   679             }
       
   680         else
       
   681             {
       
   682             // Only part of the string fits
       
   683             TInt charsToAdd = KMaxDetailsLength - aDetails.Length();
       
   684 
       
   685             if ( charsToAdd <= 0 )
       
   686                 {
       
   687                 // Cannot add any more chars 
       
   688                 break;
       
   689                 }
       
   690 
       
   691             if ( charsToAdd >= stringToAdd.Length() )
       
   692                 {
       
   693                 // Guarantee that charsToAdd is not larger that stringToAdd lenght 
       
   694                 charsToAdd = stringToAdd.Length();
       
   695                 }
       
   696 
       
   697             aDetails.Append( stringToAdd.Left( charsToAdd ) );
       
   698             if ( addressBuf )
       
   699                 {
       
   700                 CleanupStack::PopAndDestroy( addressBuf );
       
   701                 }
       
   702             break;
       
   703             }
       
   704         }
       
   705     }
       
   706 
       
   707 // ----------------------------------------------------
       
   708 // CUniAddressHandler::ShowInvalidRecipientInfoNotesL
       
   709 // ----------------------------------------------------
       
   710 //
       
   711 EXPORT_C void CUniAddressHandler::ShowInvalidRecipientInfoNotesL()
       
   712     {
       
   713     if ( iInvalidRecipients )
       
   714         {
       
   715         for ( TInt current = 0; current < iInvalidRecipients->Count(); current++ )
       
   716             {
       
   717             ShowAddressInfoNoteL( *iInvalidRecipients->At( current )->Address(),
       
   718                                   *iInvalidRecipients->At( current )->Name() );
       
   719             }
       
   720             
       
   721         delete iInvalidRecipients;
       
   722         iInvalidRecipients = NULL;
       
   723         }
       
   724     }
       
   725 
       
   726 // ---------------------------------------------------------
       
   727 // CUniAddressHandler::ShowAddressInfoNoteL
       
   728 // ---------------------------------------------------------
       
   729 //
       
   730 void CUniAddressHandler::ShowAddressInfoNoteL( const TDesC& aAddress, const TDesC& aAlias )
       
   731     {
       
   732     TInt cleanupCount = 0;
       
   733     HBufC* string = NULL;
       
   734 
       
   735     HBufC* convertedAddress = NumberConversionLC( aAddress, ETrue );
       
   736     cleanupCount++;
       
   737 
       
   738     if ( aAlias.Length() == 0 )
       
   739         {
       
   740         string = StringLoader::LoadLC( R_UNUT_INFO_FAIL_RECIPIENT_NO_ALIAS,
       
   741                                        *convertedAddress,
       
   742                                        &iCoeEnv );
       
   743         cleanupCount++;
       
   744         }
       
   745     else
       
   746         {
       
   747         CDesCArrayFlat* stringArr = new ( ELeave ) CDesCArrayFlat( 2 );
       
   748         CleanupStack::PushL( stringArr );
       
   749         cleanupCount++;
       
   750         
       
   751         stringArr->AppendL( aAlias );    //First string
       
   752         stringArr->AppendL( *convertedAddress );  //Second string
       
   753         string = StringLoader::LoadLC( R_UNUT_INFO_FAIL_RECIPIENT,
       
   754                                        *stringArr,
       
   755                                        &iCoeEnv );
       
   756         cleanupCount++;
       
   757         }
       
   758     
       
   759     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   760     note->ExecuteLD( *string );
       
   761     
       
   762     CleanupStack::PopAndDestroy( cleanupCount );  // string, (stringArr), convertedAddress
       
   763     }
       
   764 
       
   765 // ---------------------------------------------------------
       
   766 // CUniAddressHandler::RemoveIllegalChars
       
   767 // ---------------------------------------------------------
       
   768 
       
   769 TBool CUniAddressHandler::RemoveIllegalChars( TDes& aString )
       
   770     {
       
   771     TBool ret( EFalse );
       
   772     for ( TInt i = 0; i < aString.Length(); i++ )
       
   773         {
       
   774         if ( !IsValidChar( (TChar) aString[ i ] ) ) 
       
   775             {
       
   776             aString.Delete( i, 1 );
       
   777             i--;
       
   778             ret = ETrue;
       
   779             }
       
   780         }
       
   781     return ret;
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------
       
   785 // CUniAddressHandler::IsValidChar
       
   786 //
       
   787 // These characters are used by system on it's internal data structure
       
   788 // and cannot be because of that used on address or alias string
       
   789 // ---------------------------------------------------------
       
   790 //
       
   791 TBool CUniAddressHandler::IsValidChar( const TChar& aChar )
       
   792     {
       
   793     // Don't allow "<" (60), ">" (62)
       
   794     return ( aChar != '<' && aChar != '>' );
       
   795     }
       
   796 
       
   797 // ----------------------------------------------------
       
   798 // CUniAddressHandler::NumberConversionLC
       
   799 // ----------------------------------------------------
       
   800 //
       
   801 HBufC* CUniAddressHandler::NumberConversionLC( const TDesC& aOrigNumber, TBool aDirection )
       
   802     {
       
   803     HBufC* addressCopy = aOrigNumber.AllocLC();
       
   804     TPtr tempTPtr = addressCopy->Des();
       
   805     if ( aDirection )
       
   806         {
       
   807         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tempTPtr );
       
   808         }
       
   809     else
       
   810         {
       
   811         AknTextUtils::ConvertDigitsTo( tempTPtr, EDigitTypeWestern );
       
   812         }
       
   813 
       
   814     return addressCopy;
       
   815     }
       
   816 
       
   817 // ----------------------------------------------------
       
   818 // CUniAddressHandler::NumberConversionLC
       
   819 // ----------------------------------------------------
       
   820 //
       
   821 void CUniAddressHandler::CleanupRecipientArray( TAny* aArray )
       
   822     {
       
   823     CMsgRecipientArray* recipientArray = static_cast<CMsgRecipientArray*>( aArray );
       
   824     
       
   825     recipientArray->ResetAndDestroy();
       
   826     delete recipientArray;
       
   827     }
       
   828 
       
   829 
       
   830 // ========== OTHER EXPORTED FUNCTIONS =====================
       
   831 
       
   832 //  End of File