89 NM_FUNCTION; |
89 NM_FUNCTION; |
90 |
90 |
91 QList<NmMailbox*> mailboxList; |
91 QList<NmMailbox*> mailboxList; |
92 int ret = listMailboxes(mailboxList); |
92 int ret = listMailboxes(mailboxList); |
93 |
93 |
94 if ( ret == NmNoError ) { |
94 if (ret == NmNoError) { |
95 QListIterator<NmMailbox*> iterator(mailboxList); |
95 QListIterator<NmMailbox*> iterator(mailboxList); |
96 while (iterator.hasNext()) { |
96 while (iterator.hasNext()) { |
97 NmMailbox *box = iterator.next(); |
97 NmMailbox *box = iterator.next(); |
98 mailboxIdList.append(box->id()); |
98 mailboxIdList.append(box->id()); |
99 delete box; |
99 delete box; |
119 id.SetNullId(); |
119 id.SetNullId(); |
120 RPointerArray<CFSMailBox> mailBoxes; |
120 RPointerArray<CFSMailBox> mailBoxes; |
121 |
121 |
122 //if id.IsNullId(), mailboxes are listed from all plugins. |
122 //if id.IsNullId(), mailboxes are listed from all plugins. |
123 //otherwise, only from the given one. |
123 //otherwise, only from the given one. |
124 TInt rcode = mFSfw->ListMailBoxes(id,mailBoxes); |
124 TInt rcode = mFSfw->ListMailBoxes(id, mailBoxes); |
125 |
125 |
126 if ( rcode == NmNoError ) { |
126 if (rcode == NmNoError) { |
127 // convert mailbox data to QT classes |
127 // convert mailbox data to QT classes |
128 NmMailbox* box(0); |
128 NmMailbox *box(NULL); |
129 for(TInt i=0;i<mailBoxes.Count();i++) { |
129 for (TInt i(0) ; i < mailBoxes.Count(); i++) { |
130 box = NULL; |
130 box = NULL; |
131 if (mailBoxes[i]) { |
131 if (mailBoxes[i]) { |
132 box = mailBoxes[i]->GetNmMailbox(); |
132 box = mailBoxes[i]->GetNmMailbox(); |
133 } |
133 } |
134 if (box) { |
134 if (box) { |
135 mailboxList.append(box); |
135 mailboxList.append(box); |
136 } |
136 } |
137 } |
137 } |
138 } |
138 } |
139 mailBoxes.ResetAndDestroy(); |
139 mailBoxes.ResetAndDestroy(); |
140 return rcode; |
140 return rcode; |
141 } |
141 } |
142 |
142 |
143 /*! |
143 /*! |
144 Get a pointer to a new mailbox object for the mailbox identified by id. |
144 Get a pointer to a new mailbox object for the mailbox identified by id. |
184 \param folderId Id of the requested folder |
184 \param folderId Id of the requested folder |
185 \param message Pointer reference to receive a folder object, ownership is transferred. |
185 \param message Pointer reference to receive a folder object, ownership is transferred. |
186 |
186 |
187 \return Error code. |
187 \return Error code. |
188 */ |
188 */ |
189 int NmFrameworkAdapter::getFolderById( const NmId& mailboxId, const NmId& folderId, NmFolder*& folder ) |
189 int NmFrameworkAdapter::getFolderById(const NmId& mailboxId, const NmId& folderId, NmFolder*& folder) |
190 { |
190 { |
191 NM_FUNCTION; |
191 NM_FUNCTION; |
192 |
192 |
193 TRAPD(err, getFolderByIdL( mailboxId, folderId, folder ) ); |
193 TRAPD(err, getFolderByIdL(mailboxId, folderId, folder)); |
194 return err; |
194 return err; |
195 } |
195 } |
196 |
196 |
197 /*! |
197 /*! |
198 Leaving version of getFolderById function |
198 Leaving version of getFolderById function |
199 */ |
199 */ |
200 void NmFrameworkAdapter::getFolderByIdL( const NmId& mailboxId, const NmId& folderId, NmFolder*& folder ) |
200 void NmFrameworkAdapter::getFolderByIdL(const NmId& mailboxId, const NmId& folderId, NmFolder*& folder) |
201 { |
201 { |
202 NM_FUNCTION; |
202 NM_FUNCTION; |
203 |
203 |
204 CFSMailFolder* fsFolder(NULL); |
204 CFSMailFolder* fsFolder(NULL); |
205 if (mFSfw) |
205 fsFolder = mFSfw->GetFolderByUidL(TFSMailMsgId(mailboxId), TFSMailMsgId(folderId)); |
206 { |
206 if (fsFolder) { |
207 fsFolder = mFSfw->GetFolderByUidL(TFSMailMsgId(mailboxId), TFSMailMsgId(folderId)); |
207 folder = fsFolder->GetNmFolder(); |
208 if (fsFolder) |
208 delete fsFolder; |
209 { |
209 fsFolder = NULL; |
210 folder = fsFolder->GetNmFolder(); |
210 } else { |
211 delete fsFolder; |
211 User::Leave(KErrNotFound); |
212 fsFolder = NULL; |
212 } |
213 } |
213 } |
214 else |
|
215 { |
|
216 User::Leave(KErrNotFound); |
|
217 } |
|
218 } |
|
219 } |
|
220 |
214 |
221 |
215 |
222 /*! |
216 /*! |
223 Returns message from the store together with whole message part structure |
217 Returns message from the store together with whole message part structure |
224 |
218 |
265 message = newMessage->GetNmMessage(); |
259 message = newMessage->GetNmMessage(); |
266 //assign all children found by mail plugin to NmMessage |
260 //assign all children found by mail plugin to NmMessage |
267 |
261 |
268 message->removeAllChildParts(); |
262 message->removeAllChildParts(); |
269 childrenToNmMessagePartL(newMessage, message); |
263 childrenToNmMessagePartL(newMessage, message); |
|
264 delete newMessage; |
|
265 newMessage = NULL; |
270 } |
266 } |
271 else { |
267 else { |
272 User::Leave(KErrNotFound); |
268 User::Leave(KErrNotFound); |
273 } |
269 } |
274 } |
270 } |
275 |
271 |
276 /*! |
272 /*! |
277 Returns list of folders in a mailbox. |
273 Returns list of folders in a mailbox. |
278 |
274 |
279 \param mailboxId Id of the mailbox containing the folder. |
275 \param mailboxId Id of the mailbox containing the folder. |
280 \param folderList Reference to a pointer list to receive pointers to the folders. |
276 \param folderList Reference to a pointer list to receive pointers to the folders. |
281 |
277 |
282 \return Error code. |
278 \return Error code. |
283 */ |
279 */ |
284 int NmFrameworkAdapter::listFolders( |
280 int NmFrameworkAdapter::listFolders( |
285 const NmId& mailboxId, |
281 const NmId& mailboxId, |
286 QList<NmFolder*>& folderList) |
282 QList<NmFolder*>& folderList) |
287 { |
283 { |
288 NM_FUNCTION; |
284 NM_FUNCTION; |
289 |
285 int err(NmNoError); |
290 CFSMailBox* currentMailbox = NULL; |
286 CFSMailBox* currentMailbox(NULL); |
291 TRAPD (err, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId)); |
287 TRAP(err, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId)); |
292 if (KErrNone == err) { |
288 if (KErrNone == err && currentMailbox) { |
293 RPointerArray<CFSMailFolder> folders = currentMailbox->ListFolders(); |
289 RPointerArray<CFSMailFolder> folders = currentMailbox->ListFolders(); |
294 for (int i = 0; i < folders.Count(); i++) { |
290 for (int i = 0; i < folders.Count(); i++) { |
295 folderList.append(folders[i]->GetNmFolder()); |
291 folderList.append(folders[i]->GetNmFolder()); |
296 } |
292 } |
297 return KErrNone; |
293 delete currentMailbox; |
298 } |
294 currentMailbox = NULL; |
299 else { |
295 } else { |
300 return err; |
296 err = NmNotFoundError; |
301 } |
297 } |
|
298 return err; |
302 } |
299 } |
303 |
300 |
304 |
301 |
305 /*! |
302 /*! |
306 Fetches all the messages from the given folder and appends their meta data |
303 Fetches all the messages from the given folder and appends their meta data |
314 CFSMailFolder *folder, |
311 CFSMailFolder *folder, |
315 QList<NmMessageEnvelope*> &messageEnvelopeList, |
312 QList<NmMessageEnvelope*> &messageEnvelopeList, |
316 const int maxEnvelopeCount) |
313 const int maxEnvelopeCount) |
317 { |
314 { |
318 NM_FUNCTION; |
315 NM_FUNCTION; |
319 |
316 // validity of input parameters is checked in calling function |
320 if (!folder || maxEnvelopeCount < 1) { |
|
321 return; |
|
322 } |
|
323 |
|
324 int blockSize = NmListMessagesBlock; |
317 int blockSize = NmListMessagesBlock; |
325 int maxItemCount = NmMaxItemsInMessageList; |
318 int maxItemCount = NmMaxItemsInMessageList; |
326 |
319 |
327 if (maxEnvelopeCount < NmMaxItemsInMessageList) { |
320 if (maxEnvelopeCount < NmMaxItemsInMessageList) { |
328 maxItemCount = maxEnvelopeCount; |
321 maxItemCount = maxEnvelopeCount; |
426 QList<NmMessageEnvelope*> &messageEnvelopeList, |
419 QList<NmMessageEnvelope*> &messageEnvelopeList, |
427 const int maxAmountOfEnvelopes) |
420 const int maxAmountOfEnvelopes) |
428 { |
421 { |
429 NM_FUNCTION; |
422 NM_FUNCTION; |
430 |
423 |
431 TInt err = KErrNone; |
424 TInt err(KErrNone); |
432 TRAP(err, listMessagesL(mailboxId,folderId, messageEnvelopeList,maxAmountOfEnvelopes) ); |
425 TRAP(err, listMessagesL(mailboxId,folderId, messageEnvelopeList,maxAmountOfEnvelopes) ); |
433 return err; |
426 return err; |
434 } |
427 } |
435 |
428 |
436 |
429 |
505 QList<NmMessage*> &messageList, |
498 QList<NmMessage*> &messageList, |
506 const int maxAmountOfEnvelopes) |
499 const int maxAmountOfEnvelopes) |
507 { |
500 { |
508 NM_FUNCTION; |
501 NM_FUNCTION; |
509 |
502 |
510 CFSMailBox * currentMailbox(NULL); |
503 CFSMailBox* currentMailbox(NULL); |
511 CFSMailFolder* folder(NULL); |
504 CFSMailFolder* folder(NULL); |
512 |
505 |
513 //If we are requesting 0 or less mails so we can return |
506 //If we are requesting 0 or less mails so we can return |
514 if( maxAmountOfEnvelopes <= 0) |
507 if( maxAmountOfEnvelopes <= 0) |
515 { |
508 { |
728 // Get the mailbox with the given ID. |
723 // Get the mailbox with the given ID. |
729 CFSMailBox *mailbox(NULL); |
724 CFSMailBox *mailbox(NULL); |
730 mailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
725 mailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
731 |
726 |
732 if (mailbox) { |
727 if (mailbox) { |
|
728 CleanupStack::PushL(mailbox); |
733 RPointerArray<TDesC> strings; |
729 RPointerArray<TDesC> strings; |
734 CleanupResetAndDestroy<TDesC>::PushL(strings); |
730 CleanupResetAndDestroy<TDesC>::PushL(strings); |
735 |
731 |
736 // Convert the search strings to HBufCs. |
732 // Convert the search strings to HBufCs. |
737 foreach (QString string, searchStrings) { |
733 foreach (QString string, searchStrings) { |
844 TFSMailMsgId fsMboxId(mailboxId); |
841 TFSMailMsgId fsMboxId(mailboxId); |
845 TFSMailMsgId fsFolderId(folderId); |
842 TFSMailMsgId fsFolderId(folderId); |
846 TFSMailMsgId fsMsgId(messageId); |
843 TFSMailMsgId fsMsgId(messageId); |
847 TFSMailMsgId fsMsgPartId(messagePartId); |
844 TFSMailMsgId fsMsgPartId(messagePartId); |
848 |
845 |
849 CFSMailMessage* fsMessage = NULL; |
846 CFSMailMessage* fsMessage(NULL); |
850 int error = KErrNone; |
847 int error(KErrNone); |
851 TRAP(error, fsMessage = mFSfw->GetMessageByUidL(fsMboxId, fsFolderId, |
848 TRAP(error, fsMessage = mFSfw->GetMessageByUidL(fsMboxId, fsFolderId, |
852 fsMsgId, details) ); |
849 fsMsgId, details) ); |
853 |
850 |
854 CFSMailMessagePart* fsMessagePart = NULL; |
851 CFSMailMessagePart* fsMessagePart(NULL); |
855 if (fsMessage && error == KErrNone) { |
852 if (fsMessage && error == KErrNone) { |
856 TRAP(error, fsMessagePart = fsMessage->ChildPartL(fsMsgPartId) ); |
853 TRAP(error, fsMessagePart = fsMessage->ChildPartL(fsMsgPartId) ); |
857 |
854 |
858 } |
855 } |
859 if (fsMessagePart && error == KErrNone) { |
856 if (fsMessagePart && error == KErrNone) { |
860 RFile file = fsMessagePart->GetContentFileL(); |
857 RFile file = fsMessagePart->GetContentFileL(); |
861 retFile.setHandle(file); |
858 retFile.setHandle(file); |
862 } |
859 } |
|
860 delete fsMessagePart; |
|
861 fsMessagePart = NULL; |
|
862 delete fsMessage; |
|
863 fsMessage = NULL; |
863 return retFile; |
864 return retFile; |
864 } |
865 } |
865 |
866 |
866 /*! |
867 /*! |
867 Get the id of a standard folder. |
868 Get the id of a standard folder. |
877 { |
878 { |
878 NM_FUNCTION; |
879 NM_FUNCTION; |
879 |
880 |
880 TFSMailMsgId folderId; |
881 TFSMailMsgId folderId; |
881 NmId resultId(0); |
882 NmId resultId(0); |
882 CFSMailBox * currentMailbox(NULL); |
883 CFSMailBox* currentMailbox(NULL); |
883 |
884 |
884 TRAPD(error, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId) ); |
885 TRAPD(error, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId)); |
885 |
886 |
886 if( !currentMailbox || error != KErrNone ) { |
887 if(!currentMailbox || error != KErrNone) { |
887 return resultId; |
888 return resultId; |
888 } |
889 } |
889 |
890 |
890 switch(folderType) { |
891 switch(folderType) { |
891 case NmFolderInbox: |
892 case NmFolderInbox: |
892 folderId = currentMailbox->GetStandardFolderId( EFSInbox ); |
893 folderId = currentMailbox->GetStandardFolderId(EFSInbox); |
893 break; |
894 break; |
894 case NmFolderOutbox: |
895 case NmFolderOutbox: |
895 folderId = currentMailbox->GetStandardFolderId( EFSOutbox ); |
896 folderId = currentMailbox->GetStandardFolderId(EFSOutbox); |
896 break; |
897 break; |
897 case NmFolderDrafts: |
898 case NmFolderDrafts: |
898 folderId = currentMailbox->GetStandardFolderId( EFSDraftsFolder ); |
899 folderId = currentMailbox->GetStandardFolderId(EFSDraftsFolder); |
899 break; |
900 break; |
900 case NmFolderSent: |
901 case NmFolderSent: |
901 folderId = currentMailbox->GetStandardFolderId( EFSSentFolder ); |
902 folderId = currentMailbox->GetStandardFolderId(EFSSentFolder); |
902 break; |
903 break; |
903 case NmFolderDeleted: |
904 case NmFolderDeleted: |
904 folderId = currentMailbox->GetStandardFolderId( EFSDeleted ); |
905 folderId = currentMailbox->GetStandardFolderId(EFSDeleted); |
905 break; |
906 break; |
906 case NmFolderOther: |
907 case NmFolderOther: |
907 default: |
908 default: |
908 folderId = currentMailbox->GetStandardFolderId( EFSOther ); |
909 folderId = currentMailbox->GetStandardFolderId(EFSOther); |
909 break; |
910 break; |
910 } |
911 } |
911 |
912 |
912 delete currentMailbox; |
913 delete currentMailbox; |
913 currentMailbox = NULL; |
914 currentMailbox = NULL; |
914 |
915 |
955 int NmFrameworkAdapter::goOffline(const NmId& mailboxId) |
956 int NmFrameworkAdapter::goOffline(const NmId& mailboxId) |
956 { |
957 { |
957 NM_FUNCTION; |
958 NM_FUNCTION; |
958 |
959 |
959 TRAPD(err, GoOfflineL(mailboxId)); // return value not used |
960 TRAPD(err, GoOfflineL(mailboxId)); // return value not used |
960 return ( err == KErrNone ) ? NmNoError : NmGeneralError; |
961 return (err == KErrNone) ? NmNoError : NmGeneralError; |
961 } |
962 } |
962 |
963 |
963 /*! |
964 /*! |
964 Sets content for the given message part. Client shouldn't create |
965 Sets content for the given message part. Client shouldn't create |
965 message part on its own. Instead it should be requested by calling |
966 message part on its own. Instead it should be requested by calling |
998 CFSMailMessagePart* cfsPart = CFSMailMessagePart::NewLC(messageId,messagePart); |
999 CFSMailMessagePart* cfsPart = CFSMailMessagePart::NewLC(messageId,messagePart); |
999 cfsPart->SetMailBoxId(TFSMailMsgId(mailboxId)); |
1000 cfsPart->SetMailBoxId(TFSMailMsgId(mailboxId)); |
1000 cfsPart->SetFolderId(TFSMailMsgId(folderId)); |
1001 cfsPart->SetFolderId(TFSMailMsgId(folderId)); |
1001 QString contentType = messagePart.contentType(); |
1002 QString contentType = messagePart.contentType(); |
1002 |
1003 |
1003 if (cfsPart && contentType.startsWith(NmContentTypeTextPlain)) { |
1004 if (contentType.startsWith(NmContentTypeTextPlain)) { |
1004 // add 1 for max size for zero termination and prevend 0 size hbufc |
1005 // add 1 for max size for zero termination and prevend 0 size hbufc |
1005 HBufC* data = HBufC::NewLC(cfsPart->FetchedContentSize()+1); |
1006 HBufC* data = HBufC::NewLC(cfsPart->FetchedContentSize()+1); |
1006 TPtr dataPtr = data->Des(); |
1007 TPtr dataPtr = data->Des(); |
1007 TInt startOffset = 0; |
1008 TInt startOffset = 0; |
1008 |
1009 |
1009 cfsPart->GetContentToBufferL(dataPtr, startOffset); |
1010 cfsPart->GetContentToBufferL(dataPtr, startOffset); |
1010 messagePart.setTextContent(NmConverter::toQString(dataPtr), contentType); |
1011 messagePart.setTextContent(NmConverter::toQString(dataPtr), contentType); |
1011 CleanupStack::PopAndDestroy(data); |
1012 CleanupStack::PopAndDestroy(data); |
1012 } |
1013 } else { |
1013 else if (cfsPart){ |
|
1014 RFile file = cfsPart->GetContentFileL(); |
1014 RFile file = cfsPart->GetContentFileL(); |
1015 TInt fileSize = 0; |
1015 TInt fileSize = 0; |
1016 file.Size(fileSize); |
1016 file.Size(fileSize); |
1017 if (fileSize != 0) { |
1017 if (fileSize != 0) { |
1018 HBufC8* data = HBufC8::NewLC(fileSize); |
1018 HBufC8* data = HBufC8::NewLC(fileSize); |
1022 TInt dummyPos = 0; |
1022 TInt dummyPos = 0; |
1023 file.Seek(ESeekStart, dummyPos); |
1023 file.Seek(ESeekStart, dummyPos); |
1024 User::LeaveIfError(file.Read(dataPtr)); |
1024 User::LeaveIfError(file.Read(dataPtr)); |
1025 } |
1025 } |
1026 |
1026 |
1027 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml )) { |
1027 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml)) { |
1028 QRegExp rxlen("(?:charset=)(?:\"?)([\\-\\_a-zA-Z0-9]+)", Qt::CaseInsensitive); |
1028 QRegExp rxlen("(?:charset=)(?:\"?)([\\-\\_a-zA-Z0-9]+)", Qt::CaseInsensitive); |
1029 QString charset; |
1029 QString charset; |
1030 int pos = rxlen.indexIn(contentType); |
1030 int pos = rxlen.indexIn(contentType); |
1031 if (pos > -1) { |
1031 if (pos > -1) { |
1032 charset = rxlen.cap(1); |
1032 charset = rxlen.cap(1); |
1036 if (!codec) { |
1036 if (!codec) { |
1037 codec = QTextCodec::codecForName("UTF-8"); |
1037 codec = QTextCodec::codecForName("UTF-8"); |
1038 } |
1038 } |
1039 QString encodedStr = codec->toUnicode(msgBytes); |
1039 QString encodedStr = codec->toUnicode(msgBytes); |
1040 messagePart.setTextContent(encodedStr, contentType); |
1040 messagePart.setTextContent(encodedStr, contentType); |
1041 } |
1041 } else { |
1042 else { |
|
1043 messagePart.setBinaryContent(QByteArray( |
1042 messagePart.setBinaryContent(QByteArray( |
1044 reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize), contentType); |
1043 reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize), contentType); |
1045 } |
1044 } |
1046 CleanupStack::PopAndDestroy(data); |
1045 CleanupStack::PopAndDestroy(data); |
1047 } |
1046 } |
1048 file.Close(); |
1047 file.Close(); |
1049 } |
1048 } |
1050 else { |
|
1051 // null cfsPart |
|
1052 User::Leave(KErrNotFound); |
|
1053 } |
|
1054 |
|
1055 CleanupStack::PopAndDestroy(cfsPart); |
1049 CleanupStack::PopAndDestroy(cfsPart); |
1056 } |
1050 } |
1057 |
1051 |
1058 /*! |
1052 /*! |
1059 Deletes the listed messages from specific mailbox and folder. |
1053 Deletes the listed messages from specific mailbox and folder. |
1063 \param messageIdList List of ids of the messages to be deleted. |
1057 \param messageIdList List of ids of the messages to be deleted. |
1064 |
1058 |
1065 \return Error code. |
1059 \return Error code. |
1066 */ |
1060 */ |
1067 int NmFrameworkAdapter::deleteMessages( |
1061 int NmFrameworkAdapter::deleteMessages( |
1068 const NmId &mailboxId, |
1062 const NmId &mailboxId, |
1069 const NmId &folderId, |
1063 const NmId &folderId, |
1070 const QList<NmId> &messageIdList) |
1064 const QList<NmId> &messageIdList) |
1071 { |
1065 { |
1072 NM_FUNCTION; |
1066 NM_FUNCTION; |
1073 |
1067 |
1074 TInt err = NmNoError; |
1068 TInt err(NmNoError); |
1075 RArray<TFSMailMsgId> messageIds; |
1069 RArray<TFSMailMsgId> messageIds; |
1076 for (TInt i=0; i<messageIdList.size(); i++) { |
1070 for (TInt i(0); i < messageIdList.size(); i++) { |
1077 err = messageIds.Append(TFSMailMsgId(messageIdList[i])); |
1071 err = messageIds.Append(TFSMailMsgId(messageIdList[i])); |
1078 if (err!=NmNoError) { |
1072 if (err != NmNoError) { |
1079 break; |
1073 break; |
1080 } |
1074 } |
1081 } |
1075 } |
1082 if (NmNoError == err) { |
1076 if (NmNoError == err) { |
1083 TRAP(err, mFSfw->DeleteMessagesByUidL(TFSMailMsgId(mailboxId), TFSMailMsgId(folderId), messageIds)); |
1077 TRAP(err, mFSfw->DeleteMessagesByUidL(TFSMailMsgId(mailboxId), TFSMailMsgId(folderId), messageIds)); |
1084 } |
1078 } |
1085 messageIds.Close(); |
1079 messageIds.Close(); |
1086 |
1080 |
1087 return ( err == NmNoError ) ? NmNoError : NmGeneralError; |
1081 return (err == NmNoError) ? NmNoError : NmGeneralError; |
1088 } |
1082 } |
1089 |
1083 |
1090 /*! |
1084 /*! |
1091 Starts an async operation to store listed message envelopes to the given mailbox |
1085 Starts an async operation to store listed message envelopes to the given mailbox |
1092 |
1086 |
1095 \param envelopeList List of the envelope objects to store. |
1089 \param envelopeList List of the envelope objects to store. |
1096 |
1090 |
1097 \return NmStoreEnvelopesOperation |
1091 \return NmStoreEnvelopesOperation |
1098 */ |
1092 */ |
1099 QPointer<NmStoreEnvelopesOperation> NmFrameworkAdapter::storeEnvelopes( |
1093 QPointer<NmStoreEnvelopesOperation> NmFrameworkAdapter::storeEnvelopes( |
1100 const NmId &mailboxId, |
1094 const NmId &mailboxId, |
1101 const NmId &folderId, |
1095 const NmId &folderId, |
1102 const QList<const NmMessageEnvelope*> &envelopeList) |
1096 const QList<const NmMessageEnvelope*> &envelopeList) |
1103 { |
1097 { |
1104 NM_FUNCTION; |
1098 NM_FUNCTION; |
1105 |
1099 |
1106 Q_UNUSED(folderId); |
1100 Q_UNUSED(folderId); |
1107 |
1101 |
1108 QPointer<NmStoreEnvelopesOperation> operation(NULL); |
1102 QPointer<NmStoreEnvelopesOperation> operation(NULL); |
1109 RPointerArray<CFSMailMessage> envelopeMessages; |
1103 RPointerArray<CFSMailMessage> envelopeMessages; |
1110 |
1104 |
1111 int count = envelopeList.count(); |
1105 int count(envelopeList.count()); |
1112 for(int i(0); i < count; i++) { |
1106 for(int i(0); i < count; i++) { |
1113 TRAP_IGNORE(envelopeMessages.AppendL(mailMessageFromEnvelopeL(*envelopeList.at(i)))); |
1107 TRAP_IGNORE(envelopeMessages.AppendL(mailMessageFromEnvelopeL(*envelopeList.at(i)))); |
1114 } |
1108 } |
1115 |
1109 |
1116 if (envelopeMessages.Count()) { |
1110 if (envelopeMessages.Count()) { |
1240 // Mail related events: |
1234 // Mail related events: |
1241 // signal: |
1235 // signal: |
1242 // void messageEvent( |
1236 // void messageEvent( |
1243 // NmMessageEvent event, |
1237 // NmMessageEvent event, |
1244 // const NmId &folderId, |
1238 // const NmId &folderId, |
1245 // QList<NmId> &messageIds); |
1239 // QList<NmId> &messageIds |
|
1240 // const NmId& mailboxId); |
1246 // |
1241 // |
1247 // enum NmMessageEvent |
1242 // enum NmMessageEvent |
1248 // NmMessageCreated, |
1243 // NmMessageCreated, |
1249 // NmMessageChanged, |
1244 // NmMessageChanged, |
1250 // NmMessageDeleted |
1245 // NmMessageDeleted |
1362 TRAPD(error, copyMessagesL(mailboxId, messageIds, sourceFolderId, destinationFolderId)); |
1357 TRAPD(error, copyMessagesL(mailboxId, messageIds, sourceFolderId, destinationFolderId)); |
1363 return error; |
1358 return error; |
1364 } |
1359 } |
1365 |
1360 |
1366 /*! |
1361 /*! |
|
1362 Gets the signature for the given mailbox. |
|
1363 |
|
1364 \param mailboxId Id of the mailbox. |
|
1365 */ |
|
1366 int NmFrameworkAdapter::getSignature(const NmId &mailboxId, QString *&signature) |
|
1367 { |
|
1368 NM_FUNCTION; |
|
1369 TRAPD(error, getSignatureL(mailboxId, signature)); |
|
1370 |
|
1371 return error; |
|
1372 } |
|
1373 |
|
1374 /*! |
1367 Subscribe to events from a mailbox. |
1375 Subscribe to events from a mailbox. |
1368 |
1376 |
1369 \param mailboxId Id of the mailbox. |
1377 \param mailboxId Id of the mailbox. |
1370 */ |
1378 */ |
1371 void NmFrameworkAdapter::subscribeMailboxEvents(const NmId& mailboxId) |
1379 void NmFrameworkAdapter::subscribeMailboxEvents(const NmId& mailboxId) |
1385 NM_FUNCTION; |
1393 NM_FUNCTION; |
1386 |
1394 |
1387 mFSfw->UnsubscribeMailboxEvents(mailboxId, *this); |
1395 mFSfw->UnsubscribeMailboxEvents(mailboxId, *this); |
1388 } |
1396 } |
1389 |
1397 |
1390 NmId NmFrameworkAdapter::getMailboxIdByMailMsgId(TFSMailMsgId mailbox) |
|
1391 { |
|
1392 NM_FUNCTION; |
|
1393 |
|
1394 NmId nmId(0); |
|
1395 |
|
1396 QList<NmId> mailboxIds; |
|
1397 listMailboxIds(mailboxIds); |
|
1398 |
|
1399 QListIterator<NmId> iterator(mailboxIds); |
|
1400 while (iterator.hasNext()) { |
|
1401 nmId = iterator.next(); |
|
1402 if (nmId.id32() == mailbox.Id()) { |
|
1403 break; |
|
1404 } |
|
1405 } |
|
1406 mailboxIds.clear(); |
|
1407 return nmId; |
|
1408 } |
|
1409 |
1398 |
1410 /*! |
1399 /*! |
1411 Leaving version of removeMessage |
1400 Leaving version of removeMessage |
1412 */ |
1401 */ |
1413 void NmFrameworkAdapter::removeMessageL( |
1402 void NmFrameworkAdapter::removeMessageL( |
1433 const QList<quint64>& messageIds, |
1422 const QList<quint64>& messageIds, |
1434 const NmId& sourceFolderId, |
1423 const NmId& sourceFolderId, |
1435 const NmId& destinationFolderId) |
1424 const NmId& destinationFolderId) |
1436 { |
1425 { |
1437 NM_FUNCTION; |
1426 NM_FUNCTION; |
1438 |
1427 TInt count(messageIds.count()); |
|
1428 if (!count) { |
|
1429 return; |
|
1430 } |
1439 RArray<TFSMailMsgId> messages; |
1431 RArray<TFSMailMsgId> messages; |
1440 RArray<TFSMailMsgId> copiedMessages; |
1432 RArray<TFSMailMsgId> copiedMessages; |
1441 |
1433 |
1442 CleanupClosePushL(messages); |
1434 CleanupClosePushL(messages); |
1443 CleanupClosePushL(copiedMessages); |
1435 CleanupClosePushL(copiedMessages); |
1444 |
1436 |
1445 for (TInt i = 0; i < messageIds.count(); i++) { |
1437 for (TInt i = 0; i < count; i++) { |
1446 NmId tmpId(messageIds[i]); |
1438 NmId tmpId(messageIds[i]); |
1447 messages.AppendL(TFSMailMsgId(tmpId)); |
1439 messages.AppendL(TFSMailMsgId(tmpId)); |
1448 } |
1440 } |
1449 |
1441 |
1450 CFSMailBox* mailBox = NULL; |
1442 CFSMailBox* mailBox(NULL); |
1451 mailBox = mFSfw->GetMailBoxByUidL(mailboxId); |
1443 mailBox = mFSfw->GetMailBoxByUidL(mailboxId); |
1452 if (mailBox) { |
1444 if (mailBox) { |
1453 mailBox->CopyMessagesL(messages, copiedMessages, |
1445 mailBox->CopyMessagesL(messages, copiedMessages, |
1454 TFSMailMsgId(sourceFolderId), |
1446 TFSMailMsgId(sourceFolderId), |
1455 TFSMailMsgId(destinationFolderId)); |
1447 TFSMailMsgId(destinationFolderId)); |
1456 delete mailBox; |
1448 delete mailBox; |
1457 } |
1449 mailBox = NULL; |
1458 |
1450 } else { |
|
1451 User::Leave(NmNotFoundError); |
|
1452 } |
1459 CleanupStack::PopAndDestroy(2,&messages); |
1453 CleanupStack::PopAndDestroy(2,&messages); |
1460 } |
1454 } |
|
1455 |
|
1456 /*! |
|
1457 Leaving version of getSignature |
|
1458 */ |
|
1459 void NmFrameworkAdapter::getSignatureL(const NmId &mailboxId, QString *&signature) |
|
1460 { |
|
1461 NM_FUNCTION; |
|
1462 |
|
1463 HBufC *sig = mFSfw->GetSignatureL(TFSMailMsgId(mailboxId)); |
|
1464 |
|
1465 if (sig) { |
|
1466 signature = new QString(NmConverter::toQString(*sig)); |
|
1467 } |
|
1468 } |
|
1469 |
1461 |
1470 |
1462 /*! |
1471 /*! |
1463 Sends the given message. |
1472 Sends the given message. |
1464 */ |
1473 */ |
1465 QPointer<NmMessageSendingOperation> NmFrameworkAdapter::sendMessage( |
1474 QPointer<NmMessageSendingOperation> NmFrameworkAdapter::sendMessage( |
1466 NmMessage *message) |
1475 NmMessage *message) |
1467 { |
1476 { |
1468 NM_FUNCTION; |
1477 NM_FUNCTION; |
1469 |
1478 |
1470 QPointer<NmMessageSendingOperation>oper = new NmFwaMessageSendingOperation(*this, message, *mFSfw); |
1479 QPointer<NmMessageSendingOperation>oper = new NmFwaMessageSendingOperation(*this, message, *mFSfw); |
1471 return oper; |
1480 return oper; |
1472 } |
1481 } |
1473 |
1482 |
1474 /*! |
1483 /*! |
1475 Add attachment into the given message. |
1484 Add attachment into the given message. |
1476 */ |
1485 */ |
1507 CFSMailBox* mailBox = NULL; |
1516 CFSMailBox* mailBox = NULL; |
1508 TRAPD(err, mailBox = mFSfw->GetMailBoxByUidL(TFSMailMsgId(mailboxId)) ); |
1517 TRAPD(err, mailBox = mFSfw->GetMailBoxByUidL(TFSMailMsgId(mailboxId)) ); |
1509 if (KErrNone == err && mailBox) { |
1518 if (KErrNone == err && mailBox) { |
1510 TSSMailSyncState syncState = mailBox->CurrentSyncState(); |
1519 TSSMailSyncState syncState = mailBox->CurrentSyncState(); |
1511 delete mailBox; |
1520 delete mailBox; |
|
1521 mailBox = NULL; |
1512 if (EmailSyncing == syncState) { |
1522 if (EmailSyncing == syncState) { |
1513 return Synchronizing; |
1523 return Synchronizing; |
1514 } |
1524 } |
1515 else { |
1525 else { |
1516 return SyncComplete; |
1526 return SyncComplete; |
1526 */ |
1536 */ |
1527 NmConnectState NmFrameworkAdapter::connectionState(const NmId& mailboxId) const |
1537 NmConnectState NmFrameworkAdapter::connectionState(const NmId& mailboxId) const |
1528 { |
1538 { |
1529 NM_FUNCTION; |
1539 NM_FUNCTION; |
1530 |
1540 |
1531 CFSMailBox* mailBox = NULL; |
1541 CFSMailBox* mailBox(NULL); |
1532 TRAPD(err, mailBox = mFSfw->GetMailBoxByUidL(TFSMailMsgId(mailboxId)) ); |
1542 TRAPD(err, mailBox = mFSfw->GetMailBoxByUidL(TFSMailMsgId(mailboxId)) ); |
1533 if (KErrNone == err && mailBox) { |
1543 if (KErrNone == err && mailBox) { |
1534 TFSMailBoxStatus status = mailBox->GetMailBoxStatus(); |
1544 TFSMailBoxStatus status = mailBox->GetMailBoxStatus(); |
1535 delete mailBox; |
1545 delete mailBox; |
|
1546 mailBox = NULL; |
1536 if (status == EFSMailBoxOnline) { |
1547 if (status == EFSMailBoxOnline) { |
1537 return Connected; |
1548 return Connected; |
1538 } |
1549 } |
1539 else { |
1550 else { |
1540 return Disconnected; |
1551 return Disconnected; |
1601 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1612 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1602 if(currentMailbox) { |
1613 if(currentMailbox) { |
1603 CleanupStack::PushL(currentMailbox); |
1614 CleanupStack::PushL(currentMailbox); |
1604 result = currentMailbox->RefreshNowL(); |
1615 result = currentMailbox->RefreshNowL(); |
1605 CleanupStack::PopAndDestroy(currentMailbox); |
1616 CleanupStack::PopAndDestroy(currentMailbox); |
1606 currentMailbox = NULL; |
|
1607 } |
1617 } |
1608 return result; |
1618 return result; |
1609 } |
1619 } |
1610 |
1620 |
1611 /*! |
1621 /*! |
1620 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1630 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1621 if(currentMailbox) { |
1631 if(currentMailbox) { |
1622 CleanupStack::PushL(currentMailbox); |
1632 CleanupStack::PushL(currentMailbox); |
1623 currentMailbox->GoOnlineL(); |
1633 currentMailbox->GoOnlineL(); |
1624 CleanupStack::PopAndDestroy(currentMailbox); |
1634 CleanupStack::PopAndDestroy(currentMailbox); |
1625 currentMailbox = NULL; |
|
1626 } |
1635 } |
1627 return result; |
1636 return result; |
1628 } |
1637 } |
1629 |
1638 |
1630 /*! |
1639 /*! |
1632 */ |
1641 */ |
1633 int NmFrameworkAdapter::GoOfflineL(const NmId& mailboxId) |
1642 int NmFrameworkAdapter::GoOfflineL(const NmId& mailboxId) |
1634 { |
1643 { |
1635 NM_FUNCTION; |
1644 NM_FUNCTION; |
1636 |
1645 |
1637 int result(KErrNotFound); |
1646 int result(KErrNotFound); |
1638 CFSMailBox *currentMailbox(NULL); |
1647 CFSMailBox *currentMailbox(NULL); |
1639 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1648 currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId); |
1640 if(currentMailbox) { |
1649 if(currentMailbox) { |
1641 CleanupStack::PushL(currentMailbox); |
1650 CleanupStack::PushL(currentMailbox); |
1642 currentMailbox->GoOfflineL(); |
1651 currentMailbox->GoOfflineL(); |
1643 CleanupStack::PopAndDestroy(currentMailbox); |
1652 CleanupStack::PopAndDestroy(currentMailbox); |
1644 currentMailbox = NULL; |
|
1645 } |
1653 } |
1646 return result; |
1654 return result; |
1647 } |
1655 } |
1648 |
1656 |
1649 /*! |
1657 /*! |
1650 handles mailbox related events |
1658 handles mailbox related events |
1651 */ |
1659 */ |
1652 void NmFrameworkAdapter::handleMailboxEvent( TFSMailMsgId mailbox, NmMailboxEvent event) |
1660 void NmFrameworkAdapter::handleMailboxEvent(TFSMailMsgId mailbox, NmMailboxEvent event) |
1653 { |
1661 { |
1654 NM_FUNCTION; |
1662 NM_FUNCTION; |
1655 |
1663 |
1656 QList<NmId> mailboxIds; |
1664 QList<NmId> mailboxIds; |
1657 NmId nmId; |
1665 NmId nmId = mailbox.GetNmId(); |
1658 if (event == NmMailboxDeleted || |
|
1659 event == NmMailboxCreated || |
|
1660 event == NmMailboxChanged) { |
|
1661 nmId = mailbox.GetNmId(); |
|
1662 } else { |
|
1663 nmId = getMailboxIdByMailMsgId(mailbox); |
|
1664 } |
|
1665 mailboxIds.append(nmId); |
1666 mailboxIds.append(nmId); |
1666 emit mailboxEvent(event, mailboxIds); |
1667 emit mailboxEvent(event, mailboxIds); |
1667 } |
1668 } |
1668 |
1669 |
1669 /*! |
1670 /*! |