194 argument >> mimePart.contentId; |
194 argument >> mimePart.contentId; |
195 argument.endStructure(); |
195 argument.endStructure(); |
196 return argument; |
196 return argument; |
197 } |
197 } |
198 |
198 |
|
199 QDBusArgument &operator<<(QDBusArgument &argument, const QtMobility::MessagingModestFolder &folder) |
|
200 { |
|
201 argument.beginStructure(); |
|
202 argument << folder.parentAccountId; |
|
203 argument << folder.parentFolderId; |
|
204 argument << folder.modestId; |
|
205 argument << static_cast<uint>(folder.type); |
|
206 argument << folder.localizedName; |
|
207 argument.endStructure(); |
|
208 return argument; |
|
209 } |
|
210 |
|
211 const QDBusArgument &operator>>(const QDBusArgument &argument, QtMobility::MessagingModestFolder &folder) |
|
212 { |
|
213 argument.beginStructure(); |
|
214 |
|
215 argument >> folder.parentAccountId; |
|
216 QByteArray str = folder.parentAccountId.toUtf8(); |
|
217 gchar* escaped_string = gconf_escape_key(str.data(), str.length()); |
|
218 folder.parentAccountId = QString::fromUtf8(escaped_string); |
|
219 g_free(escaped_string); |
|
220 |
|
221 argument >> folder.parentFolderId; |
|
222 argument >> folder.modestId; |
|
223 |
|
224 uint type; |
|
225 argument >> type; |
|
226 folder.type = static_cast<QtMobility::MessagingModestFolderType>(type); |
|
227 |
|
228 argument >> folder.localizedName; |
|
229 argument.endStructure(); |
|
230 return argument; |
|
231 } |
|
232 |
199 QTM_BEGIN_NAMESPACE |
233 QTM_BEGIN_NAMESPACE |
200 |
234 |
201 /* configuration key definitions for modest */ |
235 /* configuration key definitions for modest */ |
202 #define MODESTENGINE_ACCOUNT_NAMESPACE "/apps/modest/accounts" |
236 #define MODESTENGINE_ACCOUNT_NAMESPACE "/apps/modest/accounts" |
203 #define MODESTENGINE_SERVER_ACCOUNT_NAMESPACE "/apps/modest/server_accounts" |
237 #define MODESTENGINE_SERVER_ACCOUNT_NAMESPACE "/apps/modest/server_accounts" |
310 QDBusPendingCallWatcher* pendingCallWatcher = new QDBusPendingCallWatcher(pendingCall); |
346 QDBusPendingCallWatcher* pendingCallWatcher = new QDBusPendingCallWatcher(pendingCall); |
311 pendingCallWatcher->setProperty("setOnlyDates", true); |
347 pendingCallWatcher->setProperty("setOnlyDates", true); |
312 connect(pendingCallWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), |
348 connect(pendingCallWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), |
313 this, SLOT(pendingGetUnreadMessagesFinishedSlot(QDBusPendingCallWatcher*))); |
349 this, SLOT(pendingGetUnreadMessagesFinishedSlot(QDBusPendingCallWatcher*))); |
314 |
350 |
|
351 QList<MessagingModestFolder> modestFolders; |
|
352 foldersFromModest(modestFolders); |
|
353 if (modestFolders.count() > 0) { |
|
354 for (int i=0; i < modestFolders.count(); i++) { |
|
355 if (modestFolders[i].type == MessagingModestFolderTypeInbox && modestFolders[i].parentAccountId != "local_folders") { |
|
356 QMessageAccountId accountId = accountIdFromModestAccountId(modestFolders[i].parentAccountId); |
|
357 if (accountExists(accountId)) { |
|
358 QString id = accountId.toString()+"&"+accountEmailProtocolAsString(accountId)+"&"+modestFolders[i].modestId; |
|
359 startObservingModestFolder(id); |
|
360 } |
|
361 } |
|
362 } |
|
363 } |
|
364 |
315 qWarning() << "ModestEngine::ModestEngine Initialized successfully"; |
365 qWarning() << "ModestEngine::ModestEngine Initialized successfully"; |
316 } |
366 } |
317 |
367 |
318 ModestEngine::~ModestEngine() |
368 ModestEngine::~ModestEngine() |
319 { |
369 { |
320 g_object_unref(m_gconfclient); |
370 g_object_unref(m_gconfclient); |
321 m_gconfclient=NULL; |
371 m_gconfclient=NULL; |
|
372 |
|
373 if (m_observed_folders.count()) { |
|
374 for (int i = m_observed_folders.count()-1; i >= 0; i--) { |
|
375 stopObservingModestFolder(m_observed_folders[i]); |
|
376 } |
|
377 } |
322 } |
378 } |
323 |
379 |
324 ModestEngine* ModestEngine::instance() |
380 ModestEngine* ModestEngine::instance() |
325 { |
381 { |
326 return modestEngine(); |
382 return modestEngine(); |
767 |
856 |
768 if (iAccounts.isEmpty()) { |
857 if (iAccounts.isEmpty()) { |
769 return folderIds; |
858 return folderIds; |
770 } |
859 } |
771 |
860 |
772 QFileInfoList localFolders = this->localFolders(); |
861 m_folderCache.clear(); |
773 QString localRootFolder = this->localRootFolder(); |
862 |
774 |
863 QList<MessagingModestFolder> modestFolders; |
775 foreach (QMessageAccount value, iAccounts) { |
864 foldersFromModest(modestFolders); |
776 QMessageAccountId accountId = value.id(); |
865 |
777 QString rootFolder = accountRootFolder(accountId); |
866 if (modestFolders.count() > 0) { |
778 QFileInfoList folders = this->accountFolders(accountId); |
867 foreach (QMessageAccount value, iAccounts) { |
779 |
868 QMessageAccountId accountId = value.id(); |
780 for (int i=0; i < folders.count(); i++) { |
869 // Add folder to cache |
781 QString filePath = folders[i].absoluteFilePath(); |
870 QString modestAccountId = modestAccountIdFromAccountId(accountId); |
782 QString id = accountId.toString()+"&"+accountEmailProtocolAsString(accountId)+"&"+filePath.right(filePath.size()-rootFolder.size()-1); |
871 for (int j=0; j < modestFolders.count(); j++) { |
783 id = id.remove("/subfolders"); |
872 if (modestFolders[j].parentAccountId == modestAccountId) { |
784 folderIds.append(QMessageFolderId(id)); |
873 MessagingModestFolder folder = modestFolders[j]; |
785 } |
874 QString id = accountId.toString()+"&"+accountEmailProtocolAsString(accountId)+"&"+folder.modestId; |
786 |
875 folder.id = id; |
787 // Each account sees local folders as account folders |
876 m_folderCache.insert(id, folder); |
788 for (int i=0; i < localFolders.count(); i++) { |
877 |
789 QString filePath = localFolders[i].absoluteFilePath(); |
878 folderIds.append(QMessageFolderId(id)); |
790 QString id = accountId.toString()+"&"+"maildir"+"&"+filePath.right(filePath.size()-localRootFolder.size()-1); |
879 } |
791 folderIds.append(QMessageFolderId(id)); |
880 } |
|
881 for (int j=0; j < modestFolders.count(); j++) { |
|
882 if (modestFolders[j].parentAccountId == "local_folders") { |
|
883 MessagingModestFolder folder = modestFolders[j]; |
|
884 QString id = accountId.toString()+"&"+"maildir"+"&"+folder.modestId; |
|
885 folder.id = id; |
|
886 m_folderCache.insert(id, folder); |
|
887 |
|
888 folderIds.append(QMessageFolderId(id)); |
|
889 } |
|
890 } |
|
891 } |
|
892 } else { |
|
893 QFileInfoList localFolders = this->localFolders(); |
|
894 QString localRootFolder = this->localRootFolder(); |
|
895 |
|
896 foreach (QMessageAccount value, iAccounts) { |
|
897 QMessageAccountId accountId = value.id(); |
|
898 QString rootFolder = accountRootFolder(accountId); |
|
899 QFileInfoList folders = this->accountFolders(accountId); |
|
900 |
|
901 for (int i=0; i < folders.count(); i++) { |
|
902 QString filePath = folders[i].absoluteFilePath(); |
|
903 QString modestId = filePath.right(filePath.size()-rootFolder.size()-1); |
|
904 modestId = modestId.remove("/subfolders"); |
|
905 QString id = accountId.toString()+"&"+accountEmailProtocolAsString(accountId)+"&"+modestId; |
|
906 folderIds.append(QMessageFolderId(id)); |
|
907 |
|
908 // Add folder to cache |
|
909 MessagingModestFolder folder; |
|
910 folder.id = id; |
|
911 folder.modestId = modestId; |
|
912 if (modestId.lastIndexOf('/') == -1) { |
|
913 // Folder does not have subfolders |
|
914 folder.name = modestId; |
|
915 if ((accountEmailProtocolAsString(accountId) == "pop") && (folder.name == "cache")) { |
|
916 folder.name = "Inbox"; |
|
917 } |
|
918 } else { |
|
919 // Folder has subfolders |
|
920 folder.name = modestId.right(modestId.length()-modestId.lastIndexOf('/')-1); |
|
921 folder.parentFolderId = modestId.left(modestId.lastIndexOf('/')); |
|
922 } |
|
923 folder.parentAccountId = modestAccountIdFromAccountId(accountId); |
|
924 folder.type = MessagingModestFolderTypeUnknown; |
|
925 m_folderCache.insert(id, folder); |
|
926 } |
|
927 |
|
928 // Each account sees local folders as account folders |
|
929 for (int i=0; i < localFolders.count(); i++) { |
|
930 QString filePath = localFolders[i].absoluteFilePath(); |
|
931 QString modestId = filePath.right(filePath.size()-localRootFolder.size()-1); |
|
932 QString id = accountId.toString()+"&"+"maildir"+"&"+modestId; |
|
933 folderIds.append(QMessageFolderId(id)); |
|
934 |
|
935 // Add folder to cache |
|
936 MessagingModestFolder folder; |
|
937 folder.id = id; |
|
938 folder.modestId = modestId; |
|
939 if (modestId.lastIndexOf('/') == -1) { |
|
940 // Folder does not have subfolders |
|
941 folder.name = modestId; |
|
942 if ((accountEmailProtocolAsString(accountId) == "pop") && (folder.name == "cache")) { |
|
943 folder.name = "Inbox"; |
|
944 } |
|
945 } else { |
|
946 // Folder has subfolders |
|
947 folder.name = modestId.right(modestId.length()-modestId.lastIndexOf('/')-1); |
|
948 folder.parentFolderId = modestId.left(modestId.lastIndexOf('/')); |
|
949 } |
|
950 folder.parentAccountId = "local_folders"; |
|
951 folder.type = MessagingModestFolderTypeUnknown; |
|
952 m_folderCache.insert(id, folder); |
|
953 } |
792 } |
954 } |
793 } |
955 } |
794 |
956 |
795 MessagingHelper::filterFolders(folderIds, filter); |
957 MessagingHelper::filterFolders(folderIds, filter); |
796 isFiltered = true; |
958 isFiltered = true; |
804 return queryFolders(filter, QMessageFolderSortOrder(), 0, 0, isFiltered, isSorted).count(); |
966 return queryFolders(filter, QMessageFolderSortOrder(), 0, 0, isFiltered, isSorted).count(); |
805 } |
967 } |
806 |
968 |
807 QMessageFolder ModestEngine::folder(const QMessageFolderId &id) const |
969 QMessageFolder ModestEngine::folder(const QMessageFolderId &id) const |
808 { |
970 { |
|
971 QMessageFolder folder; |
|
972 |
809 QString idString = id.toString(); |
973 QString idString = id.toString(); |
810 int endOfAccountId = idString.indexOf('&'); |
974 if (m_folderCache.contains(idString)) { |
811 int endOfProtocolString = idString.lastIndexOf('&'); |
975 MessagingModestFolder modestFolder = m_folderCache.value(idString); |
812 QString accountId = idString.left(endOfAccountId); |
976 int endOfAccountId = idString.indexOf('&'); |
813 QString protocolString = idString.mid(endOfAccountId+1, endOfProtocolString-endOfAccountId-1); |
977 QString accountId = idString.left(endOfAccountId); |
814 QString folder = idString.right(idString.length()-idString.lastIndexOf('&')-1); |
978 QString folderPath = idString.right(idString.length()-idString.lastIndexOf('&')-1); |
815 QMessageFolderId parentId; |
979 QMessageFolderId parentId; |
816 QString name; |
980 QString name; |
817 if (folder.lastIndexOf('/') == -1) { |
981 if (folderPath.lastIndexOf('/') != -1) { |
818 // Folder does not have subfolders |
982 // Folder has subfolders |
819 name = folder; |
983 parentId = idString.left(idString.lastIndexOf('/')); |
820 if ((protocolString == "pop") && (name == "cache")) { |
984 } |
821 name = "Inbox"; |
985 |
|
986 if (modestFolder.localizedName.isEmpty()) { |
|
987 folder = QMessageFolderPrivate::from(id, |
|
988 QMessageAccountId(accountId), |
|
989 parentId, |
|
990 modestFolder.name, |
|
991 folderPath); |
|
992 } else { |
|
993 folder = QMessageFolderPrivate::from(id, |
|
994 QMessageAccountId(accountId), |
|
995 parentId, |
|
996 modestFolder.localizedName, |
|
997 folderPath); |
|
998 } |
|
999 } |
|
1000 |
|
1001 return folder; |
|
1002 } |
|
1003 |
|
1004 bool ModestEngine::startObservingModestFolder(const QMessageFolderId& folderId) const |
|
1005 { |
|
1006 if (!m_QtmPluginDBusInterface->isValid() || iAccounts.isEmpty()) { |
|
1007 return false; |
|
1008 } |
|
1009 |
|
1010 if (!m_observed_folders.contains(folderId)) { |
|
1011 QDBusPendingCall pendingCall = m_QtmPluginDBusInterface->asyncCall("AddFolderObserver", |
|
1012 QVariant::fromValue(modestAccountIdFromFolderId(folderId)), |
|
1013 QVariant::fromValue(modestFolderIdFromFolderId(folderId))); |
|
1014 QDBusPendingCallWatcher pendingCallWatcher(pendingCall); |
|
1015 pendingCallWatcher.waitForFinished(); |
|
1016 |
|
1017 QDBusMessage msg = pendingCallWatcher.reply(); |
|
1018 |
|
1019 if (msg.type() == QDBusMessage::ReplyMessage) { |
|
1020 if (m_observed_folders.count() == 0) { |
|
1021 m_QtmPluginDBusInterface->connection().connect(MODESTENGINE_QTM_PLUGIN_NAME, |
|
1022 MODESTENGINE_QTM_PLUGIN_PATH, |
|
1023 MODESTENGINE_QTM_PLUGIN_NAME, |
|
1024 "FolderContentsChanged", |
|
1025 (ModestEngine*)this, |
|
1026 SLOT(modestFolderContentsChangedSlot(QDBusMessage))); |
|
1027 } |
|
1028 |
|
1029 m_observed_folders.append(folderId); |
|
1030 |
|
1031 return true; |
822 } |
1032 } |
823 } else { |
1033 } else { |
824 // Folder has subfolders |
1034 return true; |
825 name = folder.right(folder.length()-folder.lastIndexOf('/')-1); |
1035 } |
826 parentId = idString.left(idString.lastIndexOf('/')); |
1036 |
827 } |
1037 return false; |
828 return QMessageFolderPrivate::from(id, QMessageAccountId(accountId), parentId, name, folder); |
1038 } |
|
1039 |
|
1040 bool ModestEngine::stopObservingModestFolder(const QMessageFolderId& folderId) const |
|
1041 { |
|
1042 if (!m_QtmPluginDBusInterface->isValid() || iAccounts.isEmpty()) { |
|
1043 return false; |
|
1044 } |
|
1045 |
|
1046 if (m_observed_folders.contains(folderId)) { |
|
1047 QDBusPendingCall pendingCall = m_QtmPluginDBusInterface->asyncCall("RemoveFolderObserver", |
|
1048 QVariant::fromValue(modestAccountIdFromFolderId(folderId)), |
|
1049 QVariant::fromValue(modestFolderIdFromFolderId(folderId))); |
|
1050 QDBusPendingCallWatcher pendingCallWatcher(pendingCall); |
|
1051 pendingCallWatcher.waitForFinished(); |
|
1052 |
|
1053 QDBusMessage msg = pendingCallWatcher.reply(); |
|
1054 |
|
1055 if (msg.type() == QDBusMessage::ReplyMessage) { |
|
1056 m_observed_folders.removeOne(folderId); |
|
1057 |
|
1058 if (m_observed_folders.count() == 0) { |
|
1059 m_QtmPluginDBusInterface->connection().disconnect(MODESTENGINE_QTM_PLUGIN_NAME, |
|
1060 MODESTENGINE_QTM_PLUGIN_PATH, |
|
1061 MODESTENGINE_QTM_PLUGIN_NAME, |
|
1062 "FolderContentsChanged", |
|
1063 (ModestEngine*)this, |
|
1064 SLOT(modestFolderContentsChangedSlot(QDBusMessage))); |
|
1065 } |
|
1066 |
|
1067 return true; |
|
1068 } |
|
1069 } |
|
1070 |
|
1071 return false; |
|
1072 } |
|
1073 |
|
1074 void ModestEngine::modestFolderContentsChangedSlot(QDBusMessage msg) |
|
1075 { |
|
1076 QList<QVariant> arguments = msg.arguments(); |
|
1077 |
|
1078 QString modestAccountId = arguments.takeFirst().toString(); |
|
1079 QString modestFolderId = arguments.takeFirst().toString(); |
|
1080 QMessageAccountId accountId = accountIdFromModestAccountId(modestAccountId); |
|
1081 QString protocol = accountEmailProtocolAsString(accountId); |
|
1082 if ((protocol == "pop") && (modestFolderId == "INBOX")) { |
|
1083 modestFolderId = "cache"; |
|
1084 } |
|
1085 QString folderId = accountId.toString()+"&"+accountEmailProtocolAsString(accountId)+"&"+modestFolderId; |
|
1086 |
|
1087 qlonglong change = arguments.takeFirst().toLongLong(); |
|
1088 QVariant variant = arguments.takeFirst(); |
|
1089 QList<QString> messageIds = variant.toStringList(); |
|
1090 if (change == 4) { // Headers added |
|
1091 for (int i = 0; i < messageIds.count(); i++) { |
|
1092 QMessageId messageId = folderId+"/"+messageIds[i]; |
|
1093 notification(messageId, ModestEngine::Added); |
|
1094 } |
|
1095 }/* else if (change == 8) { // Headers removed |
|
1096 for (int i = 0; i < messageIds.count(); i++) { |
|
1097 QMessageId messageId = folderId+"/"+messageIds[i]; |
|
1098 notification(messageId, ModestEngine::Removed); |
|
1099 } |
|
1100 }*/ |
829 } |
1101 } |
830 |
1102 |
831 void ModestEngine::watchAllKnownEmailFolders() |
1103 void ModestEngine::watchAllKnownEmailFolders() |
832 { |
1104 { |
833 QFileInfoList localFolders = this->localFolders(); |
1105 QFileInfoList localFolders = this->localFolders(); |
879 int filenameBegin = filePath.lastIndexOf('/')+1; |
1151 int filenameBegin = filePath.lastIndexOf('/')+1; |
880 QString fileName = filePath.mid(filenameBegin,filePath.lastIndexOf('.')-filenameBegin); |
1152 QString fileName = filePath.mid(filenameBegin,filePath.lastIndexOf('.')-filenameBegin); |
881 if (!fileName.endsWith("summary")) { |
1153 if (!fileName.endsWith("summary")) { |
882 if (events & (IN_MOVED_TO | IN_CREATE)) { |
1154 if (events & (IN_MOVED_TO | IN_CREATE)) { |
883 if (events != (IN_MOVED_TO | IN_MOVED_FROM)) { |
1155 if (events != (IN_MOVED_TO | IN_MOVED_FROM)) { |
|
1156 // Wait a moment to make sure that Modest has finished adding message |
|
1157 QEventLoop eventLoop; |
|
1158 QTimer::singleShot(100, &eventLoop, SLOT(quit())); |
|
1159 eventLoop.exec(); |
884 notification(messageIdFromModestMessageFilePath(filePath), ModestEngine::Added); |
1160 notification(messageIdFromModestMessageFilePath(filePath), ModestEngine::Added); |
885 } |
1161 } |
886 } else if (events & IN_DELETE) { |
1162 } else if (events & IN_DELETE) { |
887 notification(messageIdFromModestMessageFilePath(filePath), ModestEngine::Removed); |
1163 notification(messageIdFromModestMessageFilePath(filePath), ModestEngine::Removed); |
888 } |
1164 } |
1152 subType = subType.left(index).trimmed(); |
1433 subType = subType.left(index).trimmed(); |
1153 |
1434 |
1154 QRegExp charsetPattern("charset=(\\S+)"); |
1435 QRegExp charsetPattern("charset=(\\S+)"); |
1155 index = charsetPattern.indexIn(remainder); |
1436 index = charsetPattern.indexIn(remainder); |
1156 if (index != -1) { |
1437 if (index != -1) { |
1157 charset = charsetPattern.cap(1).toLatin1(); |
1438 charset = charsetPattern.cap(1).toLatin1().toUpper(); |
1158 } |
1439 } |
1159 } |
1440 } |
1160 } |
1441 } |
1161 |
1442 |
1162 if (charset.isEmpty()) { |
1443 if (charset.isEmpty()) { |
1163 charset = "UTF-8"; |
1444 charset = "UTF-8"; |
1164 } |
1445 } |
1165 |
1446 |
1166 QMessageContentContainerId existingBodyId(message.bodyId()); |
1447 // Accept only text type Body |
1167 if (existingBodyId.isValid()) { |
1448 if (mainType.toLower() == "text") { |
1168 if (existingBodyId == QMessageContentContainerPrivate::bodyContentId()) { |
1449 QMessageContentContainerId existingBodyId(message.bodyId()); |
1169 // The body content is in the message itself |
1450 if (existingBodyId.isValid()) { |
1170 container->_containingMessageId = messageId.toString(); |
1451 if (existingBodyId == QMessageContentContainerPrivate::bodyContentId()) { |
1171 container->_attachmentId = contentId; |
1452 // The body content is in the message itself |
1172 container->_name = fileName; |
1453 container->_containingMessageId = messageId.toString(); |
1173 container->_type = mainType; |
1454 container->_attachmentId = contentId; |
1174 container->_subType = subType; |
1455 container->_name = fileName; |
1175 container->_charset = charset; |
1456 container->_type = mainType; |
1176 container->_size = 0; |
1457 container->_subType = subType; |
1177 container->_available = true; |
1458 container->_charset = charset; |
|
1459 container->_size = 0; |
|
1460 container->_available = true; |
|
1461 } else { |
|
1462 // The body content is in the first attachment |
|
1463 QMessageContentContainerPrivate *attachmentContainer(QMessageContentContainerPrivate::implementation(*container->attachment(existingBodyId))); |
|
1464 attachmentContainer->_containingMessageId = messageId.toString(); |
|
1465 attachmentContainer->_attachmentId = contentId; |
|
1466 attachmentContainer->_name = fileName; |
|
1467 attachmentContainer->_type = mainType; |
|
1468 attachmentContainer->_subType = subType; |
|
1469 attachmentContainer->_charset = charset; |
|
1470 attachmentContainer->_size = 0; |
|
1471 attachmentContainer->_available = true; |
|
1472 } |
1178 } else { |
1473 } else { |
1179 // The body content is in the first attachment |
1474 if (container->_attachments.isEmpty()) { |
1180 QMessageContentContainerPrivate *attachmentContainer(QMessageContentContainerPrivate::implementation(*container->attachment(existingBodyId))); |
1475 // Put the content directly into the message |
1181 attachmentContainer->_containingMessageId = messageId.toString(); |
1476 container->_containingMessageId = messageId.toString(); |
1182 attachmentContainer->_attachmentId = contentId; |
1477 container->_attachmentId = contentId; |
1183 attachmentContainer->_name = fileName; |
1478 container->_name = fileName; |
1184 attachmentContainer->_type = mainType; |
1479 container->_type = mainType; |
1185 attachmentContainer->_subType = subType; |
1480 container->_subType = subType; |
1186 attachmentContainer->_charset = charset; |
1481 container->_charset = charset; |
1187 attachmentContainer->_size = 0; |
1482 container->_size = 0; |
1188 attachmentContainer->_available = true; |
1483 container->_available = true; |
1189 } |
1484 privateMessage->_bodyId = QMessageContentContainerPrivate::bodyContentId(); |
1190 } else { |
1485 } else { |
1191 if (container->_attachments.isEmpty()) { |
1486 // Add the body as the first attachment |
1192 // Put the content directly into the message |
1487 QMessageContentContainer newBody; |
1193 container->_containingMessageId = messageId.toString(); |
1488 QMessageContentContainerPrivate *attachmentContainer = QMessageContentContainerPrivate::implementation(newBody); |
1194 container->_attachmentId = contentId; |
1489 attachmentContainer->_containingMessageId = messageId.toString(); |
1195 container->_name = fileName; |
1490 attachmentContainer->_attachmentId = contentId; |
1196 container->_type = mainType; |
1491 attachmentContainer->_name = fileName; |
1197 container->_subType = subType; |
1492 attachmentContainer->_type = mainType; |
1198 container->_charset = charset; |
1493 attachmentContainer->_subType = subType; |
1199 container->_size = 0; |
1494 attachmentContainer->_charset = charset; |
1200 container->_available = true; |
1495 attachmentContainer->_size = 0; |
1201 privateMessage->_bodyId = QMessageContentContainerPrivate::bodyContentId(); |
1496 attachmentContainer->_available = true; |
1202 } else { |
1497 privateMessage->_bodyId = container->prependContent(newBody); |
1203 // Add the body as the first attachment |
1498 } |
1204 QMessageContentContainer newBody; |
|
1205 QMessageContentContainerPrivate *attachmentContainer = QMessageContentContainerPrivate::implementation(newBody); |
|
1206 attachmentContainer->_containingMessageId = messageId.toString(); |
|
1207 attachmentContainer->_attachmentId = contentId; |
|
1208 attachmentContainer->_name = fileName; |
|
1209 attachmentContainer->_type = mainType; |
|
1210 attachmentContainer->_subType = subType; |
|
1211 attachmentContainer->_charset = charset; |
|
1212 attachmentContainer->_size = 0; |
|
1213 attachmentContainer->_available = true; |
|
1214 privateMessage->_bodyId = container->prependContent(newBody); |
|
1215 } |
1499 } |
1216 } |
1500 } |
1217 } else { |
1501 } else { |
1218 // Attachment |
1502 // Attachment |
1219 QString fullMimeType = modestMessage.mimeParts[i].mimeType; |
1503 QString fullMimeType = modestMessage.mimeParts[i].mimeType; |
1373 accountName = modestAccountIdFromAccountId(message.parentAccountId()); |
1654 accountName = modestAccountIdFromAccountId(message.parentAccountId()); |
1374 } |
1655 } |
1375 } |
1656 } |
1376 senderInfo["account-name"] = accountName; |
1657 senderInfo["account-name"] = accountName; |
1377 |
1658 |
1378 QDBusPendingCall pendingCall = m_QtmPluginDBusInterface->asyncCall ( |
1659 QList<QVariant> arguments; |
1379 "AddMessage", |
1660 arguments << modestFolder; |
1380 QVariant::fromValue (modestFolder), |
1661 arguments << QVariant::fromValue(senderInfo); |
1381 QVariant::fromValue (senderInfo), |
1662 arguments << QVariant::fromValue(recipients); |
1382 QVariant::fromValue (recipients), |
1663 arguments << QVariant::fromValue(messageData); |
1383 QVariant::fromValue (messageData), |
1664 arguments << QVariant::fromValue(attachments); |
1384 QVariant::fromValue (attachments), |
1665 arguments << QVariant::fromValue(images); |
1385 QVariant::fromValue (images), |
1666 arguments << priority; |
1386 priority, |
1667 arguments << QVariant::fromValue(headers); |
1387 QVariant::fromValue (headers)); |
1668 |
|
1669 QDBusPendingCall pendingCall = m_QtmPluginDBusInterface->asyncCallWithArgumentList("AddMessage", |
|
1670 arguments); |
1388 |
1671 |
1389 if (pendingCall.isError()) { |
1672 if (pendingCall.isError()) { |
1390 qWarning() << "DBus call failed! " << pendingCall.error(); |
1673 qWarning() << "DBus call failed! " << pendingCall.error(); |
1391 return false; |
1674 return false; |
1392 } |
1675 } |
1411 accountEmailProtocolAsString(message.parentAccountId())+ |
1694 accountEmailProtocolAsString(message.parentAccountId())+ |
1412 "&"+modestFolder+"/"+msg.arguments()[0].toString(); |
1695 "&"+modestFolder+"/"+msg.arguments()[0].toString(); |
1413 } |
1696 } |
1414 privateMessage->_id = QMessageId(messageId); |
1697 privateMessage->_id = QMessageId(messageId); |
1415 |
1698 |
|
1699 // Use update functionality to set Priority & Read status |
|
1700 // <=> Modest Plugin can not set Priority & Read status |
|
1701 // immediately after message creation in add call |
|
1702 updateMessage(message); |
|
1703 |
1416 return true; |
1704 return true; |
1417 } |
1705 } |
1418 |
1706 |
1419 bool ModestEngine::updateMessage(QMessage &message) |
1707 bool ModestEngine::updateMessage(QMessage &message) |
1420 { |
1708 { |
1421 Q_UNUSED(message) // TODO: |
1709 if (!m_QtmPluginDBusInterface->isValid() || iAccounts.isEmpty()) { |
1422 |
1710 return false; |
1423 return false; |
1711 } |
|
1712 |
|
1713 if (!message.id().isValid()) { |
|
1714 return false; |
|
1715 } |
|
1716 |
|
1717 QString modestAccountId = modestAccountIdFromMessageId(message.id()); |
|
1718 QString modestFolderId = modestFolderIdFromMessageId(message.id()); |
|
1719 QString modestMessageId = modestMessageIdFromMessageId(message.id()); |
|
1720 |
|
1721 QString modestFolder; |
|
1722 ModestStringMap senderInfo; |
|
1723 ModestStringMap recipients; |
|
1724 ModestStringMap messageData; |
|
1725 ModestStringMapList attachments; |
|
1726 ModestStringMapList images; |
|
1727 uint priority = 0; |
|
1728 ModestStringMap headers; |
|
1729 |
|
1730 qDebug() << __PRETTY_FUNCTION__; |
|
1731 |
|
1732 // Only read status & priority can be updated using Modest |
|
1733 if (message.status() & QMessage::Read) { |
|
1734 messageData["read"] = ""; |
|
1735 } |
|
1736 priority = getModestPriority (message); |
|
1737 |
|
1738 QList<QVariant> arguments; |
|
1739 arguments << QVariant::fromValue(modestAccountId); |
|
1740 arguments << QVariant::fromValue(modestFolderId); |
|
1741 arguments << QVariant::fromValue(modestMessageId); |
|
1742 arguments << QVariant::fromValue(senderInfo); |
|
1743 arguments << QVariant::fromValue(recipients); |
|
1744 arguments << QVariant::fromValue(messageData); |
|
1745 arguments << QVariant::fromValue(attachments); |
|
1746 arguments << QVariant::fromValue(images); |
|
1747 arguments << priority; |
|
1748 arguments << QVariant::fromValue(headers); |
|
1749 |
|
1750 QDBusPendingCall pendingCall = m_QtmPluginDBusInterface->asyncCallWithArgumentList("UpdateMessage", |
|
1751 arguments); |
|
1752 |
|
1753 if (pendingCall.isError()) { |
|
1754 qWarning() << "DBus call failed! " << pendingCall.error(); |
|
1755 return false; |
|
1756 } |
|
1757 |
|
1758 QDBusPendingCallWatcher pendingCallWatcher(pendingCall); |
|
1759 pendingCallWatcher.waitForFinished(); |
|
1760 QDBusMessage msg = pendingCallWatcher.reply(); |
|
1761 if (msg.type() == QDBusMessage::ErrorMessage) { |
|
1762 qWarning() << "Failed to update message via modest: " << msg.errorMessage(); |
|
1763 return false; |
|
1764 } |
|
1765 |
|
1766 return true; |
1424 } |
1767 } |
1425 |
1768 |
1426 bool ModestEngine::removeMessage(const QMessageId &id, QMessageManager::RemovalOption option) |
1769 bool ModestEngine::removeMessage(const QMessageId &id, QMessageManager::RemovalOption option) |
1427 { |
1770 { |
1428 Q_UNUSED(option) // TODO: |
1771 Q_UNUSED(option) // TODO: |
2365 } else { |
2725 } else { |
2366 file.close(); |
2726 file.close(); |
2367 } |
2727 } |
2368 |
2728 |
2369 return result; |
2729 return result; |
|
2730 } |
|
2731 |
|
2732 bool ModestEngine::retrieveBody(QMessageService& messageService, const QMessageId &id) |
|
2733 { |
|
2734 if (!id.isValid()) return false; |
|
2735 |
|
2736 QMessage msg = message(id, true); |
|
2737 QMessageContentContainerId attachmentId = msg.bodyId(); |
|
2738 |
|
2739 //if (!attachmentId.isValid()) return false; |
|
2740 |
|
2741 return retrieve(messageService, id, attachmentId, &msg); |
|
2742 } |
|
2743 |
|
2744 bool ModestEngine::retrieve(QMessageService& messageService, const QMessageId &id, |
|
2745 const QMessageContentContainerId &attachmentId, QMessage *msg) |
|
2746 { |
|
2747 QByteArray result; |
|
2748 |
|
2749 if (!id.isValid()) return false; |
|
2750 //if (!attachmentId.isValid()) return false; |
|
2751 |
|
2752 QString modestAccountId = modestAccountIdFromMessageId(id); |
|
2753 QString modestFolderId = modestFolderIdFromMessageId(id); |
|
2754 QString modestMessageId = modestMessageIdFromMessageId(id); |
|
2755 QString modestAttachmentId; |
|
2756 int opId = -1; |
|
2757 |
|
2758 QMessage message; |
|
2759 |
|
2760 if (msg != 0) { |
|
2761 message = *msg; |
|
2762 } else { |
|
2763 message = this->message(id, true); |
|
2764 } |
|
2765 |
|
2766 QMessageContentContainer cont = message.find(attachmentId); |
|
2767 QMessageContentContainerPrivate *contPrivate = QMessageContentContainerPrivate::implementation(cont); |
|
2768 |
|
2769 if (contPrivate != 0) { |
|
2770 modestAttachmentId = contPrivate->_attachmentId; |
|
2771 } |
|
2772 |
|
2773 if (m_pending_downloads.count() == 0) { |
|
2774 m_QtmPluginDBusInterface->connection().connect(MODESTENGINE_QTM_PLUGIN_NAME, |
|
2775 MODESTENGINE_QTM_PLUGIN_PATH, |
|
2776 MODESTENGINE_QTM_PLUGIN_NAME, |
|
2777 "PartDownloadFinished", |
|
2778 (ModestEngine*)this, |
|
2779 SLOT(mimePartDownloadFinishedSlot(QDBusMessage))); |
|
2780 } |
|
2781 |
|
2782 QDBusPendingReply<int> reply = m_QtmPluginDBusInterface->asyncCall("DownloadMimePart", |
|
2783 QVariant::fromValue(modestAccountId), |
|
2784 QVariant::fromValue(modestFolderId), |
|
2785 QVariant::fromValue(modestMessageId), |
|
2786 QVariant::fromValue(modestAttachmentId)); |
|
2787 |
|
2788 reply.waitForFinished(); |
|
2789 |
|
2790 if (reply.isError()) { |
|
2791 if (m_pending_downloads.count() == 0) { |
|
2792 m_QtmPluginDBusInterface->connection().disconnect(MODESTENGINE_QTM_PLUGIN_NAME, |
|
2793 MODESTENGINE_QTM_PLUGIN_PATH, |
|
2794 MODESTENGINE_QTM_PLUGIN_NAME, |
|
2795 "PartDownloadFinished", |
|
2796 (ModestEngine*)this, |
|
2797 SLOT(mimePartDownloadFinishedSlot(QDBusMessage))); |
|
2798 } |
|
2799 return false; |
|
2800 } |
|
2801 |
|
2802 opId = reply.argumentAt<0>(); |
|
2803 |
|
2804 QMessageServicePrivate* privateService = QMessageServicePrivate::implementation(messageService); |
|
2805 m_pending_downloads.insert(opId, privateService); |
|
2806 |
|
2807 return true; |
|
2808 } |
|
2809 |
|
2810 void ModestEngine::mimePartDownloadFinishedSlot(QDBusMessage msg) |
|
2811 { |
|
2812 QList<QVariant> arguments = msg.arguments(); |
|
2813 int operationId = arguments.takeFirst().toInt(); |
|
2814 |
|
2815 if (m_pending_downloads.contains(operationId)) { |
|
2816 QMessageServicePrivate* privateService = m_pending_downloads.take(operationId); |
|
2817 |
|
2818 privateService->_pendingRequestCount--; |
|
2819 |
|
2820 bool success = arguments.takeFirst().toBool(); |
|
2821 if (success) { |
|
2822 privateService->setFinished(true); |
|
2823 } else { |
|
2824 privateService->setFinished(false); |
|
2825 } |
|
2826 |
|
2827 if (m_pending_downloads.count() == 0) { |
|
2828 m_QtmPluginDBusInterface->connection().disconnect(MODESTENGINE_QTM_PLUGIN_NAME, |
|
2829 MODESTENGINE_QTM_PLUGIN_PATH, |
|
2830 MODESTENGINE_QTM_PLUGIN_NAME, |
|
2831 "PartDownloadFinished", |
|
2832 (ModestEngine*)this, |
|
2833 SLOT(mimePartDownloadFinishedSlot(QDBusMessage))); |
|
2834 } |
|
2835 } |
2370 } |
2836 } |
2371 |
2837 |
2372 void ModestEngine::notification(const QMessageId& messageId, NotificationType notificationType) const |
2838 void ModestEngine::notification(const QMessageId& messageId, NotificationType notificationType) const |
2373 { |
2839 { |
2374 QMessageId realMessageId = messageId; |
2840 QMessageId realMessageId = messageId; |