1013 } else { |
1013 } else { |
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 // Reserve buffer for content |
1019 TPtr8 dataPtr = data->Des(); |
1019 QByteArray byteArray; |
1020 |
1020 QT_TRYCATCH_LEAVING(byteArray = QByteArray(fileSize, 0)); |
1021 if (fileSize != 0) { |
1021 TUint8* ptr = reinterpret_cast<unsigned char*>(byteArray.data()); |
1022 TInt dummyPos = 0; |
1022 TPtr8 dataPtr(ptr, byteArray.capacity()); |
1023 file.Seek(ESeekStart, dummyPos); |
1023 |
1024 User::LeaveIfError(file.Read(dataPtr)); |
1024 // Read data from the file |
1025 } |
1025 TInt dummyPos = 0; |
|
1026 file.Seek(ESeekStart, dummyPos); |
|
1027 User::LeaveIfError(file.Read(dataPtr)); |
1026 |
1028 |
1027 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml)) { |
1029 if (contentType.startsWith(NmContentTypeTextHtml) || contentType.contains( NmContentDescrAttachmentHtml)) { |
1028 QRegExp rxlen("(?:charset=)(?:\"?)([\\-\\_a-zA-Z0-9]+)", Qt::CaseInsensitive); |
1030 QRegExp rxlen("(?:charset=)(?:\"?)([\\-\\_a-zA-Z0-9]+)", Qt::CaseInsensitive); |
1029 QString charset; |
1031 QString charset; |
1030 int pos = rxlen.indexIn(contentType); |
1032 int pos = rxlen.indexIn(contentType); |
1031 if (pos > -1) { |
1033 if (pos > -1) { |
1032 charset = rxlen.cap(1); |
1034 charset = rxlen.cap(1); |
1033 } |
1035 } |
1034 QByteArray msgBytes = QByteArray(reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize); |
|
1035 QTextCodec *codec = QTextCodec::codecForName(charset.toAscii()); |
1036 QTextCodec *codec = QTextCodec::codecForName(charset.toAscii()); |
1036 if (!codec) { |
1037 if (!codec) { |
1037 codec = QTextCodec::codecForName("UTF-8"); |
1038 codec = QTextCodec::codecForName("UTF-8"); |
1038 } |
1039 } |
1039 QString encodedStr = codec->toUnicode(msgBytes); |
1040 QString encodedStr = codec->toUnicode(byteArray); |
1040 messagePart.setTextContent(encodedStr, contentType); |
1041 messagePart.setTextContent(encodedStr, contentType); |
1041 } else { |
1042 } else { |
1042 messagePart.setBinaryContent(QByteArray( |
1043 messagePart.setBinaryContent(byteArray, contentType); |
1043 reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize), contentType); |
|
1044 } |
1044 } |
1045 CleanupStack::PopAndDestroy(data); |
|
1046 } |
1045 } |
1047 file.Close(); |
1046 file.Close(); |
1048 } |
1047 } |
1049 CleanupStack::PopAndDestroy(cfsPart); |
1048 CleanupStack::PopAndDestroy(cfsPart); |
1050 } |
1049 } |
1217 TAny* param3) |
1216 TAny* param3) |
1218 { |
1217 { |
1219 NM_FUNCTION; |
1218 NM_FUNCTION; |
1220 |
1219 |
1221 switch (aEvent) { |
1220 switch (aEvent) { |
|
1221 case TFSEventMailboxSettingsChanged: |
|
1222 break; |
|
1223 |
|
1224 // Folder related events: |
|
1225 case TFSEventFoldersDeleted: |
|
1226 handleFoldersEvent(param1, param2, NmFolderIsDeleted, mailbox); |
|
1227 break; |
|
1228 case TFSEventNewFolder: |
|
1229 handleFoldersEvent(param1, param2, NmFolderIsCreated, mailbox); |
|
1230 break; |
|
1231 |
1222 // Mailbox related events: |
1232 // Mailbox related events: |
1223 case TFSEventNewMailbox: |
1233 case TFSEventNewMailbox: |
1224 handleMailboxEvent(mailbox, NmMailboxCreated); |
1234 handleMailboxEvent(mailbox, NmMailboxCreated); |
1225 break; |
1235 break; |
1226 case TFSEventMailboxDeleted: |
1236 case TFSEventMailboxDeleted: |
1793 default: |
1803 default: |
1794 // ignore other statuses |
1804 // ignore other statuses |
1795 break; |
1805 break; |
1796 }; |
1806 }; |
1797 } |
1807 } |
|
1808 |
|
1809 /*! |
|
1810 function to handle folder event |
|
1811 */ |
|
1812 void NmFrameworkAdapter::handleFoldersEvent( |
|
1813 TAny* param1, TAny* param2, NmFolderEvent event, TFSMailMsgId mailbox) |
|
1814 { |
|
1815 NM_FUNCTION; |
|
1816 |
|
1817 // aParam1: RArray<TFSMailMsgId>* aEntries |
|
1818 // aParam2: TFSMailMsgId* aParentFolder |
|
1819 // aParam3: NULL |
|
1820 |
|
1821 NmId mailboxId(0); |
|
1822 mailboxId = mailbox.GetNmId(); |
|
1823 |
|
1824 NmId nmMsgId(0); |
|
1825 QList<NmId> folderIds; |
|
1826 |
|
1827 RArray<TFSMailMsgId>* fsEntries = reinterpret_cast<RArray<TFSMailMsgId>*> (param1); |
|
1828 TFSMailMsgId* fsFolderId = reinterpret_cast<TFSMailMsgId*> (param2); |
|
1829 NmId folderId = fsFolderId->GetNmId(); |
|
1830 NmId inputFolderId = NmFrameworkAdapter::getStandardFolderId(mailboxId, NmFolderInbox); |
|
1831 |
|
1832 TFSMailMsgId fsMsgId; |
|
1833 for(TInt i = 0; i < fsEntries->Count(); i++){ |
|
1834 fsMsgId = (*fsEntries)[i]; |
|
1835 folderId = fsMsgId.GetNmId(); |
|
1836 folderIds.append(folderId); |
|
1837 } |
|
1838 |
|
1839 emit folderEvent(event, folderIds, mailboxId); |
|
1840 } |
|
1841 |
1798 Q_EXPORT_PLUGIN(NmFrameworkAdapter) |
1842 Q_EXPORT_PLUGIN(NmFrameworkAdapter) |
1799 |
1843 |