fix gmail attachment download
This commit is contained in:
parent
eeb12394a4
commit
6ffc2c0a8d
6 changed files with 20 additions and 17 deletions
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
MessageTextBrowser::MessageTextBrowser(QWidget* parent) : QTextBrowser(parent) {}
|
MessageTextBrowser::MessageTextBrowser(QWidget* parent) : QTextBrowser(parent) {}
|
||||||
|
|
||||||
MessageTextBrowser::~MessageTextBrowser() {}
|
|
||||||
|
|
||||||
QVariant MessageTextBrowser::loadResource(int type, const QUrl& name) {
|
QVariant MessageTextBrowser::loadResource(int type, const QUrl& name) {
|
||||||
Q_UNUSED(name)
|
Q_UNUSED(name)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ class MessageTextBrowser : public QTextBrowser {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MessageTextBrowser(QWidget* parent = 0);
|
explicit MessageTextBrowser(QWidget* parent = nullptr);
|
||||||
virtual ~MessageTextBrowser();
|
virtual ~MessageTextBrowser() = default;
|
||||||
|
|
||||||
QVariant loadResource(int type, const QUrl& name);
|
QVariant loadResource(int type, const QUrl& name);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#define GMAIL_OAUTH_SCOPE "https://mail.google.com/"
|
#define GMAIL_OAUTH_SCOPE "https://mail.google.com/"
|
||||||
|
|
||||||
#define GMAIL_API_BATCH_UPD_LABELS "https://www.googleapis.com/gmail/v1/users/me/messages/batchModify"
|
#define GMAIL_API_BATCH_UPD_LABELS "https://www.googleapis.com/gmail/v1/users/me/messages/batchModify"
|
||||||
#define GMAIL_API_GET_ATTACHMENT "https://www.googleapis.com/gmail/v1/users/me/messages/%20/attachments/"
|
#define GMAIL_API_GET_ATTACHMENT "https://www.googleapis.com/gmail/v1/users/me/messages/%1/attachments/%2"
|
||||||
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
|
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
|
||||||
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
|
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
|
||||||
#define GMAIL_API_BATCH "https://www.googleapis.com/batch"
|
#define GMAIL_API_BATCH "https://www.googleapis.com/batch"
|
||||||
|
|
|
@ -118,14 +118,16 @@ bool GmailServiceRoot::downloadAttachmentOnMyOwn(const QUrl& url) const {
|
||||||
QString file = QFileDialog::getSaveFileName(qApp->mainFormWidget(), tr("Select attachment destination file"),
|
QString file = QFileDialog::getSaveFileName(qApp->mainFormWidget(), tr("Select attachment destination file"),
|
||||||
qApp->homeFolder() + QDir::separator() + parts.at(0));
|
qApp->homeFolder() + QDir::separator() + parts.at(0));
|
||||||
|
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty() && parts.size() == 3) {
|
||||||
Downloader* down = network()->downloadAttachment(parts.at(1));
|
Downloader* down = network()->downloadAttachment(parts.at(1), parts.at(2));
|
||||||
FormDownloadAttachment form(file, down, qApp->mainFormWidget());
|
FormDownloadAttachment form(file, down, qApp->mainFormWidget());
|
||||||
|
|
||||||
form.exec();
|
form.exec();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> GmailServiceRoot::serviceMenu() {
|
QList<QAction*> GmailServiceRoot::serviceMenu() {
|
||||||
|
|
|
@ -72,20 +72,21 @@ void GmailNetworkFactory::setUsername(const QString& username) {
|
||||||
m_username = username;
|
m_username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
Downloader* GmailNetworkFactory::downloadAttachment(const QString& attachment_id) {
|
Downloader* GmailNetworkFactory::downloadAttachment(const QString& msg_id, const QString& attachment_id) {
|
||||||
Downloader* downloader = new Downloader();
|
Downloader* downloader = new Downloader();
|
||||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||||
|
|
||||||
if (bearer.isEmpty()) {
|
if (bearer.isEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
QString target_url = QString(GMAIL_API_GET_ATTACHMENT).arg(msg_id, attachment_id);
|
||||||
|
|
||||||
QString target_url = QString(GMAIL_API_GET_ATTACHMENT) + attachment_id;
|
downloader->appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit());
|
||||||
|
downloader->downloadFile(target_url);
|
||||||
|
|
||||||
downloader->appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit());
|
return downloader;
|
||||||
downloader->downloadFile(target_url);
|
}
|
||||||
|
|
||||||
return downloader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Status& error) {
|
QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Status& error) {
|
||||||
|
@ -356,7 +357,9 @@ bool GmailNetworkFactory::fillFullMessage(Message& msg, const QJsonObject& json,
|
||||||
}
|
}
|
||||||
else if (!filename.isEmpty()) {
|
else if (!filename.isEmpty()) {
|
||||||
// We have attachment.
|
// We have attachment.
|
||||||
msg.m_enclosures.append(Enclosure(filename + QL1S(GMAIL_ATTACHMENT_SEP) + body["attachmentId"].toString(),
|
msg.m_enclosures.append(Enclosure(filename +
|
||||||
|
QL1S(GMAIL_ATTACHMENT_SEP) + msg.m_customId +
|
||||||
|
QL1S(GMAIL_ATTACHMENT_SEP) + body["attachmentId"].toString(),
|
||||||
filename + QString(" (%1 KB)").arg(QString::number(body["size"].toInt() / 1000.0))));
|
filename + QString(" (%1 KB)").arg(QString::number(body["size"].toInt() / 1000.0))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class GmailNetworkFactory : public QObject {
|
||||||
// Returned items do not have primary IDs assigned.
|
// Returned items do not have primary IDs assigned.
|
||||||
//RootItem* feedsCategories();
|
//RootItem* feedsCategories();
|
||||||
|
|
||||||
Downloader* downloadAttachment(const QString& attachment_id);
|
Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id);
|
||||||
|
|
||||||
QList<Message> messages(const QString& stream_id, Feed::Status& error);
|
QList<Message> messages(const QString& stream_id, Feed::Status& error);
|
||||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue