151 { |
151 { |
152 return 0; |
152 return 0; |
153 } |
153 } |
154 |
154 |
155 /*! |
155 /*! |
|
156 Returns folder |
|
157 |
|
158 \param mailboxId Id of the mailbox containing the folder. |
|
159 \param folderId Id of the requested folder |
|
160 \param message Pointer reference to receive a folder object, ownership is transferred. |
|
161 |
|
162 \return Error code. |
|
163 */ |
|
164 int NmFrameworkAdapter::getFolderById( const NmId& mailboxId, const NmId& folderId, NmFolder*& folder ) |
|
165 { |
|
166 TRAPD(err, getFolderByIdL( mailboxId, folderId, folder ) ); |
|
167 return err; |
|
168 } |
|
169 |
|
170 /*! |
|
171 Leaving version of getFolderById function |
|
172 */ |
|
173 void NmFrameworkAdapter::getFolderByIdL( const NmId& mailboxId, const NmId& folderId, NmFolder*& folder ) |
|
174 { |
|
175 CFSMailFolder* fsFolder(NULL); |
|
176 if (mFSfw) |
|
177 { |
|
178 fsFolder = mFSfw->GetFolderByUidL(TFSMailMsgId(mailboxId), TFSMailMsgId(folderId)); |
|
179 if (fsFolder) |
|
180 { |
|
181 folder = fsFolder->GetNmFolder(); |
|
182 delete fsFolder; |
|
183 fsFolder = NULL; |
|
184 } |
|
185 else |
|
186 { |
|
187 User::Leave(KErrNotFound); |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 |
|
193 /*! |
156 Returns message from the store together with whole message part structure |
194 Returns message from the store together with whole message part structure |
157 |
195 |
158 \param mailboxId Id of the mailbox containing the folder. |
196 \param mailboxId Id of the mailbox containing the folder. |
159 \param folderId Id of the folder containing the message. |
197 \param folderId Id of the folder containing the message. |
160 \param messageId Id of the message. |
198 \param messageId Id of the message. |
241 int NmFrameworkAdapter::listMessages( |
279 int NmFrameworkAdapter::listMessages( |
242 const NmId &mailboxId, |
280 const NmId &mailboxId, |
243 const NmId &folderId, |
281 const NmId &folderId, |
244 QList<NmMessageEnvelope*> &messageEnvelopeList) |
282 QList<NmMessageEnvelope*> &messageEnvelopeList) |
245 { |
283 { |
246 TRAPD(err, listMessagesL(mailboxId,folderId,messageEnvelopeList)); |
284 TRAPD(err, listMessagesL(mailboxId,folderId,messageEnvelopeList, nmMaxItemsInMessageList)); |
247 return err; |
285 return err; |
248 } |
286 } |
|
287 |
|
288 int NmFrameworkAdapter::listMessages( |
|
289 const NmId& mailboxId, |
|
290 const NmId& folderId, |
|
291 QList<NmMessageEnvelope*> &messageEnvelopeList, |
|
292 const int maxAmountOfEnvelopes) |
|
293 { |
|
294 TInt err = KErrNone; |
|
295 TRAP(err, listMessagesL(mailboxId,folderId, messageEnvelopeList,maxAmountOfEnvelopes) ); |
|
296 return err; |
|
297 } |
249 |
298 |
250 /*! |
299 /*! |
251 Leaving version of list messages |
300 Leaving version of list messages |
252 */ |
301 */ |
253 void NmFrameworkAdapter::listMessagesL( |
302 void NmFrameworkAdapter::listMessagesL( |
254 const NmId &mailboxId, |
303 const NmId &mailboxId, |
255 const NmId &folderId, |
304 const NmId &folderId, |
256 QList<NmMessageEnvelope*> &messageEnvelopeList) |
305 QList<NmMessageEnvelope*> &messageEnvelopeList, |
|
306 const int maxAmountOfEnvelopes) |
257 { |
307 { |
258 CFSMailBox * currentMailbox(NULL); |
308 CFSMailBox * currentMailbox(NULL); |
259 CFSMailFolder* folder(NULL); |
309 CFSMailFolder* folder(NULL); |
|
310 |
|
311 //If we are requesting 0 or less mails so we can return |
|
312 if( maxAmountOfEnvelopes <= 0) |
|
313 { |
|
314 return; |
|
315 } |
|
316 |
|
317 int blockSize = nmListMessagesBlock; |
|
318 int maxLimit = nmMaxItemsInMessageList; |
|
319 if( maxAmountOfEnvelopes < nmMaxItemsInMessageList ) |
|
320 { |
|
321 maxLimit = maxAmountOfEnvelopes; |
|
322 if(maxAmountOfEnvelopes < nmListMessagesBlock) |
|
323 { |
|
324 blockSize = maxAmountOfEnvelopes; |
|
325 } |
|
326 } |
|
327 |
260 |
328 |
261 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
329 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
262 if (!currentMailbox) { |
330 if (!currentMailbox) { |
263 User::Leave(KErrNotFound); |
331 User::Leave(KErrNotFound); |
264 } |
332 } |
290 CleanupResetAndDestroy<CFSMailMessage>::PushL(messages); |
358 CleanupResetAndDestroy<CFSMailMessage>::PushL(messages); |
291 |
359 |
292 //Message list is fetched in blocks to prevent OOM in protocol plugin side |
360 //Message list is fetched in blocks to prevent OOM in protocol plugin side |
293 bool moreMessagesToFollow(false); |
361 bool moreMessagesToFollow(false); |
294 moreMessagesToFollow = iterator->NextL( |
362 moreMessagesToFollow = iterator->NextL( |
295 TFSMailMsgId(), nmListMessagesBlock, messages); |
363 TFSMailMsgId(), blockSize, messages); |
296 for ( int i = nmListMessagesBlock; |
364 for ( int i = blockSize; |
297 i < nmMaxItemsInMessageList && moreMessagesToFollow ; |
365 i < maxLimit && moreMessagesToFollow ; |
298 i += nmListMessagesBlock ) { |
366 i += blockSize ) { |
299 moreMessagesToFollow = iterator->NextL( |
367 moreMessagesToFollow = iterator->NextL( |
300 messages[i-1]->GetMessageId(), nmListMessagesBlock, messages); |
368 messages[i-1]->GetMessageId(), blockSize, messages); |
301 } |
369 } |
302 |
370 |
303 //Add all found emails to the result list |
371 //Add all found emails to the result list |
304 for(TInt i=0; i<messages.Count(); i++) { |
372 for(TInt i=0; i<messages.Count(); i++) { |
305 NmMessageEnvelope* newEnvelope(NULL); |
373 NmMessageEnvelope* newEnvelope(NULL); |
341 Starts a message part fetching operation. |
409 Starts a message part fetching operation. |
342 |
410 |
343 \param mailboxId Id of the mailbox containing the folder. |
411 \param mailboxId Id of the mailbox containing the folder. |
344 \param folderId Id of the folder containing the message. |
412 \param folderId Id of the folder containing the message. |
345 \param messageId Id of message containing the message parts |
413 \param messageId Id of message containing the message parts |
346 \param messagePartIds array of ids to be fetched |
414 \param messagePartId id of message part |
347 |
415 |
348 \return An NmOperation object for the operation, ownership is transferred to caller |
416 \return An NmOperation object for the operation, ownership is transferred to caller |
349 */ |
417 */ |
350 NmOperation *NmFrameworkAdapter::fetchMessagePart( |
418 NmOperation *NmFrameworkAdapter::fetchMessagePart( |
351 const NmId &mailboxId, |
419 const NmId &mailboxId, |
354 const NmId &messagePartId) |
422 const NmId &messagePartId) |
355 { |
423 { |
356 NmOperation *oper = new NmFwaMessagePartFetchingOperation( |
424 NmOperation *oper = new NmFwaMessagePartFetchingOperation( |
357 mailboxId, folderId, messageId, messagePartId, *mFSfw); |
425 mailboxId, folderId, messageId, messagePartId, *mFSfw); |
358 return oper; |
426 return oper; |
|
427 } |
|
428 |
|
429 /*! |
|
430 Returns sharable file handle to message part content |
|
431 |
|
432 \param mailboxId Id of the mailbox containing the folder. |
|
433 \param folderId Id of the folder containing the message. |
|
434 \param messageId Id of message containing the message parts |
|
435 \param messagePartId id of message part |
|
436 |
|
437 \return XQSharableFile, sharable file object |
|
438 */ |
|
439 XQSharableFile NmFrameworkAdapter::messagePartFile( |
|
440 const NmId &mailboxId, |
|
441 const NmId &folderId, |
|
442 const NmId &messageId, |
|
443 const NmId &messagePartId) |
|
444 { |
|
445 XQSharableFile retFile; |
|
446 TFSMailDetails details(EFSMsgDataEnvelope); |
|
447 TFSMailMsgId fsMboxId(mailboxId); |
|
448 TFSMailMsgId fsFolderId(folderId); |
|
449 TFSMailMsgId fsMsgId(messageId); |
|
450 TFSMailMsgId fsMsgPartId(messagePartId); |
|
451 |
|
452 CFSMailMessage* fsMessage = NULL; |
|
453 int error = KErrNone; |
|
454 TRAP(error, fsMessage = mFSfw->GetMessageByUidL(fsMboxId, fsFolderId, |
|
455 fsMsgId, details) ); |
|
456 |
|
457 CFSMailMessagePart* fsMessagePart = NULL; |
|
458 if (fsMessage && error == KErrNone) { |
|
459 TRAP(error, fsMessagePart = fsMessage->ChildPartL(fsMsgPartId) ); |
|
460 |
|
461 } |
|
462 if (fsMessagePart && error == KErrNone) { |
|
463 RFile file = fsMessagePart->GetContentFileL(); |
|
464 retFile.setHandle(file); |
|
465 } |
|
466 return retFile; |
359 } |
467 } |
360 |
468 |
361 /*! |
469 /*! |
362 Get the id of a standard folder. |
470 Get the id of a standard folder. |
363 |
471 |
422 TRAPD(err, RefreshMailboxL(mailboxId)); // return value not used |
530 TRAPD(err, RefreshMailboxL(mailboxId)); // return value not used |
423 return ( err == KErrNone ) ? NmNoError : NmGeneralError; |
531 return ( err == KErrNone ) ? NmNoError : NmGeneralError; |
424 } |
532 } |
425 |
533 |
426 /*! |
534 /*! |
|
535 Connect to mailbox if not already connected and refresh. |
|
536 |
|
537 \param mailboxId Id of the mailbox. |
|
538 \return Async request id or error code. |
|
539 */ |
|
540 int NmFrameworkAdapter::goOnline(const NmId& mailboxId) |
|
541 { |
|
542 TRAPD(err, GoOnlineL(mailboxId)); // return value not used |
|
543 return ( err == KErrNone ) ? NmNoError : NmGeneralError; |
|
544 } |
|
545 |
|
546 /*! |
|
547 Disconnect to mailbox if not already disconnected. |
|
548 |
|
549 \param mailboxId Id of the mailbox. |
|
550 \return Async request id or error code. |
|
551 */ |
|
552 int NmFrameworkAdapter::goOffline(const NmId& mailboxId) |
|
553 { |
|
554 TRAPD(err, GoOfflineL(mailboxId)); // return value not used |
|
555 return ( err == KErrNone ) ? NmNoError : NmGeneralError; |
|
556 } |
|
557 |
|
558 /*! |
427 Sets content for the given message part. Client shouldn't create |
559 Sets content for the given message part. Client shouldn't create |
428 message part on its own. Instead it should be requested by calling |
560 message part on its own. Instead it should be requested by calling |
429 e.g. getMessageById. |
561 e.g. getMessageById. |
430 |
562 |
431 \param mailboxId Id of the mailbox containing the folder (Unused). |
563 \param mailboxId Id of the mailbox containing the folder (Unused). |
482 file.Seek(ESeekStart, dummyPos); |
614 file.Seek(ESeekStart, dummyPos); |
483 User::LeaveIfError(file.Read(dataPtr)); |
615 User::LeaveIfError(file.Read(dataPtr)); |
484 } |
616 } |
485 |
617 |
486 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml )) { |
618 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml )) { |
487 messagePart.setTextContent( QString::fromUtf8(reinterpret_cast<const char*>( |
619 QRegExp rxlen("(?:charset=)(?:\"?)([\\-\\_a-zA-Z0-9]+)", Qt::CaseInsensitive); |
488 dataPtr.Ptr()), fileSize), contentType); |
620 QString charset; |
|
621 int pos = rxlen.indexIn(contentType); |
|
622 if (pos > -1) { |
|
623 charset = rxlen.cap(1); |
|
624 } |
|
625 QByteArray msgBytes = QByteArray(reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize); |
|
626 QTextCodec *codec = QTextCodec::codecForName(charset.toAscii()); |
|
627 if (!codec) { |
|
628 codec = QTextCodec::codecForName("iso-8859-1"); |
|
629 } |
|
630 QString encodedStr = codec->toUnicode(msgBytes); |
|
631 messagePart.setTextContent(encodedStr, contentType); |
489 } |
632 } |
490 else { |
633 else { |
491 messagePart.setBinaryContent(QByteArray( |
634 messagePart.setBinaryContent(QByteArray( |
492 reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize), contentType); |
635 reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize), contentType); |
493 } |
636 } |
961 } |
1104 } |
962 return result; |
1105 return result; |
963 } |
1106 } |
964 |
1107 |
965 /*! |
1108 /*! |
|
1109 Leaving Go Online function |
|
1110 */ |
|
1111 int NmFrameworkAdapter::GoOnlineL(const NmId& mailboxId) |
|
1112 { |
|
1113 int result(KErrNotFound); |
|
1114 CFSMailBox *currentMailbox(NULL); |
|
1115 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
|
1116 if(currentMailbox) { |
|
1117 CleanupStack::PushL(currentMailbox); |
|
1118 currentMailbox->GoOnlineL(); |
|
1119 CleanupStack::PopAndDestroy(currentMailbox); |
|
1120 currentMailbox = NULL; |
|
1121 } |
|
1122 return result; |
|
1123 } |
|
1124 |
|
1125 /*! |
|
1126 Leaving Go Offline function |
|
1127 */ |
|
1128 int NmFrameworkAdapter::GoOfflineL(const NmId& mailboxId) |
|
1129 { |
|
1130 int result(KErrNotFound); |
|
1131 CFSMailBox *currentMailbox(NULL); |
|
1132 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
|
1133 if(currentMailbox) { |
|
1134 CleanupStack::PushL(currentMailbox); |
|
1135 currentMailbox->GoOfflineL(); |
|
1136 CleanupStack::PopAndDestroy(currentMailbox); |
|
1137 currentMailbox = NULL; |
|
1138 } |
|
1139 return result; |
|
1140 } |
|
1141 |
|
1142 /*! |
966 handles mailbox related events |
1143 handles mailbox related events |
967 */ |
1144 */ |
968 void NmFrameworkAdapter::handleMailboxEvent( TFSMailMsgId mailbox, NmMailboxEvent event) |
1145 void NmFrameworkAdapter::handleMailboxEvent( TFSMailMsgId mailbox, NmMailboxEvent event) |
969 { |
1146 { |
970 QList<NmId> mailboxIds; |
1147 QList<NmId> mailboxIds; |
1049 } |
1226 } |
1050 |
1227 |
1051 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox) |
1228 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox) |
1052 { |
1229 { |
1053 TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 ); |
1230 TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 ); |
1054 |
1231 NmOperationCompletionEvent event; |
1055 NmId id = NmConverter::mailMsgIdToNmId(mailbox); |
1232 event.mMailboxId = NmConverter::mailMsgIdToNmId(mailbox); |
|
1233 |
1056 switch(*state) |
1234 switch(*state) |
1057 { |
1235 { |
1058 case StartingSync: |
1236 case StartingSync: |
1059 { |
1237 { |
1060 emit syncStateEvent(Synchronizing, id); |
1238 event.mCompletionCode = NmNoError; |
|
1239 emit syncStateEvent(Synchronizing, event); |
|
1240 break; |
1061 } |
1241 } |
1062 break; |
|
1063 case FinishedSuccessfully: |
1242 case FinishedSuccessfully: |
1064 { |
1243 { |
1065 emit syncStateEvent(SyncComplete, id); |
1244 event.mCompletionCode = NmNoError; |
|
1245 emit syncStateEvent(SyncComplete, event); |
|
1246 break; |
1066 } |
1247 } |
1067 break; |
1248 case PasswordNotVerified: |
|
1249 { |
|
1250 event.mCompletionCode = NmAuthenticationError; |
|
1251 emit syncStateEvent(SyncComplete, event); |
|
1252 break; |
|
1253 } |
1068 case SyncError: |
1254 case SyncError: |
1069 default: |
1255 default: |
1070 { |
1256 { |
1071 emit syncStateEvent(SyncComplete,id); |
1257 event.mCompletionCode = NmServerConnectionError; |
|
1258 emit syncStateEvent(SyncComplete, event); |
|
1259 break; |
1072 } |
1260 } |
1073 break; |
|
1074 }; |
1261 }; |
1075 } |
1262 } |
1076 Q_EXPORT_PLUGIN(NmFrameworkAdapter) |
1263 Q_EXPORT_PLUGIN(NmFrameworkAdapter) |
1077 |
1264 |