Commit 0d303c01 authored by Martin Straka's avatar Martin Straka

Modified send log via email

parent e7ce33d5
......@@ -54,13 +54,16 @@ void addAttachmentToEmailMessage(QString &message, const QString &attachName,
message += newLine;
}
QString createEmailMessage(const QString &body, const QString &subj,
const QString &boundary)
QString createEmailMessage(const QString &to, const QString &body,
const QString &subj, const QString &boundary)
{
const QString newLine("\n"); /* "\r\n" ? */
/* Rudimentary header. */
QString message("Subject: " + subj + newLine);
if (!to.isEmpty()) {
message += "To: " + to + newLine;
}
message += "MIME-Version: 1.0" + newLine;
message += "Content-Type: multipart/mixed;" + newLine +
" boundary=\"" + boundary + "\"" + newLine;
......
......@@ -40,13 +40,14 @@ void addAttachmentToEmailMessage(QString &message, const QString &attachName,
/*!
* @brief Creates email header and message body.
*
* @param[in] to Recipient mail address.
* @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);
QString createEmailMessage(const QString &to, const QString &body,
const QString &subject, const QString &boundary);
/*!
* @brief Adds last line into email.
......
......@@ -302,8 +302,10 @@ void Files::sendLogViaEmail(const QString &logContent)
if (msgResponse == Dialogues::NO) {
return;
}
QString subject = "Mobile Datovka: Log File";
QString body = "Mobile Datovka";
QString to("datove-schranky@labs.nic.cz");
QString subject("Mobile Datovka: Log File");
QString body("Mobile Datovka");
body.append("\nVersion: " + QStringLiteral(VERSION));
body.append("\nOS: " + QSysInfo::productType() + " " + QSysInfo::productVersion());
body.append("\nArch: " + QSysInfo::currentCpuArchitecture());
......@@ -317,11 +319,11 @@ void Files::sendLogViaEmail(const QString &logContent)
attachmentList.append(filePath);
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
QString emailMessage = createEmailMessage(to, body, subject, boundary);
addAttachmentToEmailMessage(emailMessage, "mobile-datovka.log",
logContent.toUtf8().toBase64(), boundary);
finishEmailMessage(emailMessage, boundary);
sendEmail(emailMessage, attachmentList, subject, body, 0);
sendEmail(emailMessage, attachmentList, to, subject, body, "Log");
}
void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
......@@ -404,7 +406,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
QString targetPath(appEmailDirPath(QString::number(msgId)));
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
QString emailMessage = createEmailMessage(QString(), body, subject,
boundary);
QStringList filePathList;
/* Write attachment files to email directory */
......@@ -424,7 +427,8 @@ void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
finishEmailMessage(emailMessage, boundary);
/* Send email */
sendEmail(emailMessage, filePathList, subject, body, msgId);
sendEmail(emailMessage, filePathList, QString(), subject, body,
QString::number(msgId));
}
void Files::deleteFileDb(const QString &userName)
......@@ -651,7 +655,8 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
QStringList fileList;
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
QString emailMessage = createEmailMessage(QString(), body, subject,
boundary);
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
QString targetPath(appEmailDirPath(msgIdStr));
......@@ -675,7 +680,8 @@ void Files::sendAttachmentEmailZfo(const QVariant &attachModelVariant,
finishEmailMessage(emailMessage, boundary);
sendEmail(emailMessage, fileList, subject, body, msgId);
sendEmail(emailMessage, fileList, QString(), subject, body,
QString::number(msgId));
}
void Files::saveMsgFilesToDisk(const QString &userName,
......@@ -793,8 +799,10 @@ void Files::deleteTmpFileFromStorage(const QString &filePath)
}
void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
const QString &subject, const QString &body, qint64 msgId)
const QString &to, const QString &subject, const QString &body,
const QString &msgId)
{
Q_UNUSED(to);
Q_UNUSED(subject);
Q_UNUSED(body);
Q_UNUSED(emailMessage);
......@@ -804,18 +812,17 @@ void Files::sendEmail(const QString &emailMessage, const QStringList &fileList,
#if defined Q_OS_IOS
UrlOpener urlOpener;
urlOpener.createEmail(body, subject, fileList);
urlOpener.createEmail(body, to, subject, fileList);
#elif defined Q_OS_ANDROID
QDesktopServices::openUrl(QUrl("mailto:?subject=" + subject +
"&body=" + body));
QDesktopServices::openUrl(QUrl("mailto:?to=" + to
+ "&subject=" + subject + "&body=" + body));
#else
QString tmpEmailFile = writeFile(
appEmailDirPath(QString::number(msgId)),
QString::number(msgId) + "_mail.eml", emailMessage.toUtf8());
QString tmpEmailFile = writeFile(appEmailDirPath(msgId),
msgId + "_mail.eml", emailMessage.toUtf8());
QDesktopServices::openUrl(QUrl::fromLocalFile(tmpEmailFile));
#endif
......
......@@ -334,13 +334,15 @@ private:
*
* @param[in] emailMessage Eml email content.
* @param[in] fileList File list for email.
* @param[in] to Recipient mail addreess.
* @param[in] subject Email subject.
* @param[in] body Email body.
* @param[in] msgId Message ID.
*/
static
void sendEmail(const QString &emailMessage, const QStringList &fileList,
const QString &subject, const QString &body, qint64 msgId);
const QString &to, const QString &subject, const QString &body,
const QString &msgId);
/*!
* @brief Parse xml data of zfo file.
......
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