|
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: ImumMboxSettingsUtils.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <SendUiConsts.h> // Constants |
|
22 #include <ImumInSettingsDataCollection.h> // MImumInSettingsDataCollection |
|
23 #include <ImumInMailboxServices.h> |
|
24 #include <ImumInMailboxUtilities.h> |
|
25 |
|
26 #include "ImumMboxSettingsUtils.h" |
|
27 #include "ImumMtmLogging.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // CONSTANTS |
|
32 // MACROS |
|
33 // LOCAL CONSTANTS AND MACROS |
|
34 // MODULE DATA STRUCTURES |
|
35 // LOCAL FUNCTION PROTOTYPES |
|
36 // FORWARD DECLARATIONS |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // ImumMboxSettingsUtils::SetLoginInformationL() |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 void ImumMboxSettingsUtils::SetLoginInformationL( |
|
46 CImumInternalApi& aMailboxApi, |
|
47 const TDesC8& aUserName, |
|
48 const TDesC8& aPassword, |
|
49 const TBool aPasswordTemporary, |
|
50 const TMsvId aServiceId ) |
|
51 { |
|
52 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::SetLoginInformationL, 0, mtm, KImumMtmLog ); |
|
53 IMUM_IN(); |
|
54 |
|
55 // Retrieve the settings of the mailbox |
|
56 const MImumInMailboxUtilities& utils = aMailboxApi.MailboxUtilitiesL(); |
|
57 TMsvEntry entry = utils.GetMailboxEntryL( aServiceId ); |
|
58 CImumInSettingsData* accountsettings = |
|
59 aMailboxApi.MailboxServicesL().LoadMailboxSettingsL( aServiceId ); |
|
60 CleanupStack::PushL( accountsettings ); |
|
61 MImumInSettingsDataCollection* connection = NULL; |
|
62 |
|
63 // Get the correct connection settings |
|
64 switch( entry.iMtm.iUid ) |
|
65 { |
|
66 case KSenduiMtmPop3UidValue: |
|
67 case KSenduiMtmImap4UidValue: |
|
68 connection = &accountsettings->GetInSetL( 0 ); |
|
69 break; |
|
70 |
|
71 case KSenduiMtmSmtpUidValue: |
|
72 connection = &accountsettings->GetInSetL( 1 ); |
|
73 break; |
|
74 |
|
75 // Default, just leave |
|
76 default: |
|
77 User::Leave( KErrUnknown ); |
|
78 break; |
|
79 } |
|
80 |
|
81 // Set login data to settings |
|
82 User::LeaveIfError( connection->SetAttr( |
|
83 TImumDaSettings::EKeyUsername, aUserName ) ); |
|
84 User::LeaveIfError( connection->SetAttr( |
|
85 TImumDaSettings::EKeyPassword, aPassword ) ); |
|
86 User::LeaveIfError( connection->SetAttr( |
|
87 TImumInSettings::EKeyTemporaryUsername, EFalse ) ); |
|
88 User::LeaveIfError( connection->SetAttr( |
|
89 TImumInSettings::EKeyTemporaryPassword, aPasswordTemporary ) ); |
|
90 |
|
91 // Save mailbox data |
|
92 aMailboxApi.MailboxServicesL().SaveMailboxSettingsL( *accountsettings ); |
|
93 CleanupStack::PopAndDestroy( accountsettings ); |
|
94 accountsettings = NULL; |
|
95 connection = NULL; |
|
96 IMUM_OUT(); |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // ImumMboxSettingsUtils::GetLoginInformationL() |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 void ImumMboxSettingsUtils::GetLoginInformationL( |
|
104 CImumInternalApi& aMailboxApi, |
|
105 TDes8& aUserName, |
|
106 TDes8& aPassword, |
|
107 TBool& aPasswordTemporary, |
|
108 const TMsvId aServiceId ) |
|
109 { |
|
110 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::GetLoginInformationL, 0, mtm, KImumMtmLog ); |
|
111 IMUM_IN(); |
|
112 |
|
113 // Retrieve the settings of the mailbox |
|
114 CImumInSettingsData* accountsettings = |
|
115 aMailboxApi.MailboxServicesL().LoadMailboxSettingsL( aServiceId ); |
|
116 CleanupStack::PushL( accountsettings ); |
|
117 |
|
118 TMsvEntry entry = |
|
119 aMailboxApi.MailboxUtilitiesL().GetMailboxEntryL( aServiceId ); |
|
120 GetLoginInformationL( *accountsettings, entry.iMtm, aUserName, aPassword, |
|
121 aPasswordTemporary ); |
|
122 |
|
123 CleanupStack::PopAndDestroy( accountsettings ); |
|
124 IMUM_OUT(); |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // ImumMboxSettingsUtils::GetLoginInformationL() |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 void ImumMboxSettingsUtils::GetLoginInformationL( |
|
132 const CImumInSettingsData& aAccountSettings, |
|
133 TUid aMtmUid, |
|
134 TDes8& aUserName, |
|
135 TDes8& aPassword, |
|
136 TBool& aPasswordTemporary ) |
|
137 { |
|
138 // Get login information. Avoid loading settings data. Use caller's data |
|
139 // set and execute faster. |
|
140 |
|
141 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::GetLoginInformationL, 0, mtm, KImumMtmLog ); |
|
142 IMUM_IN(); |
|
143 |
|
144 TInt dataIndex = 0; |
|
145 switch( aMtmUid.iUid ) |
|
146 { |
|
147 case KSenduiMtmPop3UidValue: |
|
148 case KSenduiMtmImap4UidValue: |
|
149 break; |
|
150 case KSenduiMtmSmtpUidValue: |
|
151 dataIndex = 1; |
|
152 break; |
|
153 // Default, just leave |
|
154 default: |
|
155 User::Leave( KErrUnknown ); |
|
156 } |
|
157 MImumInSettingsDataCollection& connection = aAccountSettings.GetInSetL( dataIndex ); |
|
158 |
|
159 // Read the data |
|
160 User::LeaveIfError( connection.GetAttr( |
|
161 TImumDaSettings::EKeyUsername, aUserName ) ); |
|
162 User::LeaveIfError( connection.GetAttr( |
|
163 TImumDaSettings::EKeyPassword, aPassword ) ); |
|
164 User::LeaveIfError( connection.GetAttr( |
|
165 TImumInSettings::EKeyTemporaryPassword, aPasswordTemporary ) ); |
|
166 IMUM_OUT(); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // ImumMboxSettingsUtils::IsImap4() |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 TBool ImumMboxSettingsUtils::IsImap4( const CImumInSettingsData& aSettings ) |
|
174 { |
|
175 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::IsImap4, 0, mtm, KImumMtmLog ); |
|
176 IMUM_IN(); |
|
177 |
|
178 TInt protocol = TImumDaSettings::EValueProtocolUnset; |
|
179 TRAP_IGNORE( aSettings.GetInSetL( 0 ).GetAttr( TImumDaSettings::EKeyProtocol, protocol ) ); |
|
180 // protocol == TImumDaSettings::EValueProtocolUnset if leave should happen |
|
181 |
|
182 IMUM_OUT(); |
|
183 return ( protocol == TImumDaSettings::EValueProtocolImap4 ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // ImumMboxSettingsUtils::ValidateSettingsL() |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 TBool ImumMboxSettingsUtils::ValidateSettingsL( |
|
191 CImumInternalApi& aMailboxApi, |
|
192 const TMsvId aMailboxId ) |
|
193 { |
|
194 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::ValidateSettingsL, 0, mtm, KImumMtmLog ); |
|
195 IMUM_IN(); |
|
196 |
|
197 CImumInSettingsData* accountsettings = |
|
198 aMailboxApi.MailboxServicesL().LoadMailboxSettingsL( aMailboxId ); |
|
199 CleanupStack::PushL( accountsettings ); |
|
200 |
|
201 TBool ok = !accountsettings->Validate(); |
|
202 |
|
203 CleanupStack::PopAndDestroy( accountsettings ); |
|
204 accountsettings = NULL; |
|
205 IMUM_OUT(); |
|
206 |
|
207 return ok; |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // ImumMboxSettingsUtils::SetLastUpdateInfoL() |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 void ImumMboxSettingsUtils::SetLastUpdateInfoL( |
|
215 CImumInternalApi& aEmailApi, |
|
216 TMsvId aMailboxId, |
|
217 const TBool& aSuccessful ) |
|
218 { |
|
219 IMUM_STATIC_CONTEXT( ImumMboxSettingsUtils::SetLastUpdateInfoL, 0, mtm, KImumMtmLog ); |
|
220 IMUM_IN(); |
|
221 |
|
222 if ( aSuccessful ) |
|
223 { |
|
224 TTime hometime = TTime(); |
|
225 hometime.HomeTime(); |
|
226 |
|
227 aEmailApi.MailboxServicesL().SetLastUpdateInfoL( aMailboxId, |
|
228 aSuccessful, hometime ); |
|
229 } |
|
230 IMUM_OUT(); |
|
231 } |