diff options
Diffstat (limited to '')
-rw-r--r-- | src/Mime.cpp | 233 | ||||
-rw-r--r-- | src/gpg/GpgContext.cpp | 55 | ||||
-rw-r--r-- | src/smtp/mimemultipart.cpp | 2 | ||||
-rw-r--r-- | src/smtp/mimepart.cpp | 2 | ||||
-rw-r--r-- | src/ui/AttachmentTableModel.cpp | 134 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 7 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowUI.cpp | 22 | ||||
-rw-r--r-- | src/ui/widgets/Attachments.cpp | 180 |
8 files changed, 0 insertions, 635 deletions
diff --git a/src/Mime.cpp b/src/Mime.cpp deleted file mode 100644 index 8e4c8d72..00000000 --- a/src/Mime.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/** - * This file is part of GPGFrontend. - * - * GPGFrontend 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -/* TODO: proper import / copyright statement - * - */ - -#include "Mime.h" - -Mime::Mime(QByteArray *message) { - splitParts(message); - /* - mMessage = message; - int bStart = mMessage->indexOf("boundary=\"") + 10 ; - int bEnd = mMessage->indexOf("\"\n", bStart ); - - qDebug() << "bStart: " << bStart << " bEnd: " << bEnd; - mBoundary = new QByteArray(mMessage->mid(bStart, bEnd - bStart)); - qDebug() << "boundary: " << *mBoundary; - - Part *p1 = new Part(); - - int nb = mMessage->indexOf(*mBoundary, bEnd) + mBoundary->length() +1 ; - qDebug() << "nb: " << nb; - int eh = mMessage->indexOf("\n\n", nb); - qDebug() << "eh: " << eh; - QByteArray *header = new QByteArray(mMessage->mid(nb , eh - nb)); - qDebug() << "header:" << header; - - // split header at newlines - foreach(QByteArray tmp , header->split(* "\n")) { - // split lines at : - QList<QByteArray> tmp2 = tmp.split(* ":"); - p1->header.insert(QString(tmp2[0].trimmed()), QString(tmp2[1].trimmed())); - } - - QHashIterator<QString, QString> i(p1->header); - while (i.hasNext()) { - i.next(); - qDebug() << "found: " << i.key() << ":" << i.value() << endl; - } - - int nb2 = mMessage->indexOf(*mBoundary, eh); - - p1->body = mMessage->mid(eh , nb2 - eh); - - QTextCodec *codec = QTextCodec::codecForName("ISO-8859-15"); - QString qs = codec->toUnicode(p1->body); - qDebug() << "body: " << qs; - */ -} - -Mime::~Mime() -= default; - -void Mime::splitParts(QByteArray *message) { - int pos1, pos2, headEnd; - MimePart p_tmp; - - // find the boundary - pos1 = message->indexOf("boundary=\"") + 10; - pos2 = message->indexOf("\"\n", pos1); - QByteArray boundary = message->mid(pos1, pos2 - pos1); - //qDebug() << "boundary: " << boundary; - - while (pos2 > pos1) { - - pos1 = message->indexOf(boundary, pos2) + boundary.length() + 1; - headEnd = message->indexOf("\n\n", pos1); - if (headEnd < 0) - break; - QByteArray header = message->mid(pos1, headEnd - pos1); - - p_tmp.header = parseHeader(&header); - - pos2 = message->indexOf(boundary, headEnd); - p_tmp.body = message->mid(headEnd, pos2 - headEnd); - - mPartList.append(p_tmp); - } -} - -Header Mime::parseHeader(QByteArray *header) { - - QList<HeadElem> ret; - - /** http://www.aspnetmime.com/help/welcome/overviewmimeii.html : - * If a line starts with any white space, that line is said to be 'folded' and is actually - * part of the header above it. - */ - header->replace("\n ", " "); - - //split header at newlines - foreach(QByteArray line, header->split(*"\n")) { - HeadElem elem; - //split lines at : - QList<QByteArray> tmp2 = line.split(*":"); - elem.name = tmp2[0].trimmed(); - if (tmp2[1].contains(';')) { - // split lines at ; - // TODO: what if ; is inside "" - QList<QByteArray> tmp3 = tmp2[1].split(*";"); - elem.value = QString(tmp3.takeFirst().trimmed()); - foreach(QByteArray tmp4, tmp3) { - QList<QByteArray> tmp5 = tmp4.split(*"="); - elem.params.insert(QString(tmp5[0].trimmed()), QString(tmp5[1].trimmed())); - } - } else { - elem.value = tmp2[1].trimmed(); - } - ret.append(elem); - } - return Header(ret); -} - -Header Mime::getHeader(const QByteArray *message) { - int headEnd = message->indexOf("\n\n"); - QByteArray header = message->mid(0, headEnd); - return parseHeader(&header); -} - -bool Mime::isMultipart(QByteArray *message) { - return message->startsWith("Content-Type: multipart/mixed;"); -} - -/** - * if Content-Type is specified, it should be mime - * - */ -bool Mime::isMime(const QByteArray *message) { - return message->startsWith("Content-Type:"); -} - -/*** - * quotedPrintableDecode copied from KCodecs, where it is stated: - - The quoted-printable codec as described in RFC 2045, section 6.7. is by - Rik Hemsley (C) 2001. - - */ - -static const char hexChars[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' -}; - -/******************************** KCodecs ********************************/ -// strchr(3) for broken systems. -static int rikFindChar(const char *_s, const char c) { - const char *s = _s; - - while (true) { - if ((0 == *s) || (c == *s)) break; - ++s; - if ((0 == *s) || (c == *s)) break; - ++s; - if ((0 == *s) || (c == *s)) break; - ++s; - if ((0 == *s) || (c == *s)) break; - ++s; - } - - return static_cast<int>(s - _s); -} - -void Mime::quotedPrintableDecode(const QByteArray &in, QByteArray &out) { - // clear out the output buffer - out.resize(0); - if (in.isEmpty()) - return; - - char *cursor; - const char *data; - const size_t length = in.size(); - - data = in.data(); - out.resize(static_cast<int>(length)); - cursor = out.data(); - - for (unsigned int i = 0; i < length; i++) { - char c(in[i]); - - if ('=' == c) { - if (i < length - 2) { - char c1 = in[i + 1]; - char c2 = in[i + 2]; - - if (('\n' == c1) || ('\r' == c1 && '\n' == c2)) { - // Soft line break. No output. - if ('\r' == c1) - i += 2; // CRLF line breaks - else - i += 1; - } else { - // =XX encoded byte. - - int hexChar0 = rikFindChar(hexChars, c1); - int hexChar1 = rikFindChar(hexChars, c2); - - if (hexChar0 < 16 && hexChar1 < 16) { - *cursor++ = char((hexChar0 * 16) | hexChar1); - i += 2; - } - } - } - } else { - *cursor++ = c; - } - } - - out.truncate(static_cast<int>(cursor - out.data())); -} diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 028653b7..7ec521a7 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -25,7 +25,6 @@ #include "gpg/GpgContext.h" #include <unistd.h> /* contains read/write */ -#include <Mime.h> #ifdef _WIN32 @@ -430,38 +429,6 @@ namespace GpgME { return err; } - - /** - * if this is mime, split text and attachments... - * message contains only text afterwards - */ - void parseMime(QByteArray *message) { - - QString pText; - bool show_ma_dock = false; - - Mime *mime = new Mime(message); - for (MimePart tmp : mime->parts()) { - if (tmp.header.getValue("Content-Type") == "text/plain" && - tmp.header.getValue("Content-Transfer-Encoding") != "base64") { - QByteArray body; - if (tmp.header.getValue("Content-Transfer-Encoding") == "quoted-printable") { - Mime::quotedPrintableDecode(tmp.body, body); - } else { - body = tmp.body; - } - pText.append(QString(body)); - } else { - // TODO - show_ma_dock = true; - } - } - *message = pText.toUtf8(); - if (show_ma_dock) { - // TODO - } - } - /** Decrypt QByteAarray, return QByteArray * mainly from http://basket.kde.org/ (kgpgme.cpp) */ @@ -496,28 +463,6 @@ namespace GpgME { gpgme_data_release(dataOut); } - /* - * 1) is it mime (content-type:) - * 2) parse header - * 2) choose action depending on content-type - */ - if (Mime::isMime(outBuffer)) { - Header header = Mime::getHeader(outBuffer); - // is it multipart, is multipart-parsing enabled - if (header.getValue("Content-Type") == "multipart/mixed" - && settings.value("mime/parseMime").toBool()) { - parseMime(outBuffer); - } else if (header.getValue("Content-Type") == "text/plain" - && settings.value("mime/parseQP").toBool()) { - if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") { - auto *decoded = new QByteArray(); - Mime::quotedPrintableDecode(*outBuffer, *decoded); - //TODO: remove header - outBuffer = decoded; - } - } - } - if (result != nullptr) { *result = m_result; } diff --git a/src/smtp/mimemultipart.cpp b/src/smtp/mimemultipart.cpp index a8cffed6..14a813c2 100644 --- a/src/smtp/mimemultipart.cpp +++ b/src/smtp/mimemultipart.cpp @@ -43,8 +43,6 @@ MimeMultiPart::MimeMultiPart(MultiPartType type) { cBoundary = md5.result().toHex(); } -MimeMultiPart::~MimeMultiPart() = default; - void MimeMultiPart::addPart(MimePart *part) { parts.append(part); } const QList<MimePart *> &MimeMultiPart::getParts() const { return parts; } diff --git a/src/smtp/mimepart.cpp b/src/smtp/mimepart.cpp index cbf52a4a..5d33884d 100644 --- a/src/smtp/mimepart.cpp +++ b/src/smtp/mimepart.cpp @@ -27,8 +27,6 @@ MimePart::MimePart() { cBoundary = ""; } -MimePart::~MimePart() = default; - /* [1] --- */ /* [2] Getters and Setters */ diff --git a/src/ui/AttachmentTableModel.cpp b/src/ui/AttachmentTableModel.cpp deleted file mode 100644 index 79cbdf9b..00000000 --- a/src/ui/AttachmentTableModel.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/** - * This file is part of GPGFrontend. - * - * GPGFrontend 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#include "ui/AttachmentTableModel.h" - -#include <utility> - -/** compare with http://doc.qt.nokia.com/4.6/itemviews-addressbook.html - */ - -AttachmentTableModel::AttachmentTableModel(QObject *parent) : - QAbstractTableModel(parent) { -} - -AttachmentTableModel::AttachmentTableModel(QList<MimePart> mimeparts, QObject *parent) : - QAbstractTableModel(parent) { - listOfMimeparts = std::move(mimeparts); -} - - -void AttachmentTableModel::add(const MimePart &mp) { - listOfMimeparts.append(mp); - //QModelIndex changedIndex0 = createIndex(listOfMimeparts.size(), 0); - //QModelIndex changedIndex1 = createIndex(listOfMimeparts.size(), 1); - - //emit(dataChanged(changedIndex0, changedIndex1)); - // TODO: check the data-changed signal - // reset(); -} - -MimePart AttachmentTableModel::getSelectedMimePart(QModelIndex index) { - return listOfMimeparts.at(index.row()); -} - -MimePart AttachmentTableModel::getMimePart(int index) { - return listOfMimeparts.at(index); -} - -/*QList<MimePart> AttachmentTableModel::getSelectedMimeParts(QModelIndexList indexes){ - - foreach(QModelIndex index, indexes) { - qDebug() << "ir: "<< index.row(); - } - -}*/ - -int AttachmentTableModel::rowCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return listOfMimeparts.size(); -} - -int AttachmentTableModel::columnCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return 2; -} - -QVariant AttachmentTableModel::data(const QModelIndex &index, int role) const { - - //qDebug() << "called, index: " << index.column(); - - if (!index.isValid()) - return QVariant(); - - if (index.row() >= listOfMimeparts.size() || index.row() < 0) - return QVariant(); - - if (role == Qt::DisplayRole) { - MimePart mp = listOfMimeparts.at(index.row()); - - if (index.column() == 0) - return mp.header.getParam("Content-Type", "name"); - if (index.column() == 1) - return mp.header.getValue("Content-Type"); - - } - - // set icon - // TODO more generic matching, e.g. for audio - if (role == Qt::DecorationRole && index.column() == 0) { - MimePart mp = listOfMimeparts.at(index.row()); - QString icon; - if (mp.header.getValue("Content-Type").startsWith("image")) { - icon = ":mimetypes/image-x-generic.png"; - } else { - icon = mp.header.getValue("Content-Type").replace("/", "-"); - icon = ":mimetypes/" + icon + ".png"; - } - if (!QFile::exists(icon)) icon = ":mimetypes/unknown.png"; - return QIcon(icon); - } - - return QVariant(); -} - -QVariant AttachmentTableModel::headerData(int section, Qt::Orientation orientation, int role) const { - //qDebug() << "called, section: " << section; - if (role != Qt::DisplayRole) - return QVariant(); - - if (orientation == Qt::Horizontal) { - switch (section) { - case 0: - return tr("Filename"); - - case 1: - return tr("Contenttype"); - - default: - return QVariant(); - } - } - return QVariant(); -} diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index d95a9bfe..7065e41c 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -145,13 +145,6 @@ void MainWindow::slotOpenSettingsDialog() { importButton->setToolButtonStyle(buttonStyle); fileEncButton->setToolButtonStyle(buttonStyle); - // Mime-settings - if (settings.value("mime/parseMime").toBool()) { - createAttachmentDock(); - } else if (attachmentDockCreated) { - closeAttachmentDock(); - } - // restart mainwindow if necessary if (getRestartNeeded()) { if (edit->maybeSaveAnyTab()) { diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 0f7f1040..21f6e3b7 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -447,26 +447,4 @@ void MainWindow::createDockWindows() { infoBoardDock->setWidget(infoBoard); infoBoardDock->widget()->layout()->setContentsMargins(0, 0, 0, 0); viewMenu->addAction(infoBoardDock->toggleViewAction()); - - /* Attachments-Dockwindow - */ - if (settings.value("mime/parseMime").toBool()) { - createAttachmentDock(); - } -} - -void MainWindow::createAttachmentDock() { - if (attachmentDockCreated) { - return; - } - mAttachments = new Attachments(); - attachmentDock = new QDockWidget(tr("Attached files:"), this); - attachmentDock->setObjectName("AttachmentDock"); - attachmentDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); - addDockWidget(Qt::LeftDockWidgetArea, attachmentDock); - attachmentDock->setWidget(mAttachments); - // hide till attachment is decrypted - viewMenu->addAction(attachmentDock->toggleViewAction()); - attachmentDock->hide(); - attachmentDockCreated = true; } diff --git a/src/ui/widgets/Attachments.cpp b/src/ui/widgets/Attachments.cpp deleted file mode 100644 index 8f741f66..00000000 --- a/src/ui/widgets/Attachments.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/** - * This file is part of GPGFrontend. - * - * GPGFrontend 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. - * - * Foobar 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 Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -/* TODO: - * - check content encoding (base64 / quoted-printable) and apply appropriate opperation (maybe already in mime.cpp) - * - check memory usage, use less copy operations / more references - * - possibility to clear attachment-view , e.g. with decryption or encrypting a new message - * - save all: like in thunderbird, one folder, all files go there - */ - -/* - * - save, delete (clear) all - * - each line save & clear button - * - attached files to view-menu - * - also an open button, whichs should save file to tmp-folder, and open with correct app (via QDesktopServices) - */ - - -#include "ui/widgets/Attachments.h" - -Attachments::Attachments(QWidget *parent) - : QWidget(parent) { - table = new AttachmentTableModel(this); - - tableView = new QTableView; - tableView->setModel(table); - tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - // only one entry should be selected at time - tableView->setSelectionMode(QAbstractItemView::SingleSelection); - tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); - tableView->setFocusPolicy(Qt::NoFocus); - tableView->setAlternatingRowColors(true); - tableView->verticalHeader()->hide(); - tableView->setShowGrid(false); - tableView->setColumnWidth(0, 300); - tableView->horizontalHeader()->setStretchLastSection(true); - - auto *layout = new QVBoxLayout; - layout->addWidget(tableView); - layout->setContentsMargins(0, 0, 0, 0); - setLayout(layout); - createActions(); - -} - -void Attachments::contextMenuEvent(QContextMenuEvent *event) { - QMenu menu(this); - menu.addAction(saveFileAct); - // enable open with only if allowed by user - if (settings.value("mime/openAttachment").toBool()) - menu.addAction(openFileAct); - - menu.exec(event->globalPos()); -} - -void Attachments::createActions() { - saveFileAct = new QAction(tr("Save File"), this); - saveFileAct->setToolTip(tr("Save this file")); - saveFileAct->setIcon(QIcon(":filesave.png")); - connect(saveFileAct, SIGNAL(triggered()), this, SLOT(slotSaveFile())); - - openFileAct = new QAction(tr("Open File"), this); - openFileAct->setToolTip(tr("Open this file")); - openFileAct->setIcon(QIcon(":fileopen.png")); - connect(openFileAct, SIGNAL(triggered()), this, SLOT(slotOpenFile())); - -} - -void Attachments::slotSaveFile() { - - QModelIndexList indexes = tableView->selectionModel()->selection().indexes(); - - if (indexes.empty()) { - return; - } - - // only singe-selection possible now: TODO: foreach - MimePart mp = table->getMimePart(indexes.at(0).row()); - QString filename = mp.header.getParam("Content-Type", "name"); - // TODO: find out why filename is quoted - filename.chop(1); - filename.remove(0, 1); - // TODO: check if really base64 - saveByteArrayToFile(QByteArray::fromBase64(mp.body), filename); - -} - -void Attachments::saveByteArrayToFile(QByteArray outBuffer, QString filename) { - - //QString path=""; - QString path = std::move(filename); - QString outfileName = QFileDialog::getSaveFileName(this, tr("Save File"), path); - - if (outfileName.isEmpty()) return; - - QFile outfile(outfileName); - if (!outfile.open(QFile::WriteOnly)) { - QMessageBox::warning(this, tr("File"), - tr("Cannot write file %1:\n%2.") - .arg(outfileName) - .arg(outfile.errorString())); - return; - } - - QDataStream out(&outfile); - out.writeRawData(outBuffer.data(), outBuffer.length()); - outfile.close(); -} - -/** - * WIP: TODO: - * - create attachments dir if not existing - * - ask for cleanup of dir on exit - * - remove code-duplication with saveByteArrayToFile - */ -void Attachments::slotOpenFile() { - - // TODO: make attachmentdir constant or configurable - QString attachmentDir = qApp->applicationDirPath() + "/attachments/"; - //QDir p = QDir(qApp->applicationDirPath() + "/attachments/"); - if (!QDir(attachmentDir).exists()) { - QDir().mkpath(attachmentDir); - } - - QModelIndexList indexes = tableView->selectionModel()->selection().indexes(); - MimePart mp = table->getMimePart(indexes.at(0).row()); - -// qDebug() << "mime: " << mp.header.getValue("Content-Type"); - - QString filename = mp.header.getParam("Content-Type", "name"); - // TODO: find out why filename is quoted -// qDebug() << "file: " << filename; - filename.chop(1); - filename.remove(0, 1); - filename.prepend(attachmentDir); - - // qDebug() << "file: " << filename; - QByteArray outBuffer = QByteArray::fromBase64(mp.body); - - - QFile outfile(filename); - if (!outfile.open(QFile::WriteOnly)) { - QMessageBox::warning(this, tr("File"), - tr("Cannot write file %1:\n%2.") - .arg(filename) - .arg(outfile.errorString())); - return; - } - - QDataStream out(&outfile); - out.writeRawData(outBuffer.data(), outBuffer.length()); - outfile.close(); - QDesktopServices::openUrl(QUrl("file://" + filename, QUrl::TolerantMode)); -} - -void Attachments::addMimePart(MimePart *mp) { - table->add(*mp); -} - |