31
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <e32std.h>
|
|
17 |
#include "POPS.H"
|
|
18 |
#include "POPSOP.H"
|
|
19 |
#include <pop3set.h>
|
|
20 |
|
|
21 |
#include <iapprefs.h>
|
|
22 |
#include <hash.h>
|
|
23 |
#include <pop3set.h>
|
|
24 |
#include <e32std.h>
|
|
25 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
26 |
#include "cpopsaslauthhelper.h"
|
|
27 |
#endif
|
|
28 |
#include "POPS.PAN" // impp's own panic codes
|
|
29 |
|
|
30 |
#define KPeriod 30000000 // period of timer
|
|
31 |
|
|
32 |
// Specifies how long a socket is allowed to be inactive before we close it
|
|
33 |
// down. This handles the situation where the mail server closes down the
|
|
34 |
// connection, but we don't receive any indication of that. It has been seen
|
|
35 |
// when connected using GPRS, and a long telephone call is then made.
|
|
36 |
const TInt KPopSendInactivityTimeMinutes = 30;
|
|
37 |
const TInt KPopReceiveInactivityTimeMinutes = 30;
|
|
38 |
|
|
39 |
// Utility functions used by both active objects...
|
|
40 |
GLDEF_C TBool CommandAccepted(TDesC8& aResponse)
|
|
41 |
{
|
|
42 |
// +OK signifies a successful command -ERR otherwise
|
|
43 |
return (0==aResponse.Locate('+'));
|
|
44 |
}
|
|
45 |
//
|
|
46 |
// My own panic command
|
|
47 |
//
|
|
48 |
GLDEF_C void Panic(TPopsPanic aPanic)
|
|
49 |
{
|
|
50 |
_LIT(KPanicText,"Pop3 session");
|
|
51 |
User::Panic(KPanicText, aPanic);
|
|
52 |
}
|
|
53 |
|
|
54 |
CImPop3Session::CImPop3Session()
|
|
55 |
: CMsgActive(KImPopSessionPriority)
|
|
56 |
{
|
|
57 |
__DECLARE_NAME(_S("CImPop3Session"));
|
|
58 |
}
|
|
59 |
|
|
60 |
|
|
61 |
CImPop3Session* CImPop3Session::NewL(RSocketServ& aServ, CImConnect& aConnect)
|
|
62 |
{
|
|
63 |
CImPop3Session* self = new (ELeave) CImPop3Session();
|
|
64 |
CleanupStack::PushL(self);
|
|
65 |
self->ConstructL(aServ, aConnect);
|
|
66 |
CleanupStack::Pop();
|
|
67 |
return self;
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
void CImPop3Session::ConstructL(RSocketServ& aServ, CImConnect& aConnect)
|
|
72 |
{
|
|
73 |
iSocket=CImTextServerSession::NewL(KPopSendInactivityTimeMinutes, KPopReceiveInactivityTimeMinutes, aServ, aConnect);
|
|
74 |
iNoMessages=0;
|
|
75 |
iIdTab=NULL;
|
|
76 |
iSocketConnected=EFalse;
|
|
77 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
78 |
iSaslAuthLogin = EFalse;
|
|
79 |
#endif
|
|
80 |
|
|
81 |
CActiveScheduler::Add(this); // Add PopSession to scheduler's queue
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
CImPop3Session::~CImPop3Session()
|
|
86 |
{
|
|
87 |
Cancel();
|
|
88 |
|
|
89 |
delete iPopApop;
|
|
90 |
delete iConnectReply;
|
|
91 |
delete iSocket;
|
|
92 |
delete [] iIdTab;
|
|
93 |
delete iCaf;
|
|
94 |
delete iPopCapabilities;
|
|
95 |
}
|
|
96 |
|
|
97 |
//
|
|
98 |
// Connect to Pop3 with User and Pass
|
|
99 |
//
|
|
100 |
void CImPop3Session::ConnectL(CImPop3Settings* aPopSettings, const CImIAPPreferences& aPrefs, TRequestStatus& aStatus)
|
|
101 |
{
|
|
102 |
__ASSERT_DEBUG(!IsActive(),Panic(EImppAlreadyActive));
|
|
103 |
// copy of pop settings owned by mtm
|
|
104 |
iPopSettings = aPopSettings;
|
|
105 |
|
|
106 |
iCompleted=KErrNone;
|
|
107 |
iState=EConnectingToPop; // Initialise to 1st state of state machine
|
|
108 |
|
|
109 |
Queue(aStatus);
|
|
110 |
|
|
111 |
if(iPopSettings->SSLWrapper())
|
|
112 |
{
|
|
113 |
iSocket->SSLQueueConnectL(iStatus, iPopSettings->ServerAddress(), aPopSettings->Port(), aPrefs, iPopSettings->TlsSslDomain());
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
iSocket->QueueConnectL(iStatus, iPopSettings->ServerAddress(), aPopSettings->Port(), aPrefs, iPopSettings->TlsSslDomain());
|
|
118 |
}
|
|
119 |
SetActive();
|
|
120 |
}
|
|
121 |
|
|
122 |
//
|
|
123 |
// Queue a read if mailbox is in idle state
|
|
124 |
//
|
|
125 |
void CImPop3Session::Waiting(TRequestStatus& aStatus)
|
|
126 |
{
|
|
127 |
iState=EPopConnected;
|
|
128 |
iSocket->QueueReceiveNextTextLine(iStatus);
|
|
129 |
SetActive();
|
|
130 |
Queue(aStatus);
|
|
131 |
}
|
|
132 |
//
|
|
133 |
// Put a QUIT function
|
|
134 |
//
|
|
135 |
void CImPop3Session::Quit(TRequestStatus& aStatus)
|
|
136 |
{
|
|
137 |
__ASSERT_DEBUG(!IsActive(),Panic(EImppAlreadyActive));
|
|
138 |
|
|
139 |
iState=EStopPop;
|
|
140 |
|
|
141 |
if(iSocketConnected)
|
|
142 |
{
|
|
143 |
_LIT8(KPop3CmdQuit, "QUIT\r\n");
|
|
144 |
iSocket->SendQueueReceive(iStatus,KPop3CmdQuit());
|
|
145 |
SetActive();
|
|
146 |
Queue(aStatus);
|
|
147 |
}
|
|
148 |
else
|
|
149 |
{
|
|
150 |
TRequestStatus* pS=&iStatus;
|
|
151 |
User::RequestComplete(pS,KErrNone);
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
//
|
|
156 |
// Pass the TMsg array to our Pop session
|
|
157 |
//
|
|
158 |
void CImPop3Session::SetMessageArray(TInt32* anIdArray, TUint aNoMessages)
|
|
159 |
{
|
|
160 |
iIdTab=anIdArray;
|
|
161 |
iNoMessages=aNoMessages;
|
|
162 |
}
|
|
163 |
|
|
164 |
TInt32* CImPop3Session::MessageArray()
|
|
165 |
{
|
|
166 |
return iIdTab;
|
|
167 |
}
|
|
168 |
|
|
169 |
TInt CImPop3Session::GetNumMessages()
|
|
170 |
{
|
|
171 |
return iNoMessages;
|
|
172 |
}
|
|
173 |
|
|
174 |
//
|
|
175 |
// Return Pop3 message no for a given message id
|
|
176 |
//
|
|
177 |
TInt CImPop3Session::MessageNo(TMsvId aMsgId)
|
|
178 |
// AF Using TInt reduces the available range of +ve numbers
|
|
179 |
// but shouldn't be a problem should it?
|
|
180 |
{
|
|
181 |
TInt msgNo=KErrNotFound;
|
|
182 |
TInt arrayCtr=0;
|
|
183 |
|
|
184 |
if(iIdTab==NULL || iNoMessages==0)
|
|
185 |
{
|
|
186 |
Panic(EImppBabelMsgArrayNotDefined);
|
|
187 |
}
|
|
188 |
|
|
189 |
while(arrayCtr<iNoMessages && msgNo==KErrNotFound)
|
|
190 |
{
|
|
191 |
if(TInt32(*(iIdTab+arrayCtr))==aMsgId)
|
|
192 |
{
|
|
193 |
msgNo=arrayCtr+1;
|
|
194 |
}
|
|
195 |
arrayCtr++;
|
|
196 |
}
|
|
197 |
|
|
198 |
return msgNo;
|
|
199 |
}
|
|
200 |
|
|
201 |
//
|
|
202 |
// Cancel any current operation
|
|
203 |
//
|
|
204 |
void CImPop3Session::DoCancel()
|
|
205 |
{
|
|
206 |
if(iState==EStopPop)
|
|
207 |
{
|
|
208 |
iSocket->Disconnect();
|
|
209 |
iSocketConnected=EFalse;
|
|
210 |
}
|
|
211 |
|
|
212 |
if(iState == EPopCapabilities || iState == EWaitingForReply)
|
|
213 |
{
|
|
214 |
if(iPopCapabilities)
|
|
215 |
{
|
|
216 |
iPopCapabilities->Cancel();
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
iSocket->Cancel(); // clear a pending socket call
|
|
221 |
|
|
222 |
CMsgActive::DoCancel();
|
|
223 |
}
|
|
224 |
|
|
225 |
//
|
|
226 |
// Result of last active call
|
|
227 |
//
|
|
228 |
void CImPop3Session::DoRunL()
|
|
229 |
{
|
|
230 |
if(iState==EStopPop)
|
|
231 |
{
|
|
232 |
iSocket->Disconnect();
|
|
233 |
iSocketConnected=EFalse;
|
|
234 |
}
|
|
235 |
|
|
236 |
//get the response
|
|
237 |
if(iState!=EConnectingToPop && iState!=EStopPop)
|
|
238 |
{
|
|
239 |
if(iState != EWaitingForReply)
|
|
240 |
{
|
|
241 |
TInt lineState=iSocket->GetCurrentTextLine(iResponseBuffer);
|
|
242 |
__ASSERT_ALWAYS(lineState==ECRLFTerminated,User::Leave(EImppBufferNotTerminated));
|
|
243 |
|
|
244 |
if(!CommandAccepted(iResponseBuffer))
|
|
245 |
{
|
|
246 |
User::Leave(GetPopError());
|
|
247 |
}
|
|
248 |
}
|
|
249 |
|
|
250 |
if(iPopSettings->Apop() && iState==EWaitingForReply)
|
|
251 |
{
|
|
252 |
HBufC8* connectReply = HBufC8::NewL(KImMailMaxBufferSize);
|
|
253 |
// Delete iConnectReply if not NULL & assign newly created
|
|
254 |
delete iConnectReply;
|
|
255 |
iConnectReply = connectReply;
|
|
256 |
iConnectReply->Des().Copy(iResponseBuffer);
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
if(iState!=EStopPop)
|
|
261 |
{
|
|
262 |
// successful response decide what to do next
|
|
263 |
switch(iState)
|
|
264 |
{
|
|
265 |
case EPopCapabilities:
|
|
266 |
GetCapabilitiesL();
|
|
267 |
iState = EWaitingForReply;
|
|
268 |
break;
|
|
269 |
|
|
270 |
case EWaitingForReply:
|
|
271 |
if(iPopSettings->SecureSockets())
|
|
272 |
{
|
|
273 |
iState = ERequestingTLS;
|
|
274 |
}
|
|
275 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
276 |
else if(iPopSettings->POP3Auth())
|
|
277 |
{
|
|
278 |
iState = ESaslAuthInProgress;
|
|
279 |
SelectAuthExtensionProfileL();
|
|
280 |
}
|
|
281 |
#endif
|
|
282 |
else if(iPopSettings->Apop())
|
|
283 |
{
|
|
284 |
iState=EAuthorisingApop;
|
|
285 |
}
|
|
286 |
else
|
|
287 |
{
|
|
288 |
iState++;
|
|
289 |
}
|
|
290 |
ChangeStateL();
|
|
291 |
break;
|
|
292 |
|
|
293 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
294 |
case ESaslAuthInProgress:
|
|
295 |
// To set the server response, accodring the response will be creating
|
|
296 |
// the authentication string.
|
|
297 |
iPopAuthHelper->SetLastServerMessageL(iResponseBuffer, ETrue);
|
|
298 |
iState++;
|
|
299 |
ChangeStateL();
|
|
300 |
break;
|
|
301 |
|
|
302 |
case ESaslAuthIsDone:
|
|
303 |
iSocketConnected=ETrue;
|
|
304 |
break;
|
|
305 |
#endif
|
|
306 |
|
|
307 |
case EConnectingToPop:
|
|
308 |
case EAuthorisingUser:
|
|
309 |
iState++;
|
|
310 |
ChangeStateL();
|
|
311 |
break;
|
|
312 |
|
|
313 |
case EAuthorisingPass:
|
|
314 |
case EAuthorisingApop:
|
|
315 |
iSocketConnected=ETrue;
|
|
316 |
break;
|
|
317 |
|
|
318 |
// TLS request accepted
|
|
319 |
case ERequestingTLS:
|
|
320 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
321 |
if(iPopSettings->POP3Auth())
|
|
322 |
{
|
|
323 |
iState = ESaslAuthInProgress;
|
|
324 |
SelectAuthExtensionProfileL();
|
|
325 |
}
|
|
326 |
else
|
|
327 |
#endif
|
|
328 |
{
|
|
329 |
iPopSettings->Apop() ? iState = EAuthorisingApop : iState =EAuthorisingUser;
|
|
330 |
}
|
|
331 |
ChangeStateL();
|
|
332 |
break;
|
|
333 |
}
|
|
334 |
}
|
|
335 |
}
|
|
336 |
|
|
337 |
void CImPop3Session::DoComplete(TInt& aCompleteStatus)
|
|
338 |
{
|
|
339 |
TInt status=aCompleteStatus;
|
|
340 |
if (status==KErrNone) // no error
|
|
341 |
{
|
|
342 |
return;
|
|
343 |
}
|
|
344 |
|
|
345 |
if(iSocketConnected && status==KErrCancel) // Cancel() has been called
|
|
346 |
{
|
|
347 |
return;
|
|
348 |
}
|
|
349 |
|
|
350 |
// if we've connected but it all goes wrong send a synchronous quit kludged code
|
|
351 |
switch (iState)
|
|
352 |
{
|
|
353 |
case EWaitingForReply: // stay connected
|
|
354 |
case EStopPop:
|
|
355 |
break;
|
|
356 |
case EAuthorisingUser:
|
|
357 |
case EAuthorisingPass:
|
|
358 |
case EAuthorisingApop:
|
|
359 |
case EPopConnected: // idle read has returned POP server timed out
|
|
360 |
case EConnectingToPop: // lose connection
|
|
361 |
case ERequestingTLS:
|
|
362 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
363 |
case ESaslAuthInProgress:
|
|
364 |
case ESaslAuthIsDone:
|
|
365 |
#endif
|
|
366 |
iSocket->Disconnect();
|
|
367 |
iSocketConnected=EFalse;
|
|
368 |
break;
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
void CImPop3Session::ChangeStateL()
|
|
373 |
{
|
|
374 |
//
|
|
375 |
// State machine of the POP mail session.
|
|
376 |
// (But only handle states which can leave)
|
|
377 |
// Identify state on entry, change to next state and then
|
|
378 |
// start new operation associated with that new state.
|
|
379 |
//
|
|
380 |
|
|
381 |
__ASSERT_DEBUG(!IsActive(),Panic(EImppAlreadyActive));
|
|
382 |
|
|
383 |
switch (iState)
|
|
384 |
{
|
|
385 |
case EPopCapabilities:
|
|
386 |
iSocket->QueueReceiveNextTextLine(iStatus);
|
|
387 |
break;
|
|
388 |
|
|
389 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
390 |
case ESaslAuthInProgress:
|
|
391 |
iPopAuthHelper->GetNextClientMessageL(iResponseBuffer);
|
|
392 |
iSocket->SendQueueReceive(iStatus, iResponseBuffer);
|
|
393 |
iSocket->PerformLogging(ETrue);
|
|
394 |
break;
|
|
395 |
|
|
396 |
case ESaslAuthIsDone:
|
|
397 |
iPopAuthHelper->GetNextClientMessageL(iResponseBuffer);
|
|
398 |
iSocket->SendQueueReceive(iStatus, iResponseBuffer);
|
|
399 |
iSocket->PerformLogging(ETrue);
|
|
400 |
if(iSaslAuthLogin)
|
|
401 |
{
|
|
402 |
iState = ESaslAuthInProgress;
|
|
403 |
iSaslAuthLogin = EFalse;
|
|
404 |
}
|
|
405 |
break;
|
|
406 |
#endif
|
|
407 |
|
|
408 |
case EAuthorisingUser:
|
|
409 |
case EAuthorisingApop:
|
|
410 |
{
|
|
411 |
TPtrC8 loginName=iPopSettings->LoginName();
|
|
412 |
if (iState == EAuthorisingApop)
|
|
413 |
{
|
|
414 |
TRAPD(apopErr,ConstructApopL());
|
|
415 |
if(apopErr!=KErrNone)
|
|
416 |
{
|
|
417 |
User::Leave(KPop3CannotCreateApopLogonString);
|
|
418 |
}
|
|
419 |
iSocket->PerformLogging(EFalse);
|
|
420 |
_LIT8(KPop3CmdApop, "APOP %S %S\r\n");
|
|
421 |
iSocket->SendQueueReceive(iStatus, KPop3CmdApop(), &loginName, iPopApop);
|
|
422 |
iSocket->PerformLogging(ETrue);
|
|
423 |
delete iPopApop;
|
|
424 |
iPopApop=NULL;
|
|
425 |
delete iConnectReply;
|
|
426 |
iConnectReply=NULL;
|
|
427 |
}
|
|
428 |
else
|
|
429 |
{
|
|
430 |
iSocket->PerformLogging(EFalse);
|
|
431 |
_LIT8(KPop3CmdUser, "USER %S\r\n");
|
|
432 |
iSocket->SendQueueReceive(iStatus, KPop3CmdUser(), &loginName);
|
|
433 |
iSocket->PerformLogging(ETrue);
|
|
434 |
}
|
|
435 |
break;
|
|
436 |
}
|
|
437 |
case EAuthorisingPass:
|
|
438 |
{
|
|
439 |
TPtrC8 password=iPopSettings->Password();
|
|
440 |
iSocket->PerformLogging(EFalse);
|
|
441 |
_LIT8(KPop3CmdPass, "PASS %S\r\n");
|
|
442 |
iSocket->SendQueueReceive(iStatus, KPop3CmdPass(), &password);
|
|
443 |
iSocket->PerformLogging(ETrue);
|
|
444 |
break;
|
|
445 |
}
|
|
446 |
// new request to initiate TLS
|
|
447 |
case ERequestingTLS:
|
|
448 |
_LIT8(KPop3CmdOk, "+OK");
|
|
449 |
iSocket->SetSSLTLSResponseL(KPop3CmdOk());
|
|
450 |
_LIT8(KPop3CmdStls, "STLS\r\n");
|
|
451 |
iSocket->SendQueueReceive(iStatus, KPop3CmdStls());
|
|
452 |
break;
|
|
453 |
|
|
454 |
default: // Unknown state
|
|
455 |
Panic(EImppBadSessionState);
|
|
456 |
break;
|
|
457 |
}
|
|
458 |
|
|
459 |
SetActive();
|
|
460 |
}
|
|
461 |
|
|
462 |
//
|
|
463 |
// return a pointer to our CImTextServerSession so CPop3Operations can use it
|
|
464 |
//
|
|
465 |
CImTextServerSession* CImPop3Session::TextServerSession()
|
|
466 |
{
|
|
467 |
return iSocket;
|
|
468 |
}
|
|
469 |
|
|
470 |
//
|
|
471 |
// Return POP3 error (based on what state the POP login is in
|
|
472 |
//
|
|
473 |
TInt CImPop3Session::GetPopError()
|
|
474 |
{
|
|
475 |
TInt anError=KErrGeneral;
|
|
476 |
switch (iState)
|
|
477 |
{
|
|
478 |
case EWaitingForReply:
|
|
479 |
case EPopCapabilities:
|
|
480 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
481 |
if(iPopSettings->POP3Auth() && iState != EPopCapabilities)
|
|
482 |
{
|
|
483 |
anError=KPop3AuthenticationFailed;
|
|
484 |
}
|
|
485 |
else
|
|
486 |
#endif
|
|
487 |
{
|
|
488 |
anError=KPop3CannotConnect;
|
|
489 |
}
|
|
490 |
break;
|
|
491 |
case EAuthorisingUser:
|
|
492 |
anError=KPop3InvalidUser;
|
|
493 |
break;
|
|
494 |
case EAuthorisingPass:
|
|
495 |
anError=KPop3InvalidLogin;
|
|
496 |
break;
|
|
497 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
498 |
case ESaslAuthInProgress:
|
|
499 |
anError=KPop3InvalidUser;
|
|
500 |
break;
|
|
501 |
case ESaslAuthIsDone:
|
|
502 |
anError=KPop3InvalidLogin;
|
|
503 |
break;
|
|
504 |
#endif
|
|
505 |
case EAuthorisingApop:
|
|
506 |
anError=KPop3InvalidApopLogin;
|
|
507 |
break;
|
|
508 |
case EPopConnected:
|
|
509 |
anError=KErrDisconnected; // assume that this is Pop time out
|
|
510 |
break;
|
|
511 |
case ERequestingTLS:
|
|
512 |
anError = KErrPop3TLSNegotiateFailed;
|
|
513 |
default:
|
|
514 |
break;
|
|
515 |
}
|
|
516 |
return anError;
|
|
517 |
}
|
|
518 |
|
|
519 |
//DMC
|
|
520 |
TInt CImPop3Session::MaxHeaders()
|
|
521 |
{
|
|
522 |
return iPopSettings->InboxSynchronisationLimit();
|
|
523 |
}
|
|
524 |
|
|
525 |
//
|
|
526 |
// Set and test state of iOpPending: is a pop operation currently underway?
|
|
527 |
//
|
|
528 |
void CImPop3Session::SetPending()
|
|
529 |
{
|
|
530 |
iOpPending=ETrue;
|
|
531 |
}
|
|
532 |
|
|
533 |
void CImPop3Session::SetOpNotPending()
|
|
534 |
{
|
|
535 |
iOpPending=EFalse;
|
|
536 |
}
|
|
537 |
|
|
538 |
TBool CImPop3Session::IsPending()
|
|
539 |
{
|
|
540 |
return iOpPending;
|
|
541 |
}
|
|
542 |
|
|
543 |
|
|
544 |
TBool CImPop3Session::IsConnectedToInternet()
|
|
545 |
{
|
|
546 |
return iSocketConnected;
|
|
547 |
}
|
|
548 |
|
|
549 |
//
|
|
550 |
// construct Apop string using timestamp and user password (and MD5 hash function)
|
|
551 |
//
|
|
552 |
void CImPop3Session::ConstructApopL()
|
|
553 |
{
|
|
554 |
TPtrC8 pass(iPopSettings->Password());
|
|
555 |
TPtrC8 timeStamp;
|
|
556 |
TInt timeStampEndPos=KErrNotFound;
|
|
557 |
|
|
558 |
const TInt timeStampStartPos=iConnectReply->Des().Locate('<');
|
|
559 |
if(timeStampStartPos==KErrNotFound)
|
|
560 |
{
|
|
561 |
User::Leave(KErrNotFound);
|
|
562 |
}
|
|
563 |
|
|
564 |
timeStampEndPos=iConnectReply->Des().Locate('>');
|
|
565 |
if(timeStampEndPos!=KErrNotFound && (timeStampEndPos>timeStampStartPos))
|
|
566 |
{
|
|
567 |
TInt timeStampLength=(timeStampEndPos-timeStampStartPos)+1;
|
|
568 |
timeStamp.Set(iConnectReply->Des().Mid(timeStampStartPos,timeStampLength));
|
|
569 |
}
|
|
570 |
else
|
|
571 |
{
|
|
572 |
User::Leave(KErrNotFound);
|
|
573 |
}
|
|
574 |
|
|
575 |
HBufC8* popBuf = HBufC8::NewLC(timeStamp.Length() + pass.Length());
|
|
576 |
TPtr8 bufContent=popBuf->Des();
|
|
577 |
bufContent=timeStamp;
|
|
578 |
bufContent.Append(pass);
|
|
579 |
|
|
580 |
// do MD5
|
|
581 |
CMD5* doHash = CMD5::NewL();
|
|
582 |
CleanupStack::PushL(doHash);
|
|
583 |
HBufC8* popApop = HBufC8::NewL(2*doHash->HashSize());
|
|
584 |
delete iPopApop;
|
|
585 |
iPopApop = NULL;
|
|
586 |
iPopApop = popApop;
|
|
587 |
TPtr8 hashCont=iPopApop->Des();
|
|
588 |
hashCont = doHash->Hash(*popBuf);
|
|
589 |
|
|
590 |
TBuf<32> hexHash;
|
|
591 |
// MD5 algorithm ALWAYS returns 16 bytes of data - which will be converted into
|
|
592 |
// 32 characters; each byte represented by a 2 character hex representation,
|
|
593 |
// eg 255="ff"
|
|
594 |
|
|
595 |
for (TInt j=0;j<16;j++)
|
|
596 |
{
|
|
597 |
hexHash.AppendNumFixedWidth(hashCont[j],EHex,2);
|
|
598 |
}
|
|
599 |
|
|
600 |
// copy Hex values to iPopApop so that it can be used with the APOP command
|
|
601 |
iPopApop->Des().Copy(hexHash);
|
|
602 |
|
|
603 |
CleanupStack::PopAndDestroy(2); //popBuf & doHash
|
|
604 |
}
|
|
605 |
|
|
606 |
CImCaf* CImPop3Session::GetCafL(RFs& aFs)
|
|
607 |
{
|
|
608 |
if(!iCaf)
|
|
609 |
{
|
|
610 |
iCaf = new(ELeave) CImCaf(aFs);
|
|
611 |
}
|
|
612 |
return iCaf;
|
|
613 |
}
|
|
614 |
|
|
615 |
//
|
|
616 |
// Use CAPA command to get server capabilities
|
|
617 |
//
|
|
618 |
void CImPop3Session::GetCapabilitiesL()
|
|
619 |
{
|
|
620 |
iPopCapabilities = CImPop3Capa::NewL(this);
|
|
621 |
|
|
622 |
iPopCapabilities->Start(iStatus);
|
|
623 |
SetActive();
|
|
624 |
}
|
|
625 |
|
|
626 |
TBool CImPop3Session::PipeliningSupport()
|
|
627 |
{
|
|
628 |
return iPopCapabilities->PipeliningSupport();
|
|
629 |
}
|
|
630 |
|
|
631 |
|
|
632 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
633 |
/**
|
|
634 |
Function to select SASL Authentication Mechanism supported by email server.
|
|
635 |
If CRAM-MD5 Authentication is not supported by server and if Fallback flag is enabled,
|
|
636 |
will fallback to less secure authentication mechanism.
|
|
637 |
Fallback priority will be in a following order when server dosn't support CRAM-MD5.
|
|
638 |
1. APOP
|
|
639 |
2. PLAIN
|
|
640 |
3. LOGIN
|
|
641 |
4. USER/PASS
|
|
642 |
*/
|
|
643 |
void CImPop3Session::SelectAuthExtensionProfileL()
|
|
644 |
{
|
|
645 |
// get the supported SASL Capabilities
|
|
646 |
TUint supportedAuthProfiles = iPopCapabilities->SaslAuthExtensionFlag();
|
|
647 |
|
|
648 |
// to check whether CRAM-MD5 supported by the server
|
|
649 |
if(supportedAuthProfiles & CPopAuthMechanismHelper::ECramMD5)
|
|
650 |
{
|
|
651 |
//AUTHENTICATE CRAM-MD5 implementation
|
|
652 |
iPopAuthHelper = CPopAuthCramMd5MechanismHelper::NewL(*iPopSettings);
|
|
653 |
}
|
|
654 |
// if server doesn't support CRAM-MD5, check whether FallBack enabled from POP3 email settings.
|
|
655 |
else if(iPopSettings->FallBack())
|
|
656 |
{
|
|
657 |
if(iPopSettings->Apop())
|
|
658 |
{
|
|
659 |
//APOP
|
|
660 |
iState=EAuthorisingApop;
|
|
661 |
}
|
|
662 |
else if(supportedAuthProfiles & CPopAuthMechanismHelper::EPlain)
|
|
663 |
{
|
|
664 |
//AUTHENTICATE PLAIN implementation
|
|
665 |
iPopAuthHelper = CPopAuthPlainMechanismHelper::NewL(*iPopSettings);
|
|
666 |
iState = ESaslAuthIsDone;
|
|
667 |
}
|
|
668 |
else if(supportedAuthProfiles & CPopAuthMechanismHelper::ELogin)
|
|
669 |
{
|
|
670 |
//AUTHENTICATE LOGIN implementation
|
|
671 |
iPopAuthHelper = CPopAuthLoginMechanismHelper::NewL(*iPopSettings);
|
|
672 |
iSaslAuthLogin = ETrue;
|
|
673 |
}
|
|
674 |
else
|
|
675 |
{
|
|
676 |
//USER/PASS
|
|
677 |
iState = EAuthorisingUser;
|
|
678 |
}
|
|
679 |
}
|
|
680 |
else
|
|
681 |
{
|
|
682 |
// if server doesn't support CRAM-MD5 & FallBack is Off, leave with error.
|
|
683 |
iState = EWaitingForReply;
|
|
684 |
User::Leave(GetPopError());
|
|
685 |
}
|
|
686 |
}
|
|
687 |
|
|
688 |
#endif
|
|
689 |
|