author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:28:39 +0300 | |
changeset 70 | a15d9966050f |
parent 43 | 35b64624a9e7 |
permissions | -rw-r--r-- |
31 | 1 |
/* |
2 |
* Copyright (c) 2009 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: General utilities for unified editor and plugin |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// INCLUDE FILES |
|
19 |
#include <centralrepository.h> // CRepository |
|
20 |
#include <CoreApplicationUIsSDKCRKeys.h> // offline CR keys |
|
21 |
#include <rcustomerserviceprofilecache.h> |
|
22 |
#include <MmsEngineDomainCRKeys.h> |
|
23 |
#include <MsgMediaResolver.h> |
|
24 |
#include <DRMHelper.h> |
|
70
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
25 |
#include <ccsdefs.h> // for KDefaultGsmNumberMatchLength |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
26 |
#include <telconfigcrkeys.h> // for KCRUidTelephonyConfiguration |
31 | 27 |
|
28 |
#include "MessagingVariant.hrh" |
|
29 |
#include "MessagingInternalCRKeys.h" // Keys |
|
30 |
#include "UniEditorGenUtils.h" |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
31 |
#include <xqconversions.h> |
31 | 32 |
|
33 |
// CONSTANTS |
|
34 |
const TInt KMuiuCharQuote = '\"'; |
|
35 |
const TInt KMuiuCharBackSlash = '\\'; |
|
36 |
const TInt KMuiuCharDot = '.'; |
|
37 |
const TInt KMuiuCharSpace = ' '; |
|
38 |
const TInt KMuiuCharDel = 127; |
|
39 |
const TInt KMuiuCharAt = '@'; |
|
40 |
const TInt KMuiuSpecialCharStrLen = 12; |
|
41 |
_LIT( KRFC822Specials,"()<>@,;:\\\"[]"); |
|
42 |
||
43 |
// ============================ MEMBER FUNCTIONS =============================== |
|
44 |
||
45 |
// ---------------------------------------------------- |
|
46 |
// UniEditorGenUtils::UniEditorGenUtils |
|
47 |
// @see header |
|
48 |
// ---------------------------------------------------- |
|
49 |
UniEditorGenUtils::UniEditorGenUtils() : |
|
50 |
mAbsMaxConcatenatedSms(-1), |
|
51 |
mAbsMaxSmsCharacters(-1), |
|
70
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
52 |
mMaxMmsSize(-1), |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
53 |
mMatchDigitCount(-1) |
31 | 54 |
{ |
55 |
||
56 |
} |
|
57 |
||
58 |
// ---------------------------------------------------- |
|
59 |
// UniEditorGenUtils::~UniEditorGenUtils |
|
60 |
// @see header |
|
61 |
// ---------------------------------------------------- |
|
62 |
UniEditorGenUtils::~UniEditorGenUtils() |
|
63 |
{ |
|
64 |
||
65 |
} |
|
66 |
// ---------------------------------------------------- |
|
67 |
// UniEditorGenUtils::ReadEmailOverSmsSettingsL |
|
68 |
// @see header |
|
69 |
// ---------------------------------------------------- |
|
70 |
TInt UniEditorGenUtils::ReadEmailOverSmsSettingsL( |
|
71 |
TDes& aSmsc, |
|
72 |
TDes& aDestinationAddress, |
|
73 |
TBool& aModifiable ) |
|
74 |
{ |
|
75 |
// Create storage |
|
76 |
CRepository* storage = CRepository::NewLC( KCRUidSmum ); |
|
77 |
storage->Get( KSumEmailSC, aSmsc ); |
|
78 |
storage->Get( KSumEmailGateway, aDestinationAddress ); |
|
79 |
storage->Get( KSumEmailModifiable, aModifiable ); |
|
80 |
CleanupStack::PopAndDestroy(); // storage |
|
81 |
return KErrNone; |
|
82 |
} |
|
83 |
||
84 |
// ---------------------------------------------------- |
|
85 |
// UniEditorGenUtils::WriteEmailOverSmsSettingsL |
|
86 |
// @see header |
|
87 |
// ---------------------------------------------------- |
|
88 |
TInt UniEditorGenUtils::WriteEmailOverSmsSettingsL( |
|
89 |
const TDes& aSmsc, |
|
90 |
const TDes& aDestinationAddress, |
|
91 |
const TBool& aModifiable ) |
|
92 |
{ |
|
93 |
// Create storage |
|
94 |
CRepository* storage = CRepository::NewLC( KCRUidSmum ); |
|
95 |
storage->Set( KSumEmailSC, aSmsc ); |
|
96 |
storage->Set( KSumEmailGateway, aDestinationAddress ); |
|
97 |
storage->Set( KSumEmailModifiable, aModifiable ); |
|
98 |
CleanupStack::PopAndDestroy(); // storage |
|
99 |
return KErrNone; |
|
100 |
} |
|
101 |
||
102 |
// --------------------------------------------------------- |
|
103 |
// UniEditorGenUtils::IsPhoneOfflineL |
|
104 |
// @see header |
|
105 |
// --------------------------------------------------------- |
|
106 |
TBool UniEditorGenUtils::IsPhoneOfflineL() |
|
107 |
{ |
|
108 |
TInt connAllowed ( 1 ); |
|
109 |
CRepository* repository ( CRepository::NewL( KCRUidCoreApplicationUIs ) ); |
|
110 |
TInt err = repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed ); |
|
111 |
delete repository; |
|
112 |
repository = NULL; |
|
113 |
if ( !err && !connAllowed ) |
|
114 |
{ |
|
115 |
return ETrue; |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
return EFalse; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
// ---------------------------------------------------- |
|
124 |
// UniEditorGenUtils::AcceptEmailAddressesL |
|
125 |
// @see header |
|
126 |
// ---------------------------------------------------- |
|
127 |
TBool UniEditorGenUtils::AcceptEmailAddressesL() |
|
128 |
{ |
|
129 |
CRepository* repository ( CRepository::NewL( KCRUidMuiuVariation ) ); |
|
130 |
TInt features = 0; |
|
131 |
TBool emailOverSmsVariationOn = false; |
|
132 |
TBool acceptEmailAddresses = false; |
|
133 |
||
134 |
if ( repository->Get( KMuiuSmsFeatures, features ) == KErrNone ) |
|
135 |
{ |
|
136 |
if ( features & KSmsFeatureIdEmailOverSms ) |
|
137 |
{ |
|
138 |
emailOverSmsVariationOn = ETrue; |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
delete repository; |
|
143 |
||
144 |
//TODO chk with Jerry if below is needed |
|
145 |
RCustomerServiceProfileCache* cspProfile = new (ELeave) RCustomerServiceProfileCache; |
|
146 |
TInt error = cspProfile->Open(); |
|
147 |
||
148 |
if ( error == KErrNone ) |
|
149 |
{ |
|
150 |
if ( emailOverSmsVariationOn ) |
|
151 |
{ |
|
152 |
||
153 |
// EmailOverSms bit was variated ON so let's check the bit from SIM |
|
154 |
// Get tele services flags from CSP |
|
155 |
RMobilePhone::TCspValueAdded params; |
|
156 |
// Read the CPHS bit so we know if EmailOverSms is supported |
|
157 |
error = cspProfile->CspCPHSValueAddedServices( params ); |
|
158 |
||
159 |
||
160 |
if ( error == KErrNone && |
|
161 |
params >= 0 && |
|
162 |
params & RMobilePhone::KCspSMMOEmail ) |
|
163 |
{ |
|
164 |
// It's supported |
|
165 |
acceptEmailAddresses= true; |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
cspProfile->Close(); |
|
170 |
delete cspProfile; |
|
171 |
||
172 |
return acceptEmailAddresses; |
|
173 |
} |
|
174 |
||
175 |
// ---------------------------------------------------- |
|
176 |
// UniEditorGenUtils::VerifyEmailAddressesL |
|
177 |
// @see header |
|
178 |
// ---------------------------------------------------- |
|
179 |
TBool UniEditorGenUtils::VerifyEmailAddressesL( ConvergedMessageAddressList addrList) |
|
180 |
{ |
|
181 |
TBool emailAddrPresent = EFalse; |
|
182 |
int addrCount = addrList.count(); |
|
183 |
for(int i=0; i< addrCount; i++) |
|
184 |
{ |
|
185 |
QString addr = addrList.at(i)->address(); |
|
186 |
// check if email address, contains at least 3 characters |
|
187 |
if(addr.size() >= 3) |
|
188 |
{ |
|
189 |
// search for @ from the address |
|
190 |
// however, it can't be the first or the last item |
|
191 |
for(int i = 1; i < addr.size() - 1; i++) |
|
192 |
{ |
|
193 |
if(addr.at(i) == '@') |
|
194 |
{ |
|
195 |
emailAddrPresent = ETrue; |
|
196 |
break; |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
return emailAddrPresent; |
|
202 |
} |
|
203 |
||
204 |
// ---------------------------------------------------- |
|
205 |
// UniEditorGenUtils::UTF8Size |
|
206 |
// @see header |
|
207 |
// ---------------------------------------------------- |
|
208 |
TInt UniEditorGenUtils::UTF8Size( QString aText ) |
|
209 |
{ |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
210 |
HBufC* text = XQConversions::qStringToS60Desc(aText); |
31 | 211 |
TPtrC ptr = text->Des(); |
212 |
||
213 |
TInt count = 0; |
|
214 |
TInt sizeInBytes = 0; |
|
215 |
TUint16 charValue; |
|
216 |
while ( count < ptr.Length() ) |
|
217 |
{ |
|
218 |
charValue = ptr[count]; |
|
219 |
if ( charValue < 0x80 ) |
|
220 |
{ |
|
221 |
sizeInBytes += 1; |
|
222 |
} |
|
223 |
else if ( charValue < 0x800 ) |
|
224 |
{ |
|
225 |
sizeInBytes += 2; |
|
226 |
} |
|
227 |
else //if ( charValue < 0x10000 ) |
|
228 |
{ |
|
229 |
sizeInBytes += 3; |
|
230 |
} |
|
231 |
count++; |
|
232 |
} |
|
233 |
return sizeInBytes; |
|
234 |
} |
|
235 |
||
236 |
// ---------------------------------------------------- |
|
237 |
// UniEditorGenUtils::MaxSmsRecipientsL |
|
238 |
// @see header |
|
239 |
// ---------------------------------------------------- |
|
240 |
TInt UniEditorGenUtils::MaxSmsRecipientsL() |
|
241 |
{ |
|
242 |
CRepository* repository ( CRepository::NewL( KCRUidUniEditor ) ); |
|
243 |
TInt maxSmsRecipients = KDefaultSmsRecipients; |
|
244 |
||
245 |
if ( (repository->Get( KUniEditorSoftLimitRecipientCount, maxSmsRecipients ) |
|
246 |
!= KErrNone) || (maxSmsRecipients <= 0) ) |
|
247 |
{ |
|
248 |
// Unreasonable count, change it back to default value |
|
249 |
maxSmsRecipients = KDefaultSmsRecipients; |
|
250 |
} |
|
251 |
delete repository; |
|
252 |
||
253 |
return maxSmsRecipients; |
|
254 |
} |
|
255 |
||
256 |
// ---------------------------------------------------- |
|
257 |
// UniEditorGenUtils::MaxMmsRecipientsL |
|
258 |
// @see header |
|
259 |
// ---------------------------------------------------- |
|
260 |
TInt UniEditorGenUtils::MaxMmsRecipientsL() |
|
261 |
{ |
|
262 |
CRepository* repository ( CRepository::NewL( KCRUidUniEditor ) ); |
|
263 |
TInt maxMmsRecipients = KDefaultMmsRecipients; |
|
264 |
||
265 |
if ( (repository->Get( KUniEditorMaxRecipientCount, maxMmsRecipients ) |
|
266 |
!= KErrNone) || (maxMmsRecipients <= 0)) |
|
267 |
{ |
|
268 |
// Unreasonable count, change it back to default value |
|
269 |
maxMmsRecipients = KDefaultMmsRecipients; |
|
270 |
} |
|
271 |
delete repository; |
|
272 |
||
273 |
return maxMmsRecipients; |
|
274 |
} |
|
275 |
||
276 |
// ---------------------------------------------------- |
|
277 |
// UniEditorGenUtils::MaxMmsMsgSizeL |
|
278 |
// @see header |
|
279 |
// ---------------------------------------------------- |
|
280 |
TInt UniEditorGenUtils::MaxMmsMsgSizeL() |
|
281 |
{ |
|
282 |
// optimized, to read only once from CR |
|
283 |
if(mMaxMmsSize == -1) |
|
284 |
{// not read yet, so read it now |
|
285 |
mMaxMmsSize = KDefaultMaxSize; |
|
286 |
||
287 |
CRepository* repository = CRepository::NewL( KCRUidMmsEngine ); |
|
288 |
CleanupStack::PushL( repository ); |
|
289 |
||
290 |
repository->Get( KMmsEngineMaximumSendSize, mMaxMmsSize ); |
|
291 |
||
292 |
CleanupStack::PopAndDestroy( repository ); |
|
293 |
} |
|
294 |
||
295 |
return mMaxMmsSize; |
|
296 |
} |
|
297 |
||
298 |
// ---------------------------------------------------- |
|
299 |
// UniEditorGenUtils::getFileInfoL |
|
300 |
// @see header |
|
301 |
// ---------------------------------------------------- |
|
302 |
void UniEditorGenUtils::getFileInfoL(QString filePath, |
|
303 |
int& size, |
|
304 |
QString& mimetype, |
|
305 |
TMsgMediaType& mediaType) |
|
306 |
{ |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
307 |
HBufC* filepath = XQConversions::qStringToS60Desc(filePath); |
31 | 308 |
int fileSize = 0; |
309 |
||
310 |
CMsgMediaResolver* mediaResolver; |
|
311 |
||
312 |
if(filepath) |
|
313 |
{ |
|
314 |
CleanupStack::PushL(filepath); |
|
315 |
||
316 |
mediaResolver = CMsgMediaResolver::NewLC(); |
|
317 |
||
318 |
RFile file = mediaResolver->FileHandleL(*filepath); |
|
319 |
file.Size(fileSize); |
|
320 |
fileSize+= KEstimatedMimeHeaderSize; |
|
321 |
size = fileSize; |
|
322 |
TDataType datatype; |
|
323 |
mediaResolver->RecognizeL( file, datatype ); |
|
43
35b64624a9e7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
324 |
mimetype = XQConversions::s60Desc8ToQString(datatype.Des8()); |
31 | 325 |
mediaType = mediaResolver->MediaType(datatype.Des8()); |
326 |
||
327 |
CleanupStack::PopAndDestroy(mediaResolver); |
|
328 |
CleanupStack::PopAndDestroy(filepath); |
|
329 |
} |
|
330 |
||
331 |
return; |
|
332 |
} |
|
333 |
||
334 |
// ---------------------------------------------------- |
|
335 |
// UniEditorGenUtils::MaxSmsMsgSizeL |
|
336 |
// @see header |
|
337 |
// ---------------------------------------------------- |
|
338 |
int UniEditorGenUtils::MaxSmsMsgSizeL(bool unicode) |
|
339 |
{ |
|
340 |
int maxLength = 0; |
|
341 |
int lengthOne = 0; |
|
342 |
int lengthMany = 0; |
|
343 |
||
344 |
getSmsCharacterLimits(lengthOne, lengthMany, unicode); |
|
345 |
maxLength = lengthOne; |
|
346 |
||
347 |
int maxSmsParts = absoluteMaxSmsPartsL(); |
|
348 |
if(maxSmsParts > 1) |
|
349 |
{ |
|
350 |
maxLength = maxSmsParts * lengthMany; |
|
351 |
} |
|
352 |
/* UniEditor soft limit, may not be needed |
|
353 |
int maxSmsCharacters = absoluteMaxSmsCharactersL(); |
|
354 |
if(maxSmsCharacters > 0) |
|
355 |
{ |
|
356 |
maxLength = maxSmsCharacters; |
|
357 |
} |
|
358 |
*/ |
|
359 |
return maxLength; |
|
360 |
} |
|
361 |
||
362 |
// ---------------------------------------------------- |
|
363 |
// UniEditorGenUtils::getSmsCharacterLimits |
|
364 |
// @see header |
|
365 |
// ---------------------------------------------------- |
|
366 |
void UniEditorGenUtils::getSmsCharacterLimits(int& singlePartLength, |
|
367 |
int& concatenatedPartLength, |
|
368 |
bool unicode) |
|
369 |
{ |
|
370 |
if(unicode) |
|
371 |
{ |
|
372 |
singlePartLength = KFirstUnicodeSmsLength; |
|
373 |
concatenatedPartLength = KUnicodeConcatenationInterval; |
|
374 |
} |
|
375 |
else |
|
376 |
{ |
|
377 |
singlePartLength = KFirstNormalSmsLength; |
|
378 |
concatenatedPartLength = KNormalConcatenationInterval; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
// ---------------------------------------------------- |
|
383 |
// UniEditorGenUtils::absoluteMaxSmsPartsL |
|
384 |
// @see header |
|
385 |
// ---------------------------------------------------- |
|
386 |
int UniEditorGenUtils::absoluteMaxSmsPartsL() |
|
387 |
{ |
|
388 |
// optimized, to read only once from CR |
|
389 |
if(mAbsMaxConcatenatedSms == -1) |
|
390 |
{ // not read yet, so read it now |
|
391 |
mAbsMaxConcatenatedSms = KDefaultMaxSmsSize; |
|
392 |
CRepository* repository = CRepository::NewL( KCRUidSmum ); |
|
393 |
CleanupStack::PushL( repository ); |
|
394 |
||
395 |
if ( repository->Get( KSmumMaxSubMsgCount, mAbsMaxConcatenatedSms ) || |
|
396 |
mAbsMaxConcatenatedSms < 1 || |
|
397 |
mAbsMaxConcatenatedSms > KMaxSmsSizeByStandard ) |
|
398 |
{ |
|
399 |
// Unreasonable count, change it back to 30 ( S60 default ) |
|
400 |
mAbsMaxConcatenatedSms = KMaxSmsSizeByStandard; |
|
401 |
} |
|
402 |
CleanupStack::PopAndDestroy( repository ); |
|
403 |
} |
|
404 |
return mAbsMaxConcatenatedSms; |
|
405 |
} |
|
406 |
||
407 |
// ---------------------------------------------------- |
|
408 |
// UniEditorGenUtils::absoluteMaxSmsCharactersL |
|
409 |
// @see header |
|
410 |
// ---------------------------------------------------- |
|
411 |
int UniEditorGenUtils::absoluteMaxSmsCharactersL() |
|
412 |
{ |
|
413 |
// optimized, to read only once from CR |
|
414 |
if(mAbsMaxSmsCharacters == -1) |
|
415 |
{// not read yet, so read it now |
|
416 |
CRepository* repository = CRepository::NewL( KCRUidUniEditor ); |
|
417 |
CleanupStack::PushL( repository ); |
|
418 |
repository->Get( KUniEditorMaxSmsCharacterCount, mAbsMaxSmsCharacters ); |
|
419 |
CleanupStack::PopAndDestroy( repository ); |
|
420 |
} |
|
421 |
return mAbsMaxSmsCharacters; |
|
422 |
} |
|
423 |
||
424 |
// --------------------------------------------------------- |
|
425 |
// UniEditorGenUtils::ConvertDigitsTo |
|
426 |
// @see header |
|
427 |
// --------------------------------------------------------- |
|
428 |
void UniEditorGenUtils::ConvertDigitsTo( TDes& aDes, TDigitType aDigitType ) |
|
429 |
{ |
|
430 |
TChar toArea = aDigitType; |
|
431 |
TInt length = aDes.Length(); |
|
432 |
for(int i=0; i<length; i++) |
|
433 |
{ |
|
434 |
TChar ch = aDes[i]; |
|
435 |
TChar base = NumberToBase(ch); |
|
436 |
switch (base) |
|
437 |
{ |
|
438 |
case EDigitTypeWestern: |
|
439 |
case EDigitTypeArabicIndic: |
|
440 |
case EDigitTypeEasternArabicIndic: |
|
441 |
case EDigitTypeDevanagari: |
|
442 |
case EDigitTypeThai: |
|
443 |
ch += toArea - base; |
|
444 |
aDes[i] = TUint16(ch); |
|
445 |
break; |
|
446 |
default: |
|
447 |
break; |
|
448 |
}; |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
// --------------------------------------------------------- |
|
453 |
// UniEditorGenUtils::NumberToBase |
|
454 |
// @see header |
|
455 |
// --------------------------------------------------------- |
|
456 |
TChar UniEditorGenUtils::NumberToBase(TChar ch) |
|
457 |
{ |
|
458 |
TDigitType d[] = { EDigitTypeWestern, EDigitTypeArabicIndic, EDigitTypeEasternArabicIndic, EDigitTypeDevanagari, EDigitTypeThai }; |
|
459 |
TInt i = 0; |
|
460 |
TInt num = sizeof(d)/sizeof(d[0]); |
|
461 |
while(i<num) |
|
462 |
{ |
|
463 |
if (ch>TChar(d[i]) && ch<TChar(d[i]+10)) { return d[i]; } |
|
464 |
i++; |
|
465 |
} |
|
466 |
return ch; |
|
467 |
} |
|
468 |
||
469 |
// --------------------------------------------------------- |
|
470 |
// UniEditorGenUtils::ReplaceCharacters |
|
471 |
// @see header |
|
472 |
// --------------------------------------------------------- |
|
473 |
void UniEditorGenUtils::ReplaceCharacters(TDes &aDes, const TDesC &aChars, TChar aReplacement) |
|
474 |
{ |
|
475 |
TInt src = 0; |
|
476 |
TInt srclength = aDes.Length(); |
|
477 |
while(src < srclength) |
|
478 |
{ |
|
479 |
TChar c = aDes[src]; |
|
480 |
if (aChars.LocateF(c) != KErrNotFound) |
|
481 |
aDes[src] = TUint16(aReplacement); |
|
482 |
++src; |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
// ---------------------------------------------------- |
|
487 |
// UniEditorGenUtils::IsValidEmailAddressL |
|
488 |
// @see header |
|
489 |
// ---------------------------------------------------- |
|
490 |
TBool UniEditorGenUtils::IsValidEmailAddress( const TDesC& aAddress ) |
|
491 |
{ |
|
492 |
TInt c; |
|
493 |
TInt length = aAddress.Length (); |
|
494 |
TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials ); |
|
495 |
||
496 |
// first we validate the name portion (name@domain) |
|
497 |
if ( length && aAddress[0] == KMuiuCharDot ) |
|
498 |
{ |
|
499 |
return EFalse; |
|
500 |
} |
|
501 |
for ( c = 0 ; c < length ; c++ ) |
|
502 |
{ |
|
503 |
if ( aAddress[c] == KMuiuCharQuote && ( c == 0 || |
|
504 |
aAddress[c-1] == KMuiuCharDot || aAddress[c-1] == KMuiuCharQuote ) ) |
|
505 |
{ |
|
506 |
while ( ++c < length ) |
|
507 |
{ |
|
508 |
if ( aAddress[c] == KMuiuCharQuote ) |
|
509 |
{ |
|
510 |
if( (c + 1) == length) |
|
511 |
{ |
|
512 |
return EFalse; |
|
513 |
} |
|
514 |
break; |
|
515 |
} |
|
516 |
if ( aAddress[c] == KMuiuCharBackSlash && |
|
517 |
( aAddress[++c] == KMuiuCharSpace) ) |
|
518 |
{ |
|
519 |
continue; |
|
520 |
} |
|
521 |
if ( aAddress[c] <= KMuiuCharSpace || |
|
522 |
aAddress[c] >= KMuiuCharDel ) |
|
523 |
{ |
|
524 |
return EFalse; |
|
525 |
} |
|
526 |
} |
|
527 |
if ( c++ == length ) |
|
528 |
{ |
|
529 |
return EFalse; |
|
530 |
} |
|
531 |
if ( aAddress[c] == KMuiuCharAt ) |
|
532 |
{ |
|
533 |
break; |
|
534 |
} |
|
535 |
if ( aAddress[c] != KMuiuCharDot ) |
|
536 |
{ |
|
537 |
return EFalse; |
|
538 |
} |
|
539 |
continue; |
|
540 |
} |
|
541 |
if ( aAddress[c] == KMuiuCharAt ) |
|
542 |
{ |
|
543 |
break; |
|
544 |
} |
|
545 |
if ( aAddress[c] <= KMuiuCharSpace || aAddress[c] >= KMuiuCharDel ) |
|
546 |
{ |
|
547 |
return EFalse; |
|
548 |
} |
|
549 |
if ( rfc822Specials.Locate ( aAddress[c] ) != KErrNotFound ) |
|
550 |
{ |
|
551 |
return EFalse; |
|
552 |
} |
|
553 |
} |
|
554 |
if ( c == 0 || aAddress[c-1] == KMuiuCharDot ) |
|
555 |
{ |
|
556 |
return EFalse; |
|
557 |
} |
|
558 |
// next we validate the domain portion (name@domain) |
|
559 |
if ( c == length ) |
|
560 |
{ |
|
561 |
return EFalse; |
|
562 |
} |
|
563 |
else |
|
564 |
{ |
|
565 |
c++; |
|
566 |
return IsValidDomain ( aAddress.Mid ( ( c ) , length-c ) ); |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
// ---------------------------------------------------- |
|
571 |
// UniEditorGenUtils::IsValidDomainL |
|
572 |
// @see header |
|
573 |
// ---------------------------------------------------- |
|
574 |
TBool UniEditorGenUtils::IsValidDomain ( const TDesC& aDomain ) |
|
575 |
{ |
|
576 |
TInt c = 0; |
|
577 |
TInt length = aDomain.Length (); |
|
578 |
TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials ); |
|
579 |
||
580 |
if ( length == 0 ) |
|
581 |
{ |
|
582 |
return EFalse; |
|
583 |
} |
|
584 |
||
585 |
do |
|
586 |
{ |
|
587 |
if ( aDomain[c] == KMuiuCharDot ) |
|
588 |
{ |
|
589 |
if ( c == 0 || aDomain[c-1] == KMuiuCharDot ) |
|
590 |
{ |
|
591 |
return EFalse; |
|
592 |
} |
|
593 |
} |
|
594 |
if ( aDomain[c] <= KMuiuCharSpace || aDomain[c] >= KMuiuCharDel ) |
|
595 |
{ |
|
596 |
return EFalse; |
|
597 |
} |
|
598 |
if ( rfc822Specials.Locate( aDomain[c] ) != KErrNotFound ) |
|
599 |
{ |
|
600 |
return EFalse; |
|
601 |
} |
|
602 |
} |
|
603 |
while ( ++c < length ); |
|
604 |
||
605 |
return ( aDomain[length-1] != '.' ); |
|
606 |
} |
|
607 |
||
70
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
608 |
// ---------------------------------------------------- |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
609 |
// UniEditorGenUtils::MatchPhoneNumber |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
610 |
// @see header |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
611 |
// ---------------------------------------------------- |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
612 |
TBool UniEditorGenUtils::MatchPhoneNumberL( |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
613 |
TDesC& aFirstNumber, TDesC& aSecondNumber) |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
614 |
{ |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
615 |
// if matching digit count is already read from CR, then don't do that again |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
616 |
if(mMatchDigitCount == -1) |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
617 |
{ |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
618 |
mMatchDigitCount = KDefaultGsmNumberMatchLength; |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
619 |
// Read the amount of digits to be used in contact matching |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
620 |
// The key is owned by PhoneApp |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
621 |
CRepository* repository = CRepository::NewL(KCRUidTelConfiguration); |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
622 |
CleanupStack::PushL(repository); |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
623 |
if (repository->Get(KTelMatchDigits, mMatchDigitCount) == KErrNone) |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
624 |
{ |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
625 |
// Min is 7 |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
626 |
mMatchDigitCount = Max(mMatchDigitCount, KDefaultGsmNumberMatchLength); |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
627 |
} |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
628 |
CleanupStack::PopAndDestroy(); // repository |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
629 |
} |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
630 |
|
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
631 |
// start matching |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
632 |
if( (aFirstNumber.Length() == 0) || (aSecondNumber.Length() == 0) ) |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
633 |
{ |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
634 |
return EFalse; |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
635 |
} |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
636 |
|
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
637 |
if (aFirstNumber.Right(mMatchDigitCount).CompareF( |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
638 |
aSecondNumber.Right(mMatchDigitCount)) == 0) |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
639 |
{ |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
640 |
return ETrue; |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
641 |
} |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
642 |
return EFalse; |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
643 |
} |
a15d9966050f
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
644 |
|
31 | 645 |
// End of file |