omacp/omacpadapters/EmailAdapter/src/CWPEmailSaveSmtpPopItem.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Saves SMTP POP settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CWPEmailSaveSmtpPopItem.h"
       
    21 #include    "CWPEmailItem.h"
       
    22 #include    "EmailAdapter.pan"
       
    23 #include    "WPEmail.hrh"
       
    24 #include    "Cwplog.h"
       
    25 #include    <CWPParameter.h>
       
    26 #include    <pop3set.h>
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CSaveSmtpPopItem::CSaveSmtpPopItem
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CSaveSmtpPopItem::CSaveSmtpPopItem( CWPEmailItem* aSmtpItem, 
       
    38                                     CWPEmailItem* aPopItem)
       
    39                                     : iSmtpItem( aSmtpItem ), 
       
    40                                       iPopItem( aPopItem ) 
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSaveSmtpPopItem::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CSaveSmtpPopItem::ConstructL()
       
    50     {
       
    51     CWPEmailSaveItem::ConstructL();
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSaveSmtpPopItem::NewL
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CSaveSmtpPopItem* CSaveSmtpPopItem::NewLC( CWPEmailItem* aSmtpItem, 
       
    60                                            CWPEmailItem* aPopItem )
       
    61     {
       
    62     __ASSERT_DEBUG(aSmtpItem && aPopItem, Panic(EMailAdapterNullPointer));
       
    63     CSaveSmtpPopItem* self = new( ELeave ) CSaveSmtpPopItem( aSmtpItem,
       
    64                                                              aPopItem );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------    
       
    71 // Destructor
       
    72 // -----------------------------------------------------------------------------
       
    73 CSaveSmtpPopItem::~CSaveSmtpPopItem()
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSaveSmtpPopItem::SaveL
       
    79 // (other items were commented in a header).
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CSaveSmtpPopItem::SaveL(CMsvSession* aSession)
       
    83     {    
       
    84     SaveMailSettingsToMessageServerL( *iSmtpItem, *iPopItem, ETrue, aSession );
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSaveSmtpPopItem::SummaryText
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 const TDesC& CSaveSmtpPopItem::SummaryText()
       
    93     {
       
    94     return CWPEmailSaveItem::SummaryText();
       
    95     }
       
    96     
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSaveSmtpPopItem::ValidateL
       
    99 // (other items were commented in a header).
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TBool CSaveSmtpPopItem::ValidateL()
       
   103     {
       
   104     __ASSERT_DEBUG(iPopItem && iSmtpItem, Panic(EMailAdapterNullPointer));
       
   105 
       
   106     // validate items and Provider ID
       
   107     return (ValidatePopItemL() && ValidateSmtpItemL() && 
       
   108         iSmtpItem->ParameterValue(EWPParameterProviderID) == 
       
   109         iPopItem->ParameterValue(EWPParameterProviderID));
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSaveSmtpPopItem::ValidateSmtpItemL
       
   114 // (other items were commented in a header).
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TBool CSaveSmtpPopItem::ValidateSmtpItemL()
       
   118     {
       
   119     const TDesC& ownAddress = iSmtpItem->ParameterValue(EWPParameterFrom);
       
   120     const TDesC& serverAddress = iSmtpItem->ParameterValue(EWPParameterAddr);
       
   121 
       
   122     if (ownAddress.Length() > 0
       
   123         && ownAddress.Length() <= KIacMaxAddressLength 
       
   124         && KErrNone == ValidateServerAddress(serverAddress)
       
   125         && serverAddress.Length() <= KIacMaxSendHostLength )
       
   126         {
       
   127         LOG1("CSaveSmtpPopItem::ValidateSmtpItemL %d", IsValidEmailAddressL(ownAddress));
       
   128         return IsValidEmailAddressL(ownAddress);
       
   129         }
       
   130     LOG("CSaveSmtpPopItem::ValidateSmtpItemL: Not Valid");
       
   131     return EFalse;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSaveSmtpPopItem::ValidatePopItemL
       
   136 // (other items were commented in a header).
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TBool CSaveSmtpPopItem::ValidatePopItemL()
       
   140     {
       
   141     const TDesC& userName = iPopItem->ParameterValue(EWPParameterAAuthName);
       
   142     const TDesC& password = iPopItem->ParameterValue(EWPParameterAAuthSecret);
       
   143     const TDesC& serverAddress = iPopItem->ParameterValue(EWPParameterAddr);
       
   144     const TDesC& popName = iPopItem->ParameterValue(EWPParameterName);
       
   145     const TDesC& smtpName = iSmtpItem->ParameterValue(EWPParameterName);
       
   146 
       
   147     // Replace default name if found
       
   148 	if (popName.Length() > 0)
       
   149         {
       
   150         SetDefaultNameL(popName);
       
   151         }
       
   152     else
       
   153         {
       
   154         if (smtpName.Length() > 0)
       
   155             {
       
   156             SetDefaultNameL(smtpName);        
       
   157             }
       
   158         }
       
   159     // Check max/min lenghts
       
   160     	if (KErrNone == ValidateServerAddress(serverAddress)
       
   161         && serverAddress.Length() <= KIacMaxRecHostLength 
       
   162         && userName.Length() <= KIacMaxRemMbxUserNameLength 
       
   163         && password.Length() <= KIacMaxPasswdLength && popName.Length() <= 30 &&  smtpName.Length() <= 30)
       
   164         {        	
       
   165         LOG("CSaveSmtpPopItem::ValidatePopItemL: Valid");
       
   166         return ETrue;
       
   167         }
       
   168     LOG("CSaveSmtpPopItem::ValidatePopItemL: Not Valid");
       
   169     return EFalse;
       
   170     }
       
   171     
       
   172 //  End of File