ipsservices/ipssossettings/inc/ipssetutils.h
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 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:  Utility functions for setting UI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef IPSSETUTILS_H
       
    20 #define IPSSETUTILS_H
       
    21 
       
    22 
       
    23 #include <msvstd.h>                 // TEntry
       
    24 #include <cemailaccounts.h>         // CEmailAccounts
       
    25 
       
    26 class CMsvSession;
       
    27 class CBaseMtmUi;
       
    28 /**
       
    29  *  This class contains simple tools for mailbox handling
       
    30  *
       
    31  *  @lib IpsSosSettings.lib
       
    32  *  @since FS v1.0
       
    33  */
       
    34 class IpsSetUtils
       
    35     {
       
    36 public:
       
    37 
       
    38 // New functions
       
    39 
       
    40     /**
       
    41      * Checks if given entry contains mailbox properties
       
    42      *
       
    43      * @param aEntry entry to be checked
       
    44      * @return ETrue The entry is mailbox entry
       
    45      * @return EFalse The entry is not mailbox entry
       
    46      */
       
    47     static TBool IsMailbox(
       
    48         const TMsvEntry& aEntry );
       
    49 
       
    50     /**
       
    51      * Checks if given mtm-type matches known mail mtm's
       
    52      *
       
    53      * @param aMtm Mtm to be tested
       
    54      * @param aAllowExtended Other than basic mail mtm's are accepted also
       
    55      * @return EFalse if the mtm is not recognized
       
    56      * @return ETrue if the mtm is supported type (Imap4 / Pop3 / Smtp )
       
    57      */
       
    58     static TBool IsMailMtm( const TUid& aMtm );
       
    59 
       
    60     /**
       
    61      * Finds and returns entry of the mailbox with specified id
       
    62      *
       
    63      * @param aMsvSession Session to be used for the search
       
    64      * @param aMailboxId Id of the required mailbox
       
    65      * @return Mailbox entry
       
    66      */
       
    67     static TMsvEntry GetMailboxEntryL(
       
    68         CMsvSession& aMsvSession,
       
    69         const TMsvId aMailboxId );
       
    70 
       
    71     /**
       
    72      * Finds and entry of the mailbox with specified id
       
    73      *
       
    74      * @param aMsvSession Session to be used for the search
       
    75      * @param aMailboxId Id of the required mailbox
       
    76      * @param aMailbox The entry the result shall be stored
       
    77      * @return KErrNone when the search is successful
       
    78      */
       
    79     static TInt GetMailboxEntry(
       
    80         CMsvSession& aMsvSession,
       
    81         const TMsvId aMailboxId,
       
    82         TMsvEntry& aMailbox );
       
    83 
       
    84     /**
       
    85      * Searches the mailbox entries from specified mailbox id
       
    86      *
       
    87      * @param aMailboxId Id of the required mailbox
       
    88      * @param aMsvSession Session to be used in search
       
    89      * @param aSmtpEntry Entry for Sending part of mailbox
       
    90      * @param aRelatedEntry Entry for Receiving part of mailbox
       
    91      * @return Imap4 or Pop3 mtm, based on the related mail protocol
       
    92      */
       
    93     static TUid GetMailboxEntriesL(
       
    94         const TMsvId aMailboxId,
       
    95         CMsvSession& aMsvSession,
       
    96         TMsvEntry& aSmtpEntry,
       
    97         TMsvEntry& aRelatedEntry );
       
    98 
       
    99     /**
       
   100      * Searches the mailbox entries from specified mailbox id
       
   101      *
       
   102      * @param aEntry Entry of the required mailbox
       
   103      * @param aMsvSession Session to be used in search
       
   104      * @param aSmtpEntry Entry for Sending part of mailbox
       
   105      * @param aRelatedEntry Entry for Receiving part of mailbox
       
   106      * @return Imap4 or Pop3 mtm, based on the related mail protocol
       
   107      */
       
   108     static TUid GetMailboxEntriesL(
       
   109         const TMsvEntry& aEntry,
       
   110         CMsvSession& aMsvSession,
       
   111         TMsvEntry& aSmtpEntry,
       
   112         TMsvEntry& aRelatedEntry );
       
   113 
       
   114     /**
       
   115      * Searches the correct account id to be used to load settings
       
   116      *
       
   117      * @param aMsvSession Session to be used in search
       
   118      * @param aMailboxId Id of the mailbox to be used for search
       
   119      * @return Account id of the mailbox
       
   120      */
       
   121     static TSmtpAccount GetSmtpAccountIdL(
       
   122         CMsvSession& aMsvSession,
       
   123         const TMsvId aMailboxId );
       
   124 
       
   125     /**
       
   126      * Searches the correct account id to be used to load settings
       
   127      *
       
   128      * @param aMsvSession Session to be used in search
       
   129      * @param aMailboxId Id of the mailbox to be used for search
       
   130      * @return Account id of the mailbox
       
   131      */
       
   132     static TImapAccount GetImapAccountIdL(
       
   133         CMsvSession& aMsvSession,
       
   134         const TMsvId aMailboxId );
       
   135 
       
   136     /**
       
   137      * Searches the correct account id to be used to load settings
       
   138      *
       
   139      * @param aMsvSession Session to be used in search
       
   140      * @param aMailboxId Id of the mailbox to be used for search
       
   141      * @return Account id of the mailbox
       
   142      */
       
   143     static TPopAccount GetPopAccountIdL(
       
   144         CMsvSession& aMsvSession,
       
   145         const TMsvId aMailboxId );
       
   146 
       
   147     /**
       
   148      * Searches the correct account id to be used to load settings
       
   149      *
       
   150      * @param aMsvSession Session to be used in search
       
   151      * @param aEntry Mailbox entry to be used for search
       
   152      * @return Account id of the mailbox
       
   153      */
       
   154     static TSmtpAccount GetSmtpAccountIdL(
       
   155         CMsvSession& aMsvSession,
       
   156         const TMsvEntry& aEntry );
       
   157 
       
   158     /**
       
   159      * Searches the correct account id to be used to load settings
       
   160      *
       
   161      * @param aMsvSession Session to be used in search
       
   162      * @param aEntry Mailbox entry to be used for search
       
   163      * @return Account id of the mailbox
       
   164      */
       
   165     static TImapAccount GetImapAccountIdL(
       
   166         CMsvSession& aMsvSession,
       
   167         const TMsvEntry& aEntry );
       
   168 
       
   169     /**
       
   170      * Searches the correct account id to be used to load settings
       
   171      *
       
   172      * @param aMsvSession Session to be used in search
       
   173      * @param aEntry Mailbox entry to be used for search
       
   174      * @return Account id of the mailbox
       
   175      */
       
   176     static TPopAccount GetPopAccountIdL(
       
   177         CMsvSession& aMsvSession,
       
   178         const TMsvEntry& aEntry );
       
   179 
       
   180     /**
       
   181      * Searches the correct account id to be used to load settings
       
   182      *
       
   183      * @param aEntry aPopMailboxId Id of the Pop3 mailbox
       
   184      * @return Account id of the mailbox
       
   185      */
       
   186     static TPopAccount GetPopAccountIdL(
       
   187         const TMsvId aPopMailboxId );
       
   188 
       
   189     /**
       
   190      * Searches the correct account id to be used to load settings
       
   191      *
       
   192      * @param aEntry aImapMailboxId Id of the Imap4 mailbox
       
   193      * @return Account id of the mailbox
       
   194      */
       
   195     static TImapAccount GetImapAccountIdL(
       
   196         const TMsvId aImapMailboxId );
       
   197 
       
   198     /**
       
   199      * Searches the correct account id to be used to load settings
       
   200      *
       
   201      * @param aEntry aSmtpMailboxId Id of the Smtp mailbox
       
   202      * @return Account id of the mailbox
       
   203      */
       
   204     static TSmtpAccount GetSmtpAccountIdL(
       
   205         const TMsvId aSmtpMailboxId );
       
   206 
       
   207     /**
       
   208      * Searches the correct entry of specified protocol for required mailbox
       
   209      *
       
   210      * @param aMsvSession Session to be used in search
       
   211      * @param aEntry Entry for result to be stored
       
   212      * @param aMailboxId Id of the required mailbox
       
   213      * @param aGetSendingService Get either receiving or sending type
       
   214      * @return TInt KErrNone if search is successful
       
   215      */
       
   216     static TInt GetMailboxServiceId(
       
   217         CMsvSession& aMsvSession,
       
   218         TMsvEntry& aEntry,
       
   219         const TMsvId aMailboxId,
       
   220         const TBool aGetSendingService );
       
   221 
       
   222     /**
       
   223      * Searches through the provided mailbox for subscribed folders
       
   224      *
       
   225      * @param aMsvSession Session to be used in search
       
   226      * @param aMailboxId Id of the mailbox to be searched
       
   227      * @return Number of subscribed folders
       
   228      */
       
   229     static TInt CountSubscribedFoldersL(
       
   230         CMsvSession& aMsvSession,
       
   231         const TMsvId aMailboxId );
       
   232 
       
   233     /**
       
   234      * Checks if the mailbox has any subscribed folders.
       
   235      * Slightly faster than CountSubscribedFoldersL
       
   236      *
       
   237      * @param aMsvSession Session to be used in search
       
   238      * @param aMailboxId Id of the mailbox to be searched
       
   239      * @return ETrue if mailbox has subscribed folders
       
   240      * @return EFalse if mailbox has NOT subscribed folders
       
   241      */
       
   242     static TBool HasSubscribedFoldersL(
       
   243         CMsvSession& aMsvSession,
       
   244         const TMsvId aMailboxId );
       
   245 
       
   246     /**
       
   247      * Checks if the offered folder entry is inbox
       
   248      *
       
   249      * @param aMsvSession Session to be used
       
   250      * @param aFolderEntry Folder entry
       
   251      * @return ETrue if the folder is inbox
       
   252      * @return EFalse if the folder is NOT inbox
       
   253      */
       
   254     static TBool IsInbox(
       
   255         CMsvSession& aMsvSession,
       
   256         const TMsvEntry& aFolderEntry );
       
   257 
       
   258     /**
       
   259      * Email address check based on RFC2822
       
   260      *
       
   261      * @param aAddress: email address to be checked.
       
   262      * @return Returns ETrue if aAddress is a lexically valid emailaddress.
       
   263      */
       
   264     IMPORT_C static TBool IsValidEmailAddressL( const TDesC& aAddress );
       
   265 
       
   266     /**
       
   267      * Server address check based on RFC2822
       
   268      *
       
   269      * @param aDomain: domain to be checked.
       
   270      * @return Returns ETrue if aDomain is a lexically valid domain name.
       
   271      */
       
   272     static TBool IsValidDomainL( const TDesC& aAddress );
       
   273 
       
   274     /**
       
   275      * Gets related mailbox ID
       
   276      *
       
   277      * @param aMsvSession Message server session.
       
   278      * @param aMailboxId Unique mailbox entry id with return parameter.
       
   279      * @return KErrNone, when ok.
       
   280      */
       
   281     static TInt GetRelatedMailboxId(
       
   282         CMsvSession& aMsvSession,
       
   283         TMsvId& aMailboxId );
       
   284     
       
   285     /**    
       
   286      * Retrieves security port.
       
   287      *
       
   288      * @param aSecurity Current security setting.
       
   289      * @param aIncoming Defines security type.
       
   290      * @param aIsImap4 For protocol type.
       
   291      * @return Correct port number.
       
   292      */
       
   293     static TUint32 GetDefaultSecurityPort(
       
   294         const TInt aSecurity,
       
   295         const TBool aIncoming,
       
   296         const TBool aIsImap4 );
       
   297     
       
   298     /**    
       
   299      * Retrieves msv id of service entry
       
   300      *
       
   301      * @param aAccountId id of TPopAccount or TImapAccount
       
   302      * @param aMtmId KSenduiMtmImap4Uid or KSenduiMtmPop3Uid
       
   303      * @param aMsvId reference to msv id where service id is stored
       
   304      * @param aMsvId reference where smtp msv id is stored 
       
   305      */
       
   306     static void GetServiceIdFromAccountIdL(
       
   307         const TUint32 aAccountId,
       
   308         const TUid aMtmId,
       
   309         TMsvId& aServiceId,
       
   310         TMsvId& aSmtpId );
       
   311     
       
   312     /**    
       
   313      * Creates smtp settings object
       
   314      *
       
   315      * @param aAccountId id of TPopAccount or TImapAccount
       
   316      * @param aMtmId KSenduiMtmImap4Uid or KSenduiMtmPop3Uid
       
   317      * @return pointer to CImSmtpSettings
       
   318      */
       
   319     static CImSmtpSettings* GetSmtpSettingsFromAccountIdL(
       
   320         const TUint32 aAccountId,
       
   321         const TUid aMtmId );
       
   322     
       
   323     
       
   324         
       
   325 private:
       
   326 
       
   327 // New functions
       
   328 
       
   329     /**
       
   330      * Calculates the number of subscribed folders
       
   331      *
       
   332      * @param aMsvSession Session to be used in search
       
   333      * @param aFolderId Id of the folder to be searched
       
   334      * @param aCount Variable to store the number of subscribed folders
       
   335      */
       
   336     static void DoCountSubscribedFoldersL(
       
   337         CMsvSession& aMsvSession,
       
   338         const TMsvId aFolderId,
       
   339         TInt& aCount );
       
   340 
       
   341     /**
       
   342      * Simplifies the MtmUi's query Mtm
       
   343      *
       
   344      * @param aMailboxId, Mailbox id to be checked
       
   345      * @param aMtmUi, MtmUi to be used for the query
       
   346      * @return The result of the query
       
   347      */
       
   348     static TInt QueryMailboxValidityL(
       
   349         const TMsvId aMailboxId,
       
   350         CBaseMtmUi& aMtmUi );
       
   351     };
       
   352 
       
   353 #endif // IPSSETUTILS_H
       
   354 
       
   355 // End of File