From 4b9ae942606322ad49bd97922737400fff5ea142 Mon Sep 17 00:00:00 2001 From: ubbo Date: Thu, 29 Jul 2010 12:33:40 +0000 Subject: decode quoted printable git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@363 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- attachments.cpp | 2 +- attachmenttablemodel.cpp | 8 +-- gpgwin.cpp | 37 +++++++++-- mime.cpp | 19 +++++- mime.h | 36 ++++++++-- release/ts/gpg4usb_en.ts | 166 +++++++++++++++++++++++++---------------------- release/ts/gpg4usb_es.ts | 140 ++++++++++++++++++++------------------- release/ts/gpg4usb_fr.ts | 166 +++++++++++++++++++++++++---------------------- settingsdialog.cpp | 6 ++ settingsdialog.h | 1 + 10 files changed, 340 insertions(+), 241 deletions(-) diff --git a/attachments.cpp b/attachments.cpp index 3debb91..5c08bf1 100644 --- a/attachments.cpp +++ b/attachments.cpp @@ -88,7 +88,7 @@ void Attachments::saveFile() // only singe-selection possible now: TODO: foreach MimePart mp = table->getMimePart(indexes.at(0).row()); - QString filename = mp.getParam("Content-Type", "name"); + QString filename = mp.header.getParam("Content-Type", "name"); // TODO: find out why filename is quoted filename.chop(1); filename.remove(0, 1); diff --git a/attachmenttablemodel.cpp b/attachmenttablemodel.cpp index 2ef3821..9389b7e 100644 --- a/attachmenttablemodel.cpp +++ b/attachmenttablemodel.cpp @@ -77,9 +77,9 @@ QVariant AttachmentTableModel::data(const QModelIndex &index, int role) const MimePart mp = listOfMimeparts.at(index.row()); if (index.column() == 0) - return mp.getParam("Content-Type", "name"); + return mp.header.getParam("Content-Type", "name"); if (index.column() == 1) - return mp.getValue("Content-Type"); + return mp.header.getValue("Content-Type"); } @@ -88,10 +88,10 @@ QVariant AttachmentTableModel::data(const QModelIndex &index, int role) const if (role == Qt::DecorationRole && index.column() == 0) { MimePart mp = listOfMimeparts.at(index.row()); QString icon; - if (mp.getValue("Content-Type").startsWith("image")) { + if (mp.header.getValue("Content-Type").startsWith("image")) { icon = iconPath + "/mimetypes/image-x-generic.png"; } else { - icon = mp.getValue("Content-Type").replace("/", "-"); + icon = mp.header.getValue("Content-Type").replace("/", "-"); icon = iconPath + "/mimetypes/" + icon + ".png"; } if (!QFile::exists(icon)) icon = iconPath + "/mimetypes/unknown.png"; diff --git a/gpgwin.cpp b/gpgwin.cpp index 22dbe89..33c31fa 100644 --- a/gpgwin.cpp +++ b/gpgwin.cpp @@ -520,10 +520,35 @@ void GpgWin::decrypt() preventNoDataErr(&text); mCtx->decrypt(text, tmp); if (!tmp->isEmpty()) { - // is it mime? - if (settings.value("mime/parseMime").toBool()) { - parseMime(tmp); + + /** + * 1) is it mime (content-type:) + * 2) parse header + * 2) choose action depending on content-type + */ + + if(Mime::isMime(tmp)) { + Header header = Mime::getHeader(tmp); + + // is it multipart, is multipart-parsing enabled + if(header.getValue("Content-Type") == "multipart/mixed" + && settings.value("mime/parseMime").toBool()) { + + parseMime(tmp); + + } else if(header.getValue("Content-Type") == "text/plain" + && settings.value("mime/parseQP").toBool()){ + + if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") { + QByteArray *decode = new QByteArray(); + Mime::quotedPrintableDecode(*tmp, *decode); + //TODO: remove header + tmp = decode; + + } + } } + edit->setPlainText(QString::fromUtf8(*tmp)); } } @@ -546,11 +571,11 @@ void GpgWin::parseMime(QByteArray *message) Mime *mime = new Mime(message); foreach(MimePart tmp, mime->parts()) { - if (tmp.getValue("Content-Type") == "text/plain" - && tmp.getValue("Content-Transfer-Encoding") != "base64") { + if (tmp.header.getValue("Content-Type") == "text/plain" + && tmp.header.getValue("Content-Transfer-Encoding") != "base64") { QByteArray body; - if (tmp.getValue("Content-Transfer-Encoding") == "quoted-printable") { + if (tmp.header.getValue("Content-Transfer-Encoding") == "quoted-printable") { Mime::quotedPrintableDecode(tmp.body, body); } else { diff --git a/mime.cpp b/mime.cpp index f2afd65..50c1b3d 100644 --- a/mime.cpp +++ b/mime.cpp @@ -113,7 +113,7 @@ void Mime::splitParts(QByteArray *message) } } -QList Mime::parseHeader(QByteArray *header) +Header Mime::parseHeader(QByteArray *header) { QList ret; @@ -144,7 +144,13 @@ QList Mime::parseHeader(QByteArray *header) } ret.append(elem); } - return ret; + 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) @@ -152,6 +158,15 @@ 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: diff --git a/mime.h b/mime.h index 7ce4162..b6268e3 100644 --- a/mime.h +++ b/mime.h @@ -41,14 +41,23 @@ public: }; -class MimePart +class Header { public: - QList header; - QByteArray body; + QList headElems; + + Header() {} + + Header(QList heads) { + headElems = heads; + } + + void setHeader(QList heads) { + headElems = heads; + } QString getValue(QString key) { - foreach(HeadElem tmp, header) { + foreach(HeadElem tmp, headElems) { //qDebug() << "gv: " << tmp.name << ":" << tmp.value; if (tmp.name == key) return tmp.value; @@ -57,7 +66,7 @@ public: } QHash getParams(QString key) { - foreach(HeadElem tmp, header) { + foreach(HeadElem tmp, headElems) { //qDebug() << "gv: " << tmp.name << ":" << tmp.value; if (tmp.name == key) //return tmp.value; @@ -67,7 +76,7 @@ public: } QString getParam(QString key, QString pKey) { - foreach(HeadElem tmp, header) { + foreach(HeadElem tmp, headElems) { //qDebug() << "gv: " << tmp.name << ":" << tmp.value; if (tmp.name == key) return tmp.params.value(pKey); @@ -75,6 +84,17 @@ public: return ""; } + +}; + +class MimePart +{ +public: + Header header; + QByteArray body; + + + /* QDataStream & operator<<(QDataStream& Stream, const Part& P) { foreach(HeadElem tmp, header) { @@ -91,11 +111,13 @@ public: Mime(QByteArray *message); // Constructor ~Mime(); // Destructor static bool isMultipart(QByteArray *message); + static bool isMime(const QByteArray *message); QList parts() { return mPartList; } void splitParts(QByteArray *message); - QList parseHeader(QByteArray *header); + static Header getHeader(const QByteArray *message); + static Header parseHeader(QByteArray *header); static void quotedPrintableDecode(const QByteArray& in, QByteArray& out); private: diff --git a/release/ts/gpg4usb_en.ts b/release/ts/gpg4usb_en.ts index 514e025..4a3620e 100644 --- a/release/ts/gpg4usb_en.ts +++ b/release/ts/gpg4usb_en.ts @@ -107,367 +107,377 @@ GpgWin - + &Open... - + Open an existing file - + &Save - + Save the current File - + Save &As - + Save the current File as... - + &Print - + Print Document - + &Quit - + Quit Program - + &Undo - + Undo Last Edit Action - + + &Redo + + + + + Redo Last Edit Action + + + + &Paste - + Paste Text From Clipboard - + Cu&t - + Cut the current selection's contents to the clipboard - + &Copy - + Copy the current selection's contents to the clipboard - + Select &All - + Select the whole text - + Open settings dialog - + &Encrypt - + Encrypt Message - + &Decrypt - + Decrypt Message - + &File Encryption - + Encrypt/Decrypt File - + Import New Key From File - + Import New Key From Editor - + Key Management - + Open Keymanagement - + Open Import New Key Dialog - + &About - + Show the application's About box - - - + + + &File - + &Edit - + &Help - + File - + Append Selected Key(s) To Text - + Se&ttings - + Online &Tutorial - + Open Online Tutorial - + Append The Selected Keys To Text in Editor - + &Keys - + &Import Key From... - + &View - - + + Ready - + Encrypt for: - + Attached files: - - + + Application - + Cannot read file %1: %2. - + File loaded - + %1[*] - %2 - + The document has been modified. Do you want to save your changes? - + Cannot write file %1: %2. - + Saved '%1' - + Open Key - + Key Files - + All Files - + couldn't open file: - - + + &Editor - - + + &Clipboard - + Import New Key From Clipboard - - + + Import Key - + &Crypt - + Crypt - + Key - + Edit - + About - + <center>This Application allows you to do simple<br>encryption/decryption of your text-message or file.<br>It's licensed under the GPL v2.0<br><br><b>Developer:</b><br>Bene, Heimer, Juergen, Nils, Ubbo<br><br><b>Translation:</b><br>Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato (es)<br><br>If you have any questions and/or<br>suggestions, contact us at<br>gpg4usb at cpunk.de</a><br><br>or feel free to meet us in our xmpp-channel:<br>gpg4usb at conference.jabber.ccc.de</center> - + Import Key From... diff --git a/release/ts/gpg4usb_es.ts b/release/ts/gpg4usb_es.ts index a8b162b..9afb72d 100644 --- a/release/ts/gpg4usb_es.ts +++ b/release/ts/gpg4usb_es.ts @@ -190,6 +190,16 @@ + &Redo + + + + + Redo Last Edit Action + + + + &Paste &Pegar @@ -198,12 +208,12 @@ Crtl+V - + Paste Text From Clipboard Pegar Texto desde Portapapeles - + Cu&t Corta&r @@ -212,12 +222,12 @@ Crtl+X - + Cut the current selection's contents to the clipboard Cortar contenido seleccion actual al portapapeles - + &Copy &Copiar @@ -226,12 +236,12 @@ Crtl+C - + Copy the current selection's contents to the clipboard Copiar contenido seleccion actual al portapapeles - + Select &All Seleccionar &Todo @@ -240,22 +250,22 @@ Crtl+A - + Select the whole text Seleccionar todo el texto - + Se&ttings Con&figuracion - + Open settings dialog Abrir dialogo configuracion - + &Encrypt &Cifrar @@ -264,12 +274,12 @@ Crtl+E - + Encrypt Message Cifrar Mensaje - + &Decrypt &Descifrar @@ -278,220 +288,220 @@ Crtl+D - + Decrypt Message Descifrar Mensaje - + &File Encryption &Cifrado Archivo - + Encrypt/Decrypt File Cifrar / Descifrar Archivo - - - + + + &File &Archivo - + Import New Key From File Importar Nueva Llave Desde Archivo - - + + &Editor &Editor - + Import New Key From Editor Importar Nueva Llave Desde Editor - - + + &Clipboard &Portapapeles - + Import New Key From Clipboard Importar Nueva Llave Desde Portapapeles - + Key Management Administar Llaves - + Open Keymanagement Abrir Administrar Llaves - - + + Import Key Importar Llave - + Open Import New Key Dialog Abrir Dialogo Importar Nueva Llave - + &About &Acerca de - + Show the application's About box Mostrar caja Acerca de programa - + Online &Tutorial Tutorial &Online - + Open Online Tutorial Abrir Tutorial Online - + Append Selected Key(s) To Text Adjuntar Llave(s) Seleccionadas Al Texto - + Append The Selected Keys To Text in Editor Adjuntar Llaves Seleccionadas Al Texto en Editor - + &Edit &Editar - + &Crypt &Cifrar - + &Keys &Llaves - + &Import Key From... &Importar Llave Desde... - + &View &Ver - + &Help &Ayuda - + Crypt Cifrar - + Key Llave - + Edit Editar - - + + Ready Listo - + Encrypt for: Cifrar para: - + Attached files: Archivos Adjuntos: - - + + Application Programa - + Cannot read file %1: %2. No puedo leer archivo %1: %2. - + File loaded Archivo cargado - + %1[*] - %2 %1[*] - %2 - + The document has been modified. Do you want to save your changes? El documento ha sido modificado. Quiere usted guardar los cambios? - + File Archivo - + Cannot write file %1: %2. No puedo escribir archivo %1: %2. - + Saved '%1' Guardado '%1' - + About Acerca de' - + <center>This Application allows you to do simple<br>encryption/decryption of your text-message or file.<br>It's licensed under the GPL v2.0<br><br><b>Developer:</b><br>Bene, Heimer, Juergen, Nils, Ubbo<br><br><b>Translation:</b><br>Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato (es)<br><br>If you have any questions and/or<br>suggestions, contact us at<br>gpg4usb at cpunk.de</a><br><br>or feel free to meet us in our xmpp-channel:<br>gpg4usb at conference.jabber.ccc.de</center> duplicate entry <center>Este Programa le permite hacer un facil<br>cifrado/descifrado de sus mensajes de texto o archivos.<br>Esta licenciado bajo el GPL v2.0<br><br><b>Programadores:</b><br>Bene, Heimer, Juergen, Nils, Ubbo<br><br><b>Traduccion:</b><br>Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato13 (es)<br><br>Si usted tiene alguna pregunta y/ o <br>sugerencia, contacte con nosotros en<br>gpg4usb en cpunk.de</a><br><br>o puede encontrarnos en nuestro xmpp-channel:<br>gpg4usb en conference.jabber.ccc.de</center> @@ -501,27 +511,27 @@ Quiere usted guardar los cambios? <center>Este Programa le permite hacer un facil<br>cifrado/descifrado de sus mensajes de texto o archivos.<br>Esta licenciado bajo el GPL v2.0<br><br><b>Programadores:</b><br>Bene, Heimer, Juergen, Nils, Ubbo<br><br><b>Traduccion:</b><br>Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato13 (es)<br><br>Si usted tiene alguna pregunta y/ o <br>sugerencia, contacte con nosotros en<br>gpg4usb en cpunk.de</a><br><br>o puede encontrarnos en nuestro xmpp-channel:<br>gpg4usb en conference.jabber.ccc.de</center> - + Open Key Abrir Llave - + Key Files Archivos de Llaves - + All Files Todos Archivos - + couldn't open file: no se pudo abrir el archivo: - + Import Key From... Importar Llave Desde... diff --git a/release/ts/gpg4usb_fr.ts b/release/ts/gpg4usb_fr.ts index e992d65..bd8878a 100644 --- a/release/ts/gpg4usb_fr.ts +++ b/release/ts/gpg4usb_fr.ts @@ -119,344 +119,354 @@ GpgWin - + &Open... &Ouvrir... - + Open an existing file Ouvrir un fichier existant - + &Save &Enregistrer - + Save the current File Enregistrer le fichier en cours - + Save &As Enregistrer &sous - + Save the current File as... Enregistrer le fichier en cours sous... - + &Print &Imprimer - + Print Document Imprimer fichier - + &Quit &Fermer - + Quit Program Fermer programme - + &Undo - + Undo Last Edit Action - + + &Redo + + + + + Redo Last Edit Action + + + + &Paste &Coller - + Paste Text From Clipboard Coller depuis le presse-papiers - + Cu&t Cou&per - + Cut the current selection's contents to the clipboard Couper et ajouter dans le presse papiers - + &Copy &Copier - + Copy the current selection's contents to the clipboard Copier et ajouter dans le presse papiers - + Select &All Selectionner &tout - + Select the whole text Selectionner tout le texte - + Se&ttings - + Open settings dialog - + &Encrypt &Crypter - + Encrypt Message Crypter message - + &Decrypt &Decrypter - + Decrypt Message Decrypter message - + &File Encryption Cryptage du &fichier - + Encrypt/Decrypt File Crypter/Decrypter fichier - - - + + + &File &Fichier - + Import New Key From File Importer nouvelle cle depuis le fichier - - + + &Editor &Editeur - + Import New Key From Editor Importer nouvelle cle depuis l'editeur - - + + &Clipboard &Presse papiers - + Import New Key From Clipboard Importer nouvelle cle depuis le presse papiers - + Key Management gestion des cles - + Open Keymanagement Ouvrir le gestionaire des cles - - + + Import Key Importer cles - + Open Import New Key Dialog Ouvrir la fenetre d'import de nouvelle cle - + Online &Tutorial - + Open Online Tutorial - + Crypt Crypt-Toolbar - + Key - + Edit - + Attached files: - + <center>This Application allows you to do simple<br>encryption/decryption of your text-message or file.<br>It's licensed under the GPL v2.0<br><br><b>Developer:</b><br>Bene, Heimer, Juergen, Nils, Ubbo<br><br><b>Translation:</b><br>Alessandro (pt_br), Alex (fr), Kirill (ru), Viriato (es)<br><br>If you have any questions and/or<br>suggestions, contact us at<br>gpg4usb at cpunk.de</a><br><br>or feel free to meet us in our xmpp-channel:<br>gpg4usb at conference.jabber.ccc.de</center> - + &About &A propos - + Show the application's About box Afficher la fenetre d'information - + Append Selected Key(s) To Text joindre les cles selectionees au texte - + Append The Selected Keys To Text in Editor joindre les cles selectionees au texte dans l'editeur - + &Edit bla - + &Crypt &Crypter - + &Keys &Cles - + &Import Key From... &Importer une cle depuis... - + &View &Affichage - + &Help &Aide - - + + Ready - + Encrypt for: - - + + Application - + Cannot read file %1: %2. - + File loaded - + %1[*] - %2 - + The document has been modified. Do you want to save your changes? Le document a ete modifie. Voulez-vous enregistrer les modifications? - + File Fichier - + Cannot write file %1: %2. Fichier protege en ecriture %1: %2. - + Saved '%1' Fichiers enregistres '%1' - + About A propos @@ -465,27 +475,27 @@ Do you want to save your changes? <center>Cette application vous permet de crypter ou decrypter<br> simplement votre texte-message ou fichier.<br> Logiciel libre v2.0<br> <b>Developpeurs:</b> Bene, Heimer, Juergen, Nils, Ubbo<br><br><b> Traduction:</b><br>Kirill (ru), Axel (fr)<br><br> Si vous avez questions ou propositions, <br>contactez nous sur notre email <br>gpgusb at cpunk.de</a> ou par xmpp-chat <br>gpg4usb at conference.jabber.ccc.de</center> - + Open Key - + Key Files Fichiers des cles - + All Files - + couldn't open file: Fichier non-ouvrable: - + Import Key From... diff --git a/settingsdialog.cpp b/settingsdialog.cpp index 1b64acd..ed71294 100755 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -125,6 +125,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) mimeParseBoxLayout = new QHBoxLayout(); mimeParseCheckBox = new QCheckBox(tr("Try to split attachments from PGP-MIME ecrypted messages."), this); mimeParseBoxLayout->addWidget(mimeParseCheckBox); + mimeQPCheckBox = new QCheckBox(tr("Try to recognice quoted printable."), this); + mimeParseBoxLayout->addWidget(mimeQPCheckBox); mimeParseBox->setLayout(mimeParseBoxLayout); /***************************************** @@ -193,6 +195,9 @@ void SettingsDialog::setSettings() // MIME-Parsing if (settings.value("mime/parsemime").toBool()) mimeParseCheckBox->setCheckState(Qt::Checked); + // Qouted Printable + if (settings.value("mime/parseQP").toBool()) mimeQPCheckBox->setCheckState(Qt::Checked); + //Language setting QString langKey = settings.value("int/lang").toString(); QString langValue = lang.value(langKey); @@ -230,6 +235,7 @@ void SettingsDialog::applySettings() settings.setValue("keys/keySave", saveCheckedKeysCheckBox->isChecked()); settings.setValue("mime/parsemime" , mimeParseCheckBox->isChecked()); + settings.setValue("mime/parseQP" , mimeQPCheckBox->isChecked()); settings.setValue("int/lang", lang.key(langSelectBox->currentText())); diff --git a/settingsdialog.h b/settingsdialog.h index f0833ee..a1480b8 100755 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -61,6 +61,7 @@ private: QCheckBox *windowSizeCheckBox; QCheckBox *saveCheckedKeysCheckBox; QCheckBox *mimeParseCheckBox; + QCheckBox *mimeQPCheckBox; QComboBox *langSelectBox; QHash lang; -- cgit v1.2.3