Commit c6f22482 authored by Martin Straka's avatar Martin Straka

Files refactoring - part 1

parent 9643366c
......@@ -85,6 +85,7 @@ TRANSLATIONS_FILES += \
SOURCES += \
src/accounts.cpp \
src/auxiliaries/attachment_helper.cpp \
src/auxiliaries/email_helper.cpp \
src/dialogues/dialogues.cpp \
src/dialogues/qml_dialogue_helper.cpp \
src/dialogues/qml_input_dialogue.cpp \
......@@ -144,6 +145,7 @@ SOURCES += \
HEADERS += \
src/accounts.h \
src/auxiliaries/attachment_helper.h \
src/auxiliaries/email_helper.h \
src/common.h \
src/dialogues/dialogues.h \
src/dialogues/qml_dialogue_helper.h \
......
......@@ -172,7 +172,7 @@ Component {
isds.doIsdsAction("downloadMessage", userName)
pageView.pop(StackView.Immediate)
} else if (index == 1) {
files.sendAttachmentsWithEmailFromDb(userName, msgId)
files.sendAttachmentsWithEmail(userName, msgId)
pageView.pop(StackView.Immediate)
} else if (index == 2) {
files.saveAttachmentsToDiskDb(userName, msgId)
......
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include <QDateTime>
#include <QMimeDatabase>
#include <QMimeType>
#include "src/auxiliaries/email_helper.h"
void addAttachmentToEmailMessage(QString &message, const QString &attachName,
const QByteArray &base64, const QString &boundary)
{
const QString newLine("\n"); /* "\r\n" ? */
QMimeDatabase mimeDb;
QMimeType mimeType(
mimeDb.mimeTypeForData(QByteArray::fromBase64(base64)));
message += newLine;
message += "--" + boundary + newLine;
message += "Content-Type: " + mimeType.name() + "; charset=UTF-8;"
+ newLine + " name=\"" + attachName + "\"" + newLine;
message += "Content-Transfer-Encoding: base64" + newLine;
message += "Content-Disposition: attachment;" + newLine +
" filename=\"" + attachName + "\"" + newLine;
for (int i = 0; i < base64.size(); ++i) {
if ((i % 60) == 0) {
message += newLine;
}
message += base64.at(i);
}
message += newLine;
}
QString createEmailMessage(const QString &body, const QString &subj,
const QString &boundary)
{
const QString newLine("\n"); /* "\r\n" ? */
/* Rudimentary header. */
QString message("Subject: " + subj + newLine);
message += "MIME-Version: 1.0" + newLine;
message += "Content-Type: multipart/mixed;" + newLine +
" boundary=\"" + boundary + "\"" + newLine;
/* Body. */
message += newLine;
message += "--" + boundary + newLine;
message += "Content-Type: text/plain; charset=UTF-8" + newLine;
message += "Content-Transfer-Encoding: 8bit" + newLine;
message += newLine;
message += "-- " + newLine; /* Must contain the space. */
message += body + newLine;
return message;
}
void finishEmailMessage(QString &message, const QString &boundary)
{
const QString newLine("\n"); /* "\r\n" ? */
message += newLine + "--" + boundary + "--" + newLine;
}
QString generateBoundaryString(void)
{
return "-----123456789asdfghj_" +
QDateTime::currentDateTimeUtc().toString("dd.MM.yyyy-HH:mm:ss.zzz");
}
QString generateEmailBodyText(qint64 dmId, const QString &from,
const QString &to, const QString &delivered)
{
QString body(QObject::tr("ID") + ": ");
body += QString::number(dmId) + "\n";
body += QObject::tr("FROM") + ": ";
body += from + "\n";
body += QObject::tr("TO") + ": ";
body += to + "\n";
body += QObject::tr("DELIVERED") + ": ";
body += delivered + "\n\n---\n";
body += QObject::tr("This email has been generated with Datovka "
"application based on a data message (%1) delivered "
"to databox.").arg(dmId);
body += "\n";
return body;
}
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#ifndef _EMAIL_HELPER_H_
#define _EMAIL_HELPER_H_
#include <QObject>
/*!
* @brief Add attachment into email.
*
* @param[in,out] message String to append data to.
* @param[in] attachName Attachment name.
* @param[in] base64 Base64-encoded attachment.
* @param[in] boundary Boundary to be used.
*/
void addAttachmentToEmailMessage(QString &message, const QString &attachName,
const QByteArray &base64, const QString &boundary);
/*!
* @brief Creates email header and message body.
*
* @param[in] body Email body.
* @param[in] subj Subject text.
* @param[in] boundary Boundary to be used.
* @return Email header string.
*/
QString createEmailMessage(const QString &body, const QString &subject,
const QString &boundary);
/*!
* @brief Adds last line into email.
*
* @param[in,out] message String to append data to.
* @param[in] boundary Boundary to be used.
*/
void finishEmailMessage(QString &message, const QString &boundary);
/*!
* @brief Generates boundary string for email body parts.
*
* @return Boundary string.
*/
QString generateBoundaryString(void);
/*!
* @brief Creates email body text.
*
* @param[in] dmId Message ID.
* @param[in] from Sender name.
* @param[in] to Recipient name.
* @param[in] delivered Delivery time.
* @return Email body string.
*/
QString generateEmailBodyText(qint64 dmId, const QString &from,
const QString &to, const QString &delivered);
#endif /* _EMAIL_HELPER_H_ */
This diff is collapsed.
......@@ -45,10 +45,6 @@ public:
};
Q_ENUM(FileIdType)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
/*!
* @brief Constructor.
*
......@@ -56,13 +52,36 @@ public:
*/
explicit Files(QObject *parent = Q_NULLPTR);
/*!
* @brief Declare various properties to the QML system.
*/
static
void declareQML(void);
/*!
* @brief Generates a notification dialogue about the
* result of attachment saving.
*
* @param[in] destPath Path to which the attachment was saved.
*/
static
void attachmentSavingNotification(const QString &destPath);
/*!
* @brief Obtain path for storing attachments.
*
* @return Path to location where attachment can be stored.
*/
static
QString fileSaveLocation(void);
/*!
* @brief Get attachment file icon from file name.
*
* @param[in] fileName File name.
* @return File icon resources string.
*/
Q_INVOKABLE
Q_INVOKABLE static
QString getAttachmentFileIcon(const QString &fileName);
/*!
......@@ -71,7 +90,7 @@ public:
* @param[in] filePath Path to file.
* @return File size in bytes.
*/
Q_INVOKABLE
Q_INVOKABLE static
qint64 getAttachmentSizeInBytes(const QString &filePath);
/*!
......@@ -99,6 +118,9 @@ public:
/*!
* @brief Open attachment in default application.
*
* @param[in] fileName File name.
* @param[in] base64Data File content base64.
*/
Q_INVOKABLE static
void openAttachment(const QString &fileName,
......@@ -106,6 +128,8 @@ public:
/*!
* @brief Open attachment from path in default application.
*
* @param[in] filePath File path.
*/
Q_INVOKABLE static
void openAttachmentFromPath(const QString &filePath);
......@@ -114,15 +138,19 @@ public:
* @brief Send attachments from database with email application.
*
* @param[in] userName User name of account.
* @param[in] msgId Message id.
* @param[in] msgId Message id.
*/
Q_INVOKABLE void sendAttachmentsWithEmailFromDb(const QString &userName,
Q_INVOKABLE
void sendAttachmentsWithEmail(const QString &userName,
qint64 msgId);
/*!
* @brief Delete file database.
*
* @param[in] userName User name of account.
*/
Q_INVOKABLE void deleteFileDb(const QString &userName);
Q_INVOKABLE
void deleteFileDb(const QString &userName);
/*!
* @brief Delete files from all file databases
......@@ -135,7 +163,8 @@ public:
/*!
* @brief Vacuum all file databases.
*/
Q_INVOKABLE void vacuumFileDbs(void);
Q_INVOKABLE
void vacuumFileDbs(void);
/*!
* @brief Delete message attachments from databases.
......@@ -207,7 +236,7 @@ public:
* @param[out] attachModel Attachment model to be set.
* @param[in] userName Identifies the account.
* @param[in] msgId Message identifier.
* @return true if success.
* @return True if success.
*/
static
bool setAttachmentModel(FileListModel &attachModel,
......@@ -275,10 +304,10 @@ private:
* @brief Send email.
*
* @param[in] emailMessage Eml email content.
* @param[in] fileList File list for email.
* @param[in] subject Email subject
* @param[in] body Email body.
* @param[in] msgId Message ID.
* @param[in] fileList File list for email.
* @param[in] subject Email subject
* @param[in] body Email body.
* @param[in] msgId Message ID.
*/
static
void sendEmail(const QString &emailMessage, const QStringList &fileList,
......
......@@ -47,11 +47,13 @@ public:
/*!
* @brief Constructor.
*
* @param[in] parent Parent object.
*/
Messages(QObject *parent = Q_NULLPTR);
/*!
* @brief Declare various properties to the QML system..
* @brief Declare various properties to the QML system.
*/
static
void declareQML(void);
......
......@@ -31,6 +31,7 @@
#include <QSqlRecord>
#include <QStandardPaths>
#include "src/auxiliaries/email_helper.h"
#include "src/common.h"
#include "src/io/filesystem.h"
#include "src/models/messagemodel.h"
......@@ -453,19 +454,9 @@ bool MessageDb::getMessageDataForEmail(qint64 dmId, QString &body,
query.bindValue(":dmID", dmId);
if (query.exec() && query.isActive() &&
query.first() && query.isValid()) {
body += QObject::tr("ID") + ": ";
body += QString::number(dmId) + "\n";
body += QObject::tr("FROM") + ": ";
body += query.value(0).toString() + "\n";
body += QObject::tr("TO") + ": ";
body += query.value(1).toString() + "\n";
body += QObject::tr("DELIVERED") + ": ";
body += dateTimeStrFromDbFormat(query.value(2).toString(),
DATETIME_QML_FORMAT) + "\n\n---\n";
body += QObject::tr("This email has been generated with Datovka "
"application based on a data message (%1) delivered "
"to databox.").arg(dmId);
body += "\n";
body = generateEmailBodyText(dmId, query.value(0).toString(),
query.value(1).toString(), dateTimeStrFromDbFormat(
query.value(2).toString(), DATETIME_QML_FORMAT));
subject = query.value(3).toString();
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment