kioslaves

mimeheader.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mimeheader.h  -  description
00003                              -------------------
00004     begin                : Fri Oct 20 2000
00005     copyright            : (C) 2000 by Sven Carstens
00006     email                : s.carstens@gmx.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef MIMEHEADER_H
00019 #define MIMEHEADER_H
00020 
00021 #include <qptrlist.h>
00022 #include <qdict.h>
00023 
00024 #include "mimehdrline.h"
00025 #include "mimeio.h"
00026 #include "rfcdecoder.h"
00027 
00032 class mimeHeader
00033 {
00034 public:
00035   mimeHeader ();
00036   virtual ~ mimeHeader ();
00037 
00038   virtual void addHdrLine (mimeHdrLine *);
00039   virtual void outputHeader (mimeIO &);
00040   virtual void outputPart (mimeIO &);
00041 
00042 
00043   QCString outputParameter (QDict < QString > *);
00044 
00045   int parsePart (mimeIO &, const QString&);
00046   int parseBody (mimeIO &, QCString &, const QString&, bool mbox = false);
00047 
00048   // parse a header. returns true if it had a leading 'From ' line
00049   bool parseHeader (mimeIO &);
00050 
00051   QString getDispositionParm (const QCString&);
00052   void setDispositionParm (const QCString&, const QString&);
00053   QDictIterator < QString > getDispositionIterator ();
00054 
00055   QString getTypeParm (const QCString&);
00056   void setTypeParm (const QCString&, const QString&);
00057   QDictIterator < QString > getTypeIterator ();
00058 
00059   // recursively serialize all important contents to the QDataStream
00060   void serialize(QDataStream& stream);
00061 
00062   const QCString& getType ()
00063   {
00064     return contentType;
00065   }
00066   void setType (const QCString & _str)
00067   {
00068     contentType = _str;
00069   }
00070 
00071   const QCString& getDescription ()
00072   {
00073     return _contentDescription;
00074   }
00075   void setDescription (const QCString & _str)
00076   {
00077     _contentDescription = _str;
00078   }
00079 
00080   QCString getDisposition ()
00081   {
00082     return _contentDisposition;
00083   }
00084   void setDisposition (const QCString & _str)
00085   {
00086     _contentDisposition = _str;
00087   }
00088 
00089   QCString getEncoding ()
00090   {
00091     return contentEncoding;
00092   }
00093   void setEncoding (const QCString & _str)
00094   {
00095     contentEncoding = _str;
00096   }
00097 
00098   QCString getMD5 ()
00099   {
00100     return contentMD5;
00101   }
00102   void setMD5 (const QCString & _str)
00103   {
00104     contentMD5 = _str;
00105   }
00106 
00107   QCString getID ()
00108   {
00109     return contentID;
00110   }
00111   void setID (const QCString & _str)
00112   {
00113     contentID = _str;
00114   }
00115 
00116   unsigned long getLength ()
00117   {
00118     return contentLength;
00119   }
00120   void setLength (unsigned long _len)
00121   {
00122     contentLength = _len;
00123   }
00124 
00125   const QString & getPartSpecifier ()
00126   {
00127     return partSpecifier;
00128   }
00129   void setPartSpecifier (const QString & _str)
00130   {
00131     partSpecifier = _str;
00132   }
00133 
00134   QPtrListIterator < mimeHdrLine > getOriginalIterator ();
00135   QPtrListIterator < mimeHdrLine > getAdditionalIterator ();
00136   void setContent (const QCString &aContent)
00137   {
00138     mimeContent = aContent;
00139   }
00140   QCString getContent ()
00141   {
00142     return mimeContent;
00143   }
00144 
00145   QCString getBody ()
00146   {
00147     return preMultipartBody + postMultipartBody;
00148   }
00149   QCString getPreBody ()
00150   {
00151     return preMultipartBody;
00152   }
00153   void setPreBody (QCString & inBody)
00154   {
00155     preMultipartBody = inBody;
00156   }
00157 
00158   QCString getPostBody ()
00159   {
00160     return postMultipartBody;
00161   }
00162   void setPostBody (QCString & inBody)
00163   {
00164     postMultipartBody = inBody;
00165     contentLength = inBody.length ();
00166   }
00167 
00168   mimeHeader *getNestedMessage ()
00169   {
00170     return nestedMessage;
00171   }
00172   void setNestedMessage (mimeHeader * inPart, bool destroy = true)
00173   {
00174     if (nestedMessage && destroy)
00175       delete nestedMessage;
00176     nestedMessage = inPart;
00177   }
00178 
00179 //  mimeHeader *getNestedPart() { return nestedPart; };
00180   void addNestedPart (mimeHeader * inPart)
00181   {
00182     nestedParts.append (inPart);
00183   }
00184   QPtrListIterator < mimeHeader > getNestedIterator ()
00185   {
00186     return QPtrListIterator < mimeHeader > (nestedParts);
00187   }
00188 
00189   // clears all parts and deletes them from memory
00190   void clearNestedParts ()
00191   {
00192     nestedParts.clear ();
00193   }
00194 
00195   // clear all parameters to content-type
00196   void clearTypeParameters ()
00197   {
00198     typeList.clear ();
00199   }
00200 
00201   // clear all parameters to content-disposition
00202   void clearDispositionParameters ()
00203   {
00204     dispositionList.clear ();
00205   }
00206 
00207   // return the specified body part or NULL
00208   mimeHeader *bodyPart (const QString &);
00209 
00210 #ifdef KMAIL_COMPATIBLE
00211   ulong msgSize ()
00212   {
00213     return contentLength;
00214   }
00215   uint numBodyParts ()
00216   {
00217     return nestedParts.count ();
00218   }
00219   mimeHeader *bodyPart (int which, mimeHeader ** ret = NULL)
00220   {
00221     if (ret)
00222       (*ret) = nestedParts.at (which);
00223     return nestedParts.at (which);
00224   }
00225   void write (const QString &)
00226   {
00227   }
00228   QString typeStr ()
00229   {
00230     return QString (contentType.left (contentType.find ('/')));
00231   }
00232   void setTypeStr (const QString & _str)
00233   {
00234     contentType = QCString (_str.latin1 ()) + "/" + subtypeStr ().latin1 ();
00235   }
00236   QString subtypeStr ()
00237   {
00238     return QString (contentType.
00239                     right (contentType.length () - contentType.find ('/') -
00240                            1));
00241   }
00242   void setSubtypeStr (const QString & _str)
00243   {
00244     contentType = QCString (typeStr ().latin1 ()) + "/" + _str.latin1 ();
00245   }
00246   QString cteStr ()
00247   {
00248     return QString (getEncoding ());
00249   }
00250   void setCteStr (const QString & _str)
00251   {
00252     setEncoding (_str.latin1 ());
00253   }
00254   QString contentDisposition ()
00255   {
00256     return QString (_contentDisposition);
00257   }
00258   QString body ()
00259   {
00260     return QString (postMultipartBody);
00261   }
00262   QString charset ()
00263   {
00264     return getTypeParm ("charset");
00265   }
00266   QString bodyDecoded ();
00267   void setBodyEncoded (const QByteArray &);
00268   void setBodyEncodedBinary (const QByteArray &);
00269   QByteArray bodyDecodedBinary ();
00270   QString name ()
00271   {
00272     return QString (getTypeParm ("name"));
00273   }
00274   void setName (const QString & _str)
00275   {
00276     setTypeParm ("name", _str);
00277   }
00278   QString fileName ()
00279   {
00280     return QString (getDispositionParm ("filename"));
00281   }
00282   QString contentDescription ()
00283   {
00284     return QString (rfcDecoder::decodeRFC2047String (_contentDescription));
00285   }
00286   void setContentDescription (const QString & _str)
00287   {
00288     _contentDescription = rfcDecoder::encodeRFC2047String (_str).latin1 ();
00289   }
00290   QString msgIdMD5 ()
00291   {
00292     return QString (contentMD5);
00293   }
00294   QString iconName ();
00295   QString magicSetType (bool aAutoDecode = true);
00296   QString headerAsString ();
00297   ulong size ()
00298   {
00299     return 0;
00300   }
00301   void fromString (const QByteArray &)
00302   {;
00303   }
00304   void setContentDisposition (const QString & _str)
00305   {
00306     setDisposition (_str.latin1 ());
00307   }
00308 #endif
00309 
00310 protected:
00311   static void addParameter (const QCString&, QDict < QString > *);
00312   static QString getParameter (const QCString&, QDict < QString > *);
00313   static void setParameter (const QCString&, const QString&, QDict < QString > *);
00314 
00315   QPtrList < mimeHdrLine > originalHdrLines;
00316 
00317 private:
00318   QPtrList < mimeHdrLine > additionalHdrLines;
00319   QDict < QString > typeList;
00320   QDict < QString > dispositionList;
00321   QCString contentType;
00322   QCString _contentDisposition;
00323   QCString contentEncoding;
00324   QCString _contentDescription;
00325   QCString contentID;
00326   QCString contentMD5;
00327   unsigned long contentLength;
00328   QCString mimeContent;
00329   QCString preMultipartBody;
00330   QCString postMultipartBody;
00331   mimeHeader *nestedMessage;
00332   QPtrList < mimeHeader > nestedParts;
00333   QString partSpecifier;
00334 
00335 };
00336 
00337 #endif