clazy: fix QString(QLatin1String(...))
[trojita.git] / src / Imap / Tasks / FetchMsgMetadataTask.cpp
blob43b5ee328fa074a98f8d1ccd57302bce1f3350e3
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "FetchMsgMetadataTask.h"
25 #include "Imap/Model/ItemRoles.h"
26 #include "Imap/Model/Model.h"
27 #include "Imap/Model/MailboxTree.h"
28 #include "KeepMailboxOpenTask.h"
30 namespace Imap
32 namespace Mailbox
35 FetchMsgMetadataTask::FetchMsgMetadataTask(Model *model, const QModelIndex &mailbox, const Imap::Uids &uids) :
36 ImapTask(model), mailbox(mailbox), uids(uids)
38 Q_ASSERT(!uids.isEmpty());
39 conn = model->findTaskResponsibleFor(mailbox);
40 conn->addDependentTask(this);
43 void FetchMsgMetadataTask::perform()
45 parser = conn->parser;
46 markAsActiveTask();
48 IMAP_TASK_CHECK_ABORT_DIE;
50 Sequence seq = Sequence::fromVector(uids);
52 // we do not want to use _onlineMessageFetch because it contains UID and FLAGS
53 tag = parser->uidFetch(seq, QList<QByteArray>() << "ENVELOPE" << "INTERNALDATE" <<
54 "BODYSTRUCTURE" << "RFC822.SIZE" << "BODY.PEEK[HEADER.FIELDS (References List-Post)]");
57 bool FetchMsgMetadataTask::handleFetch(const Imap::Responses::Fetch *const resp)
59 if (! mailbox.isValid()) {
60 _failed(tr("handleFetch: mailbox disappeared"));
61 // FIXME: nice error handling
62 return false;
64 TreeItemMailbox *mailboxPtr = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItemMailbox *>(mailbox.internalPointer()));
65 Q_ASSERT(mailboxPtr);
66 model->genericHandleFetch(mailboxPtr, resp);
67 return true;
70 bool FetchMsgMetadataTask::handleStateHelper(const Imap::Responses::State *const resp)
72 if (resp->tag.isEmpty())
73 return false;
75 if (resp->tag == tag) {
77 if (resp->kind == Responses::OK) {
78 _completed();
79 } else {
80 _failed(tr("UID FETCH failed"));
81 // FIXME: error handling
83 return true;
84 } else {
85 return false;
89 QString FetchMsgMetadataTask::debugIdentification() const
91 if (!mailbox.isValid())
92 return QStringLiteral("[invalid mailbox]");
94 Q_ASSERT(!uids.isEmpty());
95 return QString::fromUtf8("%1: UIDs %2").arg(mailbox.data(RoleMailboxName).toString(),
96 QString::fromUtf8(Sequence::fromVector(uids).toByteArray()));
99 QVariant FetchMsgMetadataTask::taskData(const int role) const
101 return role == RoleTaskCompactName ? QVariant(tr("Downloading headers")) : QVariant();