messagingapp/msgutils/unieditorutils/editorgenutils/src/UniEditorGenUtils.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    26 #include "MessagingVariant.hrh"
    26 #include "MessagingVariant.hrh"
    27 #include "MessagingInternalCRKeys.h"  // Keys
    27 #include "MessagingInternalCRKeys.h"  // Keys
    28 #include "UniEditorGenUtils.h"
    28 #include "UniEditorGenUtils.h"
    29 #include "s60qconversions.h"
    29 #include "s60qconversions.h"
    30 
    30 
       
    31 // CONSTANTS
       
    32 const TInt KMuiuCharQuote = '\"';
       
    33 const TInt KMuiuCharBackSlash = '\\';
       
    34 const TInt KMuiuCharDot = '.';
       
    35 const TInt KMuiuCharSpace = ' ';
       
    36 const TInt KMuiuCharDel = 127;
       
    37 const TInt KMuiuCharAt = '@';
       
    38 const TInt KMuiuSpecialCharStrLen = 12;
       
    39 _LIT( KRFC822Specials,"()<>@,;:\\\"[]");
       
    40 
    31 // ============================ MEMBER FUNCTIONS ===============================
    41 // ============================ MEMBER FUNCTIONS ===============================
    32 
    42 
    33 // ----------------------------------------------------
    43 // ----------------------------------------------------
    34 // UniEditorGenUtils::UniEditorGenUtils
    44 // UniEditorGenUtils::UniEditorGenUtils
    35 // @see header
    45 // @see header
   161 
   171 
   162 // ----------------------------------------------------
   172 // ----------------------------------------------------
   163 // UniEditorGenUtils::VerifyEmailAddressesL
   173 // UniEditorGenUtils::VerifyEmailAddressesL
   164 // @see header
   174 // @see header
   165 // ----------------------------------------------------
   175 // ----------------------------------------------------
   166 TBool UniEditorGenUtils::VerifyEmailAddressesL( ConvergedMessageAddressList addr)
   176 TBool UniEditorGenUtils::VerifyEmailAddressesL( ConvergedMessageAddressList addrList)
   167 {
   177 {
   168   TBool emailAddrPresent =  EFalse;
   178     TBool emailAddrPresent =  EFalse;
   169 
   179     int addrCount = addrList.count();
   170   for ( int i=0; i< addr.count(); i++)
   180     for(int i=0; i< addrCount; i++)
   171   {
   181     {
   172 	  if( IsValidEmailAddress(addr[i]->address()) )
   182         QString addr = addrList.at(i)->address();
   173 	  {
   183         // check if email address, contains at least 3 characters
   174 		  emailAddrPresent = ETrue;
   184         if(addr.size() >= 3)
   175 		  break;
   185         {
   176 	  }
   186             // search for @ from the address
   177   }
   187             // however, it can't be the first or the last item
   178 
   188             for(int i = 1; i < addr.size() - 1; i++)
   179   return emailAddrPresent;
   189             {
       
   190                 if(addr.at(i) == '@')
       
   191                 {
       
   192                     emailAddrPresent = ETrue;
       
   193                     break;
       
   194                 }
       
   195             }
       
   196         }
       
   197     }
       
   198     return emailAddrPresent;
   180 }
   199 }
   181 
   200 
   182 // ----------------------------------------------------
   201 // ----------------------------------------------------
   183 // UniEditorGenUtils::UTF8Size
   202 // UniEditorGenUtils::UTF8Size
   184 // @see header
   203 // @see header
   248         }
   267         }
   249     delete repository;
   268     delete repository;
   250 
   269 
   251     return maxMmsRecipients;
   270     return maxMmsRecipients;
   252 }
   271 }
   253 
       
   254 // ----------------------------------------------------
       
   255 // UniEditorGenUtils::IsValidEmailAddress
       
   256 // @see header
       
   257 // ----------------------------------------------------
       
   258 TBool UniEditorGenUtils::IsValidEmailAddress( QString addr )
       
   259     { 
       
   260     // valid email address contains at least 3 characters
       
   261     if( addr.size() >= 3 )
       
   262         {
       
   263         // search for @ from the address. however, it can't be the first or the last item
       
   264         for ( int i = 1; i < addr.size() - 1; i++ )
       
   265             {
       
   266             if ( addr.at(i) == '@' )
       
   267                 {
       
   268                 return ETrue;
       
   269                 }
       
   270             }
       
   271         }
       
   272     return EFalse;
       
   273     }
       
   274 
   272 
   275 // ----------------------------------------------------
   273 // ----------------------------------------------------
   276 // UniEditorGenUtils::MaxMmsMsgSizeL
   274 // UniEditorGenUtils::MaxMmsMsgSizeL
   277 // @see header
   275 // @see header
   278 // ----------------------------------------------------
   276 // ----------------------------------------------------
   480         aDes[src] = TUint16(aReplacement);
   478         aDes[src] = TUint16(aReplacement);
   481     ++src;
   479     ++src;
   482         }
   480         }
   483     }
   481     }
   484 
   482 
       
   483 // ----------------------------------------------------
       
   484 // UniEditorGenUtils::IsValidEmailAddressL
       
   485 // @see header
       
   486 // ----------------------------------------------------
       
   487 TBool UniEditorGenUtils::IsValidEmailAddress( const TDesC& aAddress )
       
   488     {
       
   489     TInt c;
       
   490     TInt length = aAddress.Length ();
       
   491     TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials );
       
   492         
       
   493     // first we validate the name portion (name@domain)
       
   494     if ( length && aAddress[0] == KMuiuCharDot )
       
   495         {
       
   496         return EFalse;
       
   497         }
       
   498     for ( c = 0 ; c < length ; c++ )
       
   499         {
       
   500         if ( aAddress[c] == KMuiuCharQuote && ( c == 0 || 
       
   501         aAddress[c-1] == KMuiuCharDot || aAddress[c-1] == KMuiuCharQuote ) )
       
   502             {
       
   503             while ( ++c < length )
       
   504                 {
       
   505                 if ( aAddress[c] == KMuiuCharQuote )
       
   506                     {
       
   507                     if( (c + 1) == length)
       
   508                         {
       
   509                         return EFalse;
       
   510                         }
       
   511                     break;
       
   512                     }
       
   513                 if ( aAddress[c] == KMuiuCharBackSlash && 
       
   514                     ( aAddress[++c] == KMuiuCharSpace) ) 
       
   515                     {
       
   516                     continue;
       
   517                     }  
       
   518                 if ( aAddress[c] <= KMuiuCharSpace || 
       
   519                     aAddress[c] >= KMuiuCharDel ) 
       
   520                     {
       
   521                     return EFalse;
       
   522                     }
       
   523                 }
       
   524             if ( c++ == length )
       
   525                 {
       
   526                 return EFalse;
       
   527                 }
       
   528             if ( aAddress[c] == KMuiuCharAt )
       
   529                 {
       
   530                 break;
       
   531                 }
       
   532             if ( aAddress[c] != KMuiuCharDot )
       
   533                 {
       
   534                 return EFalse;
       
   535                 }
       
   536             continue;
       
   537             }
       
   538         if ( aAddress[c] == KMuiuCharAt )
       
   539             {
       
   540             break; 
       
   541             }
       
   542         if ( aAddress[c] <= KMuiuCharSpace || aAddress[c] >= KMuiuCharDel )
       
   543             {
       
   544             return EFalse;
       
   545             }    
       
   546         if ( rfc822Specials.Locate ( aAddress[c] ) != KErrNotFound )
       
   547             {
       
   548             return EFalse;
       
   549             }
       
   550         }
       
   551     if ( c == 0 || aAddress[c-1] == KMuiuCharDot )
       
   552         {
       
   553         return EFalse;
       
   554         }
       
   555     // next we validate the domain portion (name@domain)
       
   556     if ( c == length )
       
   557         {
       
   558         return EFalse;
       
   559         }
       
   560     else
       
   561         {
       
   562         c++; 
       
   563         return IsValidDomain ( aAddress.Mid ( ( c ) , length-c ) );
       
   564         }
       
   565     }
       
   566 
       
   567 // ----------------------------------------------------
       
   568 // UniEditorGenUtils::IsValidDomainL
       
   569 // @see header
       
   570 // ----------------------------------------------------
       
   571 TBool UniEditorGenUtils::IsValidDomain ( const TDesC& aDomain )
       
   572     {
       
   573     TInt c = 0;  
       
   574     TInt length = aDomain.Length ();
       
   575     TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials );
       
   576     
       
   577     if ( length == 0 )
       
   578         {
       
   579         return EFalse;   
       
   580         }
       
   581     
       
   582     do
       
   583         {    
       
   584         if ( aDomain[c] == KMuiuCharDot )
       
   585             {
       
   586             if ( c == 0 || aDomain[c-1] == KMuiuCharDot )
       
   587                 {
       
   588                 return EFalse;
       
   589                 }
       
   590             }
       
   591         if ( aDomain[c] <= KMuiuCharSpace || aDomain[c] >= KMuiuCharDel )
       
   592             {
       
   593             return EFalse;
       
   594             }
       
   595         if ( rfc822Specials.Locate( aDomain[c] ) != KErrNotFound )
       
   596             {
       
   597             return EFalse;
       
   598             }
       
   599         } 
       
   600     while ( ++c < length );
       
   601   
       
   602     return ( aDomain[length-1] != '.' );
       
   603     }
       
   604 
   485 // End of file
   605 // End of file