omacp/omacpadapters/EmailAdapter/Inc/CWPEmailSaveItem.h
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:  Save mail settings base class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CWPEMAILSAVEITEM_H
       
    21 #define CWPEMAILSAVEITEM_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <msvapi.h>
       
    26 #include    <cemailaccounts.h>
       
    27 #include <MuiuMsvUiServiceUtilities.h>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CWPEmailItem;
       
    31 class MWPSaveObserver;
       
    32 class CDesC16Array;
       
    33 class CMsvSession;
       
    34 class CCommsDatabase;
       
    35 
       
    36 #include <ImumDaSettingsData.h>
       
    37 #include <ImumDomainApi.h>
       
    38 #include <ImumDaMailboxServices.h>
       
    39 
       
    40 
       
    41 //Default values of Retrieval Parameters 
       
    42 const TInt64 KImumMboxDefaultAutoRetrievalStartHour = 0;
       
    43 const TInt64 KImumMboxDefaultAutoRetrievalEndHour = 0;
       
    44 const TInt KImumMboxDefaultAutoRetrieval = TImumDaSettings::EValueAutoOff;
       
    45 
       
    46 //Boundary values of Retrieval Parameters 
       
    47 const TInt KImumPollMinUpdateLimit = 5;
       
    48 const TInt KImumPollMaxUpdateLimit = 360;
       
    49 const TInt KImumMboxInboxMinUpdateLimit = 0;
       
    50 const TInt KImumMboxInboxMaxUpdateLimit = 999;
       
    51 const TInt KRetHourLowerBound = 0;
       
    52 const TInt KRetHourUpperBound = 23;
       
    53 const TInt KRetMinLowerBound = 0;
       
    54 const TInt KRetMinUpperBound = 59;
       
    55 const TInt KRetHourMinLeadLimit = 10;
       
    56 
       
    57 //Standard Lengths of Hours, Minutes and Days
       
    58 const TInt KRetHourStandardLength = 2;
       
    59 const TInt KRetMinStandardLength = 2;
       
    60 const TInt KRetDaysStandardMaxLength = 14;
       
    61 const TInt KRetDayStandardLength = 1;
       
    62 
       
    63 //Delimiters
       
    64 const TInt KColonChar = ':';
       
    65 const TInt KGTChar = '>';
       
    66 const TInt KCommaChar = ',';
       
    67 
       
    68 
       
    69 //Retrieval Days Constants
       
    70 const TInt KRetSunday = 0;
       
    71 const TInt KRetMonday = 1;
       
    72 const TInt KRetTuesday = 2;
       
    73 const TInt KRetWednesday = 3;
       
    74 const TInt KRetThursday = 4;
       
    75 const TInt KRetFriday = 5;
       
    76 const TInt KRetSaturday = 6;
       
    77 
       
    78 //Poll Values constants
       
    79 const TInt KPoll5minutes = 5;
       
    80 const TInt KPoll15minutes = 15;
       
    81 const TInt KPoll30minutes = 30;
       
    82 const TInt KPoll1Hour = 1;
       
    83 const TInt KPoll2Hours = 2;
       
    84 const TInt KPoll4Hours = 4;
       
    85 const TInt KPoll6Hours = 6;
       
    86             
       
    87 //Literals for CS parameter parsing
       
    88 _LIT( KRetSecMilliSec, "00.000000" );
       
    89 _LIT(KComma, ","); 
       
    90 _LIT( KRetLeadingZero, "0" );
       
    91 
       
    92 
       
    93 // CLASS DECLARATION
       
    94 
       
    95 /**
       
    96 *  Save settings base class.
       
    97 *
       
    98 *  @lib WPEmailAdapter.lib
       
    99 *  @since 2.0
       
   100 */
       
   101 class CWPEmailSaveItem : public CBase
       
   102     {
       
   103     public:  // Constructors and destructor
       
   104         
       
   105         /// Setting ids
       
   106         struct TSettingId
       
   107             {
       
   108             TInt32 iSmtpId;
       
   109             TInt32 iPopImapId;
       
   110             };
       
   111         
       
   112         /**
       
   113         * Symbian 2nd phase constructor.
       
   114         */
       
   115         void ConstructL();
       
   116         
       
   117         /**
       
   118         * constructor.
       
   119         */
       
   120         CWPEmailSaveItem();
       
   121         
       
   122         /**
       
   123         * Destructor.
       
   124         */
       
   125         virtual ~CWPEmailSaveItem();
       
   126 
       
   127     public: // New functions
       
   128         
       
   129         /**
       
   130         * Save settings
       
   131         * Save all settings to system.
       
   132         * @param aSession  
       
   133         * @since 2.0
       
   134         */
       
   135         virtual void SaveL( CMsvSession* aSession ) = 0;
       
   136 
       
   137         /**
       
   138         * Validate Setting content
       
   139         * Check that mandatory fields exist and 
       
   140         * maximum lengths are not exeeded.
       
   141         * @since 2.0
       
   142         * @return ETrue if settings are valid.
       
   143         */
       
   144         virtual TBool ValidateL() = 0;
       
   145 
       
   146         /**
       
   147         * Set this setting as default.
       
   148         * @since 2.0
       
   149         */
       
   150         virtual void SetAsDefaultL();
       
   151 
       
   152         /**
       
   153         * Setting name
       
   154         * @since 2.0
       
   155         * @return default setting name.
       
   156         */
       
   157         virtual const TDesC& SummaryText();
       
   158         
       
   159         /**
       
   160         * Set new default name
       
   161         * default name is used when saving settings to the
       
   162         * msgServer. 
       
   163         * @param aDefaultName new dafault name.
       
   164         */
       
   165         void SetDefaultNameL( const TDesC& aDefaultName );
       
   166 
       
   167         /**
       
   168         * Set reference to CommsDataBase
       
   169         * This is needed when saving email settings.
       
   170         * Must be set before calling SaveL. 
       
   171         * @param aCommsDataBase reference to CommsDB
       
   172         */
       
   173         void SetCommsDataBase( CCommsDatabase& aCommsDataBase );
       
   174         
       
   175         /**
       
   176         * Get data needed for removing these setting from the system.
       
   177         * @return setting IDs of saved settings.
       
   178         */
       
   179         const TDesC8& SaveData();
       
   180 
       
   181     protected:  // New functions
       
   182         
       
   183         /**
       
   184         * Saves given settings to message server
       
   185         * @param aSmtp SMTP item
       
   186         * @param aPopImap POP or IMAP item
       
   187         * @param aIsPopNotImap email POP or IMAP setting item
       
   188         * @param aSession message server session 
       
   189         * Panic if aSession is NULL,
       
   190         */
       
   191         void SaveMailSettingsToMessageServerL( CWPEmailItem& aSmtp, 
       
   192                                                CWPEmailItem& aPopImap,
       
   193                                                TBool aIsPopNotImap,
       
   194                                                CMsvSession* aSession );
       
   195 
       
   196         /**
       
   197         * Valid Email address
       
   198         * @param aAddress email address.
       
   199         * @return ETrue if address format is valid
       
   200         */
       
   201         TBool IsValidEmailAddressL(const TDesC& aAddress);
       
   202 
       
   203         /**
       
   204         * Get valid email address
       
   205         * @param aAddress
       
   206         * @return Valid email address or empty.
       
   207         */
       
   208         TPtrC GetValidEmailAddressL(const TDesC& aAddress);
       
   209 
       
   210         /**
       
   211         * Validate Text
       
   212         * @param serverAddress
       
   213         * @return KErrGeneral for server address containing only white space characters; KErrNone otherwise.
       
   214         */
       
   215         TInt ValidateText(const TDesC& serverAddress);
       
   216         
       
   217         /**
       
   218         * Validate Server Address
       
   219         * @param serverAddress
       
   220         * @return KErrNone for a valid server address; KErrGeneral otherwise.
       
   221         */
       
   222         TInt ValidateServerAddress(const TDesC& serverAddress);
       
   223         
       
   224         /**
       
   225         * Validate Port No
       
   226         * @param portVal
       
   227         * @return KErrNone for Port No falls between the valid range; KErrArgument otherwise.
       
   228         */
       
   229         TInt ValidatePortNo(const TUint& portVal);
       
   230       
       
   231     private: // New functions
       
   232 
       
   233         /**
       
   234         * Search existing email settings
       
   235         */
       
   236         TInt GetMailAccountNamesL();
       
   237 
       
   238         /**
       
   239         * Fill array with existing setting names.
       
   240         * @param aArray array to be filled 
       
   241         */
       
   242         void ExistingSettingNamesL( CDesC16Array& aArray );
       
   243         
       
   244         /**
       
   245         * Search existing setting names.
       
   246         * @param aName setting name.
       
   247         * @param aReload ETrue if reload is needed.
       
   248         * @return ETrue if setting name already exist.
       
   249         */
       
   250         TBool SettingNameAlreadyExistsL( const TDesC& aName, TBool aReload );
       
   251      
       
   252         /**
       
   253         * Fill TEntry with SMTP specific data
       
   254         * @param TEntry TEntry to be filled.
       
   255         * @param aIapName name of the used IAP
       
   256         * @param aMailboxName name of the remote mailbox
       
   257         */
       
   258         void FillTEntryWithSmtpData( TMsvEntry& aTEntry,
       
   259                                      const TDesC& aIapName, 
       
   260                                      const TDesC& aMailboxName );
       
   261             
       
   262         /**
       
   263         * Fill TEntry with POP or IMAP specific data
       
   264         * @param aTEnry TEntry to be filled.
       
   265         * @param aSmtpEntry sending host data
       
   266         * @param aMailboxName name of the remote mailbox
       
   267         * @param aIsPop ETrue to create POP or EFalse to create IMAP entry.
       
   268         */
       
   269         void FillTEntryWithPopImapData( TMsvEntry& aTEntry,
       
   270                                         const TMsvEntry& aSmtpEntry,
       
   271                                         const TDesC& aMailboxName,
       
   272                                         TBool aIsPop );
       
   273         /**
       
   274         * Convert TDesC16 to TDesC8
       
   275         */
       
   276         const TDesC8& Des16To8L(const TDesC& aDes16);
       
   277         
       
   278         /**
       
   279         * Get IAP id from WAP id
       
   280         * @param aWapId wap accesspoint id.
       
   281         * @return IAP id (panic if not found)
       
   282         */
       
   283         TUint32 IapIdFromWapIdL(TUint32 aWapId) const;
       
   284         
       
   285         /**
       
   286         * Creates a mail box
       
   287         * @param aPopImapItem pop/imap item
       
   288         * @param aSmtpItem smtp item
       
   289         * @return error
       
   290         */        
       
   291         TInt CreateMailboxEntryL( CWPEmailItem& aPopImapItem,
       
   292             CWPEmailItem& aSmtpItem  );
       
   293         
       
   294         /**
       
   295         * Validates settings name
       
   296         * @param None
       
   297         * @return None
       
   298         */        
       
   299         void ValidateSettingsNameL();
       
   300         /**
       
   301         * 
       
   302         * @param aText
       
   303         * @return None
       
   304         */
       
   305         static void IncrementNameL(TDes& aText);
       
   306         
       
   307         
       
   308         /**
       
   309         * 
       
   310         * @param aText
       
   311         * @param aMaxLength
       
   312         * @return None
       
   313         */
       
   314         static void IncrementNameL(TDes& aText, TInt aMaxLength);
       
   315         
       
   316 	/**
       
   317 	 * Set Email settings application this value is used for 
       
   318          * PNPMS service
       
   319          */        
       
   320 
       
   321 	void SetEmailAppIdForPnpServiceL(TDesC& appIDValue);
       
   322 
       
   323 	 /**
       
   324      * Sets Email Notification and Retrieval Parameters
       
   325      * @param aEmailSettingsData Email settings
       
   326      * @param aPopImapItem Pop/Imap Item
       
   327      * @param aPopImapSet Pop/Imap Set
       
   328      * @return error
       
   329      */
       
   330     TInt SetEmailNotificationRetrievalParamsL(
       
   331             CImumDaSettingsData& aEmailSettingsData,
       
   332             CWPEmailItem& aPopImapItem,
       
   333             MImumDaSettingsDataCollection& aPopImapSet);
       
   334 
       
   335     /**
       
   336      * Sets Integer Parameters like EMN, ONLINE, POLL and LMS
       
   337      * @param aEmailSettingsData Email settings
       
   338      * @param aPopImapItem Pop/Imap Item
       
   339      * @param aParamName Parameter Name
       
   340      * @return error
       
   341      */
       
   342     TInt SetIntParam(CImumDaSettingsData& aEmailSettingsData,
       
   343             CWPEmailItem& aPopImapItem, const TDesC& aParamName);
       
   344 
       
   345     /**
       
   346      * Gets the value of the Parameter in Integer form
       
   347      * @param aPopImapItem Pop/Imap Item
       
   348      * @param aParamID Parameter ID
       
   349      * @param aVal Value of the Parameter
       
   350      * @return error
       
   351      */
       
   352     TInt GetParamValue(CWPEmailItem& aPopImapItem, const TInt aParamID,
       
   353             TInt& aVal);
       
   354 
       
   355     /**
       
   356      * Gets the value of the Parameter in Integer form
       
   357      * @param aPopImapItem Pop/Imap Item
       
   358      * @param aParamName Parameter Name
       
   359      * @param aVal Value of the Parameter
       
   360      * @return error
       
   361      * */
       
   362     TInt GetParamValue(CWPEmailItem& aPopImapItem, const TDesC& aParamName,
       
   363             TInt& aVal);
       
   364 
       
   365     /**
       
   366      * Gets the value of the Parameters (Retrieval Hours and Days) 
       
   367      * from CS in String form
       
   368      * @param aCSParamValue Value of CS Parameter
       
   369      * @param aTokenMark Demarcating Character
       
   370      * @param aParm Value of the Parameter
       
   371      * @return True if Parameter value is properly Marked
       
   372      * */
       
   373     TBool GetRetParamValuesFromCS(TLex& aCSParamValue, const TInt aTokenMark,
       
   374             TPtrC& aParm);
       
   375 
       
   376     /**
       
   377      * Gets the value of Retrieval Hours parameter from CS in Integer form
       
   378      * @param aCSParamValue Value of CS Parameter
       
   379      * @param aTokenMark Demarcating Character
       
   380      * @param aRetHourMinValue Value of Retrieval Hours
       
   381      * @return error
       
   382      * */
       
   383     TInt GetRetHoursValueL(TLex& aCSParamValue, TInt aTokenMark,
       
   384             TInt64& aRetHourMinValue);
       
   385 
       
   386     /**
       
   387      * Sets the value of Retrieval Days parameter
       
   388      * @param aCSParamValue Value of CS Parameter
       
   389      * @param aEmailSettingsData Email settings
       
   390      * @return error
       
   391      * */
       
   392     TInt SetRetDaysL(TLex& aCSParamValue,
       
   393             CImumDaSettingsData& aEmailSettingsData);
       
   394     /**
       
   395      * Sets the value of Poll parameter
       
   396      * @param aEmailSettingsData Email settings
       
   397      * aPollValue Value of Poll parameter
       
   398      * @return error
       
   399      * */
       
   400     TInt SetPollValue(CImumDaSettingsData& aEmailSettingsData,
       
   401             TInt aPollValue);
       
   402     /**
       
   403      * Validates User Name and Password
       
   404      * @param aPopImapSet Pop/Imap Set
       
   405      * @return error
       
   406      */
       
   407     TInt ValidateUserNamePassword(MImumDaSettingsDataCollection& aPopImapSet, TBool& aValidUserPass);
       
   408     
       
   409     /**
       
   410      * Changes the Absolute Integer Hour/Min value to a string 
       
   411      * @param aRetHourMin Retrieval Hour/Min string got from CS parameter
       
   412      * @param aValRetHourMin Retrieval Hour/Min Value
       
   413      * @param aPtrRetHourMin Retrieval Hour/Min string got from Integer value of Hour/Min
       
   414      * @return void
       
   415      */
       
   416     void GetRetHourorMinfromIntValue(TPtrC& aRetHourMin,
       
   417             TInt64 aValRetHourMin, TPtr& aPtrRetHourMin);
       
   418     
       
   419     /**
       
   420      * Validates Retrieval Hours and Minutes
       
   421      * @param aRetHourMin Lexer of Retrieval Hours/Minutes
       
   422      * @return error
       
   423      */
       
   424     TInt ValidateRetHourorMin(TLex& aRetHourMin);
       
   425 	
       
   426 
       
   427     private:    // Data
       
   428 
       
   429         /// Ref: Message server session
       
   430         CMsvSession* iSession;
       
   431         /// Ref: CommsDataBase
       
   432         CCommsDatabase* iCommDb;
       
   433         /// Own: array of names of existing mail settings.
       
   434         CDesC16Array* iExistingSettings;
       
   435         /// Own: for converting 16 to 8 bit descriptor
       
   436         HBufC8* iBufConvert;
       
   437         //Own default name for email settings.
       
   438         HBufC* iDefaultName;
       
   439         //Own: IAP name
       
   440         HBufC*                  iIapName;
       
   441         //Created smtp entry
       
   442         TMsvEntry               iSmtpTEntry;
       
   443         //Created POP/IMAP entry
       
   444         TMsvEntry               iPopImapTEntry;
       
   445         TPckgBuf<TSettingId>    iUid;
       
   446         // Etrue if POP mail
       
   447         TBool                   iPopMail;
       
   448         
       
   449         TMsvId iDefaultMsvId;
       
   450         
       
   451         CImumDomainApi* iDomainApi;
       
   452         MImumDaMailboxServices* iServices;
       
   453 
       
   454              
       
   455     };
       
   456 
       
   457 #endif      // CWPEMAILSAVEITEM_H   
       
   458             
       
   459 // End of File