From 00bebcf42b3cd9cfdba11442d34ac2e3ed7da3bd Mon Sep 17 00:00:00 2001 From: ubbo Date: Mon, 10 May 2010 21:28:13 +0000 Subject: add mime-parser and basic attachment-recognise and show functionality git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@322 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- mime.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 mime.h (limited to 'mime.h') diff --git a/mime.h b/mime.h new file mode 100644 index 0000000..87133e0 --- /dev/null +++ b/mime.h @@ -0,0 +1,104 @@ +/* + * mime.h + * + * Copyright 2008 gpg4usb-team + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef __MIME_H__ +#define __MIME_H__ + +#include +#include +#include + + +class HeadElem { +public: + QString name; + QString value; + QHash params; + +/* QDataStream & operator<<(QDataStream& Stream, const HeadElem& H) + { + return Stream << H.name << " : " << H.value; + }*/ + +}; + +class MimePart { +public: + QList header; + QByteArray body; + + QString getValue(QString key){ + foreach(HeadElem tmp, header) { + //qDebug() << "gv: " << tmp.name << ":" << tmp.value; + if(tmp.name == key) + return tmp.value; + } + return ""; + } + + QHash getParams(QString key){ + foreach(HeadElem tmp, header) { + //qDebug() << "gv: " << tmp.name << ":" << tmp.value; + if(tmp.name == key) + //return tmp.value; + return tmp.params; + } + return *(new QHash()); + } + + QString getParam(QString key, QString pKey){ + foreach(HeadElem tmp, header) { + //qDebug() << "gv: " << tmp.name << ":" << tmp.value; + if(tmp.name == key) + return tmp.params.value(pKey); + } + return ""; + } + +/* QDataStream & operator<<(QDataStream& Stream, const Part& P) + { + foreach(HeadElem tmp, header) { + Stream << tmp << "\n"; + } + return Stream; + }*/ +}; + +class Mime +{ + +public: + Mime(QByteArray *message); // Consttructor + ~Mime(); // Destructor + static bool isMultipart(QByteArray *message); + QList parts() + { return mPartList; } + void splitParts(QByteArray *message); + QList parseHeader(QByteArray *header); + +private: + QByteArray *mMessage; + QByteArray *mBoundary; + QList mPartList; + +}; + +#endif // __MIME_H__ -- cgit v1.2.3