emailservices/nmclientapi/src/nmapipopimapsettingsmanager.cpp
changeset 74 6c59112cfd31
parent 48 10eaf342f539
child 76 38bf5461e270
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description: Handles the populating of default settings for pop and imap mailboxes
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "nmapiheaders.h"
    18 #include <nmapiheaders.h>
    19 
    19 
    20 
    20 static const unsigned int DefaultPopPort = 110;
    21 
    21 static const unsigned int DefaultImapPort = 143;
    22 
    22 static const unsigned int DefaultSmtpPort = 25;
    23 static const int DefaultPopPort = 110;
    23 
    24 static const int DefaultImapPort = 993;
    24 static const unsigned int DefaultPopPortSsl = 995;
       
    25 static const unsigned int DefaultImapPortSsl = 993;
       
    26 static const unsigned int DefaultSmtpPortSsl = 465;
    25 
    27 
    26 using namespace EmailClientApi;
    28 using namespace EmailClientApi;
    27     
    29 
    28 NmApiPopImapSettingsManager::NmApiPopImapSettingsManager()
    30 NmApiPopImapSettingsManager::NmApiPopImapSettingsManager()
    29 {    
    31 {
       
    32     NM_FUNCTION;
    30 }
    33 }
    31 
    34 
    32 NmApiPopImapSettingsManager::~NmApiPopImapSettingsManager()
    35 NmApiPopImapSettingsManager::~NmApiPopImapSettingsManager()
    33 {   
    36 {
       
    37     NM_FUNCTION;
    34 }
    38 }
    35 
    39 
    36 bool NmApiPopImapSettingsManager::populateDefaults(const QString &mailboxType, NmApiMailboxSettingsData &data)
    40 bool NmApiPopImapSettingsManager::populateDefaults(const QString &mailboxType, NmApiMailboxSettingsData &data)
    37 {
    41 {
    38     bool ret = false;
    42     NM_FUNCTION;
    39     
    43     bool ret = true;
    40     QT_TRY {
    44  
    41         if (mailboxType==NmApiMailboxTypePop) {
    45     if (mailboxType==NmApiMailboxTypePop) {
    42             populatePopDefs(data);
    46     TRAPD(err, populatePopDefaultsL(data));
    43             ret = true;
    47         if (KErrNone != err) {
    44         }
       
    45         else if (mailboxType==NmApiMailboxTypeImap) {
       
    46             populateImapDefs(data);
       
    47             ret = true;
       
    48         }
       
    49         else {
       
    50             ret = false;
    48             ret = false;
    51         }
    49         }
    52     }
    50     }
    53     QT_CATCH(...){
    51     else if (mailboxType==NmApiMailboxTypeImap) {
       
    52         TRAPD(err, populateImapDefaultsL(data));
       
    53         if (KErrNone != err) {
       
    54             ret = false;
       
    55         }
       
    56     }
       
    57     else {
       
    58         // Mailbox type not recognized
    54         ret = false;
    59         ret = false;
    55     }
    60     }
    56     
    61 
       
    62     if (ret) {
       
    63         TRAPD(err, populateSmtpDefaultsL(data));
       
    64         if (KErrNone != err) {
       
    65             ret = false;
       
    66         }
       
    67     }
       
    68 
       
    69     if (ret) {
       
    70         populateCenrepDefaults(data);
       
    71     }
    57     return ret;
    72     return ret;
    58 }
    73 }
    59 
    74 
    60 void NmApiPopImapSettingsManager::populateImapDefs(NmApiMailboxSettingsData &data)
    75 void NmApiPopImapSettingsManager::populateImapDefaultsL(NmApiMailboxSettingsData &data)
    61 {
    76 {
    62     QScopedPointer<CImImap4Settings> imapSettings(new CImImap4Settings());
    77     NM_FUNCTION;
    63     
    78     QScopedPointer<CImImap4Settings> imapSettings;
       
    79     imapSettings.reset(new (ELeave) CImImap4Settings());
       
    80 
    64     QScopedPointer<CImIAPPreferences> iapPref;
    81     QScopedPointer<CImIAPPreferences> iapPref;
    65     QT_TRAP_THROWING(iapPref.reset(CImIAPPreferences::NewLC());
    82     iapPref.reset(CImIAPPreferences::NewLC());
    66             CleanupStack::Pop(iapPref.data()));  
    83     CleanupStack::Pop(iapPref.data());  
       
    84 
       
    85     QScopedPointer<CEmailAccounts> mailAccounts;
       
    86     mailAccounts.reset(CEmailAccounts::NewL());
    67         
    87         
    68     QScopedPointer<CEmailAccounts> mailAccounts;
    88     mailAccounts->PopulateDefaultImapSettingsL(*imapSettings,*iapPref);
    69     QT_TRAP_THROWING(mailAccounts.reset(CEmailAccounts::NewL()));
       
    70         
       
    71     QT_TRAP_THROWING( mailAccounts->PopulateDefaultImapSettingsL(*imapSettings,*iapPref));
       
    72     
    89     
    73     data.setValue(IncomingLoginName, 
    90     data.setValue(IncomingLoginName, 
    74                            XQConversions::s60Desc8ToQString(imapSettings->LoginName()));
    91                             XQConversions::s60Desc8ToQString(imapSettings->LoginName()));
    75 
    92 
    76     data.setValue(IncomingPassword, 
    93     data.setValue(IncomingPassword, 
    77                            XQConversions::s60Desc8ToQString(imapSettings->Password()));
    94                             XQConversions::s60Desc8ToQString(imapSettings->Password()));
    78        
    95     
    79     data.setValue(IncomingMailServer, 
    96     data.setValue(IncomingMailServer, 
    80                            XQConversions::s60DescToQString(imapSettings->ServerAddress()));
    97                             XQConversions::s60DescToQString(imapSettings->ServerAddress()));
    81          
    98 
    82    if (imapSettings->Port()) {
    99     data.setValue(FolderPath,
    83        data.setValue(IncomingPort, imapSettings->Port());
   100                             XQConversions::s60Desc8ToQString(imapSettings->FolderPath()));
    84        }
   101 
    85    else {
   102     TBool secureSockets = imapSettings->SecureSockets();
    86        data.setValue(IncomingPort, DefaultImapPort);
   103     TBool sslWrapper = imapSettings->SSLWrapper();
    87    }
   104     
    88    
   105     if (secureSockets == true && sslWrapper == false) {
    89    data.setValue(OutgoingSecureSockets, imapSettings->SecureSockets());
   106         data.setValue(IncomingMailSecurityType, NmApiStartTls);
    90    data.setValue(OutgoingSSLWrapper, imapSettings->SSLWrapper());  
   107     }
    91 }
   108     else if (secureSockets == false && sslWrapper == true) {
    92 
   109         data.setValue(IncomingMailSecurityType, NmApiSSLTls);
    93 void NmApiPopImapSettingsManager::populatePopDefs(NmApiMailboxSettingsData &data)
   110     }
    94 {
   111     else {
    95     QScopedPointer<CImPop3Settings> popSettings(new CImPop3Settings());
   112         data.setValue(IncomingMailSecurityType, NmApiSecurityOff);
       
   113     }
       
   114     
       
   115     if (imapSettings->Port()) {
       
   116         data.setValue(IncomingPort, imapSettings->Port());
       
   117         }
       
   118     else {
       
   119         if (sslWrapper) {
       
   120             data.setValue(IncomingPort, DefaultImapPortSsl);
       
   121         }
       
   122         else{
       
   123             data.setValue(IncomingPort, DefaultImapPort);
       
   124         }
       
   125     }
       
   126     
       
   127     
       
   128 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
       
   129     if (imapSettings->IMAP4Auth()) {
       
   130         data.setValue(IncomingMailUsesAuthentication, true);
       
   131         }
       
   132     else {
       
   133         data.setValue(IncomingMailUsesAuthentication, false);
       
   134     }
       
   135 
       
   136 #endif
       
   137 
       
   138 }
       
   139 
       
   140 void NmApiPopImapSettingsManager::populatePopDefaultsL(NmApiMailboxSettingsData &data)
       
   141 {
       
   142     NM_FUNCTION;
       
   143     QScopedPointer<CImPop3Settings> popSettings;
       
   144     popSettings.reset(new (ELeave) CImPop3Settings());
    96    
   145    
    97     QScopedPointer<CImIAPPreferences> iapPref;
   146     QScopedPointer<CImIAPPreferences> iapPref;
    98     QT_TRAP_THROWING(iapPref.reset(CImIAPPreferences::NewLC());
   147     iapPref.reset(CImIAPPreferences::NewLC());
    99         CleanupStack::Pop(iapPref.data()));
   148     CleanupStack::Pop(iapPref.data());
   100  
   149  
   101     QScopedPointer<CEmailAccounts> mailAccounts;
   150     QScopedPointer<CEmailAccounts> mailAccounts;
   102     QT_TRAP_THROWING(mailAccounts.reset(CEmailAccounts::NewL()));
   151     mailAccounts.reset(CEmailAccounts::NewL());
   103     
   152     
   104     QT_TRAP_THROWING( mailAccounts->PopulateDefaultPopSettingsL(*popSettings,*iapPref));
   153     mailAccounts->PopulateDefaultPopSettingsL(*popSettings,*iapPref);
   105     
   154     
   106     data.setValue(IncomingLoginName, 
   155     data.setValue(IncomingLoginName, 
   107                         XQConversions::s60Desc8ToQString(popSettings->LoginName()));
   156                             XQConversions::s60Desc8ToQString(popSettings->LoginName()));
   108    
   157    
   109     data.setValue(IncomingPassword, 
   158     data.setValue(IncomingPassword, 
   110                         XQConversions::s60Desc8ToQString(popSettings->Password()));
   159                             XQConversions::s60Desc8ToQString(popSettings->Password()));
   111      
   160      
   112     data.setValue(IncomingMailServer, 
   161     data.setValue(IncomingMailServer, 
   113                         XQConversions::s60DescToQString(popSettings->ServerAddress()));
   162                             XQConversions::s60DescToQString(popSettings->ServerAddress()));
   114     
   163     
       
   164     TBool secureSockets = popSettings->SecureSockets();
       
   165     TBool sslWrapper = popSettings->SSLWrapper();
       
   166     
       
   167     if (secureSockets == true && sslWrapper == false) {
       
   168         data.setValue(IncomingMailSecurityType, NmApiStartTls);
       
   169     }
       
   170     else if (secureSockets == false && sslWrapper == true) {
       
   171         data.setValue(IncomingMailSecurityType, NmApiSSLTls);
       
   172     }
       
   173     else {
       
   174         data.setValue(IncomingMailSecurityType, NmApiSecurityOff);
       
   175     }
       
   176 
   115     if (popSettings->Port()) {
   177     if (popSettings->Port()) {
   116         data.setValue(IncomingPort, popSettings->Port());
   178         data.setValue(IncomingPort, popSettings->Port());
   117         }
   179         }
   118     else {
   180     else {
   119         data.setValue(IncomingPort, DefaultPopPort);
   181         if (sslWrapper) {
   120     }
   182             data.setValue(IncomingPort, DefaultPopPortSsl);
   121     
   183         }
   122     data.setValue(OutgoingSecureSockets, popSettings->SecureSockets());
   184         else{
   123     data.setValue(OutgoingSSLWrapper, popSettings->SSLWrapper());
   185             data.setValue(IncomingPort, DefaultPopPort);
   124 }
   186         }
   125 
   187     }
   126 
   188 
       
   189 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
       
   190     if (popSettings->POP3Auth()) {
       
   191         data.setValue(IncomingMailUsesAuthentication, true);
       
   192     }
       
   193     else {
       
   194         data.setValue(IncomingMailUsesAuthentication, false);
       
   195     }
       
   196 #endif
       
   197 }
       
   198 
       
   199 void NmApiPopImapSettingsManager::populateSmtpDefaultsL(NmApiMailboxSettingsData &data)
       
   200 {
       
   201     NM_FUNCTION;
       
   202     QScopedPointer<CImSmtpSettings> smtpSettings;
       
   203     smtpSettings.reset(new (ELeave) CImSmtpSettings());
       
   204    
       
   205     QScopedPointer<CImIAPPreferences> iapPref;
       
   206     iapPref.reset(CImIAPPreferences::NewLC());
       
   207     CleanupStack::Pop(iapPref.data());
       
   208  
       
   209     QScopedPointer<CEmailAccounts> mailAccounts;
       
   210     mailAccounts.reset(CEmailAccounts::NewL());
       
   211     
       
   212     mailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings,*iapPref);
       
   213     
       
   214     data.setValue(EmailAddress, 
       
   215                             XQConversions::s60DescToQString(smtpSettings->EmailAddress()));
       
   216 
       
   217     data.setValue(ReplyAddress, 
       
   218                             XQConversions::s60DescToQString(smtpSettings->ReplyToAddress()));
       
   219 
       
   220     data.setValue(EmailAlias, 
       
   221                             XQConversions::s60DescToQString(smtpSettings->EmailAlias()));
       
   222 
       
   223     data.setValue(OutgoingMailServer,
       
   224                             XQConversions::s60DescToQString(smtpSettings->ServerAddress()));
       
   225 
       
   226     QString outgoingLoginName = XQConversions::s60Desc8ToQString(smtpSettings->LoginName()); 
       
   227     QString outgoingPassword = XQConversions::s60Desc8ToQString(smtpSettings->Password()); 
       
   228     data.setValue(OutgoingLoginName, outgoingLoginName);
       
   229     data.setValue(OutgoingPassword, outgoingPassword);
       
   230 
       
   231     if (smtpSettings->SMTPAuth()) {
       
   232         QVariant incomingLoginName;
       
   233         QVariant incomingPassword;
       
   234         
       
   235         if (data.getValue(IncomingLoginName, incomingLoginName)
       
   236             && data.getValue(IncomingPassword, incomingPassword)) {
       
   237             if (incomingLoginName == outgoingLoginName && incomingPassword == outgoingPassword) {
       
   238                 // incoming login name is same than outgoing
       
   239                 data.setValue(OutgoingMailUsesAuthentication, NmApiAuthSameAsIncoming);
       
   240             }
       
   241             else {
       
   242                 // Different login for outgoing mail
       
   243                 data.setValue(OutgoingMailUsesAuthentication, NmApiAuthUserAuthentication);
       
   244             }
       
   245         }
       
   246         else {
       
   247             // didn't get incoming password or login name. 
       
   248             data.setValue(OutgoingMailUsesAuthentication, NmApiAuthUserAuthentication);
       
   249         }
       
   250     }
       
   251     else {
       
   252         data.setValue(OutgoingMailUsesAuthentication, NmApiAuthNone);
       
   253     }
       
   254     
       
   255     TBool secureSockets = smtpSettings->SecureSockets();
       
   256     TBool sslWrapper = smtpSettings->SSLWrapper();
       
   257     
       
   258     if (secureSockets == true && sslWrapper == false) {
       
   259         data.setValue(OutgoingMailSecurityType, NmApiStartTls);
       
   260     }
       
   261     else if (secureSockets == false && sslWrapper == true) {
       
   262         data.setValue(OutgoingMailSecurityType, NmApiSSLTls);
       
   263     }
       
   264     else {
       
   265         data.setValue(OutgoingMailSecurityType, NmApiSecurityOff);
       
   266     }
       
   267     
       
   268     if (smtpSettings->Port()) {
       
   269         data.setValue(OutgoingPort, smtpSettings->Port());
       
   270     }
       
   271     else {
       
   272         if (sslWrapper) {
       
   273             data.setValue(OutgoingPort, DefaultSmtpPortSsl);
       
   274         }
       
   275         else{
       
   276             data.setValue(OutgoingPort, DefaultSmtpPort);
       
   277         }
       
   278     }
       
   279 }
       
   280 
       
   281 void NmApiPopImapSettingsManager::populateCenrepDefaults(NmApiMailboxSettingsData &data)
       
   282 {
       
   283     NM_FUNCTION;
       
   284     data.setValue(DownloadPictures, int(0));
       
   285     data.setValue(MessageDivider, int(0));
       
   286     data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetSE);
       
   287     data.setValue(ReceptionUserDefinedProfile, int(0));	// 0, because default profile is save energy
       
   288     data.setValue(ReceptionInboxSyncWindow, IpsServices::DefaultValueSaveEnergyInboxSyncWindow);
       
   289     data.setValue(ReceptionGenericSyncWindowInMessages, int(0)); // all messages
       
   290     data.setValue(ReceptionRefreshPeriodOther, int(0)); // when opening mailbox. (no refreshing in save energy mode)
       
   291     data.setValue(ReceptionWeekDays, IpsServices::DefaultValueSaveEnergyReceptionDays);
       
   292     data.setValue(ReceptionDayStartTime, IpsServices::DefaultValueSaveEnergyReceptionStartTime);
       
   293     data.setValue(ReceptionDayEndTime, IpsServices::DefaultValueSaveEnergyReceptionEndTime);
       
   294     data.setValue(ReceptionRefreshPeriodDayTime, IpsServices::DefaultValueSaveEnergyReceptionRefreshPeriodDayTime);
       
   295     data.setValue(UserNameHidden, int(0));
       
   296 }