aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 23:46:01 +0000
committerubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910>2010-05-14 23:46:01 +0000
commit675fddac2f879d81b45e76cd72b50a0638cbc8ff (patch)
treec3d65b8416d95477e20f85f4cfdef5346f06add2
parentdon't try to save file if abort is hit (diff)
downloadgpg4usb-675fddac2f879d81b45e76cd72b50a0638cbc8ff.tar.gz
gpg4usb-675fddac2f879d81b45e76cd72b50a0638cbc8ff.zip
quotedPrintableDecode copied from KCodecs
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@332 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--gpgwin.cpp12
-rw-r--r--gpgwin.h1
-rw-r--r--mime.cpp100
-rw-r--r--mime.h3
4 files changed, 114 insertions, 2 deletions
diff --git a/gpgwin.cpp b/gpgwin.cpp
index 1742b4a..3d02ec6 100644
--- a/gpgwin.cpp
+++ b/gpgwin.cpp
@@ -525,7 +525,17 @@ void GpgWin::parseMime(QByteArray *message) {
foreach(MimePart tmp, mime->parts()) {
if(tmp.getValue("Content-Type")=="text/plain"
&& tmp.getValue("Content-Transfer-Encoding") != "base64") {
- pText.append(QString(tmp.body));
+
+ QByteArray body;
+ if(tmp.getValue("Content-Transfer-Encoding")=="quoted-printable") {
+
+ Mime::quotedPrintableDecode(tmp.body, body);
+ } else {
+ body = tmp.body;
+ }
+
+ pText.append(QString(body));
+
} else {
(mAttachments->addMimePart(&tmp));
showmadock=true;
diff --git a/gpgwin.h b/gpgwin.h
index 60f6f13..94da4c6 100644
--- a/gpgwin.h
+++ b/gpgwin.h
@@ -27,6 +27,7 @@
#include "attachments.h"
#include "mime.h"
#include "keymgmt.h"
+#include "kcodecs.h"
class QMainWindow;
class QPlainTextEdit;
diff --git a/mime.cpp b/mime.cpp
index 68bc13c..d68b9b5 100644
--- a/mime.cpp
+++ b/mime.cpp
@@ -19,6 +19,18 @@
* MA 02110-1301, USA.
*/
+/***
+ * 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.
+
+ */
+
+/* TODO: proper import / copyright statement
+ *
+ */
+
#include "mime.h"
#include <QDebug>
#include <QHashIterator>
@@ -138,3 +150,91 @@ bool Mime::isMultipart(QByteArray *message)
return message->startsWith("Content-Type: multipart/mixed;");
}
+/***
+ * 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(register const char * _s, const char c)
+{
+ register 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 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 unsigned int length = in.size();
+
+ data = in.data();
+ out.resize (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(cursor - out.data());
+}
diff --git a/mime.h b/mime.h
index 87133e0..8eeadb8 100644
--- a/mime.h
+++ b/mime.h
@@ -86,13 +86,14 @@ class Mime
{
public:
- Mime(QByteArray *message); // Consttructor
+ Mime(QByteArray *message); // Constructor
~Mime(); // Destructor
static bool isMultipart(QByteArray *message);
QList<MimePart> parts()
{ return mPartList; }
void splitParts(QByteArray *message);
QList<HeadElem> parseHeader(QByteArray *header);
+ static void quotedPrintableDecode(const QByteArray& in, QByteArray& out);
private:
QByteArray *mMessage;