47
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
*
|
74
|
14 |
* Description: Handles the populating of default settings for pop and imap mailboxes
|
47
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
74
|
18 |
#include <nmapiheaders.h>
|
47
|
19 |
|
74
|
20 |
static const unsigned int DefaultPopPort = 110;
|
|
21 |
static const unsigned int DefaultImapPort = 143;
|
|
22 |
static const unsigned int DefaultSmtpPort = 25;
|
47
|
23 |
|
74
|
24 |
static const unsigned int DefaultPopPortSsl = 995;
|
|
25 |
static const unsigned int DefaultImapPortSsl = 993;
|
|
26 |
static const unsigned int DefaultSmtpPortSsl = 465;
|
47
|
27 |
|
76
|
28 |
namespace EmailClientApi
|
|
29 |
{
|
47
|
30 |
NmApiPopImapSettingsManager::NmApiPopImapSettingsManager()
|
74
|
31 |
{
|
|
32 |
NM_FUNCTION;
|
47
|
33 |
}
|
|
34 |
|
|
35 |
NmApiPopImapSettingsManager::~NmApiPopImapSettingsManager()
|
74
|
36 |
{
|
|
37 |
NM_FUNCTION;
|
47
|
38 |
}
|
|
39 |
|
|
40 |
bool NmApiPopImapSettingsManager::populateDefaults(const QString &mailboxType, NmApiMailboxSettingsData &data)
|
|
41 |
{
|
74
|
42 |
NM_FUNCTION;
|
|
43 |
bool ret = true;
|
|
44 |
|
|
45 |
if (mailboxType==NmApiMailboxTypePop) {
|
|
46 |
TRAPD(err, populatePopDefaultsL(data));
|
|
47 |
if (KErrNone != err) {
|
|
48 |
ret = false;
|
47
|
49 |
}
|
74
|
50 |
}
|
|
51 |
else if (mailboxType==NmApiMailboxTypeImap) {
|
|
52 |
TRAPD(err, populateImapDefaultsL(data));
|
|
53 |
if (KErrNone != err) {
|
47
|
54 |
ret = false;
|
|
55 |
}
|
|
56 |
}
|
74
|
57 |
else {
|
|
58 |
// Mailbox type not recognized
|
47
|
59 |
ret = false;
|
|
60 |
}
|
74
|
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 |
}
|
47
|
72 |
return ret;
|
|
73 |
}
|
|
74 |
|
74
|
75 |
void NmApiPopImapSettingsManager::populateImapDefaultsL(NmApiMailboxSettingsData &data)
|
47
|
76 |
{
|
74
|
77 |
NM_FUNCTION;
|
|
78 |
QScopedPointer<CImImap4Settings> imapSettings;
|
|
79 |
imapSettings.reset(new (ELeave) CImImap4Settings());
|
|
80 |
|
47
|
81 |
QScopedPointer<CImIAPPreferences> iapPref;
|
74
|
82 |
iapPref.reset(CImIAPPreferences::NewLC());
|
|
83 |
CleanupStack::Pop(iapPref.data());
|
|
84 |
|
47
|
85 |
QScopedPointer<CEmailAccounts> mailAccounts;
|
74
|
86 |
mailAccounts.reset(CEmailAccounts::NewL());
|
47
|
87 |
|
74
|
88 |
mailAccounts->PopulateDefaultImapSettingsL(*imapSettings,*iapPref);
|
47
|
89 |
|
|
90 |
data.setValue(IncomingLoginName,
|
74
|
91 |
XQConversions::s60Desc8ToQString(imapSettings->LoginName()));
|
47
|
92 |
|
|
93 |
data.setValue(IncomingPassword,
|
74
|
94 |
XQConversions::s60Desc8ToQString(imapSettings->Password()));
|
|
95 |
|
47
|
96 |
data.setValue(IncomingMailServer,
|
74
|
97 |
XQConversions::s60DescToQString(imapSettings->ServerAddress()));
|
|
98 |
|
|
99 |
data.setValue(FolderPath,
|
|
100 |
XQConversions::s60Desc8ToQString(imapSettings->FolderPath()));
|
|
101 |
|
|
102 |
TBool secureSockets = imapSettings->SecureSockets();
|
|
103 |
TBool sslWrapper = imapSettings->SSLWrapper();
|
|
104 |
|
|
105 |
if (secureSockets == true && sslWrapper == false) {
|
|
106 |
data.setValue(IncomingMailSecurityType, NmApiStartTls);
|
|
107 |
}
|
|
108 |
else if (secureSockets == false && sslWrapper == true) {
|
|
109 |
data.setValue(IncomingMailSecurityType, NmApiSSLTls);
|
|
110 |
}
|
|
111 |
else {
|
|
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 |
|
47
|
138 |
}
|
|
139 |
|
74
|
140 |
void NmApiPopImapSettingsManager::populatePopDefaultsL(NmApiMailboxSettingsData &data)
|
47
|
141 |
{
|
74
|
142 |
NM_FUNCTION;
|
|
143 |
QScopedPointer<CImPop3Settings> popSettings;
|
|
144 |
popSettings.reset(new (ELeave) CImPop3Settings());
|
47
|
145 |
|
|
146 |
QScopedPointer<CImIAPPreferences> iapPref;
|
74
|
147 |
iapPref.reset(CImIAPPreferences::NewLC());
|
|
148 |
CleanupStack::Pop(iapPref.data());
|
47
|
149 |
|
|
150 |
QScopedPointer<CEmailAccounts> mailAccounts;
|
74
|
151 |
mailAccounts.reset(CEmailAccounts::NewL());
|
47
|
152 |
|
74
|
153 |
mailAccounts->PopulateDefaultPopSettingsL(*popSettings,*iapPref);
|
47
|
154 |
|
|
155 |
data.setValue(IncomingLoginName,
|
74
|
156 |
XQConversions::s60Desc8ToQString(popSettings->LoginName()));
|
47
|
157 |
|
|
158 |
data.setValue(IncomingPassword,
|
74
|
159 |
XQConversions::s60Desc8ToQString(popSettings->Password()));
|
47
|
160 |
|
|
161 |
data.setValue(IncomingMailServer,
|
74
|
162 |
XQConversions::s60DescToQString(popSettings->ServerAddress()));
|
|
163 |
|
|
164 |
TBool secureSockets = popSettings->SecureSockets();
|
|
165 |
TBool sslWrapper = popSettings->SSLWrapper();
|
47
|
166 |
|
74
|
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 |
|
47
|
177 |
if (popSettings->Port()) {
|
|
178 |
data.setValue(IncomingPort, popSettings->Port());
|
|
179 |
}
|
|
180 |
else {
|
74
|
181 |
if (sslWrapper) {
|
|
182 |
data.setValue(IncomingPort, DefaultPopPortSsl);
|
|
183 |
}
|
|
184 |
else{
|
|
185 |
data.setValue(IncomingPort, DefaultPopPort);
|
|
186 |
}
|
|
187 |
}
|
|
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);
|
47
|
253 |
}
|
|
254 |
|
74
|
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 |
}
|
47
|
279 |
}
|
|
280 |
|
74
|
281 |
void NmApiPopImapSettingsManager::populateCenrepDefaults(NmApiMailboxSettingsData &data)
|
|
282 |
{
|
|
283 |
NM_FUNCTION;
|
|
284 |
data.setValue(DownloadPictures, int(0));
|
|
285 |
data.setValue(MessageDivider, int(0));
|
76
|
286 |
data.setValue(ReceptionActiveProfile, EmailProfileOffsetSE);
|
74
|
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 |
}
|
76
|
297 |
}
|
|
298 |
|