diff options
author | Don Sanders <don.sanders@nokia.com> | 2012-02-10 18:11:12 +0200 |
---|---|---|
committer | Don Sanders <don.sanders@nokia.com> | 2012-02-10 18:11:12 +0200 |
commit | 04f6666d9d9e9ad3e701f7853819bea1413b1425 (patch) | |
tree | 88f7a1203571b6eb1b54e7336801c5451ff491cb | |
parent | 1ab2a5014b596148e1317a3b520860cf44252a01 (diff) | |
parent | 2b181bcc135459439e3efa9b3a304e4b55868254 (diff) |
Merge branch 'master' of scm.dev.nokia.troll.no:addons/messagingframework2012W07
22 files changed, 367 insertions, 6 deletions
diff --git a/examples/qtmail/app/emailclient.cpp b/examples/qtmail/app/emailclient.cpp index 86ada777..1ae939b6 100644 --- a/examples/qtmail/app/emailclient.cpp +++ b/examples/qtmail/app/emailclient.cpp @@ -818,6 +818,10 @@ void EmailClient::initActions() connect(settingsAction, SIGNAL(triggered()), this, SLOT(settings())); settingsAction->setIconText(QString()); + standardFoldersAction = new QAction( Qtmail::icon("Create standard folders"), tr("Create standard folders"), this ); + connect(standardFoldersAction, SIGNAL(triggered()), this, SLOT(createStandardFolders())); + standardFoldersAction->setIconText(QString()); + workOfflineAction = new QAction( Qtmail::icon("workoffline"), tr("Work offline"), this ); connect(workOfflineAction, SIGNAL(triggered()), this, SLOT(connectionStateChanged())); workOfflineAction->setCheckable(true); @@ -919,6 +923,7 @@ void EmailClient::initActions() fileMenu->addAction( cancelButton ); fileMenu->addAction( emptyTrashAction ); fileMenu->addAction( settingsAction ); + fileMenu->addAction(standardFoldersAction); fileMenu->addAction( workOfflineAction ); fileMenu->addAction( notificationAction ); fileMenu->addSeparator(); @@ -1063,6 +1068,7 @@ void EmailClient::init() searchButton = 0; synchronizeAction = 0; settingsAction = 0; + standardFoldersAction = 0; workOfflineAction = 0; emptyTrashAction = 0; moveAction = 0; @@ -2587,6 +2593,18 @@ void EmailClient::settings() settingsDialog.exec(); } +void EmailClient::createStandardFolders() +{ + QMailAccountKey retrieveKey(QMailAccountKey::status(QMailAccount::CanRetrieve, QMailDataComparator::Includes)); + QMailAccountKey enabledKey(QMailAccountKey::status(QMailAccount::Enabled, QMailDataComparator::Includes)); + availableAccounts = QMailStore::instance()->queryAccounts(retrieveKey & enabledKey); + + if (!availableAccounts.isEmpty()) { + foreach(QMailAccountId accountId, availableAccounts) + retrieveAction("createStandardfolders")->createStandardFolders(accountId); + } +} + void EmailClient::notificationStateChanged() { #ifndef QT_NO_SYSTEMTRAYICON diff --git a/examples/qtmail/app/emailclient.h b/examples/qtmail/app/emailclient.h index 541da309..2cb9d13a 100644 --- a/examples/qtmail/app/emailclient.h +++ b/examples/qtmail/app/emailclient.h @@ -265,6 +265,7 @@ protected slots: void readReplyRequested(const QMailMessageMetaData&); void settings(); + void createStandardFolders(); void notificationStateChanged(); void connectionStateChanged(); void exportPendingChanges(); @@ -388,6 +389,7 @@ private: QAction *deleteFolderAction; QAction *renameFolderAction; QAction *settingsAction; + QAction *standardFoldersAction; QAction *emptyTrashAction; QAction *deleteMailAction; QAction *detachThreadAction; @@ -439,6 +441,7 @@ private: QMailAccountIdList transmitAccountIds; QMailAccountIdList retrievalAccountIds; + QMailAccountIdList availableAccounts; QMailMessageId lastDraftId; diff --git a/src/libraries/qmfclient/CHANGES.qdoc b/src/libraries/qmfclient/CHANGES.qdoc index 4bb2a30b..fec7c4df 100644 --- a/src/libraries/qmfclient/CHANGES.qdoc +++ b/src/libraries/qmfclient/CHANGES.qdoc @@ -233,6 +233,8 @@ Changes since the QMF-1.0 release on 15/05/09: 53. Added 'void QMailMessageServer::transmitMessage(quint64 action, const QMailMessageId &messageId)' +54. Added 'void QMailRetrievalAction::createStandardFolders(const QMailAccountId &accountId)' + ***************************************************************************** Changes since the development preview release on 03/04/09: diff --git a/src/libraries/qmfclient/qmailmessageserver.cpp b/src/libraries/qmfclient/qmailmessageserver.cpp index f4e2646c..2479fb36 100644 --- a/src/libraries/qmfclient/qmailmessageserver.cpp +++ b/src/libraries/qmfclient/qmailmessageserver.cpp @@ -70,6 +70,8 @@ signals: void retrieveMessageLists(quint64, const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum, const QMailMessageSortKey &sort); void retrieveMessageList(quint64, const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum, const QMailMessageSortKey &sort); + void createStandardFolders(quint64, const QMailAccountId &accountId); + void retrieveMessages(quint64, const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec); void retrieveMessagePart(quint64, const QMailMessagePart::Location &partLocation); @@ -143,6 +145,8 @@ QMailMessageServerPrivate::QMailMessageServerPrivate(QMailMessageServer* parent) adaptor, MESSAGE(retrieveMessageList(quint64, QMailAccountId, QMailFolderId, uint, QMailMessageSortKey))); connectIpc(this, SIGNAL(retrieveMessageLists(quint64, QMailAccountId, QMailFolderIdList, uint, QMailMessageSortKey)), adaptor, MESSAGE(retrieveMessageLists(quint64, QMailAccountId, QMailFolderIdList, uint, QMailMessageSortKey))); + connectIpc(this, SIGNAL(createStandardFolders(quint64, QMailAccountId)), + adaptor, MESSAGE(createStandardFolders(quint64, QMailAccountId))); connectIpc(this, SIGNAL(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification)), adaptor, MESSAGE(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification))); connectIpc(this, SIGNAL(retrieveMessagePart(quint64, QMailMessagePart::Location)), @@ -636,6 +640,11 @@ void QMailMessageServer::retrieveMessageLists(quint64 action, const QMailAccount emit d->retrieveMessageLists(action, accountId, folderIds, minimum, sort); } +void QMailMessageServer::createStandardFolders(quint64 action, const QMailAccountId &accountId) +{ + emit d->createStandardFolders(action, accountId); +} + /*! Requests that the message server retrieve data regarding the messages identified by \a messageIds. diff --git a/src/libraries/qmfclient/qmailmessageserver.h b/src/libraries/qmfclient/qmailmessageserver.h index dca1d354..ba205655 100644 --- a/src/libraries/qmfclient/qmailmessageserver.h +++ b/src/libraries/qmfclient/qmailmessageserver.h @@ -123,6 +123,8 @@ public slots: void retrieveMessageList(quint64, const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum, const QMailMessageSortKey &sort); void retrieveMessageLists(quint64, const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum, const QMailMessageSortKey &sort); + void createStandardFolders(quint64, const QMailAccountId &accountId); + void retrieveMessages(quint64, const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec); void retrieveMessagePart(quint64, const QMailMessagePart::Location &partLocation); diff --git a/src/libraries/qmfclient/qmailserviceaction.cpp b/src/libraries/qmfclient/qmailserviceaction.cpp index 02ad3754..5114cd99 100644 --- a/src/libraries/qmfclient/qmailserviceaction.cpp +++ b/src/libraries/qmfclient/qmailserviceaction.cpp @@ -758,6 +758,34 @@ void QMailRetrievalActionPrivate::retrieveMessageLists(const QMailAccountId &acc _server->retrieveMessageLists(newAction(), accountId, folderIds, minimum, sort); } +void QMailRetrievalActionPrivate::createStandardFolders(const QMailAccountId &accountId) +{ + Q_ASSERT(!_pendingActions.count()); + + QMailAccount account(accountId); + + if (!QMail::detectStandardFolders(accountId)) { + if (!(account.status() & QMailAccount::CanCreateFolders)) { + qMailLog(Messaging) << "Unable to create folders for account: " << accountId; + if (validAction(newAction())) { + setActivity(QMailServiceAction::Successful); + emitChanges(); + } + return; + } + else { + _server->createStandardFolders(newAction(), accountId); + } + } + else { + qMailLog(Messaging) << "Standard folders matched for account: " << accountId; + if (validAction(newAction())) { + setActivity(QMailServiceAction::Successful); + emitChanges(); + } + } +} + void QMailRetrievalActionPrivate::retrieveMessages(const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec) { _server->retrieveMessages(newAction(), messageIds, spec); @@ -1012,6 +1040,23 @@ void QMailRetrievalAction::retrieveMessageLists(const QMailAccountId &accountId, } /*! + Requests that the message server create the standard folders for the + account \a accountId. If all standard folders are already set in the storage + the service action will return success immediately, in case some standard folders are + not set, a matching attempt against a predefined list of translations will be made, + if the folders can't be matched, messageserver will try to create them in the server side + and match them if the creation is successful. In case folder creation is not allowed for + the account \a accountId the service action will return. + + \sa retrieveFolderList +*/ + +void QMailRetrievalAction::createStandardFolders(const QMailAccountId &accountId) +{ + impl(this)->createStandardFolders(accountId); +} + +/*! Requests that the message server retrieve data regarding the messages identified by \a messageIds. If \a spec is \l QMailRetrievalAction::Flags, then the message server should detect if diff --git a/src/libraries/qmfclient/qmailserviceaction.h b/src/libraries/qmfclient/qmailserviceaction.h index 54690f15..87c9eede 100644 --- a/src/libraries/qmfclient/qmailserviceaction.h +++ b/src/libraries/qmfclient/qmailserviceaction.h @@ -182,6 +182,8 @@ public slots: void retrieveMessageList(const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum = 0, const QMailMessageSortKey &sort = QMailMessageSortKey()); void retrieveMessageLists(const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum = 0, const QMailMessageSortKey &sort = QMailMessageSortKey()); + void createStandardFolders(const QMailAccountId &accountId); + void retrieveMessages(const QMailMessageIdList &messageIds, RetrievalSpecification spec = MetaData); void retrieveMessagePart(const QMailMessagePart::Location &partLocation); diff --git a/src/libraries/qmfclient/qmailserviceaction_p.h b/src/libraries/qmfclient/qmailserviceaction_p.h index 53408643..9d073f09 100644 --- a/src/libraries/qmfclient/qmailserviceaction_p.h +++ b/src/libraries/qmfclient/qmailserviceaction_p.h @@ -154,6 +154,8 @@ public: void retrieveMessageList(const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum, const QMailMessageSortKey &sort); void retrieveMessageLists(const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum, const QMailMessageSortKey &sort); + void createStandardFolders(const QMailAccountId &accountId); + void retrieveMessages(const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec); void retrieveMessagePart(const QMailMessagePart::Location &partLocation); diff --git a/src/libraries/qmfclient/qmf_qt.qrc b/src/libraries/qmfclient/qmf_qt.qrc index 793b27e5..aad16048 100644 --- a/src/libraries/qmfclient/qmf_qt.qrc +++ b/src/libraries/qmfclient/qmf_qt.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/qmf"> <file alias="mime.types">resources/mime.types</file> + <file alias="translations.conf">resources/translations.conf</file> </qresource> </RCC> diff --git a/src/libraries/qmfclient/resources/translations.conf b/src/libraries/qmfclient/resources/translations.conf new file mode 100644 index 00000000..4558a05b --- /dev/null +++ b/src/libraries/qmfclient/resources/translations.conf @@ -0,0 +1,5 @@ +inbox=inbox,Inbus,Kuti e mesazheve të ardhura,ገቢ ሳጥን,صندوق الوارد,ص. الوارد،; الوارد,Մուտքի արկղ,ইনবক্স,gələnlər,Sarrerako ontzia,Уваходныя,ইনবক্স,ইনবক্স,Primljena pošta,Входящи,Bústia d'entrada,收件箱,收件匣,收件匣,Ulazni spremnik,Přijaté,Indbakke,Vastuvõetud,Saabunud,Saapuneet,Messages reçus,Boîte de réception,Caixa de entrada,შემოსული,Eingang,Εισερχόμενα,ઇનબૉક્સ,Akwatin saƙo mai shiga,דואר נכנס,इनबॉक्स,Bejövő,Innhólf,Igbe ozi mmbata,Kotak masuk,Ricevuti,受信メール,ಇನ್ಬಾಕ್ಸ್,ان-بکس,Кіріс жәшігі,ប្រអប់ទទួល,Кирүүчү почта ящиги,수신 메시지; 받은 편지함,Iesūtne,Boîte ya réception,Gautieji,Дојдовно сандаче,Boatiditra,Peti masuk,ഇന്ബോക്സ്,इनबॉक्स,Ирсэн,Innboks,ଇନ୍ବକ୍ସ,آمدخانه,صندوق دریافت,Skrzynka odbiorcza,Caixa de entrada,ਇਨਬਾਕਸ,Curier intrări,Căsuță intrări,Primljeno,ලද පණිවුඩ,Prijaté,Prejeta sporočila,Buzón de entrada,Kasha la kupokea,Inkorg,Паёмдони даромад,இன்பாக்ஸ்,ఇన్ బాక్స్,ถาดเข้า,Gelen kutusu,Gelýän,Вхідні,ان باکس,Қабул қилинганлар,Hộp thư đến,Àpò ọ̀rọ̀ tí nwọlé,I-inbhoks,Ibhokisi lengenayo +drafts=Drafts,Konsepte,Mesazhe të padërguara,ረቂቆች,مسودات,Սևագրեր,ড্ৰাফ্ট,Layihələr,Zirriborroak,Чарнавікі,খসড়া,খসড়া,Skice,Чернови,Esborranys,草稿,草稿,草稿,Nacrti,Koncepty,Kladder,Concepten,Mustandid,Mga draft,Luonnokset,Brouillons,Borrador,მონახაზები,Entwürfe,Πρόχειρα,ડ્રાફ્ટસ,Tsararrun saƙonni,טיוטות,ड्राफ़्ट,Vázlatok,Piszkozatok,Drög,Ihe edeturu,Konsep,Bozze,下書き,ಕರಡುಗಳು,ڈرافٹ/,Жобалар,សារព្រាង,Черновиктер,임시 보관함,Melnraksti,Ba brouillon,Juodraščiai,Нацрти,Vakiraoka,Draf,കരടുകള്,प्रारूप,Нооргууд,Kladd,ଡ୍ରାଫ୍ଟ,موسودې,پیش نویسها,Kopie robocze,Rascunhos,ਡ੍ਰਾਫਟ,Ciorne,Черновики,Nacrti,Meralo,කෙටුම් පත්,Koncepty,Osnutki,Borrador,Borradores,Rasimu,Utkast,Сиёҳнавис,வரைவுகள்,చిత్తు ప్రతులు,ฉบับร่าง,Taslaklar,Garalamalar,Чернетки,مسودات,Хомаки хатлар,Bản thảo,Àwọn Àkọpamọ́,Iidrafti,Izinhlaka +trash=Deleted items,Trash,Bin,Deleted Messages,العناصر المحذوفة,已删除邮件,已刪除項目,已刪除項目,Odstraněné položky,Slettede beskeder,Verwijderde items,Poistetut,Éléments supprimés,Gelöschte Objekte,פריטים שנמחקו,Törölt elemek,Pesan terhapus,Elementi eliminati,Жойылғандар,Item dipadam,Slettede elementer,موارد حذف شده,Usunięte wiadomości,Itens apagados,Itens excluídos,Articole șterse,Удаленные,Vymazané správy,Elementos borrados,Elementos eliminados,Borttagna objekt,รายการที่ลบ,Silinmiş öğeler,Видалені,Mục đã xóa +sent=sent,sent items,Sent Messages,Gestuur,Të dërguara,የተላኩ,المرسلة,Ուղարկված,প্ৰেৰিত,göndərilənlər,Bidalita,Bidaliak,Пасланыя,প্রেরিত,প্রেরিত,Poslano,Изпратени,Enviats,已发信息,寄件備份,寄件備份,Poslane,Odeslané,Sendt,Verzonden,Saadetud,Naipadala,Napadala,Padala,Lähetetyt,Envoyés,Messages envoyés,Enviadas,გაგზავნილი,Gesendete,Σταλθέντα,મોકલેલા,Aika,פריטים שנשלחו; נשלחו,भेजा गया,Elküldöttek,Elküldött,Ezipuru,Terkirim,Inviati,送信済みメール,ಕಳುಹಿಸಲಾದ,سوزمژہ,Жіберілгендер,បានផ្ញើ,Жиберилген,발신 메시지; 보낸 편지함,Nosūtītās ziņas,E tindami,Išsiųstieji,Испратено,Nalefa; Lasa,Dihantar,അയച്ചു,,प्रेषित; पाठविले; पाठविलेले,Илгээсэн,Sendt,ପଠାଗଲା,لېګل شوی,موارد ارسال شده,Wysłane,Enviadas,ਭੇਜੇ,Expediate,Отправленные,Poslato,E rometsweng,යැවු පණිවුඩ,Poslané,Poslano,Enviados,Vilivyotumwa,Sända poster,Sänt,Ирсол шуд,அனுப்பியவை,పంపించబడింది,ส่งแล้ว,Gönderilmiş öğeler,Iberilen,Надіслані,بھیجے گئے,Юборилган,Đã gửi,Ti fi ranṣẹ,Ethunyelweyo,Kuthunyelwe +spam=spam,junk,Bulk Mail,الرسائل العشوائية,垃圾邮件,垃圾電郵,垃圾郵件,nevyžádaná pošta,roskaposti,courrier indésirable,pourriel,Spam,דואר זבל,levélszemét,posta indesiderata,спам,søppelpost,هرزنامه,spamowanie,nevyžiadaná pošta,no deseado,correo no deseado,skräppost,สแปม,istenmeyen e-posta,istenmeyen,thư rác diff --git a/src/libraries/qmfclient/support/qmailnamespace.cpp b/src/libraries/qmfclient/support/qmailnamespace.cpp index be0f315f..c6b5157f 100644 --- a/src/libraries/qmfclient/support/qmailnamespace.cpp +++ b/src/libraries/qmfclient/support/qmailnamespace.cpp @@ -40,6 +40,9 @@ ****************************************************************************/ #include "qmailnamespace.h" +#include "qmailfolderkey.h" +#include "qmailstore.h" +#include "qmaillog.h" #include <QCoreApplication> #include <QDir> #include <QDebug> @@ -755,6 +758,132 @@ QString QMail::lastSystemErrorMessage() #endif } +QMap<QString, QStringList> standardFolderTranslations() +{ + QMap<QString, QStringList> folderTranslations; + + QFile file(":/qmf/translations.conf"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Unable to read " << "translations"; + return folderTranslations; + } + + QTextStream in(&file); + in.setCodec("UTF-8"); + while (!in.atEnd()) { + QString line = in.readLine(); + QStringList list = line.split("=", QString::SkipEmptyParts); + QString folderName = list.at(0); + QString transList = list.at(1); + + if (folderName == "inbox") { + QStringList inboxList = transList.split(",", QString::SkipEmptyParts); + folderTranslations.insert("inbox", inboxList); + } + else if (folderName == "drafts") { + QStringList draftsList = transList.split(",", QString::SkipEmptyParts); + folderTranslations.insert("drafts", draftsList); + } + else if(folderName == "trash") { + QStringList trashList = transList.split(",", QString::SkipEmptyParts); + folderTranslations.insert("trash", trashList); + } + else if (folderName == "sent") { + QStringList sentList = transList.split(",", QString::SkipEmptyParts); + folderTranslations.insert("sent", sentList); + } + else if (folderName == "spam") { + QStringList spamList = transList.split(",", QString::SkipEmptyParts); + folderTranslations.insert("spam", spamList); + } + } + return folderTranslations; +} + +QList<StandardFolderInfo> standardFolders() +{ + QList<StandardFolderInfo> standardFoldersList; + + QMap<QString,QStringList> folderTranslations = standardFolderTranslations(); + + if (!folderTranslations.empty()) { + standardFoldersList << StandardFolderInfo("\\Inbox", QMailFolder::Incoming, QMailFolder::InboxFolder, QMailMessage::Incoming, folderTranslations.value("inbox")) + << StandardFolderInfo("\\Drafts", QMailFolder::Drafts, QMailFolder::DraftsFolder, QMailMessage::Draft, folderTranslations.value("drafts")) + << StandardFolderInfo("\\Trash", QMailFolder::Trash, QMailFolder::TrashFolder, QMailMessage::Trash, folderTranslations.value("trash")) + << StandardFolderInfo("\\Sent", QMailFolder::Sent, QMailFolder::SentFolder, QMailMessage::Sent, folderTranslations.value("sent")) + << StandardFolderInfo("\\Spam", QMailFolder::Junk, QMailFolder::JunkFolder, QMailMessage::Junk, folderTranslations.value("spam")); + } + return standardFoldersList; +} + +bool detectStandardFolder(const QMailAccountId &accountId, StandardFolderInfo standardFolderInfo) +{ + QMailFolderId folderId; + QMailAccount account = QMailAccount(accountId); + + QMailFolderKey accountKey(QMailFolderKey::parentAccountId(accountId)); + QStringList paths = standardFolderInfo._paths; + QMailFolder::StandardFolder standardFolder(standardFolderInfo._standardFolder); + quint64 messageFlag(standardFolderInfo._messageFlag); + quint64 flag(standardFolderInfo._flag); + + QMailFolderIdList folders; + + if (!paths.isEmpty()) { + QMailFolderKey exactMatchKey = QMailFolderKey::displayName(paths, QMailDataComparator::Includes); + folders = QMailStore::instance()->queryFolders(exactMatchKey & accountKey); + if (folders.isEmpty()) { + QMailFolderKey pathKey; + foreach (const QString& path, paths) { + pathKey |= QMailFolderKey::displayName(path, QMailDataComparator::Includes); + } + folders = QMailStore::instance()->queryFolders(pathKey & accountKey); + } + } + + if (!folders.isEmpty()) { + folderId = folders.first(); + + if (folderId.isValid()) { + qMailLog(Messaging) << "Setting folder: " << QMailFolder(folderId).displayName(); + QMailFolder folder(folderId); + folder.setStatus(flag,true); + account.setStandardFolder(standardFolder, folderId); + if (!QMailStore::instance()->updateAccount(&account)) { + qWarning() << "Unable to update account" << account.id() << "to set standard folder" << QMailFolder(folderId).displayName(); + } + QMailMessageKey folderKey(QMailMessageKey::parentFolderId(folderId)); + if (!QMailStore::instance()->updateMessagesMetaData(folderKey, messageFlag, true)) { + qWarning() << "Unable to update messages in folder" << folderId << "to set flag" << messageFlag; + } + return true; + } + } + return false; +} + +bool QMail::detectStandardFolders(const QMailAccountId &accountId) +{ + QMailAccount account = QMailAccount(accountId); + bool status = true; + QList<StandardFolderInfo> standardFoldersList = standardFolders(); + + if (standardFoldersList.empty()) { + return true; + } + + foreach (StandardFolderInfo folder, standardFoldersList) { + QMailFolderId standardFolderId = account.standardFolder(folder._standardFolder); + if (!standardFolderId.isValid()) { + if (!detectStandardFolder(accountId, folder)) { + status = false; + } + } + } + QMailStore::instance()->flushIpcNotifications(); + return status; +} + /*! \enum QMail::SaslMechanism diff --git a/src/libraries/qmfclient/support/qmailnamespace.h b/src/libraries/qmfclient/support/qmailnamespace.h index 1a43d275..276b760f 100644 --- a/src/libraries/qmfclient/support/qmailnamespace.h +++ b/src/libraries/qmfclient/support/qmailnamespace.h @@ -43,6 +43,8 @@ #define QMAILNAMESPACE_H #include "qmailglobal.h" +#include "qmailaccount.h" +#include "qmailfolder.h" #include <QDate> #include <QPair> #include <QString> @@ -60,6 +62,18 @@ class QSqlDatabase; QT_END_NAMESPACE #endif +struct StandardFolderInfo +{ + StandardFolderInfo(QString flagName, quint64 flag, QMailFolder::StandardFolder standardFolder, quint64 messageFlag, QStringList paths) + :_flagName(flagName), _flag(flag), _standardFolder(standardFolder), _messageFlag(messageFlag), _paths(paths) {}; + + QString _flagName; + quint64 _flag; + QMailFolder::StandardFolder _standardFolder; + quint64 _messageFlag; + QStringList _paths; +}; + namespace QMail { QMF_EXPORT QString lastSystemErrorMessage(); @@ -88,6 +102,7 @@ namespace QMail QMF_EXPORT QString baseSubject(const QString& subject, bool *replyOrForward); QMF_EXPORT QStringList messageIdentifiers(const QString& str); + QMF_EXPORT bool detectStandardFolders(const QMailAccountId &accountId); template<typename StringType> StringType unquoteString(const StringType& src) @@ -140,7 +155,6 @@ namespace QMail PlainMechanism = 2, CramMd5Mechanism = 3 }; - } #endif diff --git a/src/libraries/qmfmessageserver/qmailmessageservice.cpp b/src/libraries/qmfmessageserver/qmailmessageservice.cpp index 0d12dedc..4a30c22b 100644 --- a/src/libraries/qmfmessageserver/qmailmessageservice.cpp +++ b/src/libraries/qmfmessageserver/qmailmessageservice.cpp @@ -802,6 +802,14 @@ bool QMailMessageSource::createFolder(const QString &name, const QMailAccountId return false; } +bool QMailMessageSource::createStandardFolders(const QMailAccountId &accountId) +{ + Q_UNUSED(accountId); + + notImplemented(); + return false; +} + /*! Invoked by the message server to rename a folder. @@ -1830,6 +1838,15 @@ bool QMailMessageSource::createFolder(const QString &name, const QMailAccountId return false; } +bool QMailMessageSource::createStandardFolders(const QMailAccountId &accountId, quint64 action) +{ + Q_UNUSED(accountId); + Q_UNUSED(action); + + notImplemented(); + return false; +} + /*! \overload renameFolder() diff --git a/src/libraries/qmfmessageserver/qmailmessageservice.h b/src/libraries/qmfmessageserver/qmailmessageservice.h index d12bc16c..cb7e8a94 100644 --- a/src/libraries/qmfmessageserver/qmailmessageservice.h +++ b/src/libraries/qmfmessageserver/qmailmessageservice.h @@ -163,6 +163,8 @@ public slots: virtual bool createFolder(const QString &name, const QMailAccountId &accountId, const QMailFolderId &parentId); virtual bool createFolder(const QString &name, const QMailAccountId &accountId, const QMailFolderId &parentId, quint64 action); + virtual bool createStandardFolders(const QMailAccountId &accountId); + virtual bool createStandardFolders(const QMailAccountId &accountId, quint64 action); virtual bool renameFolder(const QMailFolderId &folderId, const QString &name); virtual bool renameFolder(const QMailFolderId &folderId, const QString &name, quint64 action); virtual bool deleteFolder(const QMailFolderId &folderId); diff --git a/src/plugins/messageservices/imap/imapservice.cpp b/src/plugins/messageservices/imap/imapservice.cpp index db25390d..07f6a275 100644 --- a/src/plugins/messageservices/imap/imapservice.cpp +++ b/src/plugins/messageservices/imap/imapservice.cpp @@ -149,6 +149,7 @@ public slots: virtual bool flagMessages(const QMailMessageIdList &ids, quint64 setMask, quint64 unsetMask); virtual bool createFolder(const QString &name, const QMailAccountId &accountId, const QMailFolderId &parentId); + virtual bool createStandardFolders(const QMailAccountId &accountId); virtual bool deleteFolder(const QMailFolderId &folderId); virtual bool renameFolder(const QMailFolderId &folderId, const QString &name); @@ -942,10 +943,69 @@ bool ImapService::Source::createFolder(const QString &name, const QMailAccountId _service->errorOccurred(QMailServiceAction::Status::ErrInvalidData, tr("Cannot create empty named folder")); return false; } + bool matchFolderRequired = false; + _service->_client->strategyContext()->createFolderStrategy.createFolder(parentId, name, matchFolderRequired); - _service->_client->strategyContext()->createFolderStrategy.createFolder(parentId, name); + appendStrategy(&_service->_client->strategyContext()->createFolderStrategy); + if(!_unavailable) + return initiateStrategy(); + return true; +} + +bool ImapService::Source::createStandardFolders(const QMailAccountId &accountId) +{ + if (!_service->_client) { + _service->errorOccurred(QMailServiceAction::Status::ErrFrameworkFault, tr("Account disabled")); + return false; + } + + if (!accountId.isValid()) { + _service->errorOccurred(QMailServiceAction::Status::ErrInvalidData, tr("No account specified")); + return false; + } + + QMailAccount account = QMailAccount(accountId); + QStringList folderNames; + QList<QMailFolder::StandardFolder> defaultFolders; + defaultFolders << QMailFolder::DraftsFolder << QMailFolder::SentFolder << + QMailFolder::TrashFolder << QMailFolder::JunkFolder; + + //fix me create the names from the translations + foreach (QMailFolder::StandardFolder folder, defaultFolders) { + QMailFolderId standardFolderId = account.standardFolder(folder); + + if (!standardFolderId.isValid()) { + switch (folder) { + case QMailFolder::DraftsFolder: + folderNames << tr("Drafts"); + break; + case QMailFolder::SentFolder: + folderNames << tr("Sent"); + break; + case QMailFolder::JunkFolder: + folderNames << tr("Junk"); + break; + case QMailFolder::TrashFolder: + folderNames << tr("Trash"); + break; + default: + return false; + break; + } + } + } + + //Create the folder in the root + QMailFolder dummyParent; + for (int i = 0; i < folderNames.size(); ++i) { + qMailLog(Messaging) << "Creating folder: " << folderNames.at(i); + bool matchFolderRequired = true; + _service->_client->strategyContext()->createFolderStrategy.createFolder(dummyParent.id(), folderNames.at(i), matchFolderRequired); + } appendStrategy(&_service->_client->strategyContext()->createFolderStrategy); + + if(!_unavailable) return initiateStrategy(); return true; diff --git a/src/plugins/messageservices/imap/imapstrategy.cpp b/src/plugins/messageservices/imap/imapstrategy.cpp index e8b7672d..15141a98 100644 --- a/src/plugins/messageservices/imap/imapstrategy.cpp +++ b/src/plugins/messageservices/imap/imapstrategy.cpp @@ -677,8 +677,9 @@ void ImapCreateFolderStrategy::transition(ImapStrategyContextBase* context, cons } } -void ImapCreateFolderStrategy::createFolder(const QMailFolderId &folderParent, const QString &name) +void ImapCreateFolderStrategy::createFolder(const QMailFolderId &folderParent, const QString &name, bool matchFoldersRequired) { + _matchFoldersRequired = matchFoldersRequired; _folders.append(qMakePair(folderParent, name)); } @@ -703,9 +704,13 @@ void ImapCreateFolderStrategy::process(ImapStrategyContextBase *context) void ImapCreateFolderStrategy::folderCreated(ImapStrategyContextBase *context, const QString &folder) { - if(--_inProgress == 0) + if (--_inProgress == 0) { + if (_matchFoldersRequired) { + QMailAccountId accountId = context->config().id(); + QMail::detectStandardFolders(accountId); + } context->operationCompleted(); - + } Q_UNUSED(folder) } diff --git a/src/plugins/messageservices/imap/imapstrategy.h b/src/plugins/messageservices/imap/imapstrategy.h index 41e0004f..1bce9a01 100644 --- a/src/plugins/messageservices/imap/imapstrategy.h +++ b/src/plugins/messageservices/imap/imapstrategy.h @@ -176,7 +176,7 @@ public: virtual ~ImapCreateFolderStrategy() {} virtual void transition(ImapStrategyContextBase *, const ImapCommand, const OperationStatus); - virtual void createFolder(const QMailFolderId &folder, const QString &name); + virtual void createFolder(const QMailFolderId &folder, const QString &name, bool matchFoldersRequired); virtual void folderCreated(ImapStrategyContextBase *context, const QString &folder); protected: virtual void handleCreate(ImapStrategyContextBase *context); @@ -185,6 +185,9 @@ protected: QList<QPair<QMailFolderId, QString> > _folders; int _inProgress; + +private: + bool _matchFoldersRequired; }; diff --git a/src/tools/messageserver/mailmessageclient.cpp b/src/tools/messageserver/mailmessageclient.cpp index 86459eb7..3a65b838 100644 --- a/src/tools/messageserver/mailmessageclient.cpp +++ b/src/tools/messageserver/mailmessageclient.cpp @@ -116,6 +116,8 @@ MailMessageClient::MailMessageClient(QObject* parent) this, SIGNAL(retrieveMessageLists(quint64, QMailAccountId, QMailFolderIdList, uint, QMailMessageSortKey))); connectIpc(adaptor, MESSAGE(retrieveMessageList(quint64, QMailAccountId, QMailFolderId, uint, QMailMessageSortKey)), this, SIGNAL(retrieveMessageList(quint64, QMailAccountId, QMailFolderId, uint, QMailMessageSortKey))); + connectIpc(adaptor, MESSAGE(createStandardFolders(quint64, QMailAccountId)), + this, SIGNAL(createStandardFolders(quint64, QMailAccountId))); connectIpc(adaptor, MESSAGE(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification)), this, SIGNAL(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification))); connectIpc(adaptor, MESSAGE(retrieveMessagePart(quint64, QMailMessagePart::Location)), diff --git a/src/tools/messageserver/mailmessageclient.h b/src/tools/messageserver/mailmessageclient.h index f5d46d79..cc2b287b 100644 --- a/src/tools/messageserver/mailmessageclient.h +++ b/src/tools/messageserver/mailmessageclient.h @@ -74,6 +74,8 @@ signals: void retrieveMessageList(quint64, const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum, const QMailMessageSortKey &sort); void retrieveMessageLists(quint64, const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum, const QMailMessageSortKey &sort); + void createStandardFolders(quint64, const QMailAccountId &accountId); + void retrieveMessages(quint64, const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec); void retrieveMessagePart(quint64, const QMailMessagePart::Location &partLocation); diff --git a/src/tools/messageserver/messageserver.cpp b/src/tools/messageserver/messageserver.cpp index a8efa7ca..a5d82612 100644 --- a/src/tools/messageserver/messageserver.cpp +++ b/src/tools/messageserver/messageserver.cpp @@ -173,6 +173,8 @@ MessageServer::MessageServer(QObject *parent) handler, SLOT(retrieveMessageList(quint64, QMailAccountId, QMailFolderId, uint, QMailMessageSortKey))); connect(client, SIGNAL(retrieveMessageLists(quint64, QMailAccountId, QMailFolderIdList, uint, QMailMessageSortKey)), handler, SLOT(retrieveMessageLists(quint64, QMailAccountId, QMailFolderIdList, uint, QMailMessageSortKey))); + connect(client, SIGNAL(createStandardFolders(quint64, QMailAccountId)), + handler, SLOT(createStandardFolders(quint64, QMailAccountId))); connect(client, SIGNAL(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification)), handler, SLOT(retrieveMessages(quint64, QMailMessageIdList, QMailRetrievalAction::RetrievalSpecification))); connect(client, SIGNAL(retrieveMessagePart(quint64, QMailMessagePart::Location)), diff --git a/src/tools/messageserver/servicehandler.cpp b/src/tools/messageserver/servicehandler.cpp index c146bab4..7d3b9574 100644 --- a/src/tools/messageserver/servicehandler.cpp +++ b/src/tools/messageserver/servicehandler.cpp @@ -1579,6 +1579,40 @@ bool ServiceHandler::dispatchRetrieveMessageLists(quint64 action, const QByteArr return true; } +void ServiceHandler::createStandardFolders(quint64 action, const QMailAccountId &accountId) +{ + QSet<QMailMessageService*> sources(sourceServiceSet(accountId)); + if (sources.isEmpty()) { + reportFailure(action, QMailServiceAction::Status::ErrNoConnection, tr("Unable to retrieve standard folders for unconfigured account")); + } + else { + enqueueRequest(action, serialize(accountId), sources, &ServiceHandler::dispatchCreateStandardFolders, &ServiceHandler::retrievalCompleted, RetrieveFolderListRequestType); + } +} + +bool ServiceHandler::dispatchCreateStandardFolders(quint64 action, const QByteArray &data) +{ + QMailAccountId accountId; + + deserialize(data, accountId); + + if (QMailMessageSource *source = accountSource(accountId)) { + bool success(sourceService.value(source)->usesConcurrentActions() + ? source->createStandardFolders(accountId, action) + : source->createStandardFolders(accountId)); + if (success) { + return true; + } else { + qWarning() << "Unable to service request to create standard folder for account:" << accountId; + return false; + } + + } else { + reportFailure(action, QMailServiceAction::Status::ErrFrameworkFault, tr("Unable to locate source for account"), accountId); + return false; + } +} + void ServiceHandler::retrieveMessages(quint64 action, const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec) { QMap<QMailAccountId, QMailMessageIdList> messageLists(accountMessages(messageIds)); diff --git a/src/tools/messageserver/servicehandler.h b/src/tools/messageserver/servicehandler.h index ea3d95cd..7751d295 100644 --- a/src/tools/messageserver/servicehandler.h +++ b/src/tools/messageserver/servicehandler.h @@ -71,6 +71,7 @@ public slots: void retrieveFolderList(quint64, const QMailAccountId &accountId, const QMailFolderId &folderId, bool descending); void retrieveMessageList(quint64, const QMailAccountId &accountId, const QMailFolderId &folderId, uint minimum, const QMailMessageSortKey &sort); void retrieveMessageLists(quint64, const QMailAccountId &accountId, const QMailFolderIdList &folderIds, uint minimum, const QMailMessageSortKey &sort); + void createStandardFolders(quint64, const QMailAccountId &accountId); void retrieveMessages(quint64, const QMailMessageIdList &messageIds, QMailRetrievalAction::RetrievalSpecification spec); void retrieveMessagePart(quint64, const QMailMessagePart::Location &partLocation); void retrieveMessageRange(quint64, const QMailMessageId &messageId, uint minimum); @@ -253,6 +254,7 @@ private: bool dispatchRetrieveFolderList(quint64, const QByteArray &data); bool dispatchRetrieveMessageList(quint64, const QByteArray &data); bool dispatchRetrieveMessageLists(quint64, const QByteArray &data); + bool dispatchCreateStandardFolders(quint64, const QByteArray &data); bool dispatchRetrieveMessages(quint64, const QByteArray &data); bool dispatchRetrieveMessagePart(quint64, const QByteArray &data); bool dispatchRetrieveMessageRange(quint64, const QByteArray &data); |